mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-04-24 06:57:06 -05:00
fix: fix mistakes by assuming boss_app_id was a title_id
This commit is contained in:
parent
6998b64164
commit
afd43177d6
|
|
@ -15,7 +15,6 @@ const TaskSchema = new mongoose.Schema<ITask, TaskModel, ITaskMethods>({
|
|||
enum: ['open'] // TODO - What else is there?
|
||||
},
|
||||
title_id: String,
|
||||
title_id_hash: String,
|
||||
description: Number,
|
||||
created: BigInt,
|
||||
updated: BigInt
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
import express from 'express';
|
||||
import { restrictHostnames } from '@/middleware/host-limit';
|
||||
import { config } from '@/config-manager';
|
||||
import { File } from '@/models/file';
|
||||
import { getCdnFileAsStream, streamFileToResponse } from '@/cdn';
|
||||
import { getTaskFileByDataID } from '@/database';
|
||||
|
||||
const npdi = express.Router();
|
||||
|
||||
npdi.get('/p01/data/1/:titleIdHash/:dataId/:fileHash', async (request, response) => {
|
||||
const { dataId, fileHash } = request.params;
|
||||
npdi.get('/p01/data/1/:bossAppId/:dataId/:fileHash', async (request, response) => {
|
||||
const { dataId, fileHash, bossAppId } = request.params;
|
||||
|
||||
const file = await File.findOne({
|
||||
data_id: dataId,
|
||||
hash: fileHash
|
||||
});
|
||||
const file = await getTaskFileByDataID(BigInt(dataId));
|
||||
if (!file) {
|
||||
return response.sendStatus(404);
|
||||
}
|
||||
if (file.hash !== fileHash || file.boss_app_id !== bossAppId) {
|
||||
return response.sendStatus(404);
|
||||
}
|
||||
|
||||
const fileStream = await getCdnFileAsStream('taskFile', file.file_key);
|
||||
if (!fileStream) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ import express from 'express';
|
|||
import xmlbuilder from 'xmlbuilder';
|
||||
import { config } from '@/config-manager';
|
||||
import { restrictHostnames } from '@/middleware/host-limit';
|
||||
import { Task } from '@/models/task';
|
||||
import { File } from '@/models/file';
|
||||
import { getTask, getTaskFile, getTaskFiles } from '@/database';
|
||||
import type { HydratedFileDocument } from '@/types/mongoose/file';
|
||||
import type { HydratedTaskDocument } from '@/types/mongoose/task';
|
||||
|
||||
|
|
@ -16,29 +15,24 @@ function buildFile(task: HydratedTaskDocument, file: HydratedFileDocument): any
|
|||
Type: file.type,
|
||||
Url: `https://${config.domains.npdi}/p01/data/1/${task.title_id}/${file.data_id}/${file.hash}`,
|
||||
Size: file.size,
|
||||
Notify: file.isNew
|
||||
? {
|
||||
New: file.notify_on_new.join(','),
|
||||
LED: file.notify_led
|
||||
}
|
||||
: undefined
|
||||
Notify: {
|
||||
New: file.notify_on_new.join(','),
|
||||
LED: file.notify_led
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
npts.get('/p01/tasksheet/:id/:titleIdHash/:taskId', async (request, response) => {
|
||||
const { titleIdHash, taskId } = request.params;
|
||||
// TODO tasksheet ID is unused - what is it for?
|
||||
|
||||
const task = await Task.findOne({
|
||||
id: taskId,
|
||||
title_id_hash: titleIdHash
|
||||
});
|
||||
npts.get('/p01/tasksheet/:id/:bossAppId/:taskId', async (request, response) => {
|
||||
const { bossAppId, taskId } = request.params;
|
||||
|
||||
const task = await getTask(bossAppId, taskId);
|
||||
if (!task) {
|
||||
return response.sendStatus(404);
|
||||
}
|
||||
|
||||
const files = await File.find({
|
||||
task_id: taskId
|
||||
});
|
||||
const files = await getTaskFiles(false, bossAppId, taskId);
|
||||
|
||||
const xmlContent = {
|
||||
TaskSheet: {
|
||||
|
|
@ -55,21 +49,15 @@ 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/:titleIdHash/:taskId/:fileName', async (request, response) => {
|
||||
const { titleIdHash, taskId, fileName } = request.params;
|
||||
npts.get('/p01/tasksheet/:id/:bossAppId/:taskId/:fileName', async (request, response) => {
|
||||
const { bossAppId, taskId, fileName } = request.params;
|
||||
|
||||
const task = await Task.findOne({
|
||||
id: taskId,
|
||||
title_id_hash: titleIdHash
|
||||
});
|
||||
const task = await getTask(bossAppId, taskId);
|
||||
if (!task) {
|
||||
return response.sendStatus(404);
|
||||
}
|
||||
|
||||
const file = await File.findOne({
|
||||
name: fileName,
|
||||
task_id: taskId
|
||||
});
|
||||
const file = await getTaskFile(bossAppId, taskId, fileName);
|
||||
if (!file) {
|
||||
return response.sendStatus(404);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ export interface ITask {
|
|||
creator_pid: number;
|
||||
status: 'open'; // TODO - Make this a union. What else is there?
|
||||
title_id: string;
|
||||
title_id_hash: string;
|
||||
description: string;
|
||||
created: bigint;
|
||||
updated: bigint;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user