mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-03-25 18:56:20 +00:00
Basic Jellyseerr discover page
This commit is contained in:
@@ -18,6 +18,7 @@ import {IssueStatus, IssueType} from "@/utils/jellyseerr/server/constants/issue"
|
||||
import Issue from "@/utils/jellyseerr/server/entity/Issue";
|
||||
import {RTRating} from "@/utils/jellyseerr/server/api/rating/rottentomatoes";
|
||||
import {writeErrorLog} from "@/utils/log";
|
||||
import DiscoverSlider from "@/utils/jellyseerr/server/entity/DiscoverSlider";
|
||||
|
||||
interface SearchParams {
|
||||
query: string,
|
||||
@@ -27,8 +28,8 @@ interface SearchParams {
|
||||
|
||||
interface SearchResults {
|
||||
page: number,
|
||||
total_pages: number,
|
||||
total_results: number;
|
||||
totalPages: number,
|
||||
totalResults: number;
|
||||
results: Results[];
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ export const clearJellyseerrStorageData = () => {
|
||||
storage.delete(JELLYSEERR_COOKIES);
|
||||
}
|
||||
|
||||
enum Endpoints {
|
||||
export enum Endpoints {
|
||||
STATUS = "/status",
|
||||
API_V1 = "/api/v1",
|
||||
SEARCH = "/search",
|
||||
@@ -49,9 +50,16 @@ enum Endpoints {
|
||||
RATINGS = "/ratings",
|
||||
ISSUE = "/issue",
|
||||
TV = "/tv",
|
||||
SETTINGS = "/settings",
|
||||
DISCOVER = "/discover",
|
||||
DISCOVER_TRENDING = DISCOVER + "/trending",
|
||||
DISCOVER_MOVIES = DISCOVER + "/movies",
|
||||
DISCOVER_TV = DISCOVER + TV,
|
||||
AUTH_JELLYFIN = "/auth/jellyfin",
|
||||
}
|
||||
|
||||
export type DiscoverEndpoint = Endpoints.DISCOVER_TRENDING | Endpoints.DISCOVER_MOVIES | Endpoints.DISCOVER_TV;
|
||||
|
||||
export type TestResult = {
|
||||
isValid: true;
|
||||
requiresPass: boolean;
|
||||
@@ -115,7 +123,9 @@ export class JellyseerrApi {
|
||||
};
|
||||
})
|
||||
.catch((e) => {
|
||||
console.error("Failed to test jellyseerr server url", e)
|
||||
const msg = "Failed to test jellyseerr server url";
|
||||
toast.error(msg)
|
||||
console.error(msg, e)
|
||||
return {
|
||||
isValid: false,
|
||||
requiresPass: false
|
||||
@@ -137,6 +147,16 @@ export class JellyseerrApi {
|
||||
})
|
||||
}
|
||||
|
||||
async discoverSettings(): Promise<DiscoverSlider[]> {
|
||||
return this.axios?.get<DiscoverSlider[]>(Endpoints.API_V1 + Endpoints.SETTINGS + Endpoints.DISCOVER)
|
||||
.then(({data}) => data)
|
||||
}
|
||||
|
||||
async discover(endpoint: DiscoverEndpoint, params: any): Promise<SearchResults> {
|
||||
return this.axios?.get<SearchResults>(Endpoints.API_V1 + endpoint, { params })
|
||||
.then(({data}) => data)
|
||||
}
|
||||
|
||||
async search(params: SearchParams): Promise<SearchResults> {
|
||||
const response = await this.axios?.get<SearchResults>(Endpoints.API_V1 + Endpoints.SEARCH, {params})
|
||||
return response?.data
|
||||
@@ -204,15 +224,19 @@ export class JellyseerrApi {
|
||||
return response;
|
||||
},
|
||||
(error: AxiosError) => {
|
||||
const errorMsg = "Jellyseerr response error:";
|
||||
const errorMsg = "Jellyseerr response error";
|
||||
console.error(errorMsg, error, error.response?.data);
|
||||
writeErrorLog(
|
||||
errorMsg + ` ${error.toString()}\n` +
|
||||
errorMsg + `\n` +
|
||||
`error: ${error.toString()}\n` +
|
||||
`url: ${error?.config?.url}\n` +
|
||||
`data:\n` +
|
||||
JSON.stringify(error.response?.data)
|
||||
);
|
||||
if (error.status === 403) {
|
||||
clearJellyseerrStorageData()
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user