mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-04-25 15:46:06 -05:00
feat: implement specific file gathering
This commit is contained in:
parent
ff085aadf5
commit
e41e2a9656
|
|
@ -1,8 +1,5 @@
|
||||||
import path from 'node:path';
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import xmlbuilder from 'xmlbuilder';
|
import xmlbuilder from 'xmlbuilder';
|
||||||
import { fileErrCallback } from '@/util';
|
|
||||||
import { __appRoot } from '@/app-root';
|
|
||||||
import { config } from '@/config-manager';
|
import { config } from '@/config-manager';
|
||||||
import { restrictHostnames } from '@/middleware/host-limit';
|
import { restrictHostnames } from '@/middleware/host-limit';
|
||||||
import { Task } from '@/models/task';
|
import { Task } from '@/models/task';
|
||||||
|
|
@ -45,16 +42,43 @@ npts.get('/p01/tasksheet/:id/:titleIdHash/:taskId', async (request, response) =>
|
||||||
response.send(xmlbuilder.create(xmlContent, { headless: true }).end({ pretty: true }));
|
response.send(xmlbuilder.create(xmlContent, { headless: true }).end({ pretty: true }));
|
||||||
});
|
});
|
||||||
|
|
||||||
npts.get('/p01/tasksheet/:id/:hash/:subfolder/:fileName', (request, response) => {
|
npts.get('/p01/tasksheet/:id/:titleIdHash/:taskId/:fileName', async (request, response) => {
|
||||||
const { id, hash, subfolder, fileName } = request.params;
|
const { titleIdHash, taskId, fileName } = request.params;
|
||||||
const tasksheetPath = path.normalize(`${__appRoot}/../cdn/tasksheet/${id}/${hash}/_subfolder/${subfolder}/${fileName}`);
|
|
||||||
|
|
||||||
// TODO add subfolder support
|
const task = await Task.findOne({
|
||||||
response.sendFile(tasksheetPath, {
|
id: taskId,
|
||||||
headers: {
|
title_id_hash: titleIdHash
|
||||||
'Content-Type': 'text/xml'
|
});
|
||||||
|
if (!task) {
|
||||||
|
return response.sendStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = await File.findOne({
|
||||||
|
name: fileName,
|
||||||
|
task_id: taskId
|
||||||
|
});
|
||||||
|
if (!file) {
|
||||||
|
return response.sendStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const xmlContent = {
|
||||||
|
TaskSheet: {
|
||||||
|
TitleId: task.title_id,
|
||||||
|
TaskId: task.id,
|
||||||
|
ServiceStatus: task.status,
|
||||||
|
Files: {
|
||||||
|
File: {
|
||||||
|
Filename: file.name,
|
||||||
|
DataId: file.data_id,
|
||||||
|
Type: file.type,
|
||||||
|
Url: `https://${config.domains.npdi}/p01/data/1/${task.title_id}/${file.data_id}/${file.hash}`
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, fileErrCallback(response));
|
};
|
||||||
|
|
||||||
|
response.set('Content-Type', 'application/xml; charset=utf-8');
|
||||||
|
response.send(xmlbuilder.create(xmlContent, { headless: true }).end({ pretty: true }));
|
||||||
});
|
});
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user