import type { PlaylistType, Language } from '../../runtime'; import { ApiHelper, toHeaderLanguage } from '../../runtime'; import type { IPlaylistData, PaginatedResponse, RequestPagination, IPlaylistVideoFormType, IVideoCard, IVideoData, IPlaylistCard, IPlaylistInfoType } from '../../types'; /** Сервис для работы с API плейлистов */ export class PlaylistsApiService { static async playlistLike( md: string, niche = NicheHelper.getSiteDefaultNiche(), ): Promise { return await ApiHelper.fetch( `/playlist/playlist-like/${md}`, { method: 'POST', headers: { 'X-Niche': niche, 'X-Cache-Time': '259200', 'Content-Type': 'application/json', }, }, useRuntimeConfig(), ); } static async playlistDislike( md: string, niche = NicheHelper.getSiteDefaultNiche(), ): Promise { return await ApiHelper.fetch( `/playlist/playlist-dislike/${md}`, { method: 'POST', headers: { 'X-Niche': niche, 'X-Cache-Time': '259200', 'Content-Type': 'application/json', }, }, useRuntimeConfig(), ); } static async setPlaylistView( id: string, videoView: string ): Promise { return await ApiHelper.fetch( `/playlist/playlist-view/${id}`, { method: 'POST', headers: { 'X-Cache-Time': 259200, 'Content-Type': 'application/json', }, body: { videoView, }, }, useRuntimeConfig(), ); } static async getPlaylistById( id: string, lang: Language, _limit? = 100, ): Promise { return await ApiHelper.fetch( `/playlist/get-playlist-by-id/${id}`, { method: 'GET', headers: { 'X-Language': toHeaderLanguage(lang), 'X-Cache-Time': 259200, 'Content-Type': 'application/json', }, }, useRuntimeConfig(), ); } static async getVideosByPlaylist( id: string, pagination: RequestPagination, lang: Language, limit? = 100, ): Promise> { return await ApiHelper.fetch( `/playlist/get-playlist-videos-by-id/${id}`, { method: 'GET', headers: { 'X-Language': toHeaderLanguage(lang), 'X-Cache-Time': 259200, 'Content-Type': 'application/json', }, params: { limit: limit, ...pagination, }, }, useRuntimeConfig(), ); } static async deleteVideo( pid: string, vid: string, ): Promise> { return await ApiHelper.fetch( `/playlist/delete-video/${pid}/${vid}`, { method: 'DELETE', headers: { 'X-Cache-Time': 259200, 'Content-Type': 'application/json', }, }, useRuntimeConfig(), ); } static async deletePlaylist( id: string, ): Promise> { return await ApiHelper.fetch( `/playlist/delete-playlist/${id}`, { method: 'DELETE', headers: { 'X-Cache-Time': 259200, 'Content-Type': 'application/json', }, }, useRuntimeConfig(), ); } static async refreshPlaylist( id: string, name: string, type: PlaylistType, ): Promise> { return await ApiHelper.fetch( `/playlist/refresh-playlist/${id}`, { method: 'PUT', headers: { 'X-Cache-Time': 259200, 'Content-Type': 'application/json', }, body: { name, type, }, }, useRuntimeConfig(), ); } static async getPlaylistByNiche( pagination: RequestPagination, order: string, lang: Language, niche? = NicheHelper.getSiteDefaultNiche(), ): Promise> { return await ApiHelper.fetch( '/playlist/playlists-list-by-niche', { method: 'GET', headers: { 'X-Niche': niche, 'X-Language': toHeaderLanguage(lang), 'X-Cache-Time': 259200, 'Content-Type': 'application/json', }, params: { ...pagination, order, }, }, useRuntimeConfig(), ); } static async postPlaylistVideo( data: IPlaylistVideoFormType, ) { return await ApiHelper.fetch( '/playlist/post-video', { method: 'POST', headers: { 'X-Cache-Time': 259200, 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', }, body: data, }, useRuntimeConfig(), ); } static async postPlaylist( name: string, type: PlaylistType, niche? = NicheHelper.getSiteDefaultNiche(), ) { return await ApiHelper.fetch( '/playlist/post-playlist', { method: 'POST', headers: { 'X-Cache-Time': 259200, 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', }, body: { niche: niche, name: name, type: type, }, }, useRuntimeConfig(), ); } static async getUserPlaylists( lang: Language, niche? = NicheHelper.getSiteDefaultNiche(), limit? = 100, ): Promise> { return await ApiHelper.fetch( '/playlist/get-user-playlists', { method: 'GET', headers: { 'X-Niche': niche, 'X-Language': toHeaderLanguage(lang), 'X-Cache-Time': 259200, 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*', }, params: { limit: limit, }, }, useRuntimeConfig(), ); } }