Skip to content

Commit

Permalink
[script]: Add script to update HOST_CURL and integrate into package…
Browse files Browse the repository at this point in the history
….json

- Added `scripts/update-host-curl.ts` to automate updating the `HOST_CURL` constant in `src/constants.ts`.
- Integrated the new script into `package.json` with the command `update:host-curl`.
- Added `@types/bun` dependency to `package.json`.
  • Loading branch information
tachibana-shin committed Sep 20, 2024
1 parent a1ef7ab commit bee0c0c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"quasar": "quasar",
"icongenie": "icongenie generate -m pwa -i public/favicon.png -b meta/app_bg@1024x500-blured.png --png-color 000 --splashscreen-color 000 --skip-trim",
"gen-md-screenshot": "tsx ./scripts/gen-md-screenshot.ts",
"update:host-curl": "bun run scripts/update-host-curl.ts",
"release": "tsx scripts/release.ts",
"release:pwa": "bumpp package.json --commit \"(chore): release PWA %s\" --tag \"pwa-v%s\" --push",
"ci": "bun run format && bun run lint --fix && bun run typing"
Expand Down Expand Up @@ -109,6 +110,7 @@
"@quasar/cli": "^2.4.1",
"@quasar/icongenie": "^4.0.0",
"@tachibana-shin/eslint-config": "1.0.7",
"@types/bun": "^1.1.9",
"@types/group-array": "^1.0.1",
"@types/js-cookie": "^3.0.2",
"@types/lz-string": "^1.3.34",
Expand Down
53 changes: 53 additions & 0 deletions scripts/update-host-curl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// <reference types="@types/bun" />
import { resolve } from "path"

import { $ } from "bun"

const { url } = await fetch(
"\x68\x74\x74\x70\x73\x3a\x2f\x2f\x62\x69\x74\x2e\x6c\x79\x2f\x61\x6e\x69\x6d\x65\x76\x69\x65\x74\x73\x75\x62\x74\x76",
{
referrer: "manual"
}
)

// url to array byte
const charCodes =
"[\n " +
url
.replace(/https?:\/{2}/, "")
.replace(/\/$/, "")
.split("")
.map((char) => char.charCodeAt(0))
.join(", ") +
"\n]"

const content = await Bun.file(
resolve(import.meta.dirname ?? "", "../src/constants.ts")
).text()

const indexStart = content.indexOf("// @host")
const indexStop = content.indexOf("// @end")

const newContent =
content.slice(0, indexStart) +
`// @host
export const HOST_CURL = ${charCodes}
.map((val) => String.fromCharCode(val))
.join("")
// @end` +
content.slice(indexStop)

await Bun.write(
Bun.file(resolve(import.meta.dirname ?? "", "../src/constants.ts")),
newContent
)

if (newContent !== content) {
// git commit
await $`git add src/constants.ts`
await $`git commit -m "[script]: Update \`HOST_CURL\``
await $`git pull --rebase`
await $`git push origin main`
}

export {}
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ export const TIMEOUT_GET_LAST_EP_VIEWING_IN_STORE = 5_000 // 5s

export const REGEXP_OLD_HOST_CURL = /animevietsub\.(?:\w+)/i

// @host
export const HOST_CURL = [
97, 110, 105, 109, 101, 118, 105, 101, 116, 115, 117, 98, 46, 117, 107
]
.map((val) => String.fromCharCode(val))
.join("")
// @end
export const C_URL =
[104, 116, 116, 112, 115, 58, 47, 47]
.map((val) => String.fromCharCode(val))
Expand Down

0 comments on commit bee0c0c

Please sign in to comment.