mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 22:39:38 +00:00
refac, useApiClient for loader and actions
This commit is contained in:
@@ -129,7 +129,7 @@ class VideoCommentView(ApiBaseView):
|
|||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
self.get_document(video_id)
|
self.get_document(video_id)
|
||||||
|
|
||||||
return Response(self.response, status=self.status_code)
|
return Response(self.response, status=200)
|
||||||
|
|
||||||
|
|
||||||
class VideoSimilarView(ApiBaseView):
|
class VideoSimilarView(ApiBaseView):
|
||||||
@@ -153,4 +153,4 @@ class VideoSimilarView(ApiBaseView):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
self.get_document_list(request, pagination=False)
|
self.get_document_list(request, pagination=False)
|
||||||
return Response(self.response, status=self.status_code)
|
return Response(self.response, status=200)
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
export type AppriseTaskNameType =
|
export type AppriseTaskNameType =
|
||||||
| 'update_subscribed'
|
| 'update_subscribed'
|
||||||
@@ -11,26 +7,10 @@ export type AppriseTaskNameType =
|
|||||||
| 'check_reindex';
|
| 'check_reindex';
|
||||||
|
|
||||||
const createAppriseNotificationUrl = async (taskName: AppriseTaskNameType, url: string) => {
|
const createAppriseNotificationUrl = async (taskName: AppriseTaskNameType, url: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/task/notification/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/task/notification/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { task_name: taskName, url },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
body: JSON.stringify({ task_name: taskName, url }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const appriseNotificationUrl = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('createAppriseNotificationUrl', appriseNotificationUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return appriseNotificationUrl;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createAppriseNotificationUrl;
|
export default createAppriseNotificationUrl;
|
||||||
|
|||||||
@@ -1,30 +1,10 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const createCustomPlaylist = async (playlistId: string) => {
|
const createCustomPlaylist = async (playlistId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/playlist/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/playlist/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { data: { create: playlistId } },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify({ data: { create: playlistId } }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const customPlaylist = await response.json();
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('createCustomPlaylist', customPlaylist);
|
|
||||||
}
|
|
||||||
|
|
||||||
return customPlaylist;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createCustomPlaylist;
|
export default createCustomPlaylist;
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
export type TaskScheduleNameType =
|
export type TaskScheduleNameType =
|
||||||
| 'update_subscribed'
|
| 'update_subscribed'
|
||||||
@@ -28,26 +24,10 @@ type ScheduleConfigType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const createTaskSchedule = async (taskName: TaskScheduleNameType, schedule: ScheduleConfigType) => {
|
const createTaskSchedule = async (taskName: TaskScheduleNameType, schedule: ScheduleConfigType) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/task/schedule/${taskName}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/task/schedule/${taskName}/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: schedule,
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
body: JSON.stringify(schedule),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const scheduledTask = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('createTaskSchedule', scheduledTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
return scheduledTask;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default createTaskSchedule;
|
export default createTaskSchedule;
|
||||||
|
|||||||
@@ -1,28 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const deleteApiToken = async () => {
|
const deleteApiToken = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/appsettings/token/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/token/`, {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const resetToken = await response.json();
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('deleteApiToken', resetToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resetToken;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default deleteApiToken;
|
export default deleteApiToken;
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
type AppriseTaskNameType =
|
type AppriseTaskNameType =
|
||||||
| 'update_subscribed'
|
| 'update_subscribed'
|
||||||
@@ -11,26 +7,10 @@ type AppriseTaskNameType =
|
|||||||
| 'check_reindex';
|
| 'check_reindex';
|
||||||
|
|
||||||
const deleteAppriseNotificationUrl = async (taskName: AppriseTaskNameType) => {
|
const deleteAppriseNotificationUrl = async (taskName: AppriseTaskNameType) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/task/notification/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/task/notification/`, {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
body: { task_name: taskName },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
body: JSON.stringify({ task_name: taskName }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const appriseNotification = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('deleteAppriseNotificationUrl', appriseNotification);
|
|
||||||
}
|
|
||||||
|
|
||||||
return appriseNotification;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default deleteAppriseNotificationUrl;
|
export default deleteAppriseNotificationUrl;
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const deleteChannel = async (channelId: string) => {
|
const deleteChannel = async (channelId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/channel/${channelId}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/channel/${channelId}/`, {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const channelDeleted = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('deleteChannel', channelDeleted);
|
|
||||||
}
|
|
||||||
|
|
||||||
return channelDeleted;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default deleteChannel;
|
export default deleteChannel;
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const deleteDownloadById = async (youtubeId: string) => {
|
const deleteDownloadById = async (youtubeId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/download/${youtubeId}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/download/${youtubeId}/`, {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadState = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('deleteDownloadById', downloadState);
|
|
||||||
}
|
|
||||||
|
|
||||||
return downloadState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default deleteDownloadById;
|
export default deleteDownloadById;
|
||||||
|
|||||||
@@ -1,37 +1,14 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
type FilterType = 'ignore' | 'pending';
|
type FilterType = 'ignore' | 'pending';
|
||||||
|
|
||||||
const deleteDownloadQueueByFilter = async (filter: FilterType) => {
|
const deleteDownloadQueueByFilter = async (filter: FilterType) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
|
if (filter) searchParams.append('filter', filter);
|
||||||
|
|
||||||
if (filter) {
|
return APIClient(`/api/download/?${searchParams.toString()}`, {
|
||||||
searchParams.append('filter', filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/download/?${searchParams.toString()}`, {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadState = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('deleteDownloadQueueByFilter', downloadState);
|
|
||||||
}
|
|
||||||
|
|
||||||
return downloadState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default deleteDownloadQueueByFilter;
|
export default deleteDownloadQueueByFilter;
|
||||||
|
|||||||
@@ -1,34 +1,14 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const deletePlaylist = async (playlistId: string, allVideos = false) => {
|
const deletePlaylist = async (playlistId: string, allVideos = false) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
let params = '';
|
let params = '';
|
||||||
if (allVideos) {
|
if (allVideos) {
|
||||||
params = '?delete-videos=true';
|
params = '?delete-videos=true';
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/playlist/${playlistId}/${params}`, {
|
return APIClient(`/api/playlist/${playlistId}/${params}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const playlistDeleted = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('deletePlaylist', playlistDeleted);
|
|
||||||
}
|
|
||||||
|
|
||||||
return playlistDeleted;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default deletePlaylist;
|
export default deletePlaylist;
|
||||||
|
|||||||
@@ -1,30 +1,10 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
import { TaskScheduleNameType } from './createTaskSchedule';
|
import { TaskScheduleNameType } from './createTaskSchedule';
|
||||||
|
|
||||||
const deleteTaskSchedule = async (taskName: TaskScheduleNameType) => {
|
const deleteTaskSchedule = async (taskName: TaskScheduleNameType) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/task/schedule/${taskName}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/task/schedule/${taskName}/`, {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const scheduledTask = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('deleteTaskSchedule', scheduledTask);
|
|
||||||
}
|
|
||||||
|
|
||||||
return scheduledTask;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default deleteTaskSchedule;
|
export default deleteTaskSchedule;
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const deleteVideo = async (videoId: string) => {
|
const deleteVideo = async (videoId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/video/${videoId}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/video/${videoId}/`, {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const videoDeleted = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('deleteVideo', videoDeleted);
|
|
||||||
}
|
|
||||||
|
|
||||||
return videoDeleted;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default deleteVideo;
|
export default deleteVideo;
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const deleteVideoProgressById = async (youtubeId: string) => {
|
const deleteVideoProgressById = async (youtubeId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/video/${youtubeId}/progress/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/video/${youtubeId}/progress/`, {
|
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const watchedState = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('deleteVideoProgressById', watchedState);
|
|
||||||
}
|
|
||||||
|
|
||||||
return watchedState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default deleteVideoProgressById;
|
export default deleteVideoProgressById;
|
||||||
|
|||||||
@@ -1,22 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
const logOut = async () => {
|
const logOut = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/user/logout/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/user/logout/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return response;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default logOut;
|
export default logOut;
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const queueBackup = async () => {
|
const queueBackup = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/appsettings/backup/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/backup/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const backupQueued = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('queueBackup', backupQueued);
|
|
||||||
}
|
|
||||||
|
|
||||||
return backupQueued;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default queueBackup;
|
export default queueBackup;
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
export type ReindexType = 'channel' | 'video' | 'playlist';
|
export type ReindexType = 'channel' | 'video' | 'playlist';
|
||||||
|
|
||||||
@@ -13,36 +9,15 @@ export const ReindexTypeEnum = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const queueReindex = async (id: string, type: ReindexType, reindexVideos = false) => {
|
const queueReindex = async (id: string, type: ReindexType, reindexVideos = false) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
let params = '';
|
let params = '';
|
||||||
if (reindexVideos) {
|
if (reindexVideos) {
|
||||||
params = '?extract_videos=true';
|
params = '?extract_videos=true';
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = JSON.stringify({
|
return APIClient(`/api/refresh/${params}`, {
|
||||||
[type]: [id],
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/refresh/${params}`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { [type]: [id] },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const channelDeleted = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('queueReindex', channelDeleted);
|
|
||||||
}
|
|
||||||
|
|
||||||
return channelDeleted;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default queueReindex;
|
export default queueReindex;
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const queueSnapshot = async () => {
|
const queueSnapshot = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/appsettings/snapshot/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/snapshot/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const snapshotQueued = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('queueSnapshot', snapshotQueued);
|
|
||||||
}
|
|
||||||
|
|
||||||
return snapshotQueued;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default queueSnapshot;
|
export default queueSnapshot;
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const restoreBackup = async (fileName: string) => {
|
const restoreBackup = async (fileName: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/appsettings/backup/${fileName}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/backup/${fileName}/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const backupRestored = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('restoreBackup', backupRestored);
|
|
||||||
}
|
|
||||||
|
|
||||||
return backupRestored;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default restoreBackup;
|
export default restoreBackup;
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const restoreSnapshot = async (snapshotId: string) => {
|
const restoreSnapshot = async (snapshotId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/appsettings/snapshot/${snapshotId}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/snapshot/${snapshotId}/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const backupRestored = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('restoreSnapshot', backupRestored);
|
|
||||||
}
|
|
||||||
|
|
||||||
return backupRestored;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default restoreSnapshot;
|
export default restoreSnapshot;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export type LoginResponseType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const signIn = async (username: string, password: string, saveLogin: boolean) => {
|
const signIn = async (username: string, password: string, saveLogin: boolean) => {
|
||||||
|
// works differently, response status is checked
|
||||||
const apiUrl = getApiUrl();
|
const apiUrl = getApiUrl();
|
||||||
const csrfCookie = getCookie('csrftoken');
|
const csrfCookie = getCookie('csrftoken');
|
||||||
|
|
||||||
|
|||||||
@@ -1,27 +1,10 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
const stopTaskByName = async (taskId: string) => {
|
const stopTaskByName = async (taskId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
APIClient(`/api/task/by-id/${taskId}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/task/by-id/${taskId}/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { command: 'stop' },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify({ command: 'stop' }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadQueueState = await response.json();
|
|
||||||
console.log('stopTaskByName', downloadQueueState);
|
|
||||||
|
|
||||||
return downloadQueueState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default stopTaskByName;
|
export default stopTaskByName;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import { AppSettingsConfigType } from '../loader/loadAppsettingsConfig';
|
import { AppSettingsConfigType } from '../loader/loadAppsettingsConfig';
|
||||||
|
|
||||||
type ObjectType = Record<
|
type ObjectType = Record<
|
||||||
@@ -32,23 +29,10 @@ function flattenObject(ob: ObjectType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const updateAppsettingsConfig = async (config: AppSettingsConfigType) => {
|
const updateAppsettingsConfig = async (config: AppSettingsConfigType) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/appsettings/config/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/config/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: flattenObject(config),
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
body: JSON.stringify(flattenObject(config)),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const appSettingsConfig = await response.json();
|
|
||||||
console.log('updateAppsettingsConfig', appSettingsConfig);
|
|
||||||
|
|
||||||
return appSettingsConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateAppsettingsConfig;
|
export default updateAppsettingsConfig;
|
||||||
|
|||||||
@@ -1,37 +1,20 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
const updateChannelOverwrites = async (
|
const updateChannelOverwrites = async (
|
||||||
channelId: string,
|
channelId: string,
|
||||||
configKey: string,
|
configKey: string,
|
||||||
configValue: string | boolean | number | null,
|
configValue: string | boolean | number | null,
|
||||||
) => {
|
) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
channel_overwrites: {
|
channel_overwrites: {
|
||||||
[configKey]: configValue,
|
[configKey]: configValue,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/channel/${channelId}/`, {
|
return APIClient(`/api/channel/${channelId}/`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: data,
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const channelSubscription = await response.json();
|
|
||||||
console.log('updateChannelOverwrites', channelSubscription);
|
|
||||||
|
|
||||||
return channelSubscription;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateChannelOverwrites;
|
export default updateChannelOverwrites;
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
const updateChannelSubscription = async (channelIds: string, status: boolean) => {
|
const updateChannelSubscription = async (channelIds: string, status: boolean) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const channels = [];
|
const channels = [];
|
||||||
const containsMultiple = channelIds.includes('\n');
|
const containsMultiple = channelIds.includes('\n');
|
||||||
|
|
||||||
@@ -20,23 +14,10 @@ const updateChannelSubscription = async (channelIds: string, status: boolean) =>
|
|||||||
channels.push({ channel_id: channelIds, channel_subscribed: status });
|
channels.push({ channel_id: channelIds, channel_subscribed: status });
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/channel/`, {
|
return APIClient('/api/channel/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { data: [...channels] },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify({
|
|
||||||
data: [...channels],
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const channelSubscription = await response.json();
|
|
||||||
console.log('updateChannelSubscription', channelSubscription);
|
|
||||||
|
|
||||||
return channelSubscription;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateChannelSubscription;
|
export default updateChannelSubscription;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
export type ValidatedCookieType = {
|
export type ValidatedCookieType = {
|
||||||
cookie_enabled: boolean;
|
cookie_enabled: boolean;
|
||||||
@@ -12,22 +9,9 @@ export type ValidatedCookieType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateCookie = async (): Promise<ValidatedCookieType> => {
|
const updateCookie = async (): Promise<ValidatedCookieType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/appsettings/cookie/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/cookie/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const validatedCookie = await response.json();
|
|
||||||
console.log('updateCookie', validatedCookie);
|
|
||||||
|
|
||||||
return validatedCookie;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateCookie;
|
export default updateCookie;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
type CustomPlaylistActionType = 'create' | 'up' | 'down' | 'top' | 'bottom' | 'remove';
|
type CustomPlaylistActionType = 'create' | 'up' | 'down' | 'top' | 'bottom' | 'remove';
|
||||||
|
|
||||||
@@ -10,24 +7,10 @@ const updateCustomPlaylist = async (
|
|||||||
playlistId: string,
|
playlistId: string,
|
||||||
videoId: string,
|
videoId: string,
|
||||||
) => {
|
) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/playlist/${playlistId}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/playlist/${playlistId}/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { action, video_id: videoId },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify({ action, video_id: videoId }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const customPlaylist = await response.json();
|
|
||||||
console.log('updateCustomPlaylist', action, customPlaylist);
|
|
||||||
|
|
||||||
return customPlaylist;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateCustomPlaylist;
|
export default updateCustomPlaylist;
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
const updateDownloadQueue = async (youtubeIdStrings: string, autostart: boolean) => {
|
const updateDownloadQueue = async (youtubeIdStrings: string, autostart: boolean) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const urls = [];
|
const urls = [];
|
||||||
const containsMultiple = youtubeIdStrings.includes('\n');
|
const containsMultiple = youtubeIdStrings.includes('\n');
|
||||||
|
|
||||||
@@ -25,23 +19,10 @@ const updateDownloadQueue = async (youtubeIdStrings: string, autostart: boolean)
|
|||||||
params = '?autostart=true';
|
params = '?autostart=true';
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/download/${params}`, {
|
return APIClient(`/api/download/${params}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { data: [...urls] },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify({
|
|
||||||
data: [...urls],
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadState = await response.json();
|
|
||||||
console.log('updateDownloadQueue', downloadState);
|
|
||||||
|
|
||||||
return downloadState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateDownloadQueue;
|
export default updateDownloadQueue;
|
||||||
|
|||||||
@@ -1,31 +1,12 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
export type DownloadQueueStatus = 'ignore' | 'pending' | 'priority';
|
export type DownloadQueueStatus = 'ignore' | 'pending' | 'priority';
|
||||||
|
|
||||||
const updateDownloadQueueStatusById = async (youtubeId: string, status: DownloadQueueStatus) => {
|
const updateDownloadQueueStatusById = async (youtubeId: string, status: DownloadQueueStatus) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/download/${youtubeId}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/download/${youtubeId}/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { status: status },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify({
|
|
||||||
status,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadQueueState = await response.json();
|
|
||||||
console.log('updateDownloadQueueStatusById', downloadQueueState);
|
|
||||||
|
|
||||||
return downloadQueueState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateDownloadQueueStatusById;
|
export default updateDownloadQueueStatusById;
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
const updatePlaylistSubscription = async (playlistIds: string, status: boolean) => {
|
const updatePlaylistSubscription = async (playlistIds: string, status: boolean) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const playlists = [];
|
const playlists = [];
|
||||||
const containsMultiple = playlistIds.includes('\n');
|
const containsMultiple = playlistIds.includes('\n');
|
||||||
|
|
||||||
@@ -20,23 +14,10 @@ const updatePlaylistSubscription = async (playlistIds: string, status: boolean)
|
|||||||
playlists.push({ playlist_id: playlistIds, playlist_subscribed: status });
|
playlists.push({ playlist_id: playlistIds, playlist_subscribed: status });
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/playlist/`, {
|
return APIClient('/api/playlist/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { data: [...playlists] },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify({
|
|
||||||
data: [...playlists],
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const playlistSubscription = await response.json();
|
|
||||||
console.log('updatePlaylistSubscription', playlistSubscription);
|
|
||||||
|
|
||||||
return playlistSubscription;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updatePlaylistSubscription;
|
export default updatePlaylistSubscription;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
type TaskNamesType =
|
type TaskNamesType =
|
||||||
| 'download_pending'
|
| 'download_pending'
|
||||||
@@ -11,22 +8,9 @@ type TaskNamesType =
|
|||||||
| 'rescan_filesystem';
|
| 'rescan_filesystem';
|
||||||
|
|
||||||
const updateTaskByName = async (taskName: TaskNamesType) => {
|
const updateTaskByName = async (taskName: TaskNamesType) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/task/by-name/${taskName}/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/task/by-name/${taskName}/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadQueueState = await response.json();
|
|
||||||
console.log('updateTaskByName', downloadQueueState);
|
|
||||||
|
|
||||||
return downloadQueueState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateTaskByName;
|
export default updateTaskByName;
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { SortByType, SortOrderType, ViewLayoutType } from '../../pages/Home';
|
import { SortByType, SortOrderType, ViewLayoutType } from '../../pages/Home';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
import APIClient from '../../functions/APIClient';
|
||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
|
|
||||||
export type UserMeType = {
|
export type UserMeType = {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -33,24 +30,10 @@ export type UserConfigType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateUserConfig = async (config: Partial<UserConfigType>): Promise<UserConfigType> => {
|
const updateUserConfig = async (config: Partial<UserConfigType>): Promise<UserConfigType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/user/me/', {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/user/me/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { config: config },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify({ config }),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const userConfig = await response.json();
|
|
||||||
console.log('updateUserConfig', userConfig);
|
|
||||||
|
|
||||||
return userConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateUserConfig;
|
export default updateUserConfig;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
|
|
||||||
type VideoProgressProp = {
|
type VideoProgressProp = {
|
||||||
youtubeId: string;
|
youtubeId: string;
|
||||||
@@ -9,26 +6,10 @@ type VideoProgressProp = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateVideoProgressById = async ({ youtubeId, currentProgress }: VideoProgressProp) => {
|
const updateVideoProgressById = async ({ youtubeId, currentProgress }: VideoProgressProp) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/video/${youtubeId}/progress/`, {
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/video/${youtubeId}/progress/`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: { position: currentProgress },
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify({
|
|
||||||
position: currentProgress,
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const userConfig = await response.json();
|
|
||||||
console.log('updateVideoProgressById', userConfig);
|
|
||||||
|
|
||||||
return userConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateVideoProgressById;
|
export default updateVideoProgressById;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import deleteVideoProgressById from './deleteVideoProgressById';
|
import deleteVideoProgressById from './deleteVideoProgressById';
|
||||||
|
|
||||||
export type Watched = {
|
export type Watched = {
|
||||||
@@ -10,28 +7,14 @@ export type Watched = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const updateWatchedState = async (watched: Watched) => {
|
const updateWatchedState = async (watched: Watched) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
if (watched.is_watched) {
|
if (watched.is_watched) {
|
||||||
await deleteVideoProgressById(watched.id);
|
await deleteVideoProgressById(watched.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/watched/`, {
|
return APIClient('/api/watched/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: watched,
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
|
|
||||||
body: JSON.stringify(watched),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const watchedState = await response.json();
|
|
||||||
console.log('updateWatchedState', watchedState);
|
|
||||||
|
|
||||||
return watchedState;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default updateWatchedState;
|
export default updateWatchedState;
|
||||||
|
|||||||
@@ -1,36 +1,11 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import getCookie from '../../functions/getCookie';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
type ApiTokenResponse = {
|
type ApiTokenResponse = {
|
||||||
token: string;
|
token: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadApiToken = async (): Promise<ApiTokenResponse> => {
|
const loadApiToken = async (): Promise<ApiTokenResponse> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/appsettings/token/');
|
||||||
const csrfCookie = getCookie('csrftoken');
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/token/`, {
|
|
||||||
headers: {
|
|
||||||
...defaultHeaders,
|
|
||||||
'X-CSRFToken': csrfCookie || '',
|
|
||||||
},
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const apiToken = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadApiToken', apiToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
return apiToken;
|
|
||||||
} catch {
|
|
||||||
return { token: '' };
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadApiToken;
|
export default loadApiToken;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
export type AppriseNotificationType = {
|
export type AppriseNotificationType = {
|
||||||
check_reindex?: {
|
check_reindex?: {
|
||||||
@@ -23,20 +20,7 @@ export type AppriseNotificationType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadAppriseNotification = async (): Promise<AppriseNotificationType> => {
|
const loadAppriseNotification = async (): Promise<AppriseNotificationType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/task/notification/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/task/notification/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const notification = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadAppriseNotification', notification);
|
|
||||||
}
|
|
||||||
|
|
||||||
return notification;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadAppriseNotification;
|
export default loadAppriseNotification;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
export type AppSettingsConfigType = {
|
export type AppSettingsConfigType = {
|
||||||
subscriptions: {
|
subscriptions: {
|
||||||
@@ -35,20 +32,7 @@ export type AppSettingsConfigType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadAppsettingsConfig = async (): Promise<AppSettingsConfigType> => {
|
const loadAppsettingsConfig = async (): Promise<AppSettingsConfigType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/appsettings/config/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/config/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const appSettingsConfig = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadApplicationConfig', appSettingsConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
return appSettingsConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadAppsettingsConfig;
|
export default loadAppsettingsConfig;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|||||||
import getCookie from '../../functions/getCookie';
|
import getCookie from '../../functions/getCookie';
|
||||||
|
|
||||||
const loadAuth = async () => {
|
const loadAuth = async () => {
|
||||||
|
// works differently, return response to check for status in main.tsx
|
||||||
const apiUrl = getApiUrl();
|
const apiUrl = getApiUrl();
|
||||||
const csrfCookie = getCookie('csrftoken');
|
const csrfCookie = getCookie('csrftoken');
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadBackupList = async () => {
|
const loadBackupList = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/appsettings/backup/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/backup/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const backupList = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadBackupList', backupList);
|
|
||||||
}
|
|
||||||
|
|
||||||
return backupList;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadBackupList;
|
export default loadBackupList;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
export type ChannelAggsType = {
|
export type ChannelAggsType = {
|
||||||
total_items: {
|
total_items: {
|
||||||
@@ -17,20 +14,7 @@ export type ChannelAggsType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadChannelAggs = async (channelId: string): Promise<ChannelAggsType> => {
|
const loadChannelAggs = async (channelId: string): Promise<ChannelAggsType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/channel/${channelId}/aggs/`);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/channel/${channelId}/aggs/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const channel = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadChannelAggs', channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
return channel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadChannelAggs;
|
export default loadChannelAggs;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadChannelById = async (youtubeChannelId: string) => {
|
const loadChannelById = async (youtubeChannelId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/channel/${youtubeChannelId}/`);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/channel/${youtubeChannelId}/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const channel = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadChannelById', channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
return channel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadChannelById;
|
export default loadChannelById;
|
||||||
|
|||||||
@@ -1,33 +1,14 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadChannelList = async (page: number, showSubscribed: boolean) => {
|
const loadChannelList = async (page: number, showSubscribed: boolean) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
|
|
||||||
if (page) {
|
if (page) searchParams.append('page', page.toString());
|
||||||
searchParams.append('page', page.toString());
|
if (showSubscribed) searchParams.append('filter', 'subscribed');
|
||||||
}
|
|
||||||
|
|
||||||
if (showSubscribed) {
|
const endpoint = `/api/channel/${searchParams.toString() ? `?${searchParams.toString()}` : ''}`;
|
||||||
searchParams.append('filter', 'subscribed');
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/channel/?${searchParams.toString()}`, {
|
return APIClient(endpoint);
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const channels = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadChannelList', channels);
|
|
||||||
}
|
|
||||||
|
|
||||||
return channels;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadChannelList;
|
export default loadChannelList;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
export type ChannelNavResponseType = {
|
export type ChannelNavResponseType = {
|
||||||
has_streams: boolean;
|
has_streams: boolean;
|
||||||
@@ -11,20 +8,7 @@ export type ChannelNavResponseType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadChannelNav = async (youtubeChannelId: string): Promise<ChannelNavResponseType> => {
|
const loadChannelNav = async (youtubeChannelId: string): Promise<ChannelNavResponseType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/channel/${youtubeChannelId}/nav/`);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/channel/${youtubeChannelId}/nav/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const channel = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadChannelNav', channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
return channel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadChannelNav;
|
export default loadChannelNav;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadCommentsbyVideoId = async (youtubeId: string) => {
|
const loadCommentsbyVideoId = async (youtubeId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/video/${youtubeId}/comment/`);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/video/${youtubeId}/comment/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const comments = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadCommentsbyVideoId', comments);
|
|
||||||
}
|
|
||||||
|
|
||||||
return comments;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadCommentsbyVideoId;
|
export default loadCommentsbyVideoId;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
type DownloadAggsBucket = {
|
type DownloadAggsBucket = {
|
||||||
key: string[];
|
key: string[];
|
||||||
@@ -18,20 +15,7 @@ export type DownloadAggsType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadDownloadAggs = async (): Promise<DownloadAggsType> => {
|
const loadDownloadAggs = async (): Promise<DownloadAggsType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/download/aggs/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/download/aggs/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const downloadAggs = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadDownloadAggs', downloadAggs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return downloadAggs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadDownloadAggs;
|
export default loadDownloadAggs;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
import { DownloadResponseType } from '../../pages/Download';
|
import { DownloadResponseType } from '../../pages/Download';
|
||||||
|
|
||||||
const loadDownloadQueue = async (
|
const loadDownloadQueue = async (
|
||||||
@@ -9,32 +6,15 @@ const loadDownloadQueue = async (
|
|||||||
channelId: string | null,
|
channelId: string | null,
|
||||||
showIgnored: boolean,
|
showIgnored: boolean,
|
||||||
): Promise<DownloadResponseType> => {
|
): Promise<DownloadResponseType> => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
|
|
||||||
if (page) {
|
if (page) searchParams.append('page', page.toString());
|
||||||
searchParams.append('page', page.toString());
|
if (channelId) searchParams.append('channel', channelId);
|
||||||
}
|
|
||||||
|
|
||||||
if (channelId) {
|
|
||||||
searchParams.append('channel', channelId);
|
|
||||||
}
|
|
||||||
|
|
||||||
searchParams.append('filter', showIgnored ? 'ignore' : 'pending');
|
searchParams.append('filter', showIgnored ? 'ignore' : 'pending');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/download/?${searchParams.toString()}`, {
|
const endpoint = `/api/download/${searchParams.toString() ? `?${searchParams.toString()}` : ''}`;
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const playlist = await response.json();
|
return APIClient(endpoint);
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadDownloadQueue', playlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
return playlist;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadDownloadQueue;
|
export default loadDownloadQueue;
|
||||||
|
|||||||
@@ -1,30 +1,16 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
export type NotificationPages = 'download' | 'settings' | 'channel' | 'all';
|
export type NotificationPages = 'download' | 'settings' | 'channel' | 'all';
|
||||||
|
|
||||||
const loadNotifications = async (pageName: NotificationPages, includeReindex = false) => {
|
const loadNotifications = async (pageName: NotificationPages, includeReindex = false) => {
|
||||||
const apiUrl = getApiUrl();
|
const searchParams = new URLSearchParams();
|
||||||
|
|
||||||
let params = '';
|
|
||||||
if (!includeReindex && pageName !== 'all') {
|
if (!includeReindex && pageName !== 'all') {
|
||||||
params = `?filter=${pageName}`;
|
searchParams.append('filter', pageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/notification/${params}`, {
|
const endpoint = `/api/notification/${searchParams.toString() ? `?${searchParams.toString()}` : ''}`;
|
||||||
headers: defaultHeaders,
|
return APIClient(endpoint);
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const notifications = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadNotifications', notifications);
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifications;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadNotifications;
|
export default loadNotifications;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadPlaylistById = async (playlistId: string | undefined) => {
|
const loadPlaylistById = async (playlistId: string | undefined) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/playlist/${playlistId}/`);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/playlist/${playlistId}/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const videos = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadPlaylistById', videos);
|
|
||||||
}
|
|
||||||
|
|
||||||
return videos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadPlaylistById;
|
export default loadPlaylistById;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
type PlaylistType = 'regular' | 'custom';
|
type PlaylistType = 'regular' | 'custom';
|
||||||
|
|
||||||
@@ -13,38 +10,15 @@ type LoadPlaylistListProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadPlaylistList = async ({ channel, page, subscribed, type }: LoadPlaylistListProps) => {
|
const loadPlaylistList = async ({ channel, page, subscribed, type }: LoadPlaylistListProps) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
|
|
||||||
if (channel) {
|
if (channel) searchParams.append('channel', channel);
|
||||||
searchParams.append('channel', channel);
|
if (page) searchParams.append('page', page.toString());
|
||||||
}
|
if (subscribed) searchParams.append('subscribed', subscribed.toString());
|
||||||
|
if (type) searchParams.append('type', type);
|
||||||
|
|
||||||
if (page) {
|
const endpoint = `/api/playlist/${searchParams.toString() ? `?${searchParams.toString()}` : ''}`;
|
||||||
searchParams.append('page', page.toString());
|
return APIClient(endpoint);
|
||||||
}
|
|
||||||
|
|
||||||
if (subscribed) {
|
|
||||||
searchParams.append('subscribed', subscribed.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type) {
|
|
||||||
searchParams.append('type', type);
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/playlist/?${searchParams.toString()}`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const playlist = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadPlaylistList', playlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
return playlist;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadPlaylistList;
|
export default loadPlaylistList;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
type ScheduleType = {
|
type ScheduleType = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -17,20 +14,7 @@ type ScheduleType = {
|
|||||||
export type ScheduleResponseType = ScheduleType[];
|
export type ScheduleResponseType = ScheduleType[];
|
||||||
|
|
||||||
const loadSchedule = async (): Promise<ScheduleResponseType> => {
|
const loadSchedule = async (): Promise<ScheduleResponseType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/task/schedule/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/task/schedule/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const schedule = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadSchedule', schedule);
|
|
||||||
}
|
|
||||||
|
|
||||||
return schedule;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadSchedule;
|
export default loadSchedule;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadSearch = async (query: string) => {
|
const loadSearch = async (query: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/search/?query=${query}`);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/search/?query=${query}`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const searchResults = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadSearch', searchResults);
|
|
||||||
}
|
|
||||||
|
|
||||||
return searchResults;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadSearch;
|
export default loadSearch;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadSimmilarVideosById = async (youtubeId: string) => {
|
const loadSimmilarVideosById = async (youtubeId: string) => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/video/${youtubeId}/similar/`);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/video/${youtubeId}/similar/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const videos = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadSimmilarVideosById', videos);
|
|
||||||
}
|
|
||||||
|
|
||||||
return videos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadSimmilarVideosById;
|
export default loadSimmilarVideosById;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadSnapshots = async () => {
|
const loadSnapshots = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/appsettings/snapshot/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/appsettings/snapshot/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const backupList = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadSnapshots', backupList);
|
|
||||||
}
|
|
||||||
|
|
||||||
return backupList;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadSnapshots;
|
export default loadSnapshots;
|
||||||
|
|||||||
@@ -1,28 +1,12 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
type BiggestChannelsOrderType = 'doc_count' | 'duration' | 'media_size';
|
type BiggestChannelsOrderType = 'doc_count' | 'duration' | 'media_size';
|
||||||
|
|
||||||
const loadStatsBiggestChannels = async (order: BiggestChannelsOrderType) => {
|
const loadStatsBiggestChannels = async (order: BiggestChannelsOrderType) => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
searchParams.append('order', order);
|
searchParams.append('order', order);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/stats/biggestchannels/?${searchParams.toString()}`, {
|
return APIClient(`/api/stats/biggestchannels/?${searchParams.toString()}`);
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const notifications = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadStatsBiggestChannels', notifications);
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifications;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadStatsBiggestChannels;
|
export default loadStatsBiggestChannels;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadStatsChannel = async () => {
|
const loadStatsChannel = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/stats/channel/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/stats/channel/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const notifications = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadStatsChannel', notifications);
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifications;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadStatsChannel;
|
export default loadStatsChannel;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadStatsDownload = async () => {
|
const loadStatsDownload = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/stats/download/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/stats/download/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const notifications = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadStatsDownload', notifications);
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifications;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadStatsDownload;
|
export default loadStatsDownload;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadStatsDownloadHistory = async () => {
|
const loadStatsDownloadHistory = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/stats/downloadhist/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/stats/downloadhist/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const notifications = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadStatsDownloadHistory', notifications);
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifications;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadStatsDownloadHistory;
|
export default loadStatsDownloadHistory;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadStatsPlaylist = async () => {
|
const loadStatsPlaylist = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/stats/playlist/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/stats/playlist/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const notifications = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadStatsPlaylist', notifications);
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifications;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadStatsPlaylist;
|
export default loadStatsPlaylist;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadStatsVideo = async () => {
|
const loadStatsVideo = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/stats/video/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/stats/video/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const notifications = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadStatsVideo', notifications);
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifications;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadStatsVideo;
|
export default loadStatsVideo;
|
||||||
|
|||||||
@@ -1,23 +1,7 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
const loadStatsWatchProgress = async () => {
|
const loadStatsWatchProgress = async () => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/stats/watch/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/stats/watch/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const notifications = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadStatsWatchProgress', notifications);
|
|
||||||
}
|
|
||||||
|
|
||||||
return notifications;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadStatsWatchProgress;
|
export default loadStatsWatchProgress;
|
||||||
|
|||||||
@@ -1,24 +1,8 @@
|
|||||||
import { UserMeType } from '../actions/updateUserConfig';
|
import { UserMeType } from '../actions/updateUserConfig';
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
|
|
||||||
const loadUserMeConfig = async (): Promise<UserMeType> => {
|
const loadUserMeConfig = async (): Promise<UserMeType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient('/api/user/me/');
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/user/me/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const userConfig = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadUserMeConfig', userConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
return userConfig;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadUserMeConfig;
|
export default loadUserMeConfig;
|
||||||
|
|||||||
@@ -1,24 +1,8 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
import { VideoResponseType } from '../../pages/Video';
|
import { VideoResponseType } from '../../pages/Video';
|
||||||
|
|
||||||
const loadVideoById = async (youtubeId: string): Promise<VideoResponseType> => {
|
const loadVideoById = async (youtubeId: string): Promise<VideoResponseType> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/video/${youtubeId}/`);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/video/${youtubeId}/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const videos = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadVideoById', videos);
|
|
||||||
}
|
|
||||||
|
|
||||||
return videos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadVideoById;
|
export default loadVideoById;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
import { ConfigType, SortByType, SortOrderType, VideoType } from '../../pages/Home';
|
import { ConfigType, SortByType, SortOrderType, VideoType } from '../../pages/Home';
|
||||||
import { PaginationType } from '../../components/Pagination';
|
import { PaginationType } from '../../components/Pagination';
|
||||||
|
import APIClient from '../../functions/APIClient';
|
||||||
|
|
||||||
export type VideoListByFilterResponseType = {
|
export type VideoListByFilterResponseType = {
|
||||||
data?: VideoType[];
|
data?: VideoType[];
|
||||||
@@ -27,48 +24,22 @@ type FilterType = {
|
|||||||
const loadVideoListByFilter = async (
|
const loadVideoListByFilter = async (
|
||||||
filter: FilterType,
|
filter: FilterType,
|
||||||
): Promise<VideoListByFilterResponseType> => {
|
): Promise<VideoListByFilterResponseType> => {
|
||||||
const apiUrl = getApiUrl();
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
|
|
||||||
if (filter.page) {
|
|
||||||
searchParams.append('page', filter.page.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.playlist) {
|
if (filter.playlist) {
|
||||||
searchParams.append('playlist', filter.playlist);
|
searchParams.append('playlist', filter.playlist);
|
||||||
} else if (filter.channel) {
|
} else if (filter.channel) {
|
||||||
searchParams.append('channel', filter.channel);
|
searchParams.append('channel', filter.channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter.watch) {
|
if (filter.page) searchParams.append('page', filter.page.toString());
|
||||||
searchParams.append('watch', filter.watch);
|
if (filter.watch) searchParams.append('watch', filter.watch);
|
||||||
}
|
if (filter.sort) searchParams.append('sort', filter.sort);
|
||||||
|
if (filter.order) searchParams.append('order', filter.order);
|
||||||
|
if (filter.type) searchParams.append('type', filter.type);
|
||||||
|
|
||||||
if (filter.sort) {
|
const endpoint = `/api/video/${searchParams.toString() ? `?${searchParams.toString()}` : ''}`;
|
||||||
searchParams.append('sort', filter.sort);
|
return APIClient(endpoint);
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.order) {
|
|
||||||
searchParams.append('order', filter.order);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.type) {
|
|
||||||
searchParams.append('type', filter.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/video/?${searchParams.toString()}`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const videos = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadVideoListByFilter', filter, videos);
|
|
||||||
}
|
|
||||||
|
|
||||||
return videos;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadVideoListByFilter;
|
export default loadVideoListByFilter;
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
import APIClient from '../../functions/APIClient';
|
||||||
import getApiUrl from '../../configuration/getApiUrl';
|
|
||||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
|
||||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
|
||||||
|
|
||||||
export type VideoNavResponseType = {
|
export type VideoNavResponseType = {
|
||||||
playlist_meta: {
|
playlist_meta: {
|
||||||
@@ -29,20 +26,7 @@ export type VideoNavResponseType = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const loadVideoNav = async (youtubeVideoId: string): Promise<VideoNavResponseType[]> => {
|
const loadVideoNav = async (youtubeVideoId: string): Promise<VideoNavResponseType[]> => {
|
||||||
const apiUrl = getApiUrl();
|
return APIClient(`/api/video/${youtubeVideoId}/nav/`);
|
||||||
|
|
||||||
const response = await fetch(`${apiUrl}/api/video/${youtubeVideoId}/nav/`, {
|
|
||||||
headers: defaultHeaders,
|
|
||||||
credentials: getFetchCredentials(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const videoNav = await response.json();
|
|
||||||
|
|
||||||
if (isDevEnvironment()) {
|
|
||||||
console.log('loadVideoNav', videoNav);
|
|
||||||
}
|
|
||||||
|
|
||||||
return videoNav;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default loadVideoNav;
|
export default loadVideoNav;
|
||||||
|
|||||||
60
frontend/src/functions/APIClient.ts
Normal file
60
frontend/src/functions/APIClient.ts
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import defaultHeaders from '../configuration/defaultHeaders';
|
||||||
|
import getApiUrl from '../configuration/getApiUrl';
|
||||||
|
import getFetchCredentials from '../configuration/getFetchCredentials';
|
||||||
|
import logOut from '../api/actions/logOut';
|
||||||
|
import getCookie from './getCookie';
|
||||||
|
|
||||||
|
export interface ApiClientOptions extends Omit<RequestInit, 'body'> {
|
||||||
|
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||||
|
body?: Record<string, unknown> | string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const APIClient = async (
|
||||||
|
endpoint: string,
|
||||||
|
{ method = 'GET', body, headers = {}, ...options }: ApiClientOptions = {},
|
||||||
|
) => {
|
||||||
|
const apiUrl = getApiUrl();
|
||||||
|
const csrfToken = getCookie('csrftoken');
|
||||||
|
|
||||||
|
const response = await fetch(`${apiUrl}${endpoint}`, {
|
||||||
|
method,
|
||||||
|
headers: {
|
||||||
|
...defaultHeaders,
|
||||||
|
...(csrfToken ? { 'X-CSRFToken': csrfToken } : {}),
|
||||||
|
...headers,
|
||||||
|
},
|
||||||
|
credentials: getFetchCredentials(),
|
||||||
|
body: body ? JSON.stringify(body) : undefined,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle common errors
|
||||||
|
if (response.status === 401) {
|
||||||
|
logOut();
|
||||||
|
window.location.href = '/login';
|
||||||
|
throw new Error('Unauthorized: Redirecting to login.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.status === 403) {
|
||||||
|
logOut();
|
||||||
|
window.location.href = '/login';
|
||||||
|
throw new Error('Forbidden: Access denied.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try parsing response data
|
||||||
|
let data;
|
||||||
|
try {
|
||||||
|
data = await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
data = null;
|
||||||
|
console.error(`error fetching data: ${error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(data?.detail || 'An error occurred while processing the request.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default APIClient;
|
||||||
Reference in New Issue
Block a user