Added scene tags filter.
This commit is contained in:
@@ -1,28 +1,50 @@
|
||||
import { stringify } from '@brillout/json-serializer/stringify';
|
||||
import { stringify } from '@brillout/json-serializer/stringify'; /* eslint-disable-line import/extensions */
|
||||
|
||||
import { fetchScenes } from '../scenes.js';
|
||||
import redis from '../redis.js';
|
||||
|
||||
export function curateScenesQuery(query) {
|
||||
async function getTagIdsBySlug(tagSlugs) {
|
||||
const tagIds = await Promise.all(tagSlugs.map(async (slug) => {
|
||||
if (!slug) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (Number(slug)) {
|
||||
return Number(slug); // already an ID or missing
|
||||
}
|
||||
|
||||
const tagId = await redis.hGet('traxxx:tags:id_by_slug', slug);
|
||||
|
||||
return Number(tagId);
|
||||
}));
|
||||
|
||||
return tagIds.filter(Boolean);
|
||||
}
|
||||
|
||||
export async function curateScenesQuery(query) {
|
||||
return {
|
||||
scope: query.scope || 'latest',
|
||||
actorIds: [query.actorId, ...(query.actors?.split(',') || [])].filter(Boolean).map((actorId) => Number(actorId)),
|
||||
tagIds: await getTagIdsBySlug([query.tagId, ...(query.tags?.split(',') || [])]),
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchScenesApi(req, res) {
|
||||
const {
|
||||
scenes,
|
||||
actors,
|
||||
aggActors,
|
||||
aggTags,
|
||||
limit,
|
||||
total,
|
||||
} = await fetchScenes(curateScenesQuery(req.query), {
|
||||
} = await fetchScenes(await curateScenesQuery(req.query), {
|
||||
page: Number(req.query.page) || 1,
|
||||
limit: Number(req.query.limit) || 30,
|
||||
});
|
||||
|
||||
res.send(stringify({
|
||||
scenes,
|
||||
actors,
|
||||
aggActors,
|
||||
aggTags,
|
||||
limit,
|
||||
total,
|
||||
}));
|
||||
|
||||
@@ -23,9 +23,12 @@ import { renderPage } from 'vike/server'; // eslint-disable-line import/extensio
|
||||
import { fetchScenesApi } from './scenes.js';
|
||||
import { fetchActorsApi } from './actors.js';
|
||||
|
||||
import initLogger from '../logger.js';
|
||||
|
||||
const logger = initLogger();
|
||||
const isProduction = process.env.NODE_ENV === 'production';
|
||||
|
||||
async function startServer() {
|
||||
export default async function initServer() {
|
||||
const app = express();
|
||||
const router = Router();
|
||||
|
||||
@@ -106,7 +109,5 @@ async function startServer() {
|
||||
const port = process.env.PORT || config.web.port || 3000;
|
||||
app.listen(port);
|
||||
|
||||
console.log(`Server running at http://localhost:${port}`);
|
||||
logger.info(`Server running at http://localhost:${port}`);
|
||||
}
|
||||
|
||||
startServer();
|
||||
|
||||
Reference in New Issue
Block a user