chore: update TypeScript build info cache
This commit is contained in:
+34
-3
@@ -4,9 +4,12 @@ import { randomBytes, randomUUID } from 'node:crypto';
|
||||
import Database from 'better-sqlite3';
|
||||
|
||||
const root = process.cwd();
|
||||
const dbDir = path.join(root, 'db');
|
||||
const dbFile = path.join(dbDir, 'newtube.db');
|
||||
const schemaFile = path.join(dbDir, 'schema.sql');
|
||||
const overrideDbFile = process.env.NEWTUBE_DB_FILE && String(process.env.NEWTUBE_DB_FILE).trim().length
|
||||
? path.resolve(String(process.env.NEWTUBE_DB_FILE))
|
||||
: null;
|
||||
const dbDir = overrideDbFile ? path.dirname(overrideDbFile) : path.join(root, 'db');
|
||||
const dbFile = overrideDbFile || path.join(dbDir, 'newtube.db');
|
||||
const schemaFile = path.join(root, 'db', 'schema.sql');
|
||||
|
||||
if (!fs.existsSync(dbDir)) {
|
||||
fs.mkdirSync(dbDir, { recursive: true });
|
||||
@@ -460,11 +463,39 @@ export function listPlaylists({ userId, limit = 50, offset = 0, q }) {
|
||||
: db.prepare(sql).all(userId, limit, offset);
|
||||
}
|
||||
|
||||
// List public playlists (visible to everyone)
|
||||
export function listPublicPlaylists({ limit = 50, offset = 0, q }) {
|
||||
const like = `%${(q || '').trim()}%`;
|
||||
const hasQ = typeof q === 'string' && q.trim().length > 0;
|
||||
const base = `SELECT id, user_id AS userId, name AS title, description, thumbnail, is_private AS isPrivate, created_at AS createdAt, updated_at AS updatedAt,
|
||||
(SELECT COUNT(1) FROM playlist_items WHERE playlist_id = playlists.id) AS itemsCount
|
||||
FROM playlists WHERE is_private = 0`;
|
||||
const sql = hasQ ? `${base} AND (name LIKE ? OR COALESCE(description,'') LIKE ?)
|
||||
ORDER BY updated_at DESC LIMIT ? OFFSET ?` :
|
||||
`${base} ORDER BY updated_at DESC LIMIT ? OFFSET ?`;
|
||||
return hasQ
|
||||
? db.prepare(sql).all(like, like, limit, offset)
|
||||
: db.prepare(sql).all(limit, offset);
|
||||
}
|
||||
|
||||
export function getPlaylistRaw(id) {
|
||||
return db.prepare(`SELECT id, user_id AS userId, name AS title, description, thumbnail, is_private AS isPrivate, created_at AS createdAt, updated_at AS updatedAt
|
||||
FROM playlists WHERE id = ?`).get(id);
|
||||
}
|
||||
|
||||
// Get playlist with items if allowed for a given viewer (owner or public)
|
||||
export function getPlaylistWithItemsIfAllowed({ viewerUserId, id, limit = 200, offset = 0 }) {
|
||||
const pl = db.prepare(`SELECT id, user_id AS userId, name AS title, description, thumbnail, is_private AS isPrivate, created_at AS createdAt, updated_at AS updatedAt
|
||||
FROM playlists WHERE id = ?`).get(id);
|
||||
if (!pl) return null;
|
||||
const isOwner = viewerUserId && pl.userId === viewerUserId;
|
||||
if (!isOwner && Number(pl.isPrivate) === 1) return 'forbidden';
|
||||
const items = db.prepare(`SELECT id, playlist_id AS playlistId, provider, video_id AS videoId, title, thumbnail, added_at AS addedAt, position
|
||||
FROM playlist_items WHERE playlist_id = ?
|
||||
ORDER BY position ASC LIMIT ? OFFSET ?`).all(id, limit, offset);
|
||||
return { ...pl, items };
|
||||
}
|
||||
|
||||
export function updatePlaylist({ userId, id, patch }) {
|
||||
const cur = db.prepare(`SELECT * FROM playlists WHERE id = ?`).get(id);
|
||||
if (!cur) return null;
|
||||
|
||||
Reference in New Issue
Block a user