-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
114 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
name: Deploy | ||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- 'src/**' | ||
workflow_dispatch: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { timeNow } from './utils'; | ||
import serveResult from './helpers'; | ||
|
||
export default async function checkCache(request: Request): Promise<Response> { | ||
if (request.method === 'GET' || request.method === 'HEAD') { | ||
const now = timeNow(); | ||
let cache = caches.default; | ||
let response = await cache.match(request.url); | ||
if (!response) { | ||
response = await serveResult(request); | ||
await cache.put(request.url, response.clone()); | ||
} | ||
response = new Response(response.body, response); | ||
response.headers.append('X-Response-Time', (timeNow() - now).toString()); | ||
return response; | ||
} else { | ||
return new Response( | ||
JSON.stringify({ success: false, message: 'Method not allowed' }), | ||
{ | ||
status: 405, | ||
headers: { | ||
'Content-Type': 'application/json; charset=utf-8', | ||
} | ||
} | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getUrl, Result } from './utils'; | ||
import callAPI from './routing'; | ||
|
||
export default async function serveResult(request: Request): Promise<Response> { | ||
const dc = getUrl(request).searchParams.get('decode'); | ||
let code = 200; | ||
let result: Result = await callAPI(request); | ||
if (result.name !== undefined) { | ||
result.name = result.name.replace(/\u002B/g, '%20'); | ||
if (dc === null || dc === 'true') { | ||
result.name = decodeURIComponent(result.name); | ||
} | ||
} else if (result.name === undefined || (!result.name && result.success)) { | ||
result = { success: false, message: 'Not found' }; | ||
} | ||
if (result.message === 'Bad request') { | ||
code = 400; | ||
delete result.name; | ||
} | ||
if (result.message === 'Not found') { | ||
code = 404; | ||
delete result.name; | ||
} | ||
const response = new Response(JSON.stringify(result), { | ||
status: code, | ||
headers: { | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Methods': 'GET, HEAD', | ||
'CDN-Cache-Control': 'max-age=43200, proxy-revalidate, immutable', | ||
'Content-Type': 'application/json; charset=utf-8', | ||
} | ||
}); | ||
return response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import checkCache from './handler'; | ||
|
||
export default { | ||
async fetch(request: Request): Promise<Response> { | ||
return await checkCache(request); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { endpoint, headers, Result } from '../utils'; | ||
|
||
export default async function ff(id: number): Promise<Result> { | ||
const body = `voucherPricePoint.id=8050&voucherPricePoint.price=1000&voucherPricePoint.variablePrice=0&user.userId=${id}&voucherTypeName=FREEFIRE&shopLang=id_ID&voucherTypeId=1&gvtId=1`; | ||
const response = await fetch(endpoint, { | ||
method: 'POST', | ||
headers, | ||
body | ||
}); | ||
const data = await response.json(); | ||
return { | ||
success: true, | ||
game: 'Garena Free Fire', | ||
id: id, | ||
name: data.confirmationFields.roles[0].role | ||
}; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export function getUrl(request: Request): URL { | ||
return new URL(request.url); | ||
} | ||
|
||
export function timeNow(): number { | ||
return Date.now(); | ||
} | ||
|
||
export const endpoint = 'https://order-sg.codashop.com/initPayment.action'; | ||
|
||
export const headers = new Headers({ | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}); | ||
|
||
export interface Result { | ||
success: boolean; | ||
game?: string; | ||
id?: number | string; | ||
zone?: number | string; | ||
name?: string; | ||
message?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters