mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-08-19 23:54:08 -05:00
added 3DS npdl service
This commit is contained in:
@@ -115,15 +115,29 @@ export function getTaskFilesWithAttributes(allowDeleted: boolean, bossAppID: str
|
||||
return File.find(filter);
|
||||
}
|
||||
|
||||
export function getTaskFile(bossAppID: string, taskID: string, name: string): Promise<HydratedFileDocument | null> {
|
||||
export function getTaskFile(bossAppID: string, taskID: string, name: string, country?: string, language?: string): Promise<HydratedFileDocument | null> {
|
||||
verifyConnected();
|
||||
|
||||
return File.findOne<HydratedFileDocument>({
|
||||
const filter: mongoose.FilterQuery<IFile> = {
|
||||
deleted: false,
|
||||
boss_app_id: bossAppID,
|
||||
task_id: taskID.slice(0, 7),
|
||||
name: name
|
||||
});
|
||||
};
|
||||
|
||||
if (country) {
|
||||
filter.supported_countries = {
|
||||
$in: [country]
|
||||
};
|
||||
}
|
||||
|
||||
if (language) {
|
||||
filter.supported_languages = {
|
||||
$in: [language]
|
||||
};
|
||||
}
|
||||
|
||||
return File.findOne<HydratedFileDocument>(filter);
|
||||
}
|
||||
|
||||
export function getTaskFileByDataID(dataID: bigint): Promise<HydratedFileDocument | null> {
|
||||
|
||||
@@ -15,6 +15,7 @@ import nppl from '@/services/nppl';
|
||||
import npts from '@/services/npts';
|
||||
import npdi from '@/services/npdi';
|
||||
import npfl from '@/services/npfl';
|
||||
import npdl from '@/services/npdl';
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -32,6 +33,7 @@ app.use(nppl);
|
||||
app.use(npts);
|
||||
app.use(npdi);
|
||||
app.use(npfl);
|
||||
app.use(npdl);
|
||||
|
||||
LOG_INFO('Creating 404 status handler');
|
||||
app.use((_request, response) => {
|
||||
|
||||
46
src/services/npdl.ts
Normal file
46
src/services/npdl.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import express from 'express';
|
||||
import subdomain from 'express-subdomain';
|
||||
import { getTaskFile } from '@/database';
|
||||
import { getCDNFileStream } from '@/util';
|
||||
|
||||
const npdl = express.Router();
|
||||
|
||||
npdl.get([
|
||||
'/p01/nsa/:appID/:taskID/:fileName',
|
||||
'/p01/nsa/:appID/:taskID/:languageCode/:fileName',
|
||||
'/p01/nsa/:appID/:taskID/:countryCode/:languageCode/:fileName'
|
||||
], async (request: express.Request<{
|
||||
appID: string;
|
||||
taskID: string;
|
||||
countryCode?: string;
|
||||
languageCode?: string;
|
||||
fileName: string;
|
||||
}, any, any, {
|
||||
ap?: string;
|
||||
tm?: string;
|
||||
}>, response) => {
|
||||
const { appID, taskID, countryCode, languageCode, fileName } = request.params;
|
||||
|
||||
const file = await getTaskFile(appID, taskID, fileName, countryCode, languageCode);
|
||||
|
||||
if (!file) {
|
||||
response.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
|
||||
const key = `${appID}/${taskID}/${file.hash}`;
|
||||
const readStream = await getCDNFileStream(key);
|
||||
|
||||
if (!readStream) {
|
||||
response.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
|
||||
readStream.pipe(response);
|
||||
});
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.use(subdomain('npdl.cdn', npdl));
|
||||
|
||||
export default router;
|
||||
@@ -102,10 +102,6 @@ export async function getUserDataByToken(token: string): Promise<GetUserDataResp
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCDNFile(): Promise<void> {
|
||||
|
||||
}
|
||||
|
||||
export async function getCDNFileStream(key: string): Promise<Readable | fs.ReadStream | null> {
|
||||
try {
|
||||
if (disabledFeatures.s3) {
|
||||
|
||||
Reference in New Issue
Block a user