1
- import { type BaseCacheOption , type BaseInit , type CacheResponse , getCachedFunction , type TypedResponse } from '@dvcol/base-http-client' ;
1
+ import { type BaseCacheOption , type CacheResponse } from '@dvcol/base-http-client' ;
2
2
3
3
import { CacheRetention } from '@dvcol/common-utils/common/cache' ;
4
4
import { DateUtils } from '@dvcol/common-utils/common/date' ;
@@ -13,7 +13,7 @@ import {
13
13
type TmdbPaginatedData ,
14
14
type TmdbParamPagination ,
15
15
} from '@dvcol/tmdb-http-client/models' ;
16
- import { isResponseOk , TraktClient } from '@dvcol/trakt-http-client' ;
16
+ import { TraktClient } from '@dvcol/trakt-http-client' ;
17
17
18
18
import { TraktApiExtended } from '@dvcol/trakt-http-client/models' ;
19
19
@@ -58,21 +58,19 @@ import type {
58
58
} from '@dvcol/trakt-http-client/models' ;
59
59
60
60
import type { ImagePayload } from '~/models/poster.model' ;
61
- import type { ProgressItem } from '~/models/progress.model' ;
62
61
import type { SettingsAuth , UserSetting } from '~/models/trakt-service.model' ;
63
62
64
63
import { ErrorService } from '~/services/error.service' ;
65
64
import { LoadingBarService } from '~/services/loading-bar.service' ;
66
65
import { Logger } from '~/services/logger.service' ;
67
66
import { tmdbUsedApi } from '~/services/tmdb.used.api' ;
68
67
import { traktUsedApi } from '~/services/trakt-used.api' ;
69
- import { ExternaLinks } from '~/settings/external.links' ;
70
68
import { tmdbClientSettings } from '~/settings/tmdb.api' ;
71
69
import { traktClientSettings } from '~/settings/traktv.api' ;
72
70
import { useAuthSettingsStore } from '~/stores/settings/auth.store' ;
73
71
import { useUserSettingsStore } from '~/stores/settings/user.store' ;
74
72
import { CachePrefix , ChromeCacheStore } from '~/utils/cache.utils' ;
75
- import { cancellablePaginatedWriteJson , getSessionUser } from '~/utils/trakt-service.utils' ;
73
+ import { cancellablePaginatedWriteJson , getCachedProgressEndpoint , getSessionUser } from '~/utils/trakt-service.utils' ;
76
74
77
75
const shouldEvict = ( cache ?: CacheResponse < unknown > , date ?: string | number | Date ) : boolean => {
78
76
// no cache skip
@@ -353,42 +351,7 @@ export class TraktService {
353
351
return { data : await response . json ( ) , pagination : response . pagination } ;
354
352
}
355
353
356
- private static cachedProgress = getCachedFunction (
357
- // @ts -expect-error -- CancellablePromise extends promise
358
- async ( init ?: BaseInit ) : CancellablePromise < TypedResponse < ProgressItem [ ] > > => {
359
- const response = await fetch ( ExternaLinks . trakt . onDeck , {
360
- credentials : 'include' ,
361
- ...init ,
362
- } ) ;
363
-
364
- isResponseOk ( response ) ;
365
-
366
- const htmlString = await response . text ( ) ;
367
- const htmlDoc = new DOMParser ( ) . parseFromString ( htmlString , 'text/html' ) ;
368
- const data = Array . from ( htmlDoc . querySelectorAll < HTMLAnchorElement > ( 'a[class="watch"]' ) ) . map (
369
- a => ( { ...a . dataset } ) as unknown as ProgressItem ,
370
- ) ;
371
-
372
- return new Response ( JSON . stringify ( data ) ) as TypedResponse < ProgressItem [ ] > ;
373
- } ,
374
- {
375
- cache : this . caches . trakt ,
376
- retention : CacheRetention . Hour * 2 ,
377
- key : ( param , init ) => {
378
- return JSON . stringify ( {
379
- template : {
380
- method : 'GET' ,
381
- url : ExternaLinks . trakt . onDeck ,
382
- } ,
383
- param,
384
- init : {
385
- credentials : 'include' ,
386
- ...init ,
387
- } ,
388
- } ) ;
389
- } ,
390
- } ,
391
- ) ;
354
+ private static cachedProgress = getCachedProgressEndpoint ( this . caches . trakt ) ;
392
355
393
356
static progress = {
394
357
async onDeck ( ) {
0 commit comments