diff --git a/src/cdn.ts b/src/cdn.ts index 761a7e3..c2f8fed 100644 --- a/src/cdn.ts +++ b/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 { +export async function getCDNFileAsStream(namespace: CDNamespace, key: string): Promise { 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 { - const stream = await getCdnFileAsStream(namespace, key); +export async function getCDNFileAsBuffer(namespace: CDNamespace, key: string): Promise { + const stream = await getCDNFileAsStream(namespace, key); if (!stream) { return null; } return bufferConsumer(stream); } -export async function uploadCdnFile(namespace: CdnNamespace, key: string, data: Buffer): Promise { +export async function uploadCDNFile(namespace: CDNamespace, key: string, data: Buffer): Promise { 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 { +export async function deleteCDNFile(namespace: CDNamespace, key: string): Promise { 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 diff --git a/src/services/grpc/boss/upload-file.ts b/src/services/grpc/boss/upload-file.ts index fd52af4..95d6dd2 100644 --- a/src/services/grpc/boss/upload-file.ts +++ b/src/services/grpc/boss/upload-file.ts @@ -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'; diff --git a/src/services/npdi.ts b/src/services/npdi.ts index 4353830..77d06f7 100644 --- a/src/services/npdi.ts +++ b/src/services/npdi.ts @@ -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'); } diff --git a/src/services/npdl.ts b/src/services/npdl.ts index 40704c8..a167299 100644 --- a/src/services/npdl.ts +++ b/src/services/npdl.ts @@ -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; diff --git a/src/services/spr.ts b/src/services/spr.ts index b8a3884..57dd1e1 100644 --- a/src/services/spr.ts +++ b/src/services/spr.ts @@ -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;