random changes

This commit is contained in:
X4Lo committed 2024-09-10 19:07:43 +01:00
1 parent 5008940c59
commit d06a21097f
7 files changed
+27 -61

No files matched your search

+1 -39
View File
@@ -2,8 +2,6 @@ const express = require('express');
const bodyParser = require('body-parser');
const routes = require('./routes/routes.js');
const sequelize = require('./db/database.js');
const path = require('path');
const fs = require('fs');
const app = express();
@@ -14,6 +12,7 @@ const killerRouter = require('./routes/killer.routes.js');
const errorHandler = require('./middleware/errorHandler');
const { getSettings } = require('./services/settingsService.js');
const { logToFile } = require('./services/logService.js');
const { generatePreview } = require('./services/mediaService.js');
// ? variables
let settings = getSettings()
@@ -38,43 +37,6 @@ app.use((req, res, next) => {
next();
});
// ? Routes : media access routes
app.use('/api/v1/media/:category/:type/:file', (req, res, next) => {
const category = req.params.category;
const type = req.params.type;
const file = req.params.file;
if (!['entries', 'collections', 'franchises'].includes(category)) {
return res.status(404).send('Not Found');
}
if (!['backdrops', 'posters', 'logos', 'others'].includes(type)) {
return res.status(404).send('Not Found');
}
const settings = getSettings();
const dataPath = settings.userDataPath;
const mediaPath = path.join(dataPath, 'images', category, type);
// const mediaPath = path.join(__dirname, '..', `data/images/${category}/${type}`);
const filePath = path.join(mediaPath, file);
logToFile(filePath)
fs.access(filePath, fs.constants.F_OK, (err) => {
if (err) {
return res.status(404).send('Not Found');
}
const options = {
fallthrough: false, // ! Important: don't call next middleware if file isn't found
};
// express.static(filePath, options)(req, res, next);
// Serve the file using fs.createReadStream
const stream = fs.createReadStream(filePath);
stream.pipe(res);
});
});
// ? other api routes
app.use('/api/v1', routes);