@@ -5,13 +5,7 @@ import { getJsonWriter } from '@dvcol/common-utils/common/save';
5
5
6
6
import { isResponseOk } from '@dvcol/trakt-http-client' ;
7
7
8
- import {
9
- TraktApiExtended ,
10
- type TraktApiParamsExtended ,
11
- type TraktApiParamsPagination ,
12
- type TraktApiResponse ,
13
- type TraktClientPagination ,
14
- } from '@dvcol/trakt-http-client/models' ;
8
+ import { TraktApiExtended , type TraktApiParamsExtended , type TraktApiParamsPagination , type TraktApiResponse } from '@dvcol/trakt-http-client/models' ;
15
9
16
10
import { getCookie } from '@dvcol/web-extension-utils/chrome/cookie' ;
17
11
@@ -24,26 +18,29 @@ import type { JsonWriterOptions } from '@dvcol/common-utils/common/save';
24
18
25
19
import type { CancellablePromise } from '@dvcol/common-utils/http/fetch' ;
26
20
21
+ import type { StorePagination } from '~/models/pagination.model' ;
22
+
27
23
import type { ProgressItem } from '~/models/progress.model' ;
28
24
29
25
import { PageSize } from '~/models/page-size.model' ;
30
26
31
27
import { ExternaLinks } from '~/settings/external.links' ;
32
28
33
29
import { WebConfig } from '~/settings/web.config' ;
30
+ import { clearAssign } from '~/utils/vue.utils' ;
34
31
35
32
type PaginatedQuery = TraktApiParamsExtended & TraktApiParamsPagination ;
36
33
export const paginatedWriteJson = async < Q extends PaginatedQuery = PaginatedQuery , T extends RecursiveRecord = RecursiveRecord > (
37
34
fetch : ( query : Q ) => Promise < TraktApiResponse < T > > ,
38
35
query : Q = { extended : TraktApiExtended . Full , pagination : { limit : PageSize . p1000 } } as Q ,
39
36
writerOptions ?: JsonWriterOptions ,
40
37
cancel ?: Ref < boolean > ,
41
- pagination ?: Partial < TraktClientPagination > ,
38
+ pagination ?: StorePagination ,
42
39
) : Promise < FileSystemFileHandle > => {
43
40
let response$ = fetch ( query ) ;
44
41
const writer = await getJsonWriter ( writerOptions ) ;
45
42
let response = await response$ ;
46
- if ( pagination ) Object . assign ( pagination , response . pagination ) ;
43
+ if ( pagination ) clearAssign ( pagination , response . pagination ) ;
47
44
let data = await response . json ( ) ;
48
45
49
46
/* eslint-disable no-await-in-loop */
@@ -52,7 +49,7 @@ export const paginatedWriteJson = async <Q extends PaginatedQuery = PaginatedQue
52
49
while ( ! cancel ?. value && response . pagination ?. page !== undefined && response . pagination . page < response . pagination . pageCount ) {
53
50
response$ = fetch ( { ...query , pagination : { ...query . pagination , page : response . pagination . page + 1 } } ) ;
54
51
response = await response$ ;
55
- if ( pagination ) Object . assign ( pagination , response . pagination ) ;
52
+ if ( pagination ) clearAssign ( pagination , response . pagination ) ;
56
53
data = await response . json ( ) ;
57
54
await writer . write ( data ) ;
58
55
}
@@ -63,14 +60,14 @@ export const paginatedWriteJson = async <Q extends PaginatedQuery = PaginatedQue
63
60
return writer . handle ;
64
61
} ;
65
62
66
- export type CancellableWritePromise < T > = Promise < T > & { cancel : ( ) => Promise < T > ; pagination : Partial < TraktClientPagination > } ;
63
+ export type CancellableWritePromise < T > = Promise < T > & { cancel : ( ) => Promise < T > ; pagination : StorePagination } ;
67
64
export const cancellablePaginatedWriteJson = < Q extends PaginatedQuery = PaginatedQuery , T extends RecursiveRecord = RecursiveRecord > (
68
65
fetch : ( query : Q ) => Promise < TraktApiResponse < T > > ,
69
66
query : Q = { extended : TraktApiExtended . Full , pagination : { limit : PageSize . p1000 } } as Q ,
70
67
writerOptions ?: JsonWriterOptions & { separator ?: string } ,
71
68
) : CancellableWritePromise < FileSystemFileHandle > => {
72
69
const cancel = ref ( false ) ;
73
- const pagination = reactive < Partial < TraktClientPagination > > ( { } ) ;
70
+ const pagination = reactive < StorePagination > ( { } ) ;
74
71
const promise = paginatedWriteJson ( fetch , query , writerOptions , cancel , pagination ) as CancellableWritePromise < FileSystemFileHandle > ;
75
72
promise . cancel = ( ) => {
76
73
cancel . value = true ;
0 commit comments