diff --git a/README.md b/README.md index 2eda9ab..7ae7dc6 100644 --- a/README.md +++ b/README.md @@ -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` @@ -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 @@ -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 diff --git a/index.js b/index.js index 7d7efe3..9de8902 100644 --- a/index.js +++ b/index.js @@ -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' @@ -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')) { @@ -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` @@ -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"}` @@ -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` @@ -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` @@ -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` @@ -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` @@ -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` @@ -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 -} +} \ No newline at end of file