feat: Onboarding

This commit is contained in:
Aleksi Lassila
2024-05-25 00:28:13 +03:00
parent 47845d1dd9
commit dc1b25dc22
22 changed files with 2320 additions and 65 deletions

View File

@@ -8,6 +8,7 @@ import axios from 'axios';
import { log } from '../../utils';
export type JellyfinItem = components['schemas']['BaseItemDto'];
export type JellyfinUser = components['schemas']['UserDto'];
type Type = 'movie' | 'series';
@@ -503,7 +504,7 @@ export class JellyfinApi implements Api<paths> {
getJellyfinUsers = async (
baseUrl: string | undefined = undefined,
apiKey: string | undefined = undefined
): Promise<components['schemas']['UserDto'][]> =>
): Promise<JellyfinUser[]> =>
axios
.get((baseUrl || this.getBaseUrl()) + '/Users', {
headers: {

View File

@@ -212,7 +212,7 @@ export class RadarrApi implements Api<paths> {
})
.then((res) => res.response.ok) || Promise.resolve(false);
getRadarrHealth = async (
getHealth = async (
baseUrl: string | undefined = undefined,
apiKey: string | undefined = undefined
) =>
@@ -222,8 +222,7 @@ export class RadarrApi implements Api<paths> {
'X-Api-Key': apiKey || this.getSettings()?.apiKey
}
})
.then((res) => res.status === 200)
.catch(() => false);
.catch((e) => e.response);
getRootFolders = async (
baseUrl: string | undefined = undefined,

View File

@@ -5,6 +5,7 @@ import { appState } from '../../stores/app-state.store';
import type { Api } from '../api.interface';
export type ReiverrUser = components['schemas']['UserDto'];
export type ReiverrSettings = ReiverrUser['settings'];
export class ReiverrApi implements Api<paths> {
getClient(basePath?: string, _token?: string) {
@@ -33,6 +34,18 @@ export class ReiverrApi implements Api<paths> {
}
});
}
updateUser = (user: ReiverrUser) =>
this.getClient()
?.PUT('/user/{id}', {
params: {
path: {
id: get(appState).user?.id as string
}
},
body: user
})
.then((res) => res.data);
}
export const reiverrApi = new ReiverrApi();

View File

@@ -5,17 +5,18 @@
export interface paths {
"/api/user": {
"/user": {
get: operations["UserController_getProfile"];
post: operations["UserController_create"];
};
"/api/user/{id}": {
"/user/{id}": {
get: operations["UserController_findById"];
put: operations["UserController_updateUser"];
};
"/api/auth": {
"/auth": {
post: operations["AuthController_signIn"];
};
"/api": {
"/": {
get: operations["AppController_getHello"];
};
}
@@ -59,6 +60,7 @@ export interface components {
id: string;
name: string;
isAdmin: boolean;
onboardingDone?: boolean;
settings: components["schemas"]["Settings"];
};
CreateUserDto: {
@@ -66,6 +68,11 @@ export interface components {
password: string;
isAdmin: boolean;
};
UpdateUserDto: {
name?: string;
onboardingDone?: boolean;
settings?: components["schemas"]["Settings"];
};
SignInDto: {
name: string;
password: string;
@@ -148,6 +155,26 @@ export interface operations {
};
};
};
UserController_updateUser: {
parameters: {
path: {
id: string;
};
};
requestBody: {
content: {
"application/json": components["schemas"]["UpdateUserDto"];
};
};
responses: {
/** @description User updated */
200: {
content: {
"application/json": components["schemas"]["UserDto"];
};
};
};
};
AuthController_signIn: {
requestBody: {
content: {

View File

@@ -393,7 +393,7 @@ export class SonarrApi implements ApiAsync<paths> {
// }));
// };
getSonarrHealth = async (
getHealth = async (
baseUrl: string | undefined = undefined,
apiKey: string | undefined = undefined
) =>
@@ -403,8 +403,7 @@ export class SonarrApi implements ApiAsync<paths> {
'X-Api-Key': apiKey || this.getApiKey()
}
})
.then((res) => res.status === 200)
.catch(() => false);
.catch((e) => e.response);
_getSonarrRootFolders = async (
baseUrl: string | undefined = undefined,

View File

@@ -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();

1592
src/lib/apis/tmdb/tmdb4.generated.d.ts vendored Normal file

File diff suppressed because it is too large Load Diff