diff --git a/bun.lockb b/bun.lockb index fc0936a92..5e53c761c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/commons/src/@types/DatabaseCode.ts b/commons/src/@types/DatabaseCode.ts index 586d62303..3d3db538a 100644 --- a/commons/src/@types/DatabaseCode.ts +++ b/commons/src/@types/DatabaseCode.ts @@ -1,4 +1,5 @@ export type DatabaseCode = + | string | number | { code: number diff --git a/scraper/src/commands/fetch.ts b/scraper/src/commands/fetch.ts index 9b45e7bbf..c001f3229 100644 --- a/scraper/src/commands/fetch.ts +++ b/scraper/src/commands/fetch.ts @@ -10,6 +10,7 @@ import { Kysely } from 'kysely' import { SQLDatabase } from '../@types/SQLDatabase' import { createDBConnection } from '../functions/createDBConnection' import { getRemoteHentai } from '../functions/getRemoteHentai' +import {parseUrl} from "../functions/parseUrl"; const fetchQueue = new PQueue({ concurrency: 8, @@ -42,7 +43,7 @@ export const fetch = async (entryPoint: string) => { const chunkFile = path.join(prebuiltChunkDirectory, `chunk-${i + 1}.json`) await fs.promises.writeFile( chunkFile, - JSON.stringify(chunk.map(o => (typeof o === 'number' ? o : o.code))) + JSON.stringify(chunk.map(o => (typeof o === 'number' ? o : typeof o === 'string' ? parseUrl(o) : o.code))) ) }) ) @@ -87,7 +88,7 @@ export const fetch = async (entryPoint: string) => { const orderedHentai = codes .map(code => { try { - const targetCode = typeof code === 'number' ? code : code.code + const targetCode = typeof code === 'number' ? code : typeof code === 'string' ? parseUrl(code) : code.code const targetHentai: Hentai = JSON.parse( fs .readFileSync(path.join(hentaiDirectory, `${targetCode}.json`)) diff --git a/scraper/src/functions/parseUrl.ts b/scraper/src/functions/parseUrl.ts new file mode 100644 index 000000000..9f9c64acf --- /dev/null +++ b/scraper/src/functions/parseUrl.ts @@ -0,0 +1,7 @@ +export const parseUrl = (input: string) => { + const matcher = input.match(/https?:\/\/nhentai.net\/g\/(\d+)\/?/) + if (matcher !== null && Number.isInteger(Number(matcher[1]))) + return Number(matcher[1]) + else + throw new Error("Cannot parse " + input) +} \ No newline at end of file diff --git a/web/package.json b/web/package.json index 19f63f2f3..c38b78705 100644 --- a/web/package.json +++ b/web/package.json @@ -42,7 +42,7 @@ "nanostores": "0.11.3", "p-queue": "8.0.1", "set-cookie-parser": "2.7.0", - "sharp": "0.33.1", + "sharp": "0.33.5", "trpc-svelte-query": "2.1.0", "zod": "3.23.8" },