File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 1
1
export type DatabaseCode =
2
+ | string
2
3
| number
3
4
| {
4
5
code : number
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { Kysely } from 'kysely'
10
10
import { SQLDatabase } from '../@types/SQLDatabase'
11
11
import { createDBConnection } from '../functions/createDBConnection'
12
12
import { getRemoteHentai } from '../functions/getRemoteHentai'
13
+ import { parseUrl } from "../functions/parseUrl" ;
13
14
14
15
const fetchQueue = new PQueue ( {
15
16
concurrency : 8 ,
@@ -42,7 +43,7 @@ export const fetch = async (entryPoint: string) => {
42
43
const chunkFile = path . join ( prebuiltChunkDirectory , `chunk-${ i + 1 } .json` )
43
44
await fs . promises . writeFile (
44
45
chunkFile ,
45
- JSON . stringify ( chunk . map ( o => ( typeof o === 'number' ? o : o . code ) ) )
46
+ JSON . stringify ( chunk . map ( o => ( typeof o === 'number' ? o : typeof o === 'string' ? parseUrl ( o ) : o . code ) ) )
46
47
)
47
48
} )
48
49
)
@@ -87,7 +88,7 @@ export const fetch = async (entryPoint: string) => {
87
88
const orderedHentai = codes
88
89
. map ( code => {
89
90
try {
90
- const targetCode = typeof code === 'number' ? code : code . code
91
+ const targetCode = typeof code === 'number' ? code : typeof code === 'string' ? parseUrl ( code ) : code . code
91
92
const targetHentai : Hentai = JSON . parse (
92
93
fs
93
94
. readFileSync ( path . join ( hentaiDirectory , `${ targetCode } .json` ) )
Original file line number Diff line number Diff line change
1
+ export const parseUrl = ( input : string ) => {
2
+ const matcher = input . match ( / h t t p s ? : \/ \/ n h e n t a i .n e t \/ g \/ ( \d + ) \/ ? / )
3
+ if ( matcher !== null && Number . isInteger ( Number ( matcher [ 1 ] ) ) )
4
+ return Number ( matcher [ 1 ] )
5
+ else
6
+ throw new Error ( "Cannot parse " + input )
7
+ }
You can’t perform that action at this time.
0 commit comments