mirror of
https://github.com/aleksilassila/reiverr.git
synced 2026-04-18 06:53:14 +02:00
feat: Onboarding
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import createClient from 'openapi-fetch';
|
||||
import { get } from 'svelte/store';
|
||||
import type { operations, paths } from './tmdb.generated';
|
||||
import type { operations as operations4, paths as paths4 } from './tmdb4.generated';
|
||||
import { TMDB_API_KEY, TMDB_BACKDROP_SMALL } from '../../constants';
|
||||
import { settings } from '../../stores/settings.store';
|
||||
import type { TitleType } from '../../types';
|
||||
@@ -62,10 +63,23 @@ export class TmdbApi implements Api<paths> {
|
||||
});
|
||||
}
|
||||
|
||||
static getClient4() {
|
||||
return createClient<paths4>({
|
||||
baseUrl: 'https://api.themoviedb.org',
|
||||
headers: {
|
||||
Authorization: `Bearer ${TMDB_API_KEY}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getClient() {
|
||||
return TmdbApi.getClient();
|
||||
}
|
||||
|
||||
getClient4() {
|
||||
return TmdbApi.getClient4();
|
||||
}
|
||||
|
||||
getSessionId() {
|
||||
return get(appState)?.user?.settings.tmdb.sessionId;
|
||||
}
|
||||
@@ -248,8 +262,7 @@ export class TmdbApi implements Api<paths> {
|
||||
|
||||
const top100: TmdbMovieSmall[] = await Promise.all(
|
||||
[...Array(5).keys()].map((i) =>
|
||||
this.getClient()
|
||||
// @ts-ignore
|
||||
this.getClient4()
|
||||
?.GET('/4/account/{account_object_id}/movie/recommendations', {
|
||||
params: {
|
||||
path: {
|
||||
@@ -324,8 +337,7 @@ export class TmdbApi implements Api<paths> {
|
||||
|
||||
const top100: TmdbSeriesSmall[] = await Promise.all(
|
||||
[...Array(5).keys()].map((i) =>
|
||||
this.getClient()
|
||||
// @ts-ignore
|
||||
this.getClient4()
|
||||
?.GET('/4/account/{account_object_id}/tv/recommendations', {
|
||||
params: {
|
||||
path: {
|
||||
@@ -377,6 +389,36 @@ export class TmdbApi implements Api<paths> {
|
||||
mostPopular
|
||||
};
|
||||
};
|
||||
|
||||
getConnectAccountLink = () =>
|
||||
this.getClient4()
|
||||
?.POST('/4/auth/request_token', {})
|
||||
.then((res) => res.data);
|
||||
|
||||
getAccountAccessToken = (requestToken: string) =>
|
||||
this.getClient4()
|
||||
?.POST('/4/auth/access_token', {
|
||||
body: {
|
||||
// @ts-ignore
|
||||
request_token: requestToken
|
||||
}
|
||||
})
|
||||
.then((res) => res.data);
|
||||
|
||||
getAccountDetails = () => {
|
||||
const userId = this.getUserId();
|
||||
if (!userId) return undefined;
|
||||
|
||||
return this.getClient()
|
||||
?.GET('/3/account/{account_id}', {
|
||||
params: {
|
||||
path: {
|
||||
account_id: Number(userId)
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((res) => res.data);
|
||||
};
|
||||
}
|
||||
|
||||
export const tmdbApi = new TmdbApi();
|
||||
|
||||
Reference in New Issue
Block a user