init commit

This commit is contained in:
Seya
2024-07-01 11:46:49 +07:00
commit 0a2560cbbe
4 changed files with 100 additions and 0 deletions

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 sglkc
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

10
README.md Normal file
View File

@@ -0,0 +1,10 @@
# Honkai: Star Rail Daily Check Inator
How to use:
1. Fork this repo
2. Open the forked repository
3. Go to Settings > Secrets and variables > Actions
4. Click on New repository secrets
5. Insert COOKIE on Name field
6. Copy your cookie on Secret field

55
index.js Normal file
View File

@@ -0,0 +1,55 @@
#!/usr/bin/env node
async function main() {
const cookie = process.env.COOKIE
if (!cookie) {
throw new Error('COOKIE environment variable not set!')
}
const url = new URL('https://sg-public-api.hoyolab.com/event/luna/os/sign')
url.searchParams.set('act_id', 'e202303301540311')
url.searchParams.set('lang', 'en-us')
const headers = new Headers()
headers.set('accept', 'application/json, text/plain, */*')
headers.set('accept-encoding', 'gzip, deflate, br, zstd')
headers.set('accept-language', 'en-US,en;q=0.6')
headers.set('connection', 'keep-alive')
headers.set('origin', 'https://act.hoyolab.com')
headers.set('referrer', 'https://act.hoyolab.com')
headers.set('content-type', 'application.json;charset=UTF-8')
headers.set('cookie', cookie)
headers.set('sec-ch-ua', '"Not/A)Brand";v="8", "Chromium";v="126", "Brave";v="126"')
headers.set('sec-ch-ua-mobile', '?0')
headers.set('sec-ch-ua-platform', '"Linux"')
headers.set('sec-fetch-dest', 'empty')
headers.set('sec-fech-mode', 'cors')
headers.set('sec-fetch-site', 'same-site')
headers.set('sec-gpc', '1')
headers.set('user-agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36')
const res = await fetch(url, { method: 'POST', headers })
const json = await res.json()
if (json.message === 'Not logged in' || json.retcode === -100) {
throw new Error('Not logged in. Check cookie.')
}
if (json.message.includes('already') || json.retcode === -5003) {
console.info('Already checked in for today. If this persists, check cookie.')
return
}
if (json.message === 'OK' || json.retcode === 0) {
console.info('Successfully checked in!')
return
}
}
await main()

14
package.json Normal file
View File

@@ -0,0 +1,14 @@
{
"name": "hsr-login",
"version": "1.0.0",
"description": "Honkai: Star Rail automatic daily check-in",
"private": true,
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "sglkc",
"license": "MIT"
}