Skip to content

Commit

Permalink
Add safe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
patapancakes committed Nov 15, 2024
1 parent ea1c74a commit f3672bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion api/packages/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ func List(w http.ResponseWriter, r *http.Request) {
sort = "id"
}

list, err := db.FetchPackageList(r.URL.Query().Get("type"), r.URL.Query().Get("author"), r.URL.Query().Get("search"), offset, count, sort)
var safemode bool
if r.URL.Query().Get("safemode") == "true" {
safemode = true
}

list, err := db.FetchPackageList(r.URL.Query().Get("type"), r.URL.Query().Get("author"), r.URL.Query().Get("search"), offset, count, sort, safemode)
if err != nil {
utils.WriteError(w, r, fmt.Sprintf("failed to fetch package list: %s", err))
return
Expand Down
6 changes: 5 additions & 1 deletion db/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func FetchPackage(id int, rev int) (common.Package, error) {
return pkg, nil
}

func FetchPackageList(category string, author string, search string, offset int, count int, sort string) ([]common.Package, error) {
func FetchPackageList(category string, author string, search string, offset int, count int, sort string, safemode bool) ([]common.Package, error) {
var args []any
q := "SELECT p.id, p.rev, p.type, p.name, p.dataname, p.author, IFNULL(profiles.personaname, p.legacyauthor), IFNULL(profiles.avatarmedium, \"\"), p.description, p.time FROM packages p LEFT JOIN profiles ON p.author = profiles.steamid WHERE p.rev = (SELECT MAX(p2.rev) FROM packages p2 WHERE p2.id = p.id)"

Expand All @@ -116,6 +116,10 @@ func FetchPackageList(category string, author string, search string, offset int,
args = append(args, search)
}

if safemode {
q += " AND unsafe = 0"
}

// dangerous!
if sort != "" {
q += fmt.Sprintf(" ORDER BY %s DESC", sort)
Expand Down

0 comments on commit f3672bb

Please sign in to comment.