mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-07 14:29:32 +00:00
refac, useApiClient for loader and actions
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
export type AppriseTaskNameType =
|
||||
| 'update_subscribed'
|
||||
@@ -11,26 +7,10 @@ export type AppriseTaskNameType =
|
||||
| 'check_reindex';
|
||||
|
||||
const createAppriseNotificationUrl = async (taskName: AppriseTaskNameType, url: string) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/task/notification/`, {
|
||||
return APIClient('/api/task/notification/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
body: JSON.stringify({ task_name: taskName, url }),
|
||||
body: { task_name: taskName, url },
|
||||
});
|
||||
|
||||
const appriseNotificationUrl = await response.json();
|
||||
|
||||
if (isDevEnvironment()) {
|
||||
console.log('createAppriseNotificationUrl', appriseNotificationUrl);
|
||||
}
|
||||
|
||||
return appriseNotificationUrl;
|
||||
};
|
||||
|
||||
export default createAppriseNotificationUrl;
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const createCustomPlaylist = async (playlistId: string) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/playlist/`, {
|
||||
return APIClient('/api/playlist/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify({ data: { create: playlistId } }),
|
||||
body: { data: { create: playlistId } },
|
||||
});
|
||||
|
||||
const customPlaylist = await response.json();
|
||||
if (isDevEnvironment()) {
|
||||
console.log('createCustomPlaylist', customPlaylist);
|
||||
}
|
||||
|
||||
return customPlaylist;
|
||||
};
|
||||
|
||||
export default createCustomPlaylist;
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
export type TaskScheduleNameType =
|
||||
| 'update_subscribed'
|
||||
@@ -28,26 +24,10 @@ type ScheduleConfigType = {
|
||||
};
|
||||
|
||||
const createTaskSchedule = async (taskName: TaskScheduleNameType, schedule: ScheduleConfigType) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/task/schedule/${taskName}/`, {
|
||||
return APIClient(`/api/task/schedule/${taskName}/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
body: JSON.stringify(schedule),
|
||||
body: schedule,
|
||||
});
|
||||
|
||||
const scheduledTask = await response.json();
|
||||
|
||||
if (isDevEnvironment()) {
|
||||
console.log('createTaskSchedule', scheduledTask);
|
||||
}
|
||||
|
||||
return scheduledTask;
|
||||
};
|
||||
|
||||
export default createTaskSchedule;
|
||||
|
||||
@@ -1,28 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const deleteApiToken = async () => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/appsettings/token/`, {
|
||||
return APIClient('/api/appsettings/token/', {
|
||||
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;
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
type AppriseTaskNameType =
|
||||
| 'update_subscribed'
|
||||
@@ -11,26 +7,10 @@ type AppriseTaskNameType =
|
||||
| 'check_reindex';
|
||||
|
||||
const deleteAppriseNotificationUrl = async (taskName: AppriseTaskNameType) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/task/notification/`, {
|
||||
return APIClient('/api/task/notification/', {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
body: JSON.stringify({ task_name: taskName }),
|
||||
body: { task_name: taskName },
|
||||
});
|
||||
|
||||
const appriseNotification = await response.json();
|
||||
|
||||
if (isDevEnvironment()) {
|
||||
console.log('deleteAppriseNotificationUrl', appriseNotification);
|
||||
}
|
||||
|
||||
return appriseNotification;
|
||||
};
|
||||
|
||||
export default deleteAppriseNotificationUrl;
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const deleteChannel = async (channelId: string) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/channel/${channelId}/`, {
|
||||
return APIClient(`/api/channel/${channelId}/`, {
|
||||
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;
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const deleteDownloadById = async (youtubeId: string) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/download/${youtubeId}/`, {
|
||||
return APIClient(`/api/download/${youtubeId}/`, {
|
||||
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;
|
||||
|
||||
@@ -1,37 +1,14 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
type FilterType = 'ignore' | 'pending';
|
||||
|
||||
const deleteDownloadQueueByFilter = async (filter: FilterType) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const searchParams = new URLSearchParams();
|
||||
if (filter) searchParams.append('filter', filter);
|
||||
|
||||
if (filter) {
|
||||
searchParams.append('filter', filter);
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/download/?${searchParams.toString()}`, {
|
||||
return APIClient(`/api/download/?${searchParams.toString()}`, {
|
||||
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;
|
||||
|
||||
@@ -1,34 +1,14 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const deletePlaylist = async (playlistId: string, allVideos = false) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
let params = '';
|
||||
if (allVideos) {
|
||||
params = '?delete-videos=true';
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/playlist/${playlistId}/${params}`, {
|
||||
return APIClient(`/api/playlist/${playlistId}/${params}`, {
|
||||
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;
|
||||
|
||||
@@ -1,30 +1,10 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
import { TaskScheduleNameType } from './createTaskSchedule';
|
||||
|
||||
const deleteTaskSchedule = async (taskName: TaskScheduleNameType) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/task/schedule/${taskName}/`, {
|
||||
return APIClient(`/api/task/schedule/${taskName}/`, {
|
||||
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;
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const deleteVideo = async (videoId: string) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/video/${videoId}/`, {
|
||||
return APIClient(`/api/video/${videoId}/`, {
|
||||
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;
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const deleteVideoProgressById = async (youtubeId: string) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/video/${youtubeId}/progress/`, {
|
||||
return APIClient(`/api/video/${youtubeId}/progress/`, {
|
||||
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;
|
||||
|
||||
@@ -1,22 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const logOut = async () => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/user/logout/`, {
|
||||
return APIClient('/api/user/logout/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
});
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
export default logOut;
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const queueBackup = async () => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/appsettings/backup/`, {
|
||||
return APIClient('/api/appsettings/backup/', {
|
||||
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;
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
export type ReindexType = 'channel' | 'video' | 'playlist';
|
||||
|
||||
@@ -13,36 +9,15 @@ export const ReindexTypeEnum = {
|
||||
};
|
||||
|
||||
const queueReindex = async (id: string, type: ReindexType, reindexVideos = false) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
let params = '';
|
||||
if (reindexVideos) {
|
||||
params = '?extract_videos=true';
|
||||
}
|
||||
|
||||
const body = JSON.stringify({
|
||||
[type]: [id],
|
||||
});
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/refresh/${params}`, {
|
||||
return APIClient(`/api/refresh/${params}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body,
|
||||
body: { [type]: [id] },
|
||||
});
|
||||
|
||||
const channelDeleted = await response.json();
|
||||
|
||||
if (isDevEnvironment()) {
|
||||
console.log('queueReindex', channelDeleted);
|
||||
}
|
||||
|
||||
return channelDeleted;
|
||||
};
|
||||
|
||||
export default queueReindex;
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const queueSnapshot = async () => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/appsettings/snapshot/`, {
|
||||
return APIClient('/api/appsettings/snapshot/', {
|
||||
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;
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const restoreBackup = async (fileName: string) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/appsettings/backup/${fileName}/`, {
|
||||
return APIClient(`/api/appsettings/backup/${fileName}/`, {
|
||||
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;
|
||||
|
||||
@@ -1,29 +1,9 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import isDevEnvironment from '../../functions/isDevEnvironment';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const restoreSnapshot = async (snapshotId: string) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/appsettings/snapshot/${snapshotId}/`, {
|
||||
return APIClient(`/api/appsettings/snapshot/${snapshotId}/`, {
|
||||
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;
|
||||
|
||||
@@ -12,6 +12,7 @@ export type LoginResponseType = {
|
||||
};
|
||||
|
||||
const signIn = async (username: string, password: string, saveLogin: boolean) => {
|
||||
// works differently, response status is checked
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
|
||||
@@ -1,27 +1,10 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const stopTaskByName = async (taskId: string) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/task/by-id/${taskId}/`, {
|
||||
APIClient(`/api/task/by-id/${taskId}/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify({ command: 'stop' }),
|
||||
body: { command: 'stop' },
|
||||
});
|
||||
|
||||
const downloadQueueState = await response.json();
|
||||
console.log('stopTaskByName', downloadQueueState);
|
||||
|
||||
return downloadQueueState;
|
||||
};
|
||||
|
||||
export default stopTaskByName;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
import { AppSettingsConfigType } from '../loader/loadAppsettingsConfig';
|
||||
|
||||
type ObjectType = Record<
|
||||
@@ -32,23 +29,10 @@ function flattenObject(ob: ObjectType) {
|
||||
}
|
||||
|
||||
const updateAppsettingsConfig = async (config: AppSettingsConfigType) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/appsettings/config/`, {
|
||||
return APIClient('/api/appsettings/config/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
body: JSON.stringify(flattenObject(config)),
|
||||
body: flattenObject(config),
|
||||
});
|
||||
|
||||
const appSettingsConfig = await response.json();
|
||||
console.log('updateAppsettingsConfig', appSettingsConfig);
|
||||
|
||||
return appSettingsConfig;
|
||||
};
|
||||
|
||||
export default updateAppsettingsConfig;
|
||||
|
||||
@@ -1,37 +1,20 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const updateChannelOverwrites = async (
|
||||
channelId: string,
|
||||
configKey: string,
|
||||
configValue: string | boolean | number | null,
|
||||
) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const data = {
|
||||
channel_overwrites: {
|
||||
[configKey]: configValue,
|
||||
},
|
||||
};
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/channel/${channelId}/`, {
|
||||
return APIClient(`/api/channel/${channelId}/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify(data),
|
||||
body: data,
|
||||
});
|
||||
|
||||
const channelSubscription = await response.json();
|
||||
console.log('updateChannelOverwrites', channelSubscription);
|
||||
|
||||
return channelSubscription;
|
||||
};
|
||||
|
||||
export default updateChannelOverwrites;
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const updateChannelSubscription = async (channelIds: string, status: boolean) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const channels = [];
|
||||
const containsMultiple = channelIds.includes('\n');
|
||||
|
||||
@@ -20,23 +14,10 @@ const updateChannelSubscription = async (channelIds: string, status: boolean) =>
|
||||
channels.push({ channel_id: channelIds, channel_subscribed: status });
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/channel/`, {
|
||||
return APIClient('/api/channel/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify({
|
||||
data: [...channels],
|
||||
}),
|
||||
body: { data: [...channels] },
|
||||
});
|
||||
|
||||
const channelSubscription = await response.json();
|
||||
console.log('updateChannelSubscription', channelSubscription);
|
||||
|
||||
return channelSubscription;
|
||||
};
|
||||
|
||||
export default updateChannelSubscription;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
export type ValidatedCookieType = {
|
||||
cookie_enabled: boolean;
|
||||
@@ -12,22 +9,9 @@ export type ValidatedCookieType = {
|
||||
};
|
||||
|
||||
const updateCookie = async (): Promise<ValidatedCookieType> => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/appsettings/cookie/`, {
|
||||
return APIClient('/api/appsettings/cookie/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
});
|
||||
|
||||
const validatedCookie = await response.json();
|
||||
console.log('updateCookie', validatedCookie);
|
||||
|
||||
return validatedCookie;
|
||||
};
|
||||
|
||||
export default updateCookie;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
type CustomPlaylistActionType = 'create' | 'up' | 'down' | 'top' | 'bottom' | 'remove';
|
||||
|
||||
@@ -10,24 +7,10 @@ const updateCustomPlaylist = async (
|
||||
playlistId: string,
|
||||
videoId: string,
|
||||
) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/playlist/${playlistId}/`, {
|
||||
return APIClient(`/api/playlist/${playlistId}/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify({ action, video_id: videoId }),
|
||||
body: { action, video_id: videoId },
|
||||
});
|
||||
|
||||
const customPlaylist = await response.json();
|
||||
console.log('updateCustomPlaylist', action, customPlaylist);
|
||||
|
||||
return customPlaylist;
|
||||
};
|
||||
|
||||
export default updateCustomPlaylist;
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const updateDownloadQueue = async (youtubeIdStrings: string, autostart: boolean) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const urls = [];
|
||||
const containsMultiple = youtubeIdStrings.includes('\n');
|
||||
|
||||
@@ -25,23 +19,10 @@ const updateDownloadQueue = async (youtubeIdStrings: string, autostart: boolean)
|
||||
params = '?autostart=true';
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/download/${params}`, {
|
||||
return APIClient(`/api/download/${params}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify({
|
||||
data: [...urls],
|
||||
}),
|
||||
body: { data: [...urls] },
|
||||
});
|
||||
|
||||
const downloadState = await response.json();
|
||||
console.log('updateDownloadQueue', downloadState);
|
||||
|
||||
return downloadState;
|
||||
};
|
||||
|
||||
export default updateDownloadQueue;
|
||||
|
||||
@@ -1,31 +1,12 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
export type DownloadQueueStatus = 'ignore' | 'pending' | 'priority';
|
||||
|
||||
const updateDownloadQueueStatusById = async (youtubeId: string, status: DownloadQueueStatus) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/download/${youtubeId}/`, {
|
||||
return APIClient(`/api/download/${youtubeId}/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify({
|
||||
status,
|
||||
}),
|
||||
body: { status: status },
|
||||
});
|
||||
|
||||
const downloadQueueState = await response.json();
|
||||
console.log('updateDownloadQueueStatusById', downloadQueueState);
|
||||
|
||||
return downloadQueueState;
|
||||
};
|
||||
|
||||
export default updateDownloadQueueStatusById;
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
const updatePlaylistSubscription = async (playlistIds: string, status: boolean) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const playlists = [];
|
||||
const containsMultiple = playlistIds.includes('\n');
|
||||
|
||||
@@ -20,23 +14,10 @@ const updatePlaylistSubscription = async (playlistIds: string, status: boolean)
|
||||
playlists.push({ playlist_id: playlistIds, playlist_subscribed: status });
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/playlist/`, {
|
||||
return APIClient('/api/playlist/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify({
|
||||
data: [...playlists],
|
||||
}),
|
||||
body: { data: [...playlists] },
|
||||
});
|
||||
|
||||
const playlistSubscription = await response.json();
|
||||
console.log('updatePlaylistSubscription', playlistSubscription);
|
||||
|
||||
return playlistSubscription;
|
||||
};
|
||||
|
||||
export default updatePlaylistSubscription;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
type TaskNamesType =
|
||||
| 'download_pending'
|
||||
@@ -11,22 +8,9 @@ type TaskNamesType =
|
||||
| 'rescan_filesystem';
|
||||
|
||||
const updateTaskByName = async (taskName: TaskNamesType) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/task/by-name/${taskName}/`, {
|
||||
return APIClient(`/api/task/by-name/${taskName}/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
});
|
||||
|
||||
const downloadQueueState = await response.json();
|
||||
console.log('updateTaskByName', downloadQueueState);
|
||||
|
||||
return downloadQueueState;
|
||||
};
|
||||
|
||||
export default updateTaskByName;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { SortByType, SortOrderType, ViewLayoutType } from '../../pages/Home';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
export type UserMeType = {
|
||||
id: number;
|
||||
@@ -33,24 +30,10 @@ export type UserConfigType = {
|
||||
};
|
||||
|
||||
const updateUserConfig = async (config: Partial<UserConfigType>): Promise<UserConfigType> => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/user/me/`, {
|
||||
return APIClient('/api/user/me/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify({ config }),
|
||||
body: { config: config },
|
||||
});
|
||||
|
||||
const userConfig = await response.json();
|
||||
console.log('updateUserConfig', userConfig);
|
||||
|
||||
return userConfig;
|
||||
};
|
||||
|
||||
export default updateUserConfig;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
|
||||
type VideoProgressProp = {
|
||||
youtubeId: string;
|
||||
@@ -9,26 +6,10 @@ type VideoProgressProp = {
|
||||
};
|
||||
|
||||
const updateVideoProgressById = async ({ youtubeId, currentProgress }: VideoProgressProp) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/video/${youtubeId}/progress/`, {
|
||||
return APIClient(`/api/video/${youtubeId}/progress/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify({
|
||||
position: currentProgress,
|
||||
}),
|
||||
body: { position: currentProgress },
|
||||
});
|
||||
|
||||
const userConfig = await response.json();
|
||||
console.log('updateVideoProgressById', userConfig);
|
||||
|
||||
return userConfig;
|
||||
};
|
||||
|
||||
export default updateVideoProgressById;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import defaultHeaders from '../../configuration/defaultHeaders';
|
||||
import getApiUrl from '../../configuration/getApiUrl';
|
||||
import getFetchCredentials from '../../configuration/getFetchCredentials';
|
||||
import getCookie from '../../functions/getCookie';
|
||||
import APIClient from '../../functions/APIClient';
|
||||
import deleteVideoProgressById from './deleteVideoProgressById';
|
||||
|
||||
export type Watched = {
|
||||
@@ -10,28 +7,14 @@ export type Watched = {
|
||||
};
|
||||
|
||||
const updateWatchedState = async (watched: Watched) => {
|
||||
const apiUrl = getApiUrl();
|
||||
const csrfCookie = getCookie('csrftoken');
|
||||
|
||||
if (watched.is_watched) {
|
||||
await deleteVideoProgressById(watched.id);
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiUrl}/api/watched/`, {
|
||||
return APIClient('/api/watched/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...defaultHeaders,
|
||||
'X-CSRFToken': csrfCookie || '',
|
||||
},
|
||||
credentials: getFetchCredentials(),
|
||||
|
||||
body: JSON.stringify(watched),
|
||||
body: watched,
|
||||
});
|
||||
|
||||
const watchedState = await response.json();
|
||||
console.log('updateWatchedState', watchedState);
|
||||
|
||||
return watchedState;
|
||||
};
|
||||
|
||||
export default updateWatchedState;
|
||||
|
||||
Reference in New Issue
Block a user