Max 1000 items without consent
This commit is contained in:
parent
199a44a8a7
commit
368d05349a
5 changed files with 42 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
// @ts-check
|
||||
|
||||
const {defineEventHandler, getQuery, getValidatedQuery, sendRedirect, createError, getValidatedRouterParams, getCookie} = require("h3")
|
||||
const {defineEventHandler, getQuery, getValidatedQuery, sendRedirect, createError, getValidatedRouterParams, getCookie, getRequestHeader} = require("h3")
|
||||
const {router, db, sync} = require("../passthrough")
|
||||
|
||||
/** @type {import("../pug-sync")} */
|
||||
|
@ -73,7 +73,7 @@ router.get("/:account/", defineEventHandler({
|
|||
handler: async event => {
|
||||
const {account} = await getValidatedRouterParams(event, schema.schema.account.parse)
|
||||
try {
|
||||
var {arrange, shape, filter, filter_field, filter_fuzzy} = await getValidatedQuery(event, schema.schema.appQuery.parse)
|
||||
var {arrange, shape, filter, filter_field, filter_fuzzy, show} = await getValidatedQuery(event, schema.schema.appQuery.parse)
|
||||
if (filter_field === "why" && arrange !== "album") throw new Error("filter not compatible with arrangement")
|
||||
} catch (e) {
|
||||
return sendRedirect(event, "?arrange=album&shape=grid", 302)
|
||||
|
@ -125,6 +125,12 @@ router.get("/:account/", defineEventHandler({
|
|||
throw e
|
||||
}
|
||||
|
||||
show ||= getRequestHeader(event, "BCEX-Show")
|
||||
const itemWarningLimit = arrange === "track" ? 5000 : 1000
|
||||
if (items.length >= itemWarningLimit && !show) {
|
||||
return pugSync.render(event, "too-many-items.pug", {itemCount: items.length, account, query})
|
||||
}
|
||||
|
||||
const locals = {
|
||||
items,
|
||||
account,
|
||||
|
|
|
@ -10,7 +10,8 @@ const schema = {
|
|||
shape: z.enum(["grid", "list"]),
|
||||
filter_field: z.enum(["band_name", "band_url", "item_title", "item_id", "tag", "why"]).optional(),
|
||||
filter: z.string().regex(/^[^%]+$/).optional(),
|
||||
filter_fuzzy: z.enum(["true"]).optional()
|
||||
filter_fuzzy: z.enum(["true"]).optional(),
|
||||
show: z.string().optional()
|
||||
}),
|
||||
account: z.object({
|
||||
account
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue