Skip to content

Commit 1e0ee52

Browse files
committed
feat(tmdb): create v4 endpoint
1 parent 3b49030 commit 1e0ee52

21 files changed

+693
-51
lines changed

scripts/manifest.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ import { getDirName, isDev, port, resolveParent } from './utils';
77
import type { Manifest } from 'webextension-polyfill';
88

99
export const Endpoints = {
10-
Production: 'https://api.trakt.tv',
11-
Staging: 'https://api-staging.trakt.tv',
10+
trakt: {
11+
Production: 'https://api.trakt.tv',
12+
Staging: 'https://api-staging.trakt.tv',
13+
},
14+
tvdb: 'https://api4.thetvdb.co',
15+
tmdb: {
16+
api: 'https://api.themoviedb.org',
17+
redirect: 'https://www.themoviedb.org',
18+
},
1219
} as const;
1320

1421
export const manifest: Manifest.WebExtensionManifest = {
@@ -38,10 +45,10 @@ export const manifest: Manifest.WebExtensionManifest = {
3845
web_accessible_resources: [
3946
{
4047
resources: ['/views/options/index.html'],
41-
matches: [`${Endpoints.Production}/*`, `${Endpoints.Staging}/*`],
48+
matches: [`${Endpoints.trakt.Production}/*`, `${Endpoints.trakt.Staging}/*`, `${Endpoints.tvdb}/*`, `${Endpoints.tmdb.redirect}/*`],
4249
},
4350
],
44-
host_permissions: [`${Endpoints.Production}/*`, `${Endpoints.Staging}/*`],
51+
host_permissions: [`${Endpoints.trakt.Production}/*`, `${Endpoints.trakt.Staging}/*`, `${Endpoints.tvdb}/*`, `${Endpoints.tmdb.api}/*`],
4552
content_security_policy: {
4653
// Adds localhost for vite hot reload
4754
extension_pages: isDev

src/models/tmdb/tmdb-client.model.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ export type TmdbApiPagination = {
4747
total_results?: number;
4848
};
4949

50-
export type TmdbApiResponsePageData<T = unknown> = TmdbApiPagination & {
51-
results: T[];
52-
};
50+
export type TmdbApiResponsePageData<T = unknown, C = Record<string, string>> = Partial<TmdbApiResponseData> &
51+
TmdbApiPagination & {
52+
results: T[];
53+
} & C;
5354

54-
export type TmdbPaginatedData<T = unknown> = {
55+
export type TmdbPaginatedData<T = unknown, C = unknown> = {
56+
common?: C;
5557
data: T[];
5658
pagination: TmdbApiPagination;
5759
};
@@ -62,6 +64,8 @@ export type TmdbApiQuery<T = unknown> = BaseQuery<BaseRequest, T>;
6264
export type TmdbApiTemplateOptions = BaseTemplateOptions & {
6365
/** If the method requires user authentication */
6466
auth?: boolean;
67+
/** The api version (3 or 4) */
68+
version: number | string;
6569
};
6670

6771
export type TmdbApiTemplate<Parameter extends TmdbApiParam = TmdbApiParam> = BaseTemplate<Parameter, TmdbApiTemplateOptions>;

src/models/tmdb/tmdb-entity.model.ts

+6
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ export type TmdbKeyword = {
5757
id: number;
5858
name: string;
5959
};
60+
61+
export type TmdbAccountRating = {
62+
/** Creation timestamp in ISO 8601 format (YYYY-MM-DD'T'hh:mm:ss.sssZ) */
63+
created_at: string;
64+
value: number;
65+
};

src/models/tmdb/tmdb-list.model.ts

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
1-
export type TmdbList = {
2-
account_object_id: string;
3-
adult: number;
4-
average_rating: number;
5-
backdrop_path: string;
6-
/** UTC date when the list was created (YYYY-MM-DD HH:mm:ss UTC) */
7-
created_at: string;
8-
description: string;
9-
featured: number;
1+
import type { TmdbUser } from '~/models/tmdb/tmdb-user.model';
2+
3+
type BaseTmdbList = {
104
id: number;
115
/** The ISO 3166-1 code of the country */
126
iso_3166_1: string;
137
/** The ISO 639-1 code of the language */
148
iso_639_1: string;
159
name: string;
16-
number_of_items: number;
10+
average_rating: number;
11+
description: string;
1712
poster_path: string;
13+
backdrop_path: string;
1814
public: number;
1915
revenue: number;
2016
runtime: string;
2117
sort_by: number;
18+
};
19+
20+
export type TmdbAccountListV4 = BaseTmdbList & {
21+
account_object_id: string;
22+
adult: number;
23+
/** UTC date when the list was created (YYYY-MM-DD HH:mm:ss UTC) */
24+
created_at: string;
25+
featured: number;
26+
number_of_items: number;
27+
sort_by: number;
2228
/** UTC date when the list was updated (YYYY-MM-DD HH:mm:ss UTC) */
2329
updated_at: string;
2430
};
31+
32+
export type TmdbListV4 = BaseTmdbList & {
33+
comments: Record<string, string>;
34+
created_by: TmdbUser;
35+
item_count: number;
36+
object_ids: Record<string, string>;
37+
sort_by: string;
38+
39+
// page: number;
40+
// results: TmdbMovieShort[];
41+
// total_pages: number;
42+
// total_results: number;
43+
};

src/models/tmdb/tmdb-movie.model.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import type { TmdbCollection } from '~/models/tmdb/tmdb-collection.model';
2-
import type { EntityTypes, Extended, Short, TmdbCompany, TmdbCountry, TmdbGenre, TmdbLanguage } from '~/models/tmdb/tmdb-entity.model';
2+
import type {
3+
EntityTypes,
4+
Extended,
5+
Short,
6+
TmdbAccountRating,
7+
TmdbCompany,
8+
TmdbCountry,
9+
TmdbGenre,
10+
TmdbLanguage,
11+
} from '~/models/tmdb/tmdb-entity.model';
312

413
export type TmdbMovieShort = {
14+
media_type?: 'movie';
515
adult: boolean;
616
backdrop_path: string;
717
genre_ids: number[];
@@ -39,3 +49,7 @@ export type TmdbMovie<T extends EntityTypes = Short> = T extends Extended
3949
: T extends Short
4050
? TmdbMovieShort
4151
: TmdbMovieShort | TmdbMovieExtended;
52+
53+
export type TmdbMovieRating = TmdbMovie & {
54+
account_rating: TmdbAccountRating;
55+
};

src/models/tmdb/tmdb-show.model.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import type { EntityTypes, Extended, Short, TmdbCompany, TmdbCountry, TmdbGenre, TmdbLanguage, TmdbNetwork } from '~/models/tmdb/tmdb-entity.model';
1+
import type {
2+
EntityTypes,
3+
Extended,
4+
Short,
5+
TmdbAccountRating,
6+
TmdbCompany,
7+
TmdbCountry,
8+
TmdbGenre,
9+
TmdbLanguage,
10+
TmdbNetwork,
11+
} from '~/models/tmdb/tmdb-entity.model';
212
import type { TmdbEpisode } from '~/models/tmdb/tmdb-episode.model';
313
import type { TmdbSeason } from '~/models/tmdb/tmdb-season.model';
414

@@ -11,6 +21,7 @@ export type TmdbPersonShow = {
1121
};
1222

1323
export type TmdbShowShort = {
24+
media_type?: 'tv';
1425
adult: boolean;
1526
backdrop_path: string;
1627
genre_ids: number[];
@@ -55,3 +66,7 @@ export type TmdbShow<T extends EntityTypes = Short> = T extends Extended
5566
: T extends Short
5667
? TmdbShowShort
5768
: TmdbShowShort | TmdbShowExtended;
69+
70+
export type TmdbShowRating = TmdbShowShort & {
71+
account_rating: TmdbAccountRating;
72+
};

src/models/tmdb/tmdb-user.model.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export type TmdbUser = {
2+
id: string;
3+
name: string;
4+
username: string;
5+
avatar_path: string;
6+
gravatar_hash: string;
7+
};

src/services/common/base-client.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ describe('base-client.ts', () => {
332332
it('should ignore cache if cache expired using store retention', async () => {
333333
expect.assertions(2);
334334

335-
const _cacheStore: CacheStore = new Map();
335+
const _cacheStore: CacheStore<Response> = new Map();
336336
_cacheStore.retention = 15;
337337
const _client = new TestableBaseClient({ cacheStore: _cacheStore });
338338

0 commit comments

Comments
 (0)