Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R #3

Closed
wants to merge 15 commits into from
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ GET `hsr?id=PLAYER_ID`
GET `hi?id=PLAYER_ID`

**Contoh:** https://api.isan.eu.org/nickname/hi?id=10000001
### Point Blank
GET `pb?id=ZEPETTO_ID`

**Contoh:** https://api.isan.eu.org/nickname/pb?id=wakwaw55
### Punishing: Gray Raven (AP, EU, NA)
GET `pgr?id=ID&zone=SERVER_ID`

Keterangan untuk identifikasi server: AP(Asia-Pasifik), EU(Europe), NA(North America)

**Contoh:** https://api.isan.eu.org/nickname/pgr?id=16746755&zone=AP
### Sausage Man
GET `sm?id=PLAYER_ID`

Expand All @@ -47,6 +57,12 @@ GET `sm?id=PLAYER_ID`
GET `sus?id=SPACE_ID`

**Contoh:** https://api.isan.eu.org/nickname/sus?id=15916600
### Valorant
GET `valo?id=URLEncodedRiotIdAndTag`

**Contoh region ID :** https://api.isan.eu.org/nickname/valo?id=yuyun%23123

**Contoh region non ID :** https://api.isan.eu.org/nickname/valo?id=Westbourne%23USA
## ID-REG-ONLY
Dibawah ini adalah daftar game yang hanya bisa dipakai menggunakan ID yang terdaftar dari region Indonesia
### Mobile Legends: Bang Bang
Expand All @@ -65,5 +81,19 @@ GET `aov?id=PLAYER_OR_OPEN_ID`
GET `cod?id=PLAYER_OR_OPEN_ID`

**Contoh:** https://api.isan.eu.org/nickname/cod?id=243402956362890880
## Parameter Opsional
Kamu dapat menambah parameter `decode` dan mengisi value ke `false` (default ke `true`).

Ketika value diatur ke `false` maka data nickname akan ditampilkan dala URL encoded dan untuk membacanya memerlukan function seperti `decodeURIComponent()` (dalam javascript) atau sejenisnya, saya juga lebih merekomendasikan untuk menggunakan `?decode=false`.

Sementara jika value adalah `true` maka data akan bisa dibaca secara langsung tapi kemungkinan error dan gagal dalam pembacaan data akan muncul.

Berikut adalah contoh penggunaan `?decode=false`
https://api.isan.eu.org/nickname/ml?id=1007909047&zone=13044&decode=false

Contoh penggunaan `?decode=true`
https://api.isan.eu.org/nickname/ml?id=1007909047&zone=13044&decode=true atau https://api.isan.eu.org/nickname/ml?id=1007909047&zone=13044 (sama saja).
## Monitoring
API monitoring [UptimeRobot](https://stats.uptimerobot.com/s9axzR77Fm)
# Copyright
© Projek ini dibawah lisensi: [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/), tidak terafiliasi dengan Codashop
136 changes: 95 additions & 41 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ async function callAPI(request) {
if (!id) {
return `{"success":false,"message":"Bad Request"}`
}
if (path.includes('/pgr')) {
if (zone.toLowerCase().includes('ap')) {
sn = 'Asia-Pacific'
sv = '5000'
} else if (zone.toLowerCase().includes('eu')) {
sn = 'Europe'
sv = '5001'
} else if (zone.toLowerCase().includes('na')) {
sn = 'North America'
sv = '5002'
} else {
return `{"success":false,"message":"Bad request"}`
}
const body = `voucherPricePoint.id=259947&voucherPricePoint.price=15136.0&voucherPricePoint.variablePrice=0&user.userId=${id}&user.zoneId=${sv}&voucherTypeName=PUNISHING_GRAY_RAVEN&shopLang=id_ID`
const request = new Request(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body
})
const response = await fetch(request)
const data = await response.json()
return `{"success":true,"game":"Punishing: Gray Raven","server":"${sn}","id":${id},"name":"${data.confirmationFields.username}"}`
}
if (path.includes('/hsr')) {
if (id. startsWith('6')) {
sn = 'America'
Expand All @@ -38,8 +63,7 @@ async function callAPI(request) {
})
const response = await fetch(request)
const data = await response.json()
let result = `{"success":true,"game":"Honkai: Star Rail","server":"${sn}","id":${id},"name":"${data.confirmationFields.username}"}`
return result
return `{"success":true,"game":"Honkai: Star Rail","server":"${sn}","id":${id},"name":"${data.confirmationFields.username}"}`
}
if (path.includes('/gi')) {
if (id. startsWith('6')) {
Expand Down Expand Up @@ -67,8 +91,7 @@ async function callAPI(request) {
})
const response = await fetch(request)
const data = await response.json()
let result = `{"success":true,"game":"Genshin Impact","server":"${sn}","id":${id},"name":"${data.confirmationFields.username}"}`
return result
return `{"success":true,"game":"Genshin Impact","server":"${sn}","id":${id},"name":"${data.confirmationFields.username}"}`
}
if (path.includes('/hi')) {
const body = `voucherPricePoint.id=48160&voucherPricePoint.price=16500.0&voucherPricePoint.variablePrice=0&user.userId=${id}&user.zoneId=&voucherTypeName=HONKAI_IMPACT&shopLang=id_ID`
Expand All @@ -81,8 +104,7 @@ async function callAPI(request) {
})
const response = await fetch(request)
const data = await response.json()
let result = `{"success":true,"game":"Honkai Impact 3rd","id":${id},"name":"${data.confirmationFields.username}"}`
return result
return `{"success":true,"game":"Honkai Impact 3rd","id":${id},"name":"${data.confirmationFields.username}"}`
}
if (path.includes('/ml') && !zone) {
return `{"success":false,"message":"Bad Request"}`
Expand All @@ -98,8 +120,7 @@ async function callAPI(request) {
})
const response = await fetch(request)
const data = await response.json()
let result = `{"success":true,"game":"Mobile Legends: Bang Bang","id":${id},"zoneId":${zone},"name":"${data.confirmationFields.username}"}`
return result
return `{"success":true,"game":"Mobile Legends: Bang Bang","id":${id},"zoneId":${zone},"name":"${data.confirmationFields.username}"}`
}
if (path.includes('/sm')) {
const body = `voucherPricePoint.id=256513&voucherPricePoint.price=16000.0&voucherPricePoint.variablePrice=0&user.userId=${id}&user.zoneId=global-release&voucherTypeName=SAUSAGE_MAN&shopLang=id_ID`
Expand All @@ -112,8 +133,26 @@ async function callAPI(request) {
})
const response = await fetch(request)
const data = await response.json()
let result = `{"success":true,"game":"Sausage Man","id":"${id}","name":"${data.confirmationFields.username}"}`
return result
return `{"success":true,"game":"Sausage Man","id":"${id}","name":"${data.confirmationFields.username}"}`
}
if (path.includes('/valo')) {
const body = `voucherPricePoint.id=115691&voucherPricePoint.price=15000.0&voucherPricePoint.variablePrice=0&user.userId=${id}&voucherTypeName=VALORANT&voucherTypeId=109&gvtId=139&shopLang=id_ID`
const request = new Request(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body
})
const response = await fetch(request)
const data = await response.json()
if (data.success == true) {
return `{"success":true,"game":"VALORANT","id":"${id}","region":"Indonesia","name":"${data.confirmationFields.username}"}`
} else if (data.errorCode == -200) {
return `{"success":true,"game":"VALORANT","id":"${id}","region":"","name":"${data.confirmationFields.userId}"}`
} else {
return `{"success":false,"message":"Cannot find nickname from your request."}`
}
}
if (path.includes('/ff')) {
const body = `voucherPricePoint.id=8050&voucherPricePoint.price=1000.0&voucherPricePoint.variablePrice=0&user.userId=${id}&voucherTypeName=FREEFIRE&shopLang=id_ID&voucherTypeId=1&gvtId=1`
Expand All @@ -126,8 +165,7 @@ async function callAPI(request) {
})
const response = await fetch(request)
const data = await response.json()
let result = `{"success":true,"game":"Garena Free Fire","id":${id},"name":"${data.confirmationFields.roles[0].role}"}`
return result
return `{"success":true,"game":"Garena Free Fire","id":${id},"name":"${data.confirmationFields.roles[0].role}"}`
}
if (path.includes('/cod')) {
const body = `voucherPricePoint.id=46114&voucherPricePoint.price=5000.0&voucherPricePoint.variablePrice=0&user.userId=${id}&voucherTypeName=CALL_OF_DUTY&shopLang=id_ID&voucherTypeId=1&gvtId=1`
Expand All @@ -140,8 +178,7 @@ async function callAPI(request) {
})
const response = await fetch(request)
const data = await response.json()
let result = `{"success":true,"game":"Call Of Duty","id":${id},"name":"${data.confirmationFields.roles[0].role}"}`
return result
return `{"success":true,"game":"Call Of Duty","id":${id},"name":"${data.confirmationFields.roles[0].role}"}`
}
if (path.includes('/aov')) {
const body = `voucherPricePoint.id=7946&voucherPricePoint.price=10000.0&voucherPricePoint.variablePrice=0&user.userId=${id}&voucherTypeName=AOV&shopLang=id_ID&voucherTypeId=1&gvtId=1`
Expand All @@ -154,8 +191,7 @@ async function callAPI(request) {
})
const response = await fetch(request)
const data = await response.json()
let result = `{"success":true,"game":"Garena AOV (Arena of Valor)","id":${id},"name":"${data.confirmationFields.roles[0].role}"}`
return result
return `{"success":true,"game":"Garena AOV (Arena of Valor)","id":${id},"name":"${data.confirmationFields.roles[0].role}"}`
}
if (path.includes('/sus')) {
const body = `voucherPricePoint.id=266077&voucherPricePoint.price=13000.0&voucherPricePoint.variablePrice=0&user.userId=${id}&user.zoneId=&voucherTypeName=SUPER_SUS&shopLang=id_ID`
Expand All @@ -168,56 +204,74 @@ async function callAPI(request) {
})
const response = await fetch(request)
const data = await response.json()
let result = `{"success":true,"game":"Super Sus","id":${id},"name":"${data.confirmationFields.username}"}`
return result
return `{"success":true,"game":"Super Sus","id":${id},"name":"${data.confirmationFields.username}"}`
}
if (path.includes('/pb')) {
const body = `voucherPricePoint.id=54700&voucherPricePoint.price=11000.0&voucherPricePoint.variablePrice=0&user.userId=${id}&user.zoneId=&voucherTypeName=POINT_BLANK&shopLang=id_ID`
const request = new Request(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body
})
const response = await fetch(request)
const data = await response.json()
return `{"success":true,"game":"Point Blank","id":"${id}","name":"${data.confirmationFields.username}"}`
}
else {
let result = `{"success":false,"message":"Bad request"}`
return result
return `{"success":false,"message":"Bad request"}`
}
}
catch (error) {
let result = `{"success":false,"message":"Cannot find nickname from your request."}`
return result
return `{"success":false,"message":"Cannot find nickname from your request."}`
}
}
async function serveResult(request) {
let dc = new URL(request.url).searchParams.get('decode')
let code = 200
let result = await callAPI(request)
if (result.includes('undefined')) {
if (result.includes(`"undefined"`)) {
result = `{"success":false,"message":"Cannot find nickname from your request."}`
}
if (result.includes(`"success":false`)) {
if (JSON.parse(result).success == false) {
code = 400
}
result = result.replace(/\u002B/g, ' ')
result = decodeURIComponent(result)
result = result.replace(/\u002B/g, '%20')
if (dc == false) {
result = result
}
if (!dc || dc == true) {
result = decodeURIComponent(result)
}
let response = new Response(result, {
status: code,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Method': 'GET',
'Cache-Control': 'max-age=600',
'Access-Control-Allow-Method': 'GET, HEAD',
'Cache-Control': 'public, max-age=43200',
'Content-Type': 'application/json; charset=utf-8',
}
})
return response
}
async function checkCache(request) {
if (request.method !== 'GET') {
if (request.method == 'GET' || request.method == 'HEAD') {
let now = Date.now()
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.delete('Cache-Control')
response.headers.append('X-Response-Time', Date.now() - now)
return response
}
else {
return new Response('Method Not Allowed', {
status: 405
})
}
let now = Date.now()
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.delete('Cache-Control')
response.headers.append('X-Response-Time', Date.now() - now)
return response
}
}