From 6998b641648b080bf84278bb38535553ff481cc7 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 3 Sep 2025 20:28:18 +0200 Subject: [PATCH] chore: remove usused code --- src/app-root.ts | 4 -- src/services/grpc/boss/upload-file.ts | 5 +- src/util.ts | 73 +-------------------------- 3 files changed, 4 insertions(+), 78 deletions(-) delete mode 100644 src/app-root.ts diff --git a/src/app-root.ts b/src/app-root.ts deleted file mode 100644 index 410563a..0000000 --- a/src/app-root.ts +++ /dev/null @@ -1,4 +0,0 @@ -// ! Do not move this file, it must be in the root of the project for __dirname to resolve correctly -// * Node.js does not have a built-in way to get the root directory of the project, so we need to set it manually -// * When using a bundler, __dirname will not work as expected in nested files so we need a consistent way to get the root directory -export const __appRoot = __dirname; diff --git a/src/services/grpc/boss/upload-file.ts b/src/services/grpc/boss/upload-file.ts index 2d3a7d8..7977bc8 100644 --- a/src/services/grpc/boss/upload-file.ts +++ b/src/services/grpc/boss/upload-file.ts @@ -1,9 +1,10 @@ import { Status, ServerError } from 'nice-grpc'; import { encryptWiiU } from '@pretendonetwork/boss-crypto'; -import { isValidCountryCode, isValidFileNotifyCondition, isValidFileType, isValidLanguage, md5, uploadCDNFile } from '@/util'; +import { isValidCountryCode, isValidFileNotifyCondition, isValidFileType, isValidLanguage, md5 } from '@/util'; import { getTask, getTaskFile } from '@/database'; import { File } from '@/models/file'; import { config } from '@/config-manager'; +import { uploadCdnFile } from '@/cdn'; import type { CallContext } from 'nice-grpc'; import type { AuthenticationCallContextExt } from '@/services/grpc/boss/middleware/authentication-middleware'; import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc'; @@ -112,7 +113,7 @@ export async function uploadFile(request: UploadFileRequest, context: CallContex // * upload key is not viable, as it is not always // * known during upload const key = `${bossAppID}/${taskID}/${contentHash}`; - await uploadCDNFile(key, encryptedData); + await uploadCdnFile('taskFile', key, encryptedData); } catch (error: unknown) { let message = 'Unknown file upload error'; diff --git a/src/util.ts b/src/util.ts index f8a5308..a4e12c0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,37 +1,18 @@ import crypto from 'node:crypto'; -import path from 'node:path'; import fs from 'fs-extra'; import { createChannel, createClient, Metadata } from 'nice-grpc'; -import { GetObjectCommand, PutObjectCommand, S3 } from '@aws-sdk/client-s3'; import { AccountDefinition } from '@pretendonetwork/grpc/account/account_service'; import { FriendsDefinition } from '@pretendonetwork/grpc/friends/friends_service'; -import { config, disabledFeatures } from '@/config-manager'; +import { config } from '@/config-manager'; import { logger } from './logger'; import type { FriendsClient } from '@pretendonetwork/grpc/friends/friends_service'; import type { AccountClient } from '@pretendonetwork/grpc/account/account_service'; -import type { S3Client } from '@aws-sdk/client-s3'; import type { GetNEXDataResponse } from '@pretendonetwork/grpc/account/get_nex_data_rpc'; import type { GetUserDataResponse } from '@pretendonetwork/grpc/account/get_user_data_rpc'; import type { GetUserFriendPIDsResponse } from '@pretendonetwork/grpc/friends/get_user_friend_pids_rpc'; -import type { NodeJsClient } from '@smithy/types'; import type { Response } from 'express'; -import type { Readable } from 'node:stream'; import type { Stats } from 'node:fs'; -let s3: NodeJsClient; - -if (!disabledFeatures.s3) { - s3 = new S3({ - forcePathStyle: false, - endpoint: config.cdn.s3.endpoint, - region: config.cdn.s3.region, - credentials: { - accessKeyId: config.cdn.s3.key, - secretAccessKey: config.cdn.s3.secret - } - }); -} - const gRPCAccountChannel = createChannel(`${config.grpc.account.address}:${config.grpc.account.port}`); const gRPCAccountClient: AccountClient = createClient(AccountDefinition, gRPCAccountChannel); @@ -167,55 +148,3 @@ export async function getFriends(pid: number): Promise { - try { - if (disabledFeatures.s3) { - return await getLocalCDNFile(key); - } else { - const response = await s3.send(new GetObjectCommand({ - Key: key, - Bucket: config.cdn.s3.bucket - })); - - if (!response.Body) { - return null; - } - - return response.Body; - } - } catch { - return null; - } -} - -export async function getLocalCDNFile(key: string): Promise { - const filePath = path.join(config.cdn.disk_path, key); - - if (await !fs.exists(filePath)) { - return null; - } - - return fs.createReadStream(filePath); -} - -export async function uploadCDNFile(key: string, data: Buffer): Promise { - if (disabledFeatures.s3) { - await writeLocalCDNFile(key, data); - } else { - await s3.send(new PutObjectCommand({ - Key: key, - Bucket: config.cdn.s3.bucket, - Body: data, - ACL: 'private' - })); - } -} - -export async function writeLocalCDNFile(key: string, data: Buffer): Promise { - const filePath = path.join(config.cdn.disk_path, key); - const folder = path.dirname(filePath); - - await fs.ensureDir(folder); - await fs.writeFile(filePath, data); -}