From 8db40e090840d76a3027b49c4f3332df0d026932 Mon Sep 17 00:00:00 2001 From: Hoon Kim Date: Wed, 3 Jan 2024 14:01:21 +0100 Subject: [PATCH 1/2] return hash as id --- src/app.ts | 4 ++++ src/helpers/index.ts | 5 +++++ src/routes.ts | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 4f21747..dc42931 100644 --- a/src/app.ts +++ b/src/app.ts @@ -15,6 +15,10 @@ class ServerApp { console.log('Starting the server'); this.server = express(); + if (!process.env.API_KEY || !process.env.API_SECRET || !process.env.BUCKET_UUID) { + throw new Error('API_KEY, API_SECRET, or BUCKET_UUID is not set.'); + } + this._apiInst = new ApillonApi(process.env.API_KEY, process.env.API_SECRET); this.middlewares(); diff --git a/src/helpers/index.ts b/src/helpers/index.ts index e69de29..717b657 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -0,0 +1,5 @@ +import { createHash } from 'crypto'; + +export const sha256Hash = (input: string) => { + return createHash('sha256').update(input).digest('hex'); +} diff --git a/src/routes.ts b/src/routes.ts index 000c15a..644a543 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -1,5 +1,7 @@ import { Router } from 'express'; import { PlayableBuild } from './types'; +import { sha256Hash } from './helpers'; + const routes = Router(); routes.get('/', (req, res) => { @@ -21,7 +23,7 @@ routes.get('/available-builds', async (req, res) => { folders.map((i) => { return { name: i.name, - id: i.id, + id: sha256Hash(i.CID), }; }), ); From 35fda93ac8781cf61d99223aecf30942866e4255 Mon Sep 17 00:00:00 2001 From: Hoon Kim Date: Fri, 12 Jan 2024 11:34:25 +0100 Subject: [PATCH 2/2] update port --- src/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/index.ts b/src/config/index.ts index dda32b8..77c51de 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,3 +1,3 @@ export * from './rateLimiter'; -export const port = process.env.PORT || 3000; +export const port = process.env.PORT || 6666;