Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
feat: Update PushTokenToRepo function to include CurrentDate parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
piquark6046 committed Jul 24, 2024
1 parent 2276584 commit 344d71f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions sources/git.ts
Original file line number Diff line number Diff line change
@@ -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)
})
Expand Down
7 changes: 4 additions & 3 deletions sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

Expand Down

0 comments on commit 344d71f

Please sign in to comment.