diff --git a/frontend/src/api/api.ts b/frontend/src/api/api.ts index 91b21d9..b6f3efd 100644 --- a/frontend/src/api/api.ts +++ b/frontend/src/api/api.ts @@ -1,44 +1,44 @@ -import axios from 'axios' -import type {MediaItemResponse} from '@/api/interfaces' +import axios from 'axios'; +import type { AxiosResponse } from 'axios'; +import type {DownloadResponse, MediaItemResponse} from '@/api/interfaces'; -const BASE_URL = 'http://localhost:8000/api' +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; - }); +const api = axios.create({ + baseURL: BASE_URL, +}); + +async function get(url: string): Promise> { + return api.get(url); } -function post(url: string, data: any): Promise { - return axios.post(`${BASE_URL}${url}`, data) - .then(response => response.data) - .catch(error => { - throw error; - }); +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 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' - } - }); + 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 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 +async function downloadMedia(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); +} + +export const downloadFilm = (mediaId: number, mediaSlug: string) => downloadMedia(mediaId, mediaSlug, 'MOVIE'); +export const downloadAnimeFilm = (mediaId: number, mediaSlug: string) => downloadMedia(mediaId, mediaSlug, 'OVA'); \ No newline at end of file diff --git a/frontend/src/api/interfaces.ts b/frontend/src/api/interfaces.ts index b13418c..b1d88b3 100644 --- a/frontend/src/api/interfaces.ts +++ b/frontend/src/api/interfaces.ts @@ -55,4 +55,9 @@ 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 f53f5c2..9cee5bd 100644 --- a/frontend/src/views/Details.vue +++ b/frontend/src/views/Details.vue @@ -1,8 +1,8 @@