From 344d71f9edac1f1f06a0d156effb490ae45c2586 Mon Sep 17 00:00:00 2001 From: piquark6046 Date: Wed, 24 Jul 2024 21:42:20 +0000 Subject: [PATCH] feat: Update PushTokenToRepo function to include CurrentDate parameter --- sources/git.ts | 4 ++-- sources/index.ts | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sources/git.ts b/sources/git.ts index 82a6e87..284ae0b 100644 --- a/sources/git.ts +++ b/sources/git.ts @@ -1,11 +1,11 @@ import * as GitHub from '@octokit/rest' -export async function PushTokenToRepo(Repo: string, Token: string, SHA: string, GitHubToken: string) { +export async function PushTokenToRepo(Repo: string, Token: string, SHA: string, GitHubToken: string, CurrentDate: Date) { const GitHubInstance = new GitHub.Octokit({ auth: GitHubToken }) await GitHubInstance.repos.createOrUpdateFileContents({ owner: Repo.split('/')[0], repo: Repo.split('/')[1], - path: SHA, + path: `${CurrentDate.getUTCFullYear()}/${CurrentDate.getUTCMonth()}/${CurrentDate.getUTCDate()}/${SHA}`, message: `Update for ${SHA}`, content: btoa(Token) }) diff --git a/sources/index.ts b/sources/index.ts index 3ed648e..37abfd3 100644 --- a/sources/index.ts +++ b/sources/index.ts @@ -17,25 +17,26 @@ const ProgramOptions = Program.opts() as { auth: string, repo: string, host: str const FastifyInstance = Fastify() FastifyInstance.post('/token', async (FRequest, FResponse) => { + const CurrentDate = new Date() if (typeof FRequest.body !== 'string') { FResponse.status(400).send('Invalid request') return } const SHA = Array.from(new Uint8Array(await crypto.subtle.digest('SHA-1', new TextEncoder().encode(FRequest.body)))).map(Block =>Block.toString(16).padStart(2, '0')).join('') try { - await got.get(`https://cdn.jsdelivr.net/gh/List-KR/microShield-token@main/${SHA}`, { + await got.get(`https://cdn.jsdelivr.net/gh/List-KR/microShield-token@main/${CurrentDate.getUTCFullYear()}/${CurrentDate.getUTCMonth()}/${CurrentDate.getUTCDate()}/${SHA}`, { http2: true, https: { minVersion: 'TLSv1.3', ciphers: 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256' } }).text() - FResponse.status(301).redirect(`https://cdn.jsdelivr.net/gh/List-KR/microShield-token@main/${SHA}`) + FResponse.status(301).redirect(`https://cdn.jsdelivr.net/gh/List-KR/microShield-token@main/${CurrentDate.getUTCFullYear()}/${CurrentDate.getUTCMonth()}/${CurrentDate.getUTCDate()}/${SHA}`) } catch { MemFs.fs.writeFileSync('/code.js', await Deobfuscate(FRequest.body)) const Token = ExtractCode(MemFs.fs.readFileSync('/code.js', 'utf8') as string) FResponse.status(200).send(Token) - await PushTokenToRepo(ProgramOptions.repo, Token, SHA, ProgramOptions.auth) + await PushTokenToRepo(ProgramOptions.repo, Token, SHA, ProgramOptions.auth, CurrentDate) } })