Skip to content

Commit dbbef40

Browse files
update dependencies
1 parent a1ba305 commit dbbef40

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

.github/workflows/update-token.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
grab-token:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- name: Checkout Repositori
12+
- name: Checkout Repository
1313
uses: actions/checkout@v3
1414

1515
- name: Setup Node.js
@@ -25,10 +25,19 @@ jobs:
2525
- name: Run Scraper
2626
run: node scraper.js
2727

28-
- name: Commit & Push Token ke Repo
28+
# Upload screenshot artifact if node scraper.js FAILS (exit code 1)
29+
- name: Upload Error Screenshot
30+
if: failure()
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: debug-screenshot
34+
path: error.png
35+
36+
- name: Commit & Push Token to Repo
37+
if: success()
2938
run: |
3039
git config --global user.name 'github-actions[bot]'
3140
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
3241
git add kurama_token.txt
33-
git commit -m "Auto-update token Kuramanime" || echo "Token is still the same"
42+
git commit -m "Auto-update Kuramanime token" || echo "Token is still the same"
3443
git push

scraper.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,36 @@ puppeteer.use(StealthPlugin());
77
(async () => {
88
const browser = await puppeteer.launch({
99
headless: "new",
10-
args: ['--no-sandbox', '--disable-setuid-sandbox']
10+
// Add window size to ensure the page renders properly
11+
args: ['--no-sandbox', '--disable-setuid-sandbox', '--window-size=1280,720']
1112
});
1213

1314
const page = await browser.newPage();
15+
await page.setViewport({ width: 1280, height: 720 });
1416
let token = "";
1517

1618
await page.setRequestInterception(true);
1719
page.on('request', request => {
20+
// 1. Check HTTP Headers
1821
const headers = request.headers();
19-
if (headers['authorization'] && headers['authorization'].includes('Bearer')) {
22+
if (headers['authorization']) {
2023
token = headers['authorization'].replace('Bearer ', '').trim();
21-
console.log('Token successfully captured!');
24+
}
25+
26+
// 2. Check POST Body (Form-Data or JSON)
27+
const postData = request.postData();
28+
if (request.method() === 'POST' && postData) {
29+
if (postData.includes('authorization=')) {
30+
const params = new URLSearchParams(postData);
31+
if (params.get('authorization')) {
32+
token = params.get('authorization');
33+
}
34+
} else {
35+
try {
36+
const json = JSON.parse(postData);
37+
if (json.authorization) token = json.authorization;
38+
} catch(e) {}
39+
}
2240
}
2341
request.continue();
2442
});
@@ -30,15 +48,22 @@ puppeteer.use(StealthPlugin());
3048
waitUntil: 'networkidle2',
3149
timeout: 60000
3250
});
51+
52+
// Wait an extra 5 seconds to let leviathan.js build and send the token
53+
await new Promise(r => setTimeout(r, 5000));
54+
3355
} catch (e) {
34-
console.log('Navigation timeout (Ignore if token already received).');
56+
console.log('Warning: Navigation timeout, checking if token was captured...');
3557
}
3658

37-
if (token) {
59+
if (token && token.length > 10) {
3860
fs.writeFileSync('kurama_token.txt', token);
39-
console.log('Token successfully saved to kurama_token.txt');
61+
console.log(`SUCCESS: Token retrieved -> ${token.substring(0, 15)}...`);
4062
} else {
4163
console.log('FAIL: Token not found.');
64+
// Take a screenshot of the browser for debugging purposes
65+
await page.screenshot({ path: 'error.png', fullPage: true });
66+
console.log('Failure screenshot saved as error.png');
4267
process.exit(1);
4368
}
4469

0 commit comments

Comments
 (0)