diff --git a/frontend/src/api/api.ts b/frontend/src/api/api.ts index 7ec0039..8f573bb 100644 --- a/frontend/src/api/api.ts +++ b/frontend/src/api/api.ts @@ -1,81 +1,44 @@ -import axios from "axios"; -import type { AxiosResponse } from "axios"; -import type { DownloadResponse, MediaItemResponse } from "@/api/interfaces"; - -const BASE_URL = "http://localhost:8000/api"; - -const api = axios.create({ - baseURL: BASE_URL, -}); - -async function get(url: string): Promise> { - return api.get(url); -} - -async function post(url: string, data: any): Promise> { - return api.post(url, data); -} - -export default function search( - query: string, - type: string -): Promise> { - return get(`/search?search_terms=${query}&type=${type}`); -} - -export async function getEpisodesInfo( - mediaId: number, - mediaSlug: string, - mediaType: string -): Promise { - const url = `/search/get_episodes_info?media_id=${mediaId}&media_slug=${mediaSlug}&type_media=${mediaType}`; - return fetch(`${BASE_URL}${url}`, { - method: "GET", - headers: { - "Content-Type": "text/event-stream", - }, - }); -} - -export async function getPreview( - mediaId: number, - mediaSlug: string, - mediaType: string -): Promise> { - const url = `/search/get_preview?media_id=${mediaId}&media_slug=${mediaSlug}&type_media=${mediaType}`; - return get(url); -} - -async function downloadMedia( - mediaId: number, - mediaSlug: string, - mediaType: string, - downloadId?: number, - tvSeriesEpisodeId?: number -): Promise> { - const url = `/download/`; - const data = { - media_id: mediaId, - media_slug: mediaSlug, - type_media: mediaType, - download_id: downloadId, - tv_series_episode_id: tvSeriesEpisodeId, - }; - return post(url, data); -} - -export const downloadFilm = (mediaId: number, mediaSlug: string) => - downloadMedia(mediaId, mediaSlug, "MOVIE"); -export const downloadTvSeries = ( - mediaId: number, - mediaSlug: string, - downloadId: number, - tvSeriesEpisodeId?: number -) => downloadMedia(mediaId, mediaSlug, "TV", downloadId, tvSeriesEpisodeId); -export const downloadAnimeFilm = (mediaId: number, mediaSlug: string) => - downloadMedia(mediaId, mediaSlug, "OVA"); -export const downloadAnimeSeries = ( - mediaId: number, - mediaSlug: string, - downloadId: number -) => downloadMedia(mediaId, mediaSlug, "TV_ANIME", downloadId); +import axios from 'axios' +import type {MediaItemResponse} from '@/api/interfaces' + +const BASE_URL = 'http://localhost:8000/api' + +function get(url: string): Promise { + return axios.get(`${BASE_URL}${url}`) + .then(response => response.data) + .catch(error => { + throw error; + }); +} + +function post(url: string, data: any): Promise { + return axios.post(`${BASE_URL}${url}`, data) + .then(response => response.data) + .catch(error => { + throw error; + }); +} + +export default function search(query: string, type: string) : Promise { + return get(`/search?search_terms=${query}&type=${type}`) +} + +export async function getEpisodesInfo(mediaId: number, mediaSlug: string, mediaType: string): Promise { + const url = `${BASE_URL}/search/get_episodes_info?media_id=${mediaId}&media_slug=${mediaSlug}&type_media=${mediaType}`; + return await fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'text/event-stream' + } + }); +} + +export async function downloadFilm(mediaId: number, mediaSlug: string, mediaType: string): Promise { + const url = `/download/`; + const data = { + media_id: mediaId, + media_slug: mediaSlug, + type_media: mediaType + }; + return post(url, data); +} \ No newline at end of file diff --git a/frontend/src/api/interfaces.ts b/frontend/src/api/interfaces.ts index d33f703..770eef1 100644 --- a/frontend/src/api/interfaces.ts +++ b/frontend/src/api/interfaces.ts @@ -56,9 +56,4 @@ export interface Season { export interface SeasonResponse { episodes: Season; -} - -export interface DownloadResponse { - error: string; - message: string; } \ No newline at end of file diff --git a/frontend/src/views/Details.vue b/frontend/src/views/Details.vue index 5880730..16d69b1 100644 --- a/frontend/src/views/Details.vue +++ b/frontend/src/views/Details.vue @@ -1,335 +1,267 @@ - - - - - \ No newline at end of file