Skip to content

Commit

Permalink
New scraped data table
Browse files Browse the repository at this point in the history
  • Loading branch information
patapancakes committed Nov 19, 2024
1 parent a82da00 commit 7c4691e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions api/packages/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ func List(w http.ResponseWriter, r *http.Request) {
var sort string // must NOT be user input
switch r.URL.Query().Get("sort") {
case "mostfavs":
sort = "favorites"
sort = "COALESCE(p.favorites, s.favorites, 0)"
case "mostlikes":
sort = "goods"
sort = "COALESCE(p.goods, s.goods, 0)"
case "mostdls":
sort = "downloads"
sort = "COALESCE(p.downloads, s.downloads, 0)"
case "random":
sort = "RAND()"
default: // newest
Expand Down
22 changes: 21 additions & 1 deletion db/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,27 @@ func FetchPackage(id int, rev int) (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.downloads, p.favorites, p.goods, p.bads, 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)"
q := `SELECT
p.id,
p.rev,
p.type,
p.name,
p.dataname,
COALESCE(p.author, ""),
COALESCE(pr.personaname, s.author, ""),
COALESCE(pr.avatarmedium, ""),
COALESCE(p.description, s.description, ""),
COALESCE(p.downloads, s.downloads, 0),
COALESCE(p.favorites, s.favorites, 0),
COALESCE(p.goods, s.goods, 0),
COALESCE(p.bads, s.bads, 0),
p.time
FROM packages p
LEFT JOIN profiles pr
ON p.author = pr.steamid
LEFT JOIN scraped s
ON p.id = s.id
WHERE p.rev = (SELECT MAX(p2.rev) FROM packages p2 WHERE p2.id = p.id)`

if category != "" {
q += " AND p.type = ?"
Expand Down

0 comments on commit 7c4691e

Please sign in to comment.