Add embedded player

This commit is contained in:
Cadence Ember 2025-04-06 23:16:33 +12:00
parent 70ce8ab72b
commit aa1095eef2
11 changed files with 160 additions and 110 deletions

View file

@ -67,7 +67,7 @@ const schema = {
query: z.object({
arrange: z.enum(["album", "artist", "label", "tag", "track"]),
shape: z.enum(["grid", "list"]),
filter_field: z.enum(["band_name", "band_url", "item_id", "tag", "why"]).optional(),
filter_field: z.enum(["band_name", "band_url", "item_title", "item_id", "tag", "why"]).optional(),
filter: z.string().optional(),
filter_fuzzy: z.enum(["true"]).optional()
}),

View file

@ -61,7 +61,7 @@ async function loadCollection(inputUsername) {
const preparedTrack = db.prepare("INSERT OR IGNORE INTO track (account, item_id, track_id, title, artist, track_number, duration) VALUES (@account, @item_id, @track_id, @title, @artist, @track_number, @duration)")
db.transaction(() => {
for (const [key, tracklist] of Object.entries(items.tracklists)) {
assert.match(key[0], /[at]/)
if (!key[0].match(/[at]/)) continue
for (const track of tracklist) {
preparedTrack.run({
account,

19
routes/play.js Normal file
View file

@ -0,0 +1,19 @@
// @ts-check
const {z} = require("zod")
const {sync, router} = require("../passthrough")
const {defineEventHandler} = require("h3")
const {getValidatedRouterParams} = require("h3")
/** @type {import("../pug-sync")} */
const pugSync = sync.require("../pug-sync")
const schema = z.object({
item_type: z.enum(["album", "track"]),
item_id: z.number({coerce: true})
})
router.get("/api/play/:item_type/:item_id", defineEventHandler(async event => {
const locals = await getValidatedRouterParams(event, schema.parse)
return pugSync.render(event, "player.pug", locals)
}))