mirror of
https://github.com/PretendoNetwork/BOSS.git
synced 2026-07-06 20:14:53 -05:00
chore: rename Cdn to CDN
This commit is contained in:
parent
4223d21987
commit
d77c604814
22
src/cdn.ts
22
src/cdn.ts
|
|
@ -28,21 +28,21 @@ export const cdnNamespace = {
|
|||
spr: 'spr',
|
||||
taskFile: 'taskFile'
|
||||
} as const;
|
||||
export type CdnNamespace = keyof typeof cdnNamespace;
|
||||
export type CDNamespace = keyof typeof cdnNamespace;
|
||||
|
||||
function buildKey(namespace: CdnNamespace, key: string): string {
|
||||
function buildKey(namespace: CDNamespace, key: string): string {
|
||||
return `${namespace}/${key}`;
|
||||
}
|
||||
|
||||
function buildLocalCdnPath(fullKey: string): string {
|
||||
function buildLocalCDNPath(fullKey: string): string {
|
||||
return path.join(config.cdn.disk_path, fullKey);
|
||||
}
|
||||
|
||||
export async function getCdnFileAsStream(namespace: CdnNamespace, key: string): Promise<Readable | null> {
|
||||
export async function getCDNFileAsStream(namespace: CDNamespace, key: string): Promise<Readable | null> {
|
||||
const fullKey = buildKey(namespace, key);
|
||||
|
||||
if (!s3) {
|
||||
const filePath = buildLocalCdnPath(fullKey);
|
||||
const filePath = buildLocalCDNPath(fullKey);
|
||||
const fileInfo = await fileStatOrNull(filePath);
|
||||
|
||||
if (!fileInfo) {
|
||||
|
|
@ -64,19 +64,19 @@ export async function getCdnFileAsStream(namespace: CdnNamespace, key: string):
|
|||
return response.Body;
|
||||
}
|
||||
|
||||
export async function getCdnFileAsBuffer(namespace: CdnNamespace, key: string): Promise<Buffer | null> {
|
||||
const stream = await getCdnFileAsStream(namespace, key);
|
||||
export async function getCDNFileAsBuffer(namespace: CDNamespace, key: string): Promise<Buffer | null> {
|
||||
const stream = await getCDNFileAsStream(namespace, key);
|
||||
if (!stream) {
|
||||
return null;
|
||||
}
|
||||
return bufferConsumer(stream);
|
||||
}
|
||||
|
||||
export async function uploadCdnFile(namespace: CdnNamespace, key: string, data: Buffer): Promise<void> {
|
||||
export async function uploadCDNFile(namespace: CDNamespace, key: string, data: Buffer): Promise<void> {
|
||||
const fullKey = buildKey(namespace, key);
|
||||
|
||||
if (!s3) {
|
||||
const filePath = buildLocalCdnPath(fullKey);
|
||||
const filePath = buildLocalCDNPath(fullKey);
|
||||
const folder = path.dirname(filePath);
|
||||
await fs.ensureDir(folder);
|
||||
await fs.writeFile(filePath, data);
|
||||
|
|
@ -91,11 +91,11 @@ export async function uploadCdnFile(namespace: CdnNamespace, key: string, data:
|
|||
}));
|
||||
}
|
||||
|
||||
export async function deleteCdnFile(namespace: CdnNamespace, key: string): Promise<void> {
|
||||
export async function deleteCDNFile(namespace: CDNamespace, key: string): Promise<void> {
|
||||
const fullKey = buildKey(namespace, key);
|
||||
|
||||
if (!s3) {
|
||||
const filePath = buildLocalCdnPath(fullKey);
|
||||
const filePath = buildLocalCDNPath(fullKey);
|
||||
const fileInfo = await fileStatOrNull(filePath);
|
||||
if (!fileInfo || !fileInfo.isFile()) {
|
||||
return; // Not found or not a file
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { isValidCountryCode, isValidFileNotifyCondition, isValidFileType, isVali
|
|||
import { getTask, getTaskFile } from '@/database';
|
||||
import { File } from '@/models/file';
|
||||
import { config } from '@/config-manager';
|
||||
import { uploadCdnFile } from '@/cdn';
|
||||
import { uploadCDNFile } from '@/cdn';
|
||||
import { hasPermission } from '@/services/grpc/boss/middleware/authentication-middleware';
|
||||
import type { AuthenticationCallContextExt } from '@/services/grpc/boss/middleware/authentication-middleware';
|
||||
import type { CallContext } from 'nice-grpc';
|
||||
|
|
@ -102,7 +102,7 @@ export async function uploadFile(request: UploadFileRequest, context: CallContex
|
|||
// * Because of this, using the file name in the
|
||||
// * upload key is not viable, as it is not always
|
||||
// * known during upload
|
||||
await uploadCdnFile('taskFile', key, encryptedData);
|
||||
await uploadCDNFile('taskFile', key, encryptedData);
|
||||
} catch (error: unknown) {
|
||||
let message = 'Unknown file upload error';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import express from 'express';
|
||||
import { restrictHostnames } from '@/middleware/host-limit';
|
||||
import { config } from '@/config-manager';
|
||||
import { getCdnFileAsStream, streamFileToResponse } from '@/cdn';
|
||||
import { getCDNFileAsStream, streamFileToResponse } from '@/cdn';
|
||||
import { getTaskFileByDataID } from '@/database';
|
||||
|
||||
const npdi = express.Router();
|
||||
|
|
@ -17,7 +17,7 @@ npdi.get('/p01/data/1/:bossAppId/:dataId/:fileHash', async (request, response) =
|
|||
return response.sendStatus(404);
|
||||
}
|
||||
|
||||
const fileStream = await getCdnFileAsStream('taskFile', file.file_key);
|
||||
const fileStream = await getCDNFileAsStream('taskFile', file.file_key);
|
||||
if (!fileStream) {
|
||||
throw new Error('File not found in CDN');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import express from 'express';
|
|||
import { getTaskFile } from '@/database';
|
||||
import { config } from '@/config-manager';
|
||||
import { restrictHostnames } from '@/middleware/host-limit';
|
||||
import { getCdnFileAsStream, streamFileToResponse } from '@/cdn';
|
||||
import { getCDNFileAsStream, streamFileToResponse } from '@/cdn';
|
||||
|
||||
const npdl = express.Router();
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ npdl.get([
|
|||
return;
|
||||
}
|
||||
|
||||
const readStream = await getCdnFileAsStream('taskFile', file.file_key);
|
||||
const readStream = await getCDNFileAsStream('taskFile', file.file_key);
|
||||
if (!readStream) {
|
||||
response.sendStatus(404);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import RequestException from '@/request-exception';
|
|||
import { config } from '@/config-manager';
|
||||
import { restrictHostnames } from '@/middleware/host-limit';
|
||||
import { logger } from '@/logger';
|
||||
import { getCdnFileAsBuffer, uploadCdnFile } from '@/cdn';
|
||||
import { getCDNFileAsBuffer, uploadCDNFile } from '@/cdn';
|
||||
import type { SPRSlot } from '@/types/common/spr-slot';
|
||||
|
||||
const spr = express.Router();
|
||||
|
|
@ -250,7 +250,7 @@ spr.post('/relay/0', multipartParser, async (request, response) => {
|
|||
|
||||
if (!slotData || slotData.data_hash !== dataHash) {
|
||||
const fileKey = `${request.pid}-${dataHash}`;
|
||||
await uploadCdnFile('spr', fileKey, sprSlot.data);
|
||||
await uploadCDNFile('spr', fileKey, sprSlot.data);
|
||||
slotData = await CECData.create({
|
||||
creator_pid: request.pid,
|
||||
game_id: sprSlot.gameID,
|
||||
|
|
@ -279,7 +279,7 @@ spr.post('/relay/0', multipartParser, async (request, response) => {
|
|||
const slotData = await getRandomCECData(userFriends.pids, sprSlot.gameID);
|
||||
|
||||
if (slotData) {
|
||||
const fileData = await getCdnFileAsBuffer('spr', slotData.file_key);
|
||||
const fileData = await getCDNFileAsBuffer('spr', slotData.file_key);
|
||||
if (fileData) {
|
||||
sprData = Buffer.concat([sprData, fileData]);
|
||||
sprSlot.size = slotData.size;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user