2023-05-29 18:04:03 -06:00
|
|
|
import {API_URI, ARCHIVES_API, DEFAULT_LIMIT, emptyToNull, OTP_API, VIDEOS_API, ZIM_API} from "./components/Common";
|
2023-01-31 18:08:07 -07:00
|
|
|
import {toast} from "react-semantic-toasts-2";
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
function timeoutPromise(ms, promise) {
|
|
|
|
|
// Create a timeout wrapper around a promise. If the timeout is reached, throw an error. Otherwise, return
|
|
|
|
|
// the results of the promise.
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const timeoutId = setTimeout(() => {
|
|
|
|
|
reject(new Error("promise timeout"))
|
|
|
|
|
}, ms);
|
2022-11-12 14:17:21 -07:00
|
|
|
promise.then((res) => {
|
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
|
resolve(res);
|
|
|
|
|
}, (err) => {
|
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
2021-11-01 16:42:52 -06:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 15:49:11 -07:00
|
|
|
async function apiCall(url, method, body, ms = 60_000) {
|
2021-11-01 16:42:52 -06:00
|
|
|
let init = {method};
|
|
|
|
|
if (body !== undefined) {
|
|
|
|
|
init.body = JSON.stringify(body);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a fetch promise, this will be awaited by the timeout.
|
|
|
|
|
let promise = fetch(url, init);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// await the response or error.
|
2021-12-20 16:08:13 -07:00
|
|
|
let response = await timeoutPromise(ms, promise);
|
2022-08-06 05:22:07 +00:00
|
|
|
if (200 <= response.status && response.status < 300) {
|
2022-02-04 13:55:13 -07:00
|
|
|
// Request was successful.
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
// Request encountered an error.
|
2022-01-15 18:15:23 -07:00
|
|
|
let copy = response.clone();
|
2023-07-17 14:21:27 -06:00
|
|
|
const content = await copy.json();
|
|
|
|
|
const code = content['code'];
|
|
|
|
|
if (response.status === 403 && code === 'WROL_MODE_ENABLED') {
|
2021-12-20 16:08:13 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
2021-12-30 20:45:11 -07:00
|
|
|
title: 'WROL Mode is enabled!',
|
2022-08-06 05:22:07 +00:00
|
|
|
description: 'This functionality is disabled while WROL Mode is enabled!',
|
2021-12-20 16:08:13 -07:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return response;
|
2021-11-01 16:42:52 -06:00
|
|
|
} catch (e) {
|
|
|
|
|
// Timeout, or some other exception.
|
2023-01-31 17:11:31 -07:00
|
|
|
console.error(e);
|
2021-11-01 16:42:52 -06:00
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convenience functions for API calls.
|
|
|
|
|
let apiGet = async (url) => {
|
|
|
|
|
return await apiCall(url, 'GET')
|
|
|
|
|
};
|
|
|
|
|
let apiDelete = async (url) => {
|
|
|
|
|
return await apiCall(url, 'DELETE')
|
|
|
|
|
};
|
|
|
|
|
let apiPost = async (url, body) => {
|
|
|
|
|
return await apiCall(url, 'POST', body)
|
|
|
|
|
};
|
|
|
|
|
let apiPut = async (url, body) => {
|
|
|
|
|
return await apiCall(url, 'PUT', body)
|
|
|
|
|
};
|
|
|
|
|
let apiPatch = async (url, body) => {
|
|
|
|
|
return await apiCall(url, 'PATCH', body)
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-08 09:57:04 -06:00
|
|
|
export async function updateChannel(id, channel) {
|
2022-02-16 21:57:27 -07:00
|
|
|
channel = emptyToNull(channel);
|
2022-04-08 09:57:04 -06:00
|
|
|
return await apiPut(`${VIDEOS_API}/channels/${id}`, channel);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function createChannel(channel) {
|
2022-02-16 21:57:27 -07:00
|
|
|
channel = emptyToNull(channel);
|
2021-11-01 16:42:52 -06:00
|
|
|
return await apiPost(`${VIDEOS_API}/channels`, channel);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
export async function deleteChannel(channelId) {
|
2023-07-21 15:14:09 -06:00
|
|
|
const response = await apiDelete(`${VIDEOS_API}/channels/${channelId}`);
|
|
|
|
|
if (response.status !== 204) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
console.error(content);
|
|
|
|
|
throw Error(content);
|
|
|
|
|
}
|
|
|
|
|
return response;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getChannels() {
|
|
|
|
|
let response = await apiGet(`${VIDEOS_API}/channels`);
|
2022-05-01 21:12:39 -06:00
|
|
|
if (response.status === 200) {
|
2022-05-01 21:03:30 -06:00
|
|
|
return (await response.json())['channels'];
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unexpected server response',
|
|
|
|
|
description: 'Failed to get channels. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-04-08 09:57:04 -06:00
|
|
|
export async function getChannel(id) {
|
|
|
|
|
let response = await apiGet(`${VIDEOS_API}/channels/${id}`);
|
2021-11-01 16:42:52 -06:00
|
|
|
return (await response.json())['channel'];
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 18:51:26 -06:00
|
|
|
export async function searchVideos(offset, limit, channelId, searchStr, order_by, tagNames, headline) {
|
2021-11-01 16:42:52 -06:00
|
|
|
// Build a search query to retrieve a list of videos from the API
|
2022-08-06 05:22:07 +00:00
|
|
|
offset = parseInt(offset || 0);
|
|
|
|
|
limit = parseInt(limit || DEFAULT_LIMIT);
|
2023-03-24 08:58:18 -06:00
|
|
|
let body = {offset, limit, order_by: order_by || 'rank'};
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
if (searchStr) {
|
2022-08-06 05:22:07 +00:00
|
|
|
body['search_str'] = searchStr;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
if (channelId) {
|
|
|
|
|
body['channel_id'] = parseInt(channelId);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
2023-04-05 14:37:14 -06:00
|
|
|
if (tagNames) {
|
|
|
|
|
body['tag_names'] = tagNames;
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
2023-04-12 18:51:26 -06:00
|
|
|
if (headline) {
|
|
|
|
|
body['headline'] = true;
|
|
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
console.debug('searching videos', body);
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
let response = await apiPost(`${VIDEOS_API}/search`, body);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
let data = await response.json();
|
2023-03-24 08:58:18 -06:00
|
|
|
return [data['file_groups'], data['totals']['file_groups']];
|
2021-11-01 16:42:52 -06:00
|
|
|
} else {
|
2022-05-01 21:03:30 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unexpected server response',
|
|
|
|
|
description: 'Failed to search videos. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
2022-08-06 05:22:07 +00:00
|
|
|
return [[], 0];
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getVideo(video_id) {
|
|
|
|
|
let response = await apiGet(`${VIDEOS_API}/video/${video_id}`);
|
|
|
|
|
let data = await response.json();
|
2023-03-24 08:58:18 -06:00
|
|
|
return [data['file_group'], data['prev'], data['next']];
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-09-23 16:43:45 -06:00
|
|
|
export async function deleteVideos(videoIds) {
|
2023-05-29 18:04:03 -06:00
|
|
|
if (!videoIds || videoIds.length === 0) {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Empty request',
|
|
|
|
|
description: 'Unable to delete Videos because no IDs were passed.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-21 15:14:09 -06:00
|
|
|
console.info(`Deleting Videos: ${videoIds}`);
|
2022-09-23 16:43:45 -06:00
|
|
|
const i = videoIds.join(',');
|
|
|
|
|
let response = await apiDelete(`${VIDEOS_API}/video/${i}`);
|
2021-11-01 16:42:52 -06:00
|
|
|
if (response.status !== 204) {
|
2023-07-21 15:14:09 -06:00
|
|
|
const content = response.json();
|
|
|
|
|
console.error(content);
|
|
|
|
|
throw Error(content);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getDirectories(search_str) {
|
|
|
|
|
let form_data = {'search_str': search_str || null};
|
2022-11-09 08:33:55 -07:00
|
|
|
let response = await apiPost(`${API_URI}/files/directories`, form_data);
|
2021-11-01 16:42:52 -06:00
|
|
|
if (response.status === 200) {
|
2022-11-09 08:33:55 -07:00
|
|
|
return await response.json();
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-29 20:07:40 -06:00
|
|
|
export async function getStatus() {
|
|
|
|
|
let response = await apiGet(`${API_URI}/status`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Unexpected server response', description: 'Could not get server status', time: 5000,
|
2022-06-29 20:07:40 -06:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 21:57:27 -07:00
|
|
|
export async function getSettings() {
|
2021-11-01 16:42:52 -06:00
|
|
|
let response = await apiGet(`${API_URI}/settings`);
|
2022-05-01 21:12:39 -06:00
|
|
|
if (response.status === 200) {
|
2022-05-01 21:03:30 -06:00
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Unexpected server response', description: 'Could not get settings', time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-02-16 21:57:27 -07:00
|
|
|
export async function saveSettings(settings) {
|
|
|
|
|
return await apiPatch(`${API_URI}/settings`, settings);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2021-12-20 16:08:13 -07:00
|
|
|
export async function getDownloads() {
|
|
|
|
|
let response = await apiGet(`${API_URI}/download`);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Unexpected server response', description: 'Could not get downloads', time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2021-12-20 16:08:13 -07:00
|
|
|
}
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
export async function validateRegex(regex) {
|
|
|
|
|
let response = await apiPost(`${API_URI}/valid_regex`, {regex});
|
|
|
|
|
return (await response.json())['valid'];
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 11:10:01 -07:00
|
|
|
export async function getVideosStatistics() {
|
2021-11-01 16:42:52 -06:00
|
|
|
let response = await apiGet(`${VIDEOS_API}/statistics`);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return (await response.json())['statistics'];
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Unexpected server response', description: 'Could not get statistics', time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
export async function downloadChannel(channelId) {
|
|
|
|
|
let url = `${VIDEOS_API}/channels/download/${channelId}`;
|
2021-12-30 20:45:11 -07:00
|
|
|
let response = await apiPost(url);
|
2023-02-17 17:02:38 -07:00
|
|
|
if (response.status === 400) {
|
|
|
|
|
const json = await response.json();
|
2023-07-17 14:21:27 -06:00
|
|
|
if (json['code'] === 'INVALID_DOWNLOAD') {
|
2023-02-17 17:02:38 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Cannot Download!',
|
|
|
|
|
description: 'This channel does not have a download record. Modify the frequency.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-12-30 20:45:11 -07:00
|
|
|
}
|
2023-07-17 17:32:29 -06:00
|
|
|
return response;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
export async function refreshChannel(channelId) {
|
|
|
|
|
let url = `${VIDEOS_API}/channels/refresh/${channelId}`;
|
2023-07-21 15:14:09 -06:00
|
|
|
return await fetch(url, {method: 'POST'});
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function encryptOTP(otp, plaintext) {
|
|
|
|
|
let body = {otp, plaintext};
|
2021-12-30 20:45:11 -07:00
|
|
|
let response = await apiPost(`${OTP_API}/encrypt_otp`, body);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
2021-11-01 16:42:52 -06:00
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Error!', description: 'Failed to encrypt OTP', time: 5000,
|
2021-11-01 16:42:52 -06:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function decryptOTP(otp, ciphertext) {
|
|
|
|
|
let body = {otp, ciphertext};
|
2021-12-30 20:45:11 -07:00
|
|
|
let response = await apiPost(`${OTP_API}/decrypt_otp`, body);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
2021-11-01 16:42:52 -06:00
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Error!', description: 'Failed to decrypt OTP', time: 5000,
|
2021-11-01 16:42:52 -06:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getCategories() {
|
|
|
|
|
let response = await apiGet(`${API_URI}/inventory/categories`);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return (await response.json())['categories'];
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Unexpected server response', description: 'Could not get categories', time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getBrands() {
|
|
|
|
|
let response = await apiGet(`${API_URI}/inventory/brands`);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return (await response.json())['brands'];
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Unexpected server response', description: 'Could not get brands', time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getInventories() {
|
|
|
|
|
let response = await apiGet(`${API_URI}/inventory`);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return (await response.json())['inventories'];
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Unexpected server response', description: 'Could not get inventories', time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getInventory(inventoryId) {
|
|
|
|
|
let response = await apiGet(`${API_URI}/inventory/${inventoryId}`);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Unexpected server response', description: 'Could not get inventory', time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function saveInventory(inventory) {
|
|
|
|
|
return await apiPost(`${API_URI}/inventory`, inventory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateInventory(inventoryId, inventory) {
|
|
|
|
|
delete inventory['id'];
|
|
|
|
|
return await apiPut(`${API_URI}/inventory/${inventoryId}`, inventory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteInventory(inventoryId) {
|
|
|
|
|
return await apiDelete(`${API_URI}/inventory/${inventoryId}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getItems(inventoryId) {
|
|
|
|
|
let response = await apiGet(`${API_URI}/inventory/${inventoryId}/item`);
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function saveItem(inventoryId, item) {
|
|
|
|
|
return await apiPost(`${API_URI}/inventory/${inventoryId}/item`, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateItem(itemId, item) {
|
2022-02-16 21:57:27 -07:00
|
|
|
item = emptyToNull(item);
|
2021-11-01 16:42:52 -06:00
|
|
|
return await apiPut(`${API_URI}/inventory/item/${itemId}`, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteItems(itemIds) {
|
|
|
|
|
let i = itemIds.join(',');
|
|
|
|
|
await apiDelete(`${API_URI}/inventory/item/${i}`);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-23 16:22:57 -06:00
|
|
|
export async function deleteArchives(archiveIds) {
|
2023-05-29 18:04:03 -06:00
|
|
|
if (!archiveIds || archiveIds.length === 0) {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Empty request',
|
|
|
|
|
description: 'Unable to delete Archives because no IDs were passed.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-21 15:14:09 -06:00
|
|
|
console.log(`Deleting Archives: ${archiveIds}`);
|
2022-09-23 16:22:57 -06:00
|
|
|
let i = archiveIds.join(',');
|
2023-07-21 15:14:09 -06:00
|
|
|
const response = await apiDelete(`${API_URI}/archive/${i}`);
|
|
|
|
|
if (response.status !== 204) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
console.debug(content);
|
|
|
|
|
throw Error(content['error']);
|
2022-09-23 16:22:57 -06:00
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2023-04-12 18:51:26 -06:00
|
|
|
export async function searchArchives(offset, limit, domain, searchStr, order, tagNames, headline) {
|
2021-11-01 16:42:52 -06:00
|
|
|
// Build a search query to retrieve a list of videos from the API
|
2022-02-02 14:02:51 -07:00
|
|
|
offset = parseInt(offset || 0);
|
|
|
|
|
limit = parseInt(limit || DEFAULT_LIMIT);
|
2021-11-01 16:42:52 -06:00
|
|
|
let body = {offset, limit};
|
|
|
|
|
if (domain) {
|
|
|
|
|
body['domain'] = domain;
|
|
|
|
|
}
|
2022-01-03 15:13:02 -07:00
|
|
|
if (searchStr) {
|
|
|
|
|
body['search_str'] = searchStr;
|
|
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
if (order) {
|
|
|
|
|
body['order_by'] = order;
|
|
|
|
|
}
|
2023-04-05 14:37:14 -06:00
|
|
|
if (tagNames) {
|
|
|
|
|
body['tag_names'] = tagNames;
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
2023-04-12 18:51:26 -06:00
|
|
|
if (headline) {
|
|
|
|
|
body['headline'] = true;
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
console.debug('searching archives', body);
|
2021-11-01 16:42:52 -06:00
|
|
|
let response = await apiPost(`${ARCHIVES_API}/search`, body);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
let data = await response.json();
|
2023-03-24 08:58:18 -06:00
|
|
|
return [data['file_groups'], data['totals']['file_groups']];
|
2021-11-01 16:42:52 -06:00
|
|
|
} else {
|
2022-01-15 18:15:23 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to search archives',
|
|
|
|
|
description: 'Cannot search archives. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
2023-03-24 08:58:18 -06:00
|
|
|
return [[], 0];
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchDomains() {
|
|
|
|
|
let response = await apiGet(`${ARCHIVES_API}/domains`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
let data = await response.json();
|
|
|
|
|
return [data['domains'], data['totals']['domains']];
|
|
|
|
|
} else {
|
2022-01-15 18:15:23 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Domains Error',
|
|
|
|
|
description: 'Unable to fetch Domains. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-20 16:08:13 -07:00
|
|
|
|
2022-05-16 17:56:55 -06:00
|
|
|
export async function getArchive(archiveId) {
|
|
|
|
|
const response = await apiGet(`${ARCHIVES_API}/${archiveId}`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const data = await response.json();
|
2023-03-24 08:58:18 -06:00
|
|
|
return [data['file_group'], data['history']];
|
2022-05-16 17:56:55 -06:00
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Archive Error', description: 'Unable to get Archive. See server logs.', time: 5000,
|
2022-05-16 17:56:55 -06:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 09:34:42 -06:00
|
|
|
export async function postDownload(urls, downloader, frequency, sub_downloader, excludedURLs, destination, tagNames) {
|
2023-04-01 15:34:46 -06:00
|
|
|
if (!downloader) {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Failed to submit download',
|
|
|
|
|
description: 'downloader is required, but was not provided',
|
|
|
|
|
time: 5000,
|
|
|
|
|
})
|
|
|
|
|
throw new Error('downloader is required, but was not provided');
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-09 08:33:55 -07:00
|
|
|
let body = {
|
|
|
|
|
urls: urls,
|
|
|
|
|
downloader: downloader,
|
|
|
|
|
frequency: frequency || null,
|
|
|
|
|
excluded_urls: excludedURLs,
|
|
|
|
|
destination: destination || null,
|
|
|
|
|
};
|
2022-05-20 15:15:31 -06:00
|
|
|
if (sub_downloader) {
|
|
|
|
|
body['sub_downloader'] = sub_downloader;
|
|
|
|
|
}
|
2023-04-03 09:34:42 -06:00
|
|
|
if (tagNames) {
|
|
|
|
|
body['tag_names'] = tagNames;
|
|
|
|
|
}
|
2021-12-20 16:08:13 -07:00
|
|
|
let response = await apiPost(`${API_URI}/download`, body);
|
2023-07-21 15:14:09 -06:00
|
|
|
if (response.status !== 204) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
console.error(content);
|
|
|
|
|
throw Error(content['error']);
|
|
|
|
|
}
|
2021-12-20 16:08:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function killDownload(download_id) {
|
|
|
|
|
let response = await apiPost(`${API_URI}/download/${download_id}/kill`);
|
|
|
|
|
return response;
|
|
|
|
|
}
|
2021-12-30 20:45:11 -07:00
|
|
|
|
2022-01-11 10:08:47 -07:00
|
|
|
export async function killDownloads() {
|
|
|
|
|
let response = await apiPost(`${API_URI}/download/kill`);
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startDownloads() {
|
|
|
|
|
let response = await apiPost(`${API_URI}/download/enable`);
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 20:45:11 -07:00
|
|
|
export async function getDownloaders() {
|
2022-02-04 13:55:13 -07:00
|
|
|
try {
|
|
|
|
|
let response = await apiGet(`${API_URI}/downloaders`);
|
|
|
|
|
return await response.json();
|
|
|
|
|
} catch (e) {
|
2022-05-01 21:03:30 -06:00
|
|
|
return {downloaders: []};
|
2022-02-04 13:55:13 -07:00
|
|
|
}
|
2021-12-30 20:45:11 -07:00
|
|
|
}
|
2022-01-29 16:50:22 -07:00
|
|
|
|
2022-11-12 14:17:21 -07:00
|
|
|
export async function deleteDownload(downloadId) {
|
|
|
|
|
try {
|
|
|
|
|
let response = await apiDelete(`${API_URI}/download/${downloadId}`);
|
|
|
|
|
if (response.status !== 204) {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to delete',
|
|
|
|
|
description: 'Unable to delete the download. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 18:51:26 -06:00
|
|
|
export async function filesSearch(offset, limit, searchStr, mimetypes, model, tagNames, headline) {
|
2022-02-01 14:11:14 -07:00
|
|
|
const body = {search_str: searchStr, offset: parseInt(offset), limit: parseInt(limit)};
|
2022-12-09 11:22:20 -07:00
|
|
|
if (mimetypes) {
|
|
|
|
|
body['mimetypes'] = mimetypes;
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
if (model) {
|
|
|
|
|
body['model'] = model;
|
|
|
|
|
}
|
2023-04-05 14:37:14 -06:00
|
|
|
if (tagNames) {
|
|
|
|
|
body['tag_names'] = tagNames;
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
2023-04-12 18:51:26 -06:00
|
|
|
if (headline) {
|
|
|
|
|
body['headline'] = true;
|
|
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
console.debug('searching files', body);
|
2022-02-01 14:11:14 -07:00
|
|
|
const response = await apiPost(`${API_URI}/files/search`, body);
|
2022-02-02 14:02:51 -07:00
|
|
|
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
let data = await response.json();
|
2023-03-24 08:58:18 -06:00
|
|
|
let [file_groups, total] = [data['file_groups'], data['totals']['file_groups']];
|
|
|
|
|
return [file_groups, total];
|
2022-02-02 14:02:51 -07:00
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to search files',
|
|
|
|
|
description: 'Cannot search files. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
2022-08-06 05:22:07 +00:00
|
|
|
return [null, null];
|
2022-02-02 14:02:51 -07:00
|
|
|
}
|
2022-02-01 14:11:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function refreshFiles() {
|
|
|
|
|
return await apiPost(`${API_URI}/files/refresh`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export async function refreshDirectoryFiles(paths) {
|
|
|
|
|
let body = {paths: paths};
|
2022-08-06 05:22:07 +00:00
|
|
|
try {
|
2023-03-24 08:58:18 -06:00
|
|
|
return await apiPost(`${API_URI}/files/refresh`, body);
|
2022-08-06 05:22:07 +00:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to refresh directory',
|
|
|
|
|
description: 'Cannot refresh the files in the directory. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export async function makeDirectory(path) {
|
|
|
|
|
const body = {path: path};
|
|
|
|
|
try {
|
|
|
|
|
await apiPost(`${API_URI}/files/directory`, body);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to create directory',
|
|
|
|
|
description: 'Failed to create directory. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 16:50:22 -07:00
|
|
|
export async function getFiles(directories) {
|
2023-02-15 17:40:57 -07:00
|
|
|
console.debug(`getFiles ${directories}`);
|
2022-01-29 16:50:22 -07:00
|
|
|
let body = {directories: directories || []};
|
|
|
|
|
let response = await apiPost(`${API_URI}/files`, body);
|
2022-02-02 14:02:51 -07:00
|
|
|
let {files} = await response.json();
|
|
|
|
|
return files;
|
2022-01-29 16:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export async function deleteFile(paths) {
|
|
|
|
|
let body = {paths: paths};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/delete`, body);
|
|
|
|
|
if (response.status === 409) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Delete error',
|
2023-07-17 14:21:27 -06:00
|
|
|
description: content['message'] || content['summary'],
|
2023-05-29 18:04:03 -06:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-01-29 16:50:22 -07:00
|
|
|
}
|
2022-01-30 16:59:26 -07:00
|
|
|
|
2023-03-27 20:46:31 -06:00
|
|
|
export async function fetchFilesProgress() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/files/refresh_progress`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const json = await response.json();
|
|
|
|
|
return json['progress'];
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-04 09:41:08 -07:00
|
|
|
|
2022-02-04 16:05:19 -07:00
|
|
|
export async function getHotspotStatus() {
|
2022-02-16 21:57:27 -07:00
|
|
|
let response = await getSettings();
|
|
|
|
|
return response['hotspot_status'];
|
2022-02-04 09:41:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function setHotspot(on) {
|
|
|
|
|
let response;
|
|
|
|
|
if (on) {
|
|
|
|
|
response = await apiPost(`${API_URI}/hotspot/on`);
|
|
|
|
|
} else {
|
|
|
|
|
response = await apiPost(`${API_URI}/hotspot/off`);
|
|
|
|
|
}
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
2023-07-17 14:21:27 -06:00
|
|
|
const content = await response.json();
|
|
|
|
|
const code = content['code'];
|
|
|
|
|
if (code === 'NATIVE_ONLY') {
|
2022-02-04 09:41:08 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unsupported!',
|
2023-07-17 14:21:27 -06:00
|
|
|
description: 'Hotspot is only supported outside Docker!',
|
2022-02-04 09:41:08 -07:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
2022-02-04 16:05:19 -07:00
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Error!', description: 'Could not modify hotspot. See server logs.', time: 5000,
|
2022-02-04 16:05:19 -07:00
|
|
|
});
|
2022-02-04 09:41:08 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-07 13:37:58 -07:00
|
|
|
|
|
|
|
|
export async function getThrottleStatus() {
|
2022-02-16 21:57:27 -07:00
|
|
|
let response = await getSettings();
|
|
|
|
|
return response['throttle_status'];
|
2022-02-07 13:37:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function setThrottle(on) {
|
|
|
|
|
let response;
|
|
|
|
|
if (on) {
|
|
|
|
|
response = await apiPost(`${API_URI}/throttle/on`);
|
|
|
|
|
} else {
|
|
|
|
|
response = await apiPost(`${API_URI}/throttle/off`);
|
|
|
|
|
}
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
2023-07-17 14:21:27 -06:00
|
|
|
const content = await response.json();
|
|
|
|
|
const code = content['code'];
|
|
|
|
|
if (code === 'NATIVE_ONLY') {
|
2022-02-07 13:37:58 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unsupported!',
|
|
|
|
|
description: 'Throttle is only supported on a Raspberry Pi!',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Error!', description: 'Could not modify throttle. See server logs.', time: 5000,
|
2022-02-07 13:37:58 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-08 13:26:03 -07:00
|
|
|
|
|
|
|
|
export async function getMapImportStatus() {
|
2022-03-31 07:31:15 -06:00
|
|
|
let response = await apiGet(`${API_URI}/map/files`);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Unexpected server response', description: 'Could not get import status', time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2022-03-08 13:26:03 -07:00
|
|
|
}
|
|
|
|
|
|
2022-03-31 07:31:15 -06:00
|
|
|
export async function importMapFiles(paths) {
|
|
|
|
|
let body = {'files': paths};
|
2022-03-08 13:26:03 -07:00
|
|
|
let response = await apiPost(`${API_URI}/map/import`, body);
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
2022-11-12 14:17:21 -07:00
|
|
|
type: 'error', title: 'Error!', description: 'Could not start import! See server logs.', time: 5000,
|
2022-03-08 13:26:03 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-01 16:31:49 -06:00
|
|
|
|
2022-04-01 16:45:59 -06:00
|
|
|
export async function clearCompletedDownloads() {
|
2022-04-01 16:31:49 -06:00
|
|
|
let response = await apiPost(`${API_URI}/download/clear_completed`);
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
return null
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Error!',
|
2022-04-01 16:45:59 -06:00
|
|
|
description: 'Could not clear completed downloads! See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function clearFailedDownloads() {
|
|
|
|
|
let response = await apiPost(`${API_URI}/download/clear_failed`);
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
return null
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Error!',
|
|
|
|
|
description: 'Could not clear failed downloads! See server logs.',
|
2022-04-01 16:31:49 -06:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-01 21:03:30 -06:00
|
|
|
|
2022-12-16 11:10:01 -07:00
|
|
|
export async function getStatistics() {
|
|
|
|
|
let response = await apiGet(`${API_URI}/statistics`);
|
2022-12-15 11:48:46 -07:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
const contents = await response.json();
|
2022-12-16 11:10:01 -07:00
|
|
|
return contents;
|
2022-12-15 11:48:46 -07:00
|
|
|
} else {
|
|
|
|
|
toast({
|
2023-02-17 17:02:38 -07:00
|
|
|
type: 'error', title: 'Error!', description: 'Unable to get file statistics', time: 5000,
|
2022-12-15 11:48:46 -07:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-23 16:04:09 -07:00
|
|
|
|
|
|
|
|
export async function getEvents(after) {
|
|
|
|
|
let uri = `${API_URI}/events/feed`;
|
|
|
|
|
if (after) {
|
2023-01-03 08:53:00 -07:00
|
|
|
uri = `${uri}?after=${encodeURIComponent(after)}`
|
2022-12-23 16:04:09 -07:00
|
|
|
}
|
|
|
|
|
let response = await apiGet(uri);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-24 08:58:18 -06:00
|
|
|
|
|
|
|
|
export async function getTags() {
|
|
|
|
|
let uri = `${API_URI}/tag`;
|
|
|
|
|
let response = await apiGet(uri);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const body = await response.json();
|
|
|
|
|
return body['tags'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export async function tagFileGroup(fileGroup, name) {
|
2023-04-01 11:52:41 -06:00
|
|
|
const body = {tag_name: name};
|
|
|
|
|
|
|
|
|
|
const {id, primary_path, path} = fileGroup;
|
|
|
|
|
if (id) {
|
|
|
|
|
body['file_group_id'] = id;
|
|
|
|
|
} else if (primary_path) {
|
|
|
|
|
body['file_group_primary_path'] = primary_path;
|
|
|
|
|
} else if (path) {
|
|
|
|
|
body['file_group_primary_path'] = path;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-24 08:58:18 -06:00
|
|
|
const uri = `${API_URI}/files/tag`;
|
|
|
|
|
let response = await apiPost(uri, body);
|
|
|
|
|
if (response.status !== 201) {
|
|
|
|
|
console.error('Failed to add tag');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export async function untagFileGroup(fileGroup, name) {
|
2023-04-01 11:52:41 -06:00
|
|
|
const body = {tag_name: name};
|
|
|
|
|
|
|
|
|
|
const {id, primary_path, path} = fileGroup;
|
|
|
|
|
if (id) {
|
|
|
|
|
body['file_group_id'] = id;
|
|
|
|
|
} else if (primary_path) {
|
|
|
|
|
body['file_group_primary_path'] = primary_path;
|
|
|
|
|
} else if (path) {
|
|
|
|
|
body['file_group_primary_path'] = path;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-24 08:58:18 -06:00
|
|
|
const uri = `${API_URI}/files/untag`;
|
|
|
|
|
let response = await apiPost(uri, body)
|
|
|
|
|
if (response.status !== 204) {
|
|
|
|
|
console.error('Failed to remove tag');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 16:17:33 -06:00
|
|
|
export async function saveTag(name, color, id) {
|
2023-03-24 08:58:18 -06:00
|
|
|
const body = {name: name, color: color};
|
2023-03-27 16:17:33 -06:00
|
|
|
let uri = `${API_URI}/tag`;
|
|
|
|
|
if (id) {
|
|
|
|
|
uri = `${uri}/${id}`;
|
|
|
|
|
}
|
2023-03-24 08:58:18 -06:00
|
|
|
let response = await apiPost(uri, body);
|
2023-03-27 16:17:33 -06:00
|
|
|
if (id && response.status === 200) {
|
2023-03-24 08:58:18 -06:00
|
|
|
toast({
|
2023-03-27 16:17:33 -06:00
|
|
|
type: 'info', title: 'Saved tag', description: `Saved tag: ${name}`, time: 2000,
|
|
|
|
|
});
|
|
|
|
|
} else if (response.status === 201) {
|
2023-03-24 08:58:18 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'info', title: 'Created new tag', description: `Created new tag: ${name}`, time: 2000,
|
|
|
|
|
});
|
2023-03-27 16:17:33 -06:00
|
|
|
} else {
|
|
|
|
|
console.error('Failed to create new tag');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error', title: 'Error!', description: 'Unable to save tag', time: 5000,
|
|
|
|
|
})
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 16:17:33 -06:00
|
|
|
export async function deleteTag(id, name) {
|
|
|
|
|
const uri = `${API_URI}/tag/${id}`;
|
|
|
|
|
let response = await apiDelete(uri);
|
2023-03-24 08:58:18 -06:00
|
|
|
if (response.status === 400) {
|
|
|
|
|
const content = await response.json();
|
2023-07-17 14:21:27 -06:00
|
|
|
if (content['code'] === 'USED_TAG') {
|
2023-03-24 08:58:18 -06:00
|
|
|
toast({
|
2023-07-17 14:21:27 -06:00
|
|
|
type: 'error', title: 'Error!', description: content['error'] || content['summary'], time: 5000,
|
2023-03-24 08:58:18 -06:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
} else if (response.status !== 204) {
|
|
|
|
|
console.error('Failed to delete tag');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error', title: 'Error!', description: `Unable to delete tag: ${name}`, time: 5000,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-01 11:52:41 -06:00
|
|
|
|
|
|
|
|
export async function fetchFile(path) {
|
|
|
|
|
const uri = `${API_URI}/files/file`;
|
|
|
|
|
const body = {file: path};
|
|
|
|
|
const response = await apiPost(uri, body);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return content['file'];
|
|
|
|
|
} else {
|
|
|
|
|
console.error('Unable to fetch file dict! See client logs.');
|
|
|
|
|
}
|
2023-04-10 13:15:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function sendNotification(message, url) {
|
|
|
|
|
const body = {message, url};
|
|
|
|
|
const response = await apiPost(`${API_URI}/notify`, body);
|
|
|
|
|
if (response.status === 201) {
|
|
|
|
|
toast({type: 'success', title: 'Shared', description: 'Your share was sent', time: 2000});
|
|
|
|
|
} else {
|
|
|
|
|
toast({type: 'error', title: 'Error', description: 'Your share failed to send!', time: 5000});
|
|
|
|
|
console.error('Failed to share');
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-18 22:03:45 -06:00
|
|
|
|
|
|
|
|
export async function searchDirectories(name) {
|
|
|
|
|
const body = {name: name || ''};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/search_directories`, body);
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
return [];
|
|
|
|
|
} else if (response.status === 200) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return content;
|
|
|
|
|
} else {
|
|
|
|
|
toast({type: 'error', title: 'Error', description: 'Failed to search directories!', time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export async function renamePath(path, newName) {
|
|
|
|
|
const body = {path, new_name: newName};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/rename`, body);
|
|
|
|
|
if (response.status !== 204) {
|
|
|
|
|
toast({type: 'error', title: 'Error', description: 'Failed to rename!', time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function movePaths(destination, paths) {
|
|
|
|
|
const body = {destination, paths};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/move`, body);
|
|
|
|
|
if (response.status !== 204) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
toast({type: 'error', title: 'Error', description: content['api_error'], time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchZims() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/zim`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
zims: content['zims'],
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
toast({type: 'error', title: 'Error', description: 'Cannot fetch Zims', time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchZimSubscriptions() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/zim/subscribe`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
subscriptions: content['subscriptions'],
|
|
|
|
|
catalog: content['catalog'],
|
|
|
|
|
iso_639_codes: content['iso_639_codes'],
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
toast({type: 'error', title: 'Error', description: 'Cannot fetch Zim Subscriptions', time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function searchZims(offset, limit, searchStr) {
|
|
|
|
|
offset = parseInt(offset || 0);
|
|
|
|
|
limit = parseInt(limit || DEFAULT_LIMIT);
|
|
|
|
|
let body = {offset, limit};
|
|
|
|
|
if (searchStr) {
|
|
|
|
|
body['search_str'] = searchStr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.debug('searching zims', body);
|
|
|
|
|
let response = await apiPost(`${ZIM_API}/search`, body);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
let data = await response.json();
|
|
|
|
|
return [data['zims'],];
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to search zims',
|
|
|
|
|
description: 'Cannot search zims. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
return [[], 0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function searchZim(offset, limit, searchStr, zimId, activeTags) {
|
|
|
|
|
offset = parseInt(offset || 0);
|
|
|
|
|
limit = parseInt(limit || DEFAULT_LIMIT);
|
|
|
|
|
let body = {offset, limit, search_str: searchStr, tag_names: activeTags || []};
|
|
|
|
|
|
|
|
|
|
console.debug(`Searching Zim ${zimId} for: ${searchStr} tags: ${activeTags}`);
|
|
|
|
|
let response = await apiPost(`${ZIM_API}/search/${zimId}`, body);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
const zim = content['zim'];
|
|
|
|
|
const searchLength = zim['search'].length;
|
|
|
|
|
console.debug(`Got ${searchLength} results for Zim ${zimId}`);
|
|
|
|
|
return content['zim'];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function tagZimEntry(zim_id, zim_entry, name) {
|
|
|
|
|
const body = {tag_name: name, zim_id: zim_id, zim_entry: zim_entry};
|
|
|
|
|
|
|
|
|
|
const uri = `${API_URI}/zim/tag`;
|
|
|
|
|
let response = await apiPost(uri, body);
|
|
|
|
|
if (response.status !== 201) {
|
|
|
|
|
console.error('Failed to add tag');
|
2023-04-18 22:03:45 -06:00
|
|
|
}
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function untagZimEntry(zim_id, zim_entry, name) {
|
|
|
|
|
const body = {tag_name: name, zim_id: zim_id, zim_entry: zim_entry};
|
|
|
|
|
|
|
|
|
|
const uri = `${API_URI}/zim/untag`;
|
|
|
|
|
let response = await apiPost(uri, body);
|
|
|
|
|
if (response.status !== 201) {
|
|
|
|
|
console.error('Failed to add tag');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function zimSubscribe(name, language) {
|
|
|
|
|
const body = {name, language};
|
|
|
|
|
const response = await apiPost(`${API_URI}/zim/subscribe`, body);
|
|
|
|
|
return response.status === 201;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function zimUnsubscribe(id) {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/zim/subscribe/${id}`);
|
|
|
|
|
return response.status === 204;
|
2023-04-18 22:03:45 -06:00
|
|
|
}
|
2023-06-11 12:31:56 -06:00
|
|
|
|
|
|
|
|
export async function fetchDecoded(vinNumber) {
|
|
|
|
|
const body = {vin_number: vinNumber};
|
|
|
|
|
const response = await apiPost(`${API_URI}/vin_number_decoder`, body);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return content['vin'];
|
|
|
|
|
} else if (response.status === 400) {
|
|
|
|
|
console.error('Invalid VIN Number');
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-29 18:04:03 -06:00
|
|
|
|
|
|
|
|
export async function searchEstimate(search_str, tagNames) {
|
|
|
|
|
const body = {search_str: search_str, tag_names: tagNames};
|
|
|
|
|
const response = await apiPost(`${API_URI}/search_estimate`, body);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
const zims = content['zims'];
|
|
|
|
|
let zimSum = 0;
|
|
|
|
|
zims.map(i => zimSum += i['estimate']);
|
|
|
|
|
return {
|
|
|
|
|
file_groups: content['file_groups'],
|
|
|
|
|
zims: zims,
|
|
|
|
|
zimSum: zimSum,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getOutdatedZims() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/zim/outdated`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
outdated: content['outdated'],
|
|
|
|
|
current: content['current'],
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to fetch',
|
|
|
|
|
description: 'Cannot fetch outdated Zims. See server logs.',
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteOutdatedZims() {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/zim/outdated`);
|
|
|
|
|
return response.status === 204;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function ignoreOutdatedZims() {
|
|
|
|
|
const response = await apiPost(`${API_URI}/zim/outdated`);
|
|
|
|
|
return response.status === 204;
|
|
|
|
|
}
|