mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-03-26 03:45:26 -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 xmlbuilder from 'xmlbuilder';
|
||||
import { fileErrCallback } from '@/util';
|
||||
import { __appRoot } from '@/app-root';
|
||||
import { config } from '@/config-manager';
|
||||
import { restrictHostnames } from '@/middleware/host-limit';
|
||||
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 }));
|
||||
});
|
||||
|
||||
npts.get('/p01/tasksheet/:id/:hash/:subfolder/:fileName', (request, response) => {
|
||||
const { id, hash, subfolder, fileName } = request.params;
|
||||
const tasksheetPath = path.normalize(`${__appRoot}/../cdn/tasksheet/${id}/${hash}/_subfolder/${subfolder}/${fileName}`);
|
||||
npts.get('/p01/tasksheet/:id/:titleIdHash/:taskId/:fileName', async (request, response) => {
|
||||
const { titleIdHash, taskId, fileName } = request.params;
|
||||
|
||||
// TODO add subfolder support
|
||||
response.sendFile(tasksheetPath, {
|
||||
headers: {
|
||||
'Content-Type': 'text/xml'
|
||||
const task = await Task.findOne({
|
||||
id: taskId,
|
||||
title_id_hash: titleIdHash
|
||||
});
|
||||
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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user