forked from DebaucheryLibrarian/traxxx
49 lines
1.1 KiB
JavaScript
Executable File
49 lines
1.1 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
const config = require('config');
|
|
const path = require('path');
|
|
|
|
const { fetchScene, fetchScenes, searchScenes } = require('../releases');
|
|
|
|
async function fetchSceneApi(req, res) {
|
|
const release = await fetchScene(req.params.releaseId);
|
|
|
|
if (release) {
|
|
res.send({ scene: release });
|
|
return;
|
|
}
|
|
|
|
res.status(404).send({ scene: null });
|
|
}
|
|
|
|
async function fetchScenesApi(req, res) {
|
|
const query = req.query.query || req.query.q;
|
|
const limit = req.query.limit && Number(req.query.limit);
|
|
const relevance = req.query.relevance && Number(req.query.relevance);
|
|
|
|
const releases = query
|
|
? await searchScenes(query, limit, relevance)
|
|
: await fetchScenes(req.query.limit);
|
|
|
|
res.send({ scenes: releases });
|
|
}
|
|
|
|
async function fetchScenePosterApi(req, res) {
|
|
const scene = await fetchScene(req.params.releaseId);
|
|
const posterPath = scene?.poster?.path;
|
|
|
|
if (posterPath) {
|
|
res.sendFile(path.resolve(config.media.path, posterPath));
|
|
|
|
return;
|
|
}
|
|
|
|
res.status(404).send();
|
|
}
|
|
|
|
module.exports = {
|
|
fetchScene: fetchSceneApi,
|
|
fetchScenes: fetchScenesApi,
|
|
fetchScenePoster: fetchScenePosterApi,
|
|
};
|