2024-11-02 15:14:02 -06:00
|
|
|
import {emptyToNull} from "./components/Common";
|
2023-01-31 18:08:07 -07:00
|
|
|
import {toast} from "react-semantic-toasts-2";
|
2024-03-06 17:41:04 -07:00
|
|
|
import _ from "lodash";
|
2025-12-06 14:49:46 -07:00
|
|
|
import {
|
|
|
|
|
API_URI,
|
|
|
|
|
ARCHIVES_API,
|
|
|
|
|
COLLECTIONS_API,
|
|
|
|
|
DEFAULT_LIMIT,
|
|
|
|
|
Downloaders,
|
|
|
|
|
VIDEOS_API,
|
|
|
|
|
ZIM_API
|
|
|
|
|
} from "./components/Vars";
|
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
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-24 15:35:26 -07:00
|
|
|
export class ApiDownError extends Error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const apiDownError = new ApiDownError('API is down');
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-24 15:35:26 -07:00
|
|
|
let promise;
|
2021-11-01 16:42:52 -06:00
|
|
|
try {
|
2025-01-24 15:35:26 -07:00
|
|
|
// Create a fetch promise, this will be awaited by the timeout.
|
|
|
|
|
promise = fetch(url, init);
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
// await the response or error.
|
2024-08-15 19:32:01 -06:00
|
|
|
const 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;
|
|
|
|
|
}
|
2025-01-24 15:35:26 -07:00
|
|
|
if (response.status === 502) {
|
|
|
|
|
// API is down.
|
|
|
|
|
throw apiDownError;
|
|
|
|
|
}
|
2022-02-04 13:55:13 -07:00
|
|
|
// 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();
|
2024-08-15 19:32:01 -06:00
|
|
|
console.error('API error response json', content);
|
2023-07-17 14:21:27 -06:00
|
|
|
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) {
|
2025-01-24 15:35:26 -07:00
|
|
|
if (e instanceof ApiDownError) {
|
|
|
|
|
// Throw ApiDownError immediately without logging.
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
2024-12-18 17:32:00 -07:00
|
|
|
// Ignore SyntaxError because they happen when the API is down.
|
|
|
|
|
if (!(e instanceof SyntaxError)) {
|
|
|
|
|
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)
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-15 19:32:01 -06:00
|
|
|
async function getErrorMessage(response, fallbackMessage) {
|
|
|
|
|
try {
|
|
|
|
|
const json = await response.clone().json();
|
|
|
|
|
return json.error || json.message || fallbackMessage;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// Server did not response with JSON. Return default message.
|
|
|
|
|
return fallbackMessage;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to delete channel.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unexpected server response',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
2023-07-21 15:14:09 -06:00
|
|
|
}
|
|
|
|
|
return response;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getChannels() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const 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 {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to get channels.');
|
2022-05-01 21:03:30 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unexpected server response',
|
2024-08-15 19:32:01 -06:00
|
|
|
description: message,
|
2022-05-01 21:03:30 -06:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-04-08 09:57:04 -06:00
|
|
|
export async function getChannel(id) {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${VIDEOS_API}/channels/${id}`);
|
2021-11-01 16:42:52 -06:00
|
|
|
return (await response.json())['channel'];
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-06 18:13:21 -06:00
|
|
|
export async function tagChannel(channelId, tagName, directory) {
|
|
|
|
|
const body = {
|
|
|
|
|
tag_name: tagName,
|
|
|
|
|
}
|
|
|
|
|
if (directory) {
|
|
|
|
|
body['directory'] = directory;
|
|
|
|
|
}
|
|
|
|
|
const response = await apiPost(`${VIDEOS_API}/channels/${channelId}/tag`, body);
|
|
|
|
|
if (!response.ok) {
|
2024-08-15 19:32:01 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to tag channel. See server logs.');
|
2024-08-06 18:13:21 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
2024-08-15 19:32:01 -06:00
|
|
|
title: 'Tagging Channel Failed',
|
|
|
|
|
description: message,
|
2024-08-06 18:13:21 -06:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function tagChannelInfo(channelId, tagName) {
|
2024-08-15 19:32:01 -06:00
|
|
|
channelId = channelId ? parseInt(channelId) : null;
|
|
|
|
|
const body = {channel_id: channelId, tag_name: tagName};
|
|
|
|
|
const response = await apiPost(`${VIDEOS_API}/tag_info`, body);
|
2024-08-06 18:13:21 -06:00
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json()).videos_destination;
|
|
|
|
|
}
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to get channel tag info.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Getting Channel Tag Info Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
2024-08-06 18:13:21 -06:00
|
|
|
}
|
|
|
|
|
|
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries. Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.
Database:
- Migration adds the generated column and a GIN index (rewrites the
table; a few minutes on large libraries).
Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
query (COUNT FILTER on the abc subset): `file_groups` (fast) and
`file_groups_deep`.
UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
list.
- The gap is reconciled by a hint offering deep search: count-aware on
the global search ("No results in fast search. N results available in
deep search." / "N more results available..."), generic on the module
pages (no deep estimate there). The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
?deep=true.
Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside. Also skip flaky test_download_channel on
CircleCI.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:09:08 -06:00
|
|
|
export async function searchVideos(offset, limit, channelId, searchStr, order_by, tagNames, headline, censored, deep) {
|
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;
|
|
|
|
|
}
|
2026-06-27 09:48:21 -06:00
|
|
|
if (censored) {
|
|
|
|
|
body['censored'] = true;
|
|
|
|
|
}
|
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries. Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.
Database:
- Migration adds the generated column and a GIN index (rewrites the
table; a few minutes on large libraries).
Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
query (COUNT FILTER on the abc subset): `file_groups` (fast) and
`file_groups_deep`.
UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
list.
- The gap is reconciled by a hint offering deep search: count-aware on
the global search ("No results in fast search. N results available in
deep search." / "N more results available..."), generic on the module
pages (no deep estimate there). The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
?deep=true.
Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside. Also skip flaky test_download_channel on
CircleCI.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:09:08 -06:00
|
|
|
if (deep) {
|
|
|
|
|
body['deep'] = true;
|
|
|
|
|
}
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
console.debug('searching videos', body);
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${VIDEOS_API}/search`, body);
|
2021-11-01 16:42:52 -06:00
|
|
|
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 {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to search videos.');
|
2022-05-01 21:03:30 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
2024-08-15 19:32:01 -06:00
|
|
|
title: 'Searching Videos failed',
|
|
|
|
|
description: message,
|
2022-05-01 21:03:30 -06:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
2022-08-06 05:22:07 +00:00
|
|
|
return [[], 0];
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 15:38:32 -06:00
|
|
|
export async function getVideo(fileGroupId) {
|
|
|
|
|
const response = await apiGet(`${VIDEOS_API}/${fileGroupId}`);
|
2021-11-01 16:42:52 -06:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2026-03-20 15:38:32 -06:00
|
|
|
export async function getVideoComments(fileGroupId) {
|
|
|
|
|
const response = await apiGet(`${VIDEOS_API}/${fileGroupId}/comments`);
|
2025-01-26 12:44:16 -07:00
|
|
|
let data = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
comments: data.comments,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 15:38:32 -06:00
|
|
|
export async function getVideoCaptions(fileGroupId) {
|
|
|
|
|
const response = await apiGet(`${VIDEOS_API}/${fileGroupId}/captions`);
|
2025-01-26 12:44:16 -07:00
|
|
|
let data = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
captions: data.captions,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-03 18:50:22 -06:00
|
|
|
export async function deleteFileGroups(fileGroupIds, force = false) {
|
2026-03-20 15:38:32 -06:00
|
|
|
if (!fileGroupIds || fileGroupIds.length === 0) {
|
2023-05-29 18:04:03 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Empty request',
|
2026-05-03 18:50:22 -06:00
|
|
|
description: 'Unable to delete FileGroups because no IDs were passed.',
|
2023-05-29 18:04:03 -06:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
2026-05-03 18:50:22 -06:00
|
|
|
return;
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
2026-05-03 18:50:22 -06:00
|
|
|
console.info(`Deleting FileGroups: ${fileGroupIds}`);
|
|
|
|
|
const body = {file_group_ids: fileGroupIds, force};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/delete_groups`, body);
|
2026-05-03 17:28:06 -06:00
|
|
|
if (response.ok) {
|
|
|
|
|
return response;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
2026-05-03 17:28:06 -06:00
|
|
|
try {
|
|
|
|
|
const json = await response.clone().json();
|
|
|
|
|
if (json.code === 'FILE_GROUP_IS_TAGGED' && json.file_groups) {
|
|
|
|
|
return {tagged: true, file_groups: json.file_groups};
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// Not JSON, fall through to generic error.
|
|
|
|
|
}
|
2026-05-03 18:50:22 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to delete files.');
|
2026-05-03 17:28:06 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
2026-05-03 18:50:22 -06:00
|
|
|
title: 'Delete failed',
|
2026-05-03 17:28:06 -06:00
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw Error(message);
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-19 15:02:32 -06:00
|
|
|
export async function downloadVideoMetadata(videoUrl) {
|
|
|
|
|
const downloadData = {
|
|
|
|
|
urls: [videoUrl],
|
|
|
|
|
downloader: Downloaders.Video,
|
|
|
|
|
settings: {download_metadata_only: true},
|
|
|
|
|
};
|
2024-11-02 15:14:02 -06:00
|
|
|
return await postDownload(downloadData);
|
2024-02-20 13:47:12 -07:00
|
|
|
}
|
|
|
|
|
|
2022-06-29 20:07:40 -06:00
|
|
|
export async function getStatus() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${API_URI}/status`);
|
2022-06-29 20:07:40 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not get server status.');
|
2022-06-29 20:07:40 -06:00
|
|
|
toast({
|
2024-08-15 19:32:01 -06:00
|
|
|
type: 'error',
|
|
|
|
|
title: 'Fetching Status Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
2022-06-29 20:07:40 -06:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-16 21:57:27 -07:00
|
|
|
export async function getSettings() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${API_URI}/settings`);
|
|
|
|
|
if (response.ok) {
|
2024-10-03 13:35:06 -06:00
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
archive_destination: content.archive_destination,
|
|
|
|
|
download_manager_disabled: content.download_manager_disabled,
|
|
|
|
|
download_manager_stopped: content.download_manager_stopped,
|
2026-06-28 17:30:33 -06:00
|
|
|
download_daily_limit_global: content.download_daily_limit_global,
|
|
|
|
|
download_daily_limit_per_domain: content.download_daily_limit_per_domain,
|
2024-10-03 13:35:06 -06:00
|
|
|
download_on_startup: content.download_on_startup,
|
|
|
|
|
download_timeout: content.download_timeout,
|
2026-02-20 14:37:58 -07:00
|
|
|
download_wait: content.download_wait,
|
2026-03-12 20:10:57 -06:00
|
|
|
download_window_start: content.download_window_start,
|
|
|
|
|
download_window_end: content.download_window_end,
|
2024-10-03 13:35:06 -06:00
|
|
|
hotspot_device: content.hotspot_device,
|
|
|
|
|
hotspot_on_startup: content.hotspot_on_startup,
|
|
|
|
|
hotspot_password: content.hotspot_password,
|
|
|
|
|
hotspot_ssid: content.hotspot_ssid,
|
|
|
|
|
hotspot_status: content.hotspot_status,
|
2025-12-06 14:47:52 -07:00
|
|
|
check_for_upgrades: content.check_for_upgrades,
|
2024-10-03 13:35:06 -06:00
|
|
|
ignore_outdated_zims: content.ignore_outdated_zims,
|
|
|
|
|
ignored_directories: content.ignored_directories,
|
|
|
|
|
log_level: content.log_level,
|
2026-04-04 14:56:25 -06:00
|
|
|
map_default_location: content.map_default_location,
|
2024-10-03 13:35:06 -06:00
|
|
|
map_destination: content.map_destination,
|
|
|
|
|
nav_color: content.nav_color,
|
|
|
|
|
media_directory: content.media_directory,
|
2026-06-10 15:56:20 -06:00
|
|
|
playlists_destination: content.playlists_destination,
|
2026-03-14 12:08:23 -06:00
|
|
|
require_cookies_unlocked: content.require_cookies_unlocked,
|
2026-05-14 15:51:32 -06:00
|
|
|
require_media_mounted: content.require_media_mounted,
|
2026-02-07 18:40:56 -07:00
|
|
|
save_ffprobe_json: content.save_ffprobe_json,
|
2026-01-31 12:54:27 -07:00
|
|
|
tags_directory: content.tags_directory,
|
2024-10-03 13:35:06 -06:00
|
|
|
throttle_on_startup: content.throttle_on_startup,
|
|
|
|
|
throttle_status: content.throttle_status,
|
2026-03-13 15:03:13 -06:00
|
|
|
timezone: content.timezone,
|
2024-10-03 13:35:06 -06:00
|
|
|
videos_destination: content.videos_destination,
|
|
|
|
|
wrol_mode: content.wrol_mode,
|
|
|
|
|
zims_destination: content.zims_destination,
|
|
|
|
|
}
|
2022-05-01 21:03:30 -06:00
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not get settings.');
|
2022-05-01 21:03:30 -06:00
|
|
|
toast({
|
2024-08-15 19:32:01 -06:00
|
|
|
type: 'error',
|
|
|
|
|
title: 'Fetching Settings Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
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) {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPatch(`${API_URI}/settings`, settings);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not save settings.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Saving Settings Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return response
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2021-12-20 16:08:13 -07:00
|
|
|
export async function getDownloads() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${API_URI}/download`);
|
|
|
|
|
if (response.ok) {
|
2022-05-01 21:03:30 -06:00
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not get downloads.');
|
2022-05-01 21:03:30 -06:00
|
|
|
toast({
|
2024-08-15 19:32:01 -06:00
|
|
|
type: 'error',
|
|
|
|
|
title: 'Getting Downloads Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
return response
|
2021-12-20 16:08:13 -07:00
|
|
|
}
|
|
|
|
|
|
2024-09-28 17:28:33 -06:00
|
|
|
export async function getConfigs() {
|
2024-12-03 22:30:12 -07:00
|
|
|
const response = await apiGet(`${API_URI}/config`);
|
2024-09-28 17:28:33 -06:00
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
configs: data.configs,
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not get configs.');
|
2024-09-28 17:28:33 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Getting Configs Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function postImportConfig(fileName) {
|
|
|
|
|
const body = {file_name: fileName};
|
2024-12-03 22:30:12 -07:00
|
|
|
const response = await apiPost(`${API_URI}/config/import`, body);
|
2024-09-28 17:28:33 -06:00
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not import config.');
|
2024-09-28 17:28:33 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Importing config Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return response
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-03 22:30:12 -07:00
|
|
|
export async function postDumpConfig(fileName) {
|
2024-09-28 17:28:33 -06:00
|
|
|
const body = {file_name: fileName, overwrite: true};
|
2024-12-03 22:30:12 -07:00
|
|
|
const response = await apiPost(`${API_URI}/config/dump`, body);
|
2024-09-28 17:28:33 -06:00
|
|
|
if (!response.ok) {
|
2024-12-03 22:30:12 -07:00
|
|
|
const message = await getErrorMessage(response, 'Could not dump config.');
|
2024-09-28 17:28:33 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
2024-12-03 22:30:12 -07:00
|
|
|
title: 'Dumping config failed',
|
2024-09-28 17:28:33 -06:00
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return response
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-03 22:30:12 -07:00
|
|
|
export async function getConfig(fileName) {
|
|
|
|
|
const response = await apiGet(`${API_URI}/config?file_name=${fileName}`);
|
2024-11-02 15:14:02 -06:00
|
|
|
return (await response.json())['config'];
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-22 12:56:37 -06:00
|
|
|
export async function getConfigText(fileName) {
|
|
|
|
|
const response = await apiGet(`${API_URI}/config?file_name=${fileName}`);
|
|
|
|
|
return (await response.json())['config_text'];
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-09 16:11:44 -06:00
|
|
|
export async function getConfigBackups(fileName) {
|
|
|
|
|
const response = await apiGet(`${API_URI}/config/backups?file_name=${fileName}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
return {dates: []};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function postConfigBackupPreview(fileName, backupDate, mode) {
|
|
|
|
|
const body = {file_name: fileName, backup_date: backupDate, mode};
|
|
|
|
|
const response = await apiPost(`${API_URI}/config/backup/preview`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not preview backup.');
|
|
|
|
|
toast({type: 'error', title: 'Preview failed', description: message, time: 5000});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function postConfigBackupImport(fileName, backupDate, mode) {
|
|
|
|
|
const body = {file_name: fileName, backup_date: backupDate, mode};
|
|
|
|
|
const response = await apiPost(`${API_URI}/config/backup/import`, body);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not import backup.');
|
|
|
|
|
toast({type: 'error', title: 'Backup import failed', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-03 22:30:12 -07:00
|
|
|
export async function fetchVideoDownloaderConfig() {
|
|
|
|
|
return await getConfig('videos_downloader.yaml');
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-05 16:18:03 -07:00
|
|
|
export async function fetchVideoDownloadDefaults() {
|
|
|
|
|
const response = await apiGet(`${VIDEOS_API}/download-defaults`);
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-03 22:30:12 -07:00
|
|
|
export async function updateConfig(fileName, config) {
|
2024-11-02 15:14:02 -06:00
|
|
|
const body = {config};
|
2024-12-03 22:30:12 -07:00
|
|
|
const response = await apiPost(`${API_URI}/config?file_name=${fileName}`, body);
|
2024-11-02 15:14:02 -06:00
|
|
|
if (!response.ok) {
|
|
|
|
|
throw Error('Failed to save config');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-03 22:30:12 -07:00
|
|
|
export async function updateVideoDownloaderConfig(config) {
|
|
|
|
|
return await updateConfig('videos_downloader.yaml', config);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 17:56:35 -07:00
|
|
|
export async function fetchArchiveDownloaderConfig() {
|
|
|
|
|
return await getConfig('archives_downloader.yaml');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateArchiveDownloaderConfig(config) {
|
|
|
|
|
return await updateConfig('archives_downloader.yaml', config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function postArchiveFileFormat(archive_file_format) {
|
|
|
|
|
const body = {archive_file_format};
|
|
|
|
|
return await apiPost(`${ARCHIVES_API}/file_format`, body);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-23 19:51:02 -07:00
|
|
|
export async function fetchArchiveBrowsers() {
|
|
|
|
|
const response = await apiGet(`${ARCHIVES_API}/browsers`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
return {browsers: [], available: false};
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-02 15:15:28 -07:00
|
|
|
export async function getArchiveStatistics() {
|
|
|
|
|
const response = await apiGet(`${ARCHIVES_API}/statistics`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return (await response.json())['statistics'];
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not get archive statistics.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Getting Archive Statistics Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return response
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-17 17:02:39 -06:00
|
|
|
export async function updateVideoDownloaderSettings(settings) {
|
|
|
|
|
const response = await apiPut(`${API_URI}/videos/settings`, settings);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to save settings.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Saving Settings Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-01 16:42:52 -06:00
|
|
|
export async function validateRegex(regex) {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/valid_regex`, {regex});
|
|
|
|
|
try {
|
|
|
|
|
return (await response.json())['valid'];
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-12-16 11:10:01 -07:00
|
|
|
export async function getVideosStatistics() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${VIDEOS_API}/statistics`);
|
2022-05-01 21:03:30 -06:00
|
|
|
if (response.status === 200) {
|
|
|
|
|
return (await response.json())['statistics'];
|
|
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not get statistics.');
|
2022-05-01 21:03:30 -06:00
|
|
|
toast({
|
2024-08-15 19:32:01 -06:00
|
|
|
type: 'error',
|
|
|
|
|
title: 'Getting Statistics Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
2022-05-01 21:03:30 -06:00
|
|
|
});
|
|
|
|
|
}
|
2024-08-15 19:32:01 -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}`;
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(url);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, "Failed to refresh this channel's directory");
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Failed to refresh',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return response;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
// Inventory is config-only on the backend (no DB). The frontend loads every inventory once (full), derives
|
|
|
|
|
// list/items/summary/locations client-side, and persists whole inventories on change — so there are only four
|
|
|
|
|
// inventory calls.
|
2021-11-01 16:42:52 -06:00
|
|
|
|
|
|
|
|
export async function getInventories() {
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
// Returns every inventory in full (fields + items).
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${API_URI}/inventory`);
|
|
|
|
|
if (response.ok) {
|
2022-05-01 21:03:30 -06:00
|
|
|
return (await response.json())['inventories'];
|
|
|
|
|
}
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not get inventories');
|
|
|
|
|
toast({type: 'error', title: 'Unexpected server response', description: message, time: 5000});
|
|
|
|
|
return null;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
export async function createInventory({name, type}) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/inventory`, {name, type});
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
return (await response.json())['inventory'];
|
2024-08-15 19:32:01 -06:00
|
|
|
}
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to create inventory');
|
|
|
|
|
toast({type: 'error', title: 'Unexpected server response', description: message, time: 5000});
|
|
|
|
|
return null;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
export async function saveInventory(slug, data) {
|
|
|
|
|
// Whole-inventory save (data = {name?, fields?, items?, version?}). Returns the saved inventory, or null on
|
|
|
|
|
// error/conflict so the caller can reconcile.
|
|
|
|
|
const response = await apiPut(`${API_URI}/inventory/${slug}`, data);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['inventory'];
|
2024-08-15 19:32:01 -06:00
|
|
|
}
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to save inventory');
|
|
|
|
|
toast({type: 'error', title: 'Unexpected server response', description: message, time: 5000});
|
|
|
|
|
return null;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
export async function deleteInventory(slug) {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/inventory/${slug}`);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to delete inventory');
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
toast({type: 'error', title: 'Unexpected server response', description: message, time: 5000});
|
2024-08-15 19:32:01 -06:00
|
|
|
}
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
return response;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2026-06-19 16:13:56 -06:00
|
|
|
export async function reimportInventories() {
|
|
|
|
|
// Re-read every inventory config file from disk (picks up hand-edits and copied-in files).
|
|
|
|
|
const response = await apiPost(`${API_URI}/inventory/reimport`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['inventories'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to re-import inventories');
|
|
|
|
|
toast({type: 'error', title: 'Unexpected server response', description: message, time: 5000});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getInventoryBackups(slug) {
|
|
|
|
|
const response = await apiGet(`${API_URI}/inventory/${slug}/backups`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['dates'];
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function postInventoryRestorePreview(slug, backupDate, mode) {
|
|
|
|
|
const body = {backup_date: backupDate, mode};
|
|
|
|
|
const response = await apiPost(`${API_URI}/inventory/${slug}/restore/preview`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['preview'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to preview the backup');
|
|
|
|
|
toast({type: 'error', title: 'Unexpected server response', description: message, time: 5000});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function postInventoryRestore(slug, backupDate, mode) {
|
|
|
|
|
const body = {backup_date: backupDate, mode};
|
|
|
|
|
const response = await apiPost(`${API_URI}/inventory/${slug}/restore`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['inventory'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to restore the backup');
|
|
|
|
|
toast({type: 'error', title: 'Unexpected server response', description: message, time: 5000});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
export async function getCatalog() {
|
|
|
|
|
// The shared food catalog (known items with total calories per package).
|
|
|
|
|
const response = await apiGet(`${API_URI}/inventory/catalog`);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
return (await response.json())['catalog'];
|
2024-08-15 19:32:01 -06:00
|
|
|
}
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not get the food catalog');
|
|
|
|
|
toast({type: 'error', title: 'Unexpected server response', description: message, time: 5000});
|
|
|
|
|
return null;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
export async function saveCatalog(items) {
|
|
|
|
|
const response = await apiPut(`${API_URI}/inventory/catalog`, {items});
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
return (await response.json())['catalog'];
|
2024-08-15 19:32:01 -06:00
|
|
|
}
|
Rebuild Inventory as a config-only system with food catalog and calculators
Replace the DB-backed inventory module with a config-only design and build out
food-storage tooling around it.
Inventory (config-only, no database)
- Each inventory is a YAML file at config/inventory/<slug>.yaml, loaded once
into memory and the single source of truth. New reusable MultiFileConfig
(wrolpi/common.py) manages a directory of per-entity files.
- Inventory types (food/fuel/tool) seed a customizable field schema
(text/number/quantity/date/select/location/calories). Unit math/aggregation
moved to the frontend (mathjs); Pint dropped from the backend.
- Minimal API: GET / (all inventories full), POST /, PUT /<slug> (whole-
inventory save with version-based optimistic concurrency; 404 for missing),
DELETE. Legacy inventories.yaml / old tables migrate to per-inventory files
(pound->lb), and an alembic migration drops the tables.
Frontend
- New app/src/components/inventory/ package: spreadsheet-style table with
Tab/Enter keyboard entry, sortable columns, expired-row highlighting,
customizable field editor, and pooled cross-inventory location autocomplete.
- A single useInventories store loads everything once and persists whole
inventories optimistically; list/items/summary/locations derive client-side.
- Summary groups items (default by Category), totals size x count, shows a
calories column, and embeds a ration estimate (how long the stock lasts).
Food catalog
- Shared, editable catalog (config/inventory/catalog.yaml) seeded from
catalog_defaults.yaml (~60 generic items, total calories per package) with
merge-keep-edits + tombstones. GET/PUT /api/inventory/catalog, a management
modal, and entry-row pre-fill of category/size/calories from a name match.
Calculators
- Generic Food Storage planner (like the Water calculator): household +
editable per-person/year amounts -> total to store over a chosen duration,
with women/children weighted by DGA calorie shares and an imperial/metric
toggle.
Also fixes ConfigFile.save() to accept nested file_names. Backend pytest and
frontend jest suites updated/added throughout; alembic check clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:20:10 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to save the food catalog');
|
|
|
|
|
toast({type: 'error', title: 'Unexpected server response', description: message, time: 5000});
|
|
|
|
|
return null;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries. Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.
Database:
- Migration adds the generated column and a GIN index (rewrites the
table; a few minutes on large libraries).
Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
query (COUNT FILTER on the abc subset): `file_groups` (fast) and
`file_groups_deep`.
UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
list.
- The gap is reconciled by a hint offering deep search: count-aware on
the global search ("No results in fast search. N results available in
deep search." / "N more results available..."), generic on the module
pages (no deep estimate there). The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
?deep=true.
Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside. Also skip flaky test_download_channel on
CircleCI.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:09:08 -06:00
|
|
|
export async function searchArchives(offset, limit, domain, searchStr, order, tagNames, headline, deep) {
|
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;
|
|
|
|
|
}
|
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries. Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.
Database:
- Migration adds the generated column and a GIN index (rewrites the
table; a few minutes on large libraries).
Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
query (COUNT FILTER on the abc subset): `file_groups` (fast) and
`file_groups_deep`.
UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
list.
- The gap is reconciled by a hint offering deep search: count-aware on
the global search ("No results in fast search. N results available in
deep search." / "N more results available..."), generic on the module
pages (no deep estimate there). The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
?deep=true.
Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside. Also skip flaky test_download_channel on
CircleCI.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:09:08 -06:00
|
|
|
if (deep) {
|
|
|
|
|
body['deep'] = true;
|
|
|
|
|
}
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
console.debug('searching archives', body);
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${ARCHIVES_API}/search`, body);
|
|
|
|
|
if (response.ok) {
|
2021-11-01 16:42:52 -06:00
|
|
|
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 {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Cannot search archives. See server logs.');
|
2022-01-15 18:15:23 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to search archives',
|
2024-08-15 19:32:01 -06:00
|
|
|
description: message,
|
2022-01-15 18:15:23 -07:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
2023-03-24 08:58:18 -06:00
|
|
|
return [[], 0];
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchDomains() {
|
2025-10-29 22:16:33 -06:00
|
|
|
const response = await apiGet(`${COLLECTIONS_API}?kind=domain`);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
2021-11-01 16:42:52 -06:00
|
|
|
let data = await response.json();
|
2025-12-05 17:12:21 -07:00
|
|
|
return [data['collections'], data['totals']['collections']];
|
2021-11-01 16:42:52 -06:00
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to fetch Domains. See server logs.');
|
2022-01-15 18:15:23 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Domains Error',
|
2024-08-15 19:32:01 -06:00
|
|
|
description: message,
|
2022-01-15 18:15:23 -07:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-20 16:08:13 -07:00
|
|
|
|
2026-03-17 18:35:57 -06:00
|
|
|
export async function fetchAuthors() {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}?kind=author`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let data = await response.json();
|
|
|
|
|
return [data['collections'], data['totals']['collections']];
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to fetch Authors. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Authors Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchSubjects() {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}?kind=subject`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let data = await response.json();
|
|
|
|
|
return [data['collections'], data['totals']['collections']];
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to fetch Subjects. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Subjects Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-29 22:16:33 -06:00
|
|
|
export async function fetchChannels() {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}?kind=channel`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let data = await response.json();
|
2025-12-05 17:12:21 -07:00
|
|
|
return [data['collections'], data['totals']['collections']];
|
2025-10-29 22:16:33 -06:00
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to fetch Channels. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Channels Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getDomain(domainId) {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}/${domainId}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data['collection'];
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to fetch Domain. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Domain Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateDomain(domainId, updates) {
|
|
|
|
|
updates = emptyToNull(updates);
|
|
|
|
|
const response = await apiPut(`${COLLECTIONS_API}/${domainId}`, updates);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data['collection'];
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to update Domain. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Domain Update Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getCollectionTagInfo(collectionId, tagName) {
|
|
|
|
|
const body = {
|
|
|
|
|
tag_name: tagName,
|
|
|
|
|
}
|
|
|
|
|
const response = await apiPost(`${COLLECTIONS_API}/${collectionId}/tag_info`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data;
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to get tag info. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Tag Info Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function tagDomain(domainId, tagName, directory) {
|
|
|
|
|
const body = {
|
|
|
|
|
tag_name: tagName,
|
|
|
|
|
}
|
|
|
|
|
if (directory) {
|
|
|
|
|
body['directory'] = directory;
|
|
|
|
|
}
|
|
|
|
|
const response = await apiPost(`${COLLECTIONS_API}/${domainId}/tag`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data;
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to tag Domain. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Domain Tag Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteDomain(domainId) {
|
|
|
|
|
const response = await apiDelete(`${COLLECTIONS_API}/${domainId}`);
|
|
|
|
|
if (response.status !== 204) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to delete domain.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Delete Failed',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function refreshDomain(domainId) {
|
|
|
|
|
let url = `${COLLECTIONS_API}/${domainId}/refresh`;
|
|
|
|
|
const response = await apiPost(url);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, "Failed to refresh this domain's directory");
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Failed to refresh',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'success',
|
|
|
|
|
title: 'Domain refresh started',
|
|
|
|
|
description: 'The domain directory is being refreshed',
|
|
|
|
|
time: 3000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-23 19:51:02 -07:00
|
|
|
export async function previewCollectionReorganization(collectionId) {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}/${collectionId}/reorganize/preview`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to preview reorganization. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Reorganization Preview Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function executeCollectionReorganization(collectionId) {
|
|
|
|
|
const response = await apiPost(`${COLLECTIONS_API}/${collectionId}/reorganize`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
if (data.job_id) {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'success',
|
|
|
|
|
title: 'Reorganization Started',
|
|
|
|
|
description: 'Files are being reorganized in the background',
|
|
|
|
|
time: 3000,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'info',
|
|
|
|
|
title: 'No Changes Needed',
|
|
|
|
|
description: data.message || 'No files need reorganization',
|
|
|
|
|
time: 3000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to start reorganization. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Reorganization Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getReorganizationStatus(collectionId, jobId) {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}/${collectionId}/reorganize/status/${jobId}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to get reorganization status.');
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Batch Reorganization API Functions
|
|
|
|
|
|
|
|
|
|
export async function previewBatchReorganization(kind) {
|
|
|
|
|
const endpoint = kind === 'channel' ? 'channels' : 'domains';
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}/reorganize/${endpoint}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, `Unable to get ${kind}s needing reorganization.`);
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Batch Reorganization Preview Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function executeBatchReorganization(kind) {
|
|
|
|
|
const endpoint = kind === 'channel' ? 'channels' : 'domains';
|
|
|
|
|
const response = await apiPost(`${COLLECTIONS_API}/reorganize/${endpoint}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
if (data.batch_job_id) {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'success',
|
|
|
|
|
title: 'Batch Reorganization Started',
|
|
|
|
|
description: `${data.collection_count} ${kind}s are being reorganized`,
|
|
|
|
|
time: 3000,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'info',
|
|
|
|
|
title: 'No Changes Needed',
|
|
|
|
|
description: data.message || `No ${kind}s need reorganization`,
|
|
|
|
|
time: 3000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, `Unable to start batch reorganization. See server logs.`);
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Batch Reorganization Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getBatchReorganizationStatus(batchJobId) {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}/reorganize/batch/status/${batchJobId}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to get batch reorganization status.');
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 15:18:14 -07:00
|
|
|
export async function fetchCollectionConflicts(collectionId) {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}/${collectionId}/reorganize/conflicts`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to fetch conflicts. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Conflict Fetch Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 15:38:32 -06:00
|
|
|
export async function getArchive(fileGroupId) {
|
|
|
|
|
const response = await apiGet(`${ARCHIVES_API}/${fileGroupId}`);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
2022-05-16 17:56:55 -06:00
|
|
|
const data = await response.json();
|
2024-12-03 12:44:38 -07:00
|
|
|
return {
|
|
|
|
|
file_group: data['file_group'],
|
|
|
|
|
history: data['history'],
|
|
|
|
|
}
|
2022-05-16 17:56:55 -06:00
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to get Archive. See server logs.');
|
2022-05-16 17:56:55 -06:00
|
|
|
toast({
|
2024-08-15 19:32:01 -06:00
|
|
|
type: 'error', title: 'Archive Error', description: message, time: 5000,
|
2022-05-16 17:56:55 -06:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 15:38:32 -06:00
|
|
|
export async function generateArchiveScreenshot(fileGroupId) {
|
|
|
|
|
const response = await apiPost(`${ARCHIVES_API}/${fileGroupId}/generate_screenshot`);
|
2025-10-19 11:40:02 -06:00
|
|
|
if (response.ok) {
|
|
|
|
|
toast({
|
|
|
|
|
type: 'success',
|
|
|
|
|
title: 'Screenshot Generation Queued',
|
|
|
|
|
description: 'Screenshot generation has been queued. This may take a moment.',
|
|
|
|
|
time: 3000,
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to queue screenshot generation.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Screenshot Generation Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
export async function postDownload(downloadData) {
|
|
|
|
|
if (!downloadData.downloader) {
|
2023-04-01 15:34:46 -06:00
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-03 12:44:38 -07:00
|
|
|
const body = {
|
2024-11-02 15:14:02 -06:00
|
|
|
urls: downloadData.urls,
|
|
|
|
|
destination: downloadData.destination,
|
|
|
|
|
downloader: downloadData.downloader,
|
|
|
|
|
sub_downloader: downloadData.sub_downloader || null,
|
|
|
|
|
frequency: downloadData.frequency || null,
|
|
|
|
|
tag_names: downloadData.tag_names || null,
|
|
|
|
|
settings: downloadData.settings,
|
2022-11-09 08:33:55 -07:00
|
|
|
};
|
2024-02-20 13:47:12 -07:00
|
|
|
const response = await apiPost(`${API_URI}/download`, body);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to create Download. See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error', title: 'Download Error', description: message, time: 5000,
|
|
|
|
|
});
|
2024-11-02 15:14:02 -06:00
|
|
|
throw new Error('Failed to create download');
|
2024-08-15 19:32:01 -06:00
|
|
|
}
|
2023-07-21 21:23:15 -06:00
|
|
|
return response;
|
2021-12-20 16:08:13 -07:00
|
|
|
}
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
export async function putDownload(download_id, downloadData) {
|
|
|
|
|
if (!downloadData.downloader) {
|
2024-06-25 22:12:13 -06:00
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-02 15:14:02 -06:00
|
|
|
const response = await apiPut(`${API_URI}/download/${download_id}`, downloadData);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to update Download. See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error', title: 'Download Error', description: message, time: 5000,
|
|
|
|
|
});
|
2024-11-02 15:14:02 -06:00
|
|
|
throw new Error('Failed to update download');
|
2024-08-15 19:32:01 -06:00
|
|
|
}
|
2024-06-25 22:12:13 -06:00
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 16:08:13 -07:00
|
|
|
export async function killDownload(download_id) {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/download/${download_id}/kill`);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to stop Download. See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error', title: 'Download Error', description: message, time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-12-20 16:08:13 -07:00
|
|
|
return response;
|
|
|
|
|
}
|
2021-12-30 20:45:11 -07:00
|
|
|
|
2023-09-07 21:38:19 -06:00
|
|
|
export async function restartDownload(download_id) {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/download/${download_id}/restart`);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to restart Download. See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error', title: 'Download Error', description: message, time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return response
|
2023-09-07 21:38:19 -06:00
|
|
|
}
|
|
|
|
|
|
2022-01-11 10:08:47 -07:00
|
|
|
export async function killDownloads() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/download/kill`);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to stop downloading. See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error', title: 'Download Error', description: message, time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-01-11 10:08:47 -07:00
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function startDownloads() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/download/enable`);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to start downloading. See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error', title: 'Download Error', description: message, time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-01-11 10:08:47 -07:00
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 20:45:11 -07:00
|
|
|
export async function getDownloaders() {
|
2022-02-04 13:55:13 -07:00
|
|
|
try {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${API_URI}/downloaders`);
|
|
|
|
|
// Not toasting because this will happen often.
|
2022-02-04 13:55:13 -07:00
|
|
|
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 {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiDelete(`${API_URI}/download/${downloadId}`);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to delete the download. See server logs.');
|
2022-11-12 14:17:21 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
2024-08-15 19:32:01 -06:00
|
|
|
title: 'Download Error',
|
|
|
|
|
description: message,
|
2022-11-12 14:17:21 -07:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries. Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.
Database:
- Migration adds the generated column and a GIN index (rewrites the
table; a few minutes on large libraries).
Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
query (COUNT FILTER on the abc subset): `file_groups` (fast) and
`file_groups_deep`.
UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
list.
- The gap is reconciled by a hint offering deep search: count-aware on
the global search ("No results in fast search. N results available in
deep search." / "N more results available..."), generic on the module
pages (no deep estimate there). The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
?deep=true.
Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside. Also skip flaky test_download_channel on
CircleCI.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:09:08 -06:00
|
|
|
export async function filesSearch(offset, limit, searchStr, mimetypes, model, tagNames, headline, months, fromYear, toYear, anyTag, order, suffix, path, deep) {
|
2024-07-22 16:36:57 -06:00
|
|
|
const body = {search_str: searchStr, offset: parseInt(offset), limit: parseInt(limit), any_tag: anyTag};
|
Add ESP32 firmware flasher
Browser-based ESP32/ESP8266 flasher (esptool-js + Web Serial); nothing is
uploaded to WROLPi, the flash is written straight to the device over USB.
Firmware sources (themed, tabbed): a saved set, the WROLPi media directory,
or a local file. Local files can be dropped anywhere on the page, which jumps
to the "Add from computer" dropzone. The media picker searches .bin files by
path and can detect the connected chip to filter firmware to matching images.
- Indexed file_group.suffix + path filter for fast .bin search (alembic
migration backfills via split_path_stem_and_suffix)
- modules/flasher: chip detection from ESP image headers, /search endpoint,
and flasher.yaml saved configurations (/configs CRUD)
- Flash progress modal with ETA, connect timeout, boot-mode hint, auto-
scrolling logs
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 18:24:21 -06:00
|
|
|
if (suffix) {
|
|
|
|
|
body['suffix'] = suffix;
|
|
|
|
|
}
|
|
|
|
|
if (path) {
|
|
|
|
|
body['path'] = path;
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
2024-03-06 17:41:04 -07:00
|
|
|
if (!_.isEmpty(months)) {
|
|
|
|
|
body['months'] = months.map(i => parseInt(i));
|
|
|
|
|
}
|
|
|
|
|
if (fromYear) {
|
|
|
|
|
body['from_year'] = fromYear;
|
|
|
|
|
}
|
|
|
|
|
if (toYear) {
|
|
|
|
|
body['to_year'] = toYear;
|
|
|
|
|
}
|
2025-01-26 12:44:16 -07:00
|
|
|
if (order) {
|
|
|
|
|
body['order'] = order;
|
|
|
|
|
}
|
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries. Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.
Database:
- Migration adds the generated column and a GIN index (rewrites the
table; a few minutes on large libraries).
Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
query (COUNT FILTER on the abc subset): `file_groups` (fast) and
`file_groups_deep`.
UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
list.
- The gap is reconciled by a hint offering deep search: count-aware on
the global search ("No results in fast search. N results available in
deep search." / "N more results available..."), generic on the module
pages (no deep estimate there). The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
?deep=true.
Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside. Also skip flaky test_download_channel on
CircleCI.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:09:08 -06:00
|
|
|
if (deep) {
|
|
|
|
|
body['deep'] = true;
|
|
|
|
|
}
|
2024-03-06 17:41:04 -07:00
|
|
|
console.info('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
|
|
|
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
2022-02-02 14:02:51 -07:00
|
|
|
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 {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Cannot search files. See server logs.');
|
2022-02-02 14:02:51 -07:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to search files',
|
2024-08-15 19:32:01 -06:00
|
|
|
description: message,
|
2022-02-02 14:02:51 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
Add ESP32 firmware flasher
Browser-based ESP32/ESP8266 flasher (esptool-js + Web Serial); nothing is
uploaded to WROLPi, the flash is written straight to the device over USB.
Firmware sources (themed, tabbed): a saved set, the WROLPi media directory,
or a local file. Local files can be dropped anywhere on the page, which jumps
to the "Add from computer" dropzone. The media picker searches .bin files by
path and can detect the connected chip to filter firmware to matching images.
- Indexed file_group.suffix + path filter for fast .bin search (alembic
migration backfills via split_path_stem_and_suffix)
- modules/flasher: chip detection from ESP image headers, /search endpoint,
and flasher.yaml saved configurations (/configs CRUD)
- Flash progress modal with ETA, connect timeout, boot-mode hint, auto-
scrolling logs
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 18:24:21 -06:00
|
|
|
export async function flasherSearch(chip, path) {
|
|
|
|
|
// Search .bin firmware, filtered to ESP images for the given chip (from connecting to the device).
|
|
|
|
|
const body = {};
|
|
|
|
|
if (chip) body['chip'] = chip;
|
|
|
|
|
if (path) body['path'] = path;
|
|
|
|
|
const response = await apiPost(`${API_URI}/flasher/search`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return [data['file_groups'], data['totals']['file_groups']];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Cannot search firmware. See server logs.');
|
|
|
|
|
toast({type: 'error', title: 'Unable to search firmware', description: message, time: 5000});
|
|
|
|
|
return [null, null];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getFlasherConfigs() {
|
|
|
|
|
// Return the user's saved firmware flashing configurations.
|
|
|
|
|
const response = await apiGet(`${API_URI}/flasher/configs`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data['configurations'] || [];
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function saveFlasherConfig(name, files, eraseAll) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/flasher/configs`, {name, files, erase_all: eraseAll});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Cannot save configuration. See server logs.');
|
|
|
|
|
toast({type: 'error', title: 'Unable to save configuration', description: message, time: 5000});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteFlasherConfig(name) {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/flasher/configs/${encodeURIComponent(name)}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Cannot delete configuration. See server logs.');
|
|
|
|
|
toast({type: 'error', title: 'Unable to delete configuration', description: message, time: 5000});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 15:53:47 -06:00
|
|
|
export async function refreshFiles(paths) {
|
|
|
|
|
let response;
|
2024-03-11 17:47:27 -06:00
|
|
|
if (Array.isArray(paths) && paths.length > 0) {
|
|
|
|
|
// Refresh user-selected files/directories only.
|
2023-07-27 15:53:47 -06:00
|
|
|
const body = {paths};
|
2024-03-11 17:47:27 -06:00
|
|
|
console.info(`Refreshing: ${paths}`);
|
2023-07-27 15:53:47 -06:00
|
|
|
response = await apiPost(`${API_URI}/files/refresh`, body);
|
|
|
|
|
} else {
|
2024-03-11 17:47:27 -06:00
|
|
|
console.info(`Refreshing all files`);
|
2023-07-27 15:53:47 -06:00
|
|
|
response = await apiPost(`${API_URI}/files/refresh`);
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Cannot refresh files. See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Files Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-27 15:53:47 -06:00
|
|
|
return response;
|
2022-08-06 05:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export async function makeDirectory(path) {
|
|
|
|
|
const body = {path: path};
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/files/directory`, body);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to create directory. See server logs.');
|
2023-05-29 18:04:03 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to create directory',
|
2024-08-15 19:32:01 -06:00
|
|
|
description: message,
|
2023-05-29 18:04:03 -06:00
|
|
|
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 || []};
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/files`, body);
|
|
|
|
|
// Not toasting because this will happen often.
|
2022-02-02 14:02:51 -07:00
|
|
|
let {files} = await response.json();
|
|
|
|
|
return files;
|
2022-01-29 16:50:22 -07:00
|
|
|
}
|
|
|
|
|
|
2026-02-28 08:39:10 -07:00
|
|
|
export async function getFile(path, skipTracking = false) {
|
|
|
|
|
let body = {file: path, skip_tracking: skipTracking};
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/files/file`, body);
|
2024-02-17 14:52:46 -07:00
|
|
|
if (response.ok) {
|
|
|
|
|
const {file} = await response.json();
|
|
|
|
|
return file;
|
|
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to get file data. See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Files Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
2024-02-17 14:52:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 10:40:24 -06:00
|
|
|
export async function deleteFile(paths, force = false) {
|
|
|
|
|
let body = {paths: paths, force: force};
|
2023-05-29 18:04:03 -06:00
|
|
|
const response = await apiPost(`${API_URI}/files/delete`, body);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2026-04-14 10:40:24 -06:00
|
|
|
try {
|
|
|
|
|
const json = await response.clone().json();
|
|
|
|
|
if (json.code === 'FILE_GROUP_IS_TAGGED' && json.file_groups) {
|
|
|
|
|
return {tagged: true, file_groups: json.file_groups};
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// Not JSON, fall through to generic error.
|
|
|
|
|
}
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to delete file. See server logs.');
|
2023-05-29 18:04:03 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
2024-08-15 19:32:01 -06:00
|
|
|
title: 'Files Error',
|
|
|
|
|
description: message,
|
2023-05-29 18:04:03 -06:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
return response
|
2022-01-29 16:50:22 -07:00
|
|
|
}
|
2022-01-30 16:59:26 -07:00
|
|
|
|
2026-03-15 12:58:40 -06:00
|
|
|
export async function getArchiveContents(path) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/zip/contents`, {path});
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const {contents} = await response.json();
|
|
|
|
|
return contents;
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not read archive contents.');
|
|
|
|
|
toast({type: 'error', title: 'Archive Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function downloadArchiveMember(path, member) {
|
|
|
|
|
const params = new URLSearchParams({path, member});
|
|
|
|
|
window.open(`${API_URI}/files/zip/download?${params}`, '_blank');
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-17 18:35:57 -06:00
|
|
|
export function getArchiveMemberUrl(path, member) {
|
|
|
|
|
const params = new URLSearchParams({path, member});
|
|
|
|
|
return `${API_URI}/files/zip/download?${params}`;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 20:46:31 -06:00
|
|
|
export async function fetchFilesProgress() {
|
2026-01-09 14:01:25 -07:00
|
|
|
const response = await apiGet(`${API_URI}/files/worker_status`);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
2023-03-27 20:46:31 -06:00
|
|
|
const json = await response.json();
|
2026-01-09 14:01:25 -07:00
|
|
|
return json['status'];
|
2023-03-27 20:46:31 -06:00
|
|
|
}
|
|
|
|
|
}
|
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`);
|
|
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
2022-02-04 09:41:08 -07:00
|
|
|
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 {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not modify hotspot. See server logs.');
|
2022-02-04 16:05:19 -07:00
|
|
|
toast({
|
2024-08-15 19:32:01 -06:00
|
|
|
type: 'error',
|
|
|
|
|
title: 'Hotspot Error',
|
|
|
|
|
description: message,
|
|
|
|
|
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 setThrottle(on) {
|
|
|
|
|
let response;
|
|
|
|
|
if (on) {
|
|
|
|
|
response = await apiPost(`${API_URI}/throttle/on`);
|
|
|
|
|
} else {
|
|
|
|
|
response = await apiPost(`${API_URI}/throttle/off`);
|
|
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
2022-02-07 13:37:58 -07:00
|
|
|
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 {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not modify throttle. See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Throttle Error', description: message, time: 5000});
|
2022-02-07 13:37:58 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-08 13:26:03 -07:00
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
export async function getMapFiles() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${API_URI}/map/files`);
|
|
|
|
|
if (response.ok) {
|
2022-05-01 21:03:30 -06:00
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
2026-03-29 18:58:31 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not get map files');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
2022-05-01 21:03:30 -06:00
|
|
|
}
|
2022-03-08 13:26:03 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
export async function deleteMapFile(filename) {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/map/files/${encodeURIComponent(filename)}`);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2026-03-29 18:58:31 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not delete map file');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchMapSubscriptions() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/subscribe`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not get map subscriptions');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function mapSubscribe(name, region) {
|
|
|
|
|
const body = {name, region};
|
|
|
|
|
const response = await apiPost(`${API_URI}/map/subscribe`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not subscribe to map region');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function mapUnsubscribe(region) {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/map/subscribe/${encodeURIComponent(region)}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not unsubscribe from map region');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getMapPins() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/pins`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addMapPin(lat, lon, label, color) {
|
|
|
|
|
const body = {lat, lon, label, color};
|
|
|
|
|
const response = await apiPost(`${API_URI}/map/pins`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not add map pin');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteMapPin(pinId) {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/map/pins/${pinId}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not delete map pin');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateMapPin(pinId, label, color) {
|
|
|
|
|
const body = {label, color};
|
|
|
|
|
const response = await apiPut(`${API_URI}/map/pins/${pinId}`, body);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not update map pin');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
2022-03-08 13:26:03 -07:00
|
|
|
}
|
|
|
|
|
}
|
2022-04-01 16:31:49 -06:00
|
|
|
|
2026-04-04 14:56:25 -06:00
|
|
|
export async function setMapDefaultLocation(lat, lon, zoom) {
|
|
|
|
|
try {
|
|
|
|
|
await updateConfig('wrolpi.yaml', {map_default_location: {lat, lon, zoom}});
|
|
|
|
|
toast({type: 'success', title: 'Default Location', description: 'Default map location saved', time: 3000});
|
|
|
|
|
return true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: 'Could not set default location', time: 5000});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-11 20:09:30 -06:00
|
|
|
export async function searchMap(query, limit = 12, offset = 0, lat = null, lon = null) {
|
|
|
|
|
let url = `${API_URI}/map/search?q=${encodeURIComponent(query)}&limit=${limit}&offset=${offset}`;
|
|
|
|
|
if (lat !== null && lon !== null) {
|
|
|
|
|
url += `&lat=${lat}&lon=${lon}`;
|
|
|
|
|
}
|
|
|
|
|
const response = await apiGet(url);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
return {results: [], total: 0};
|
|
|
|
|
}
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getMapSearchStatus() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/search/status`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
return {indexed: [], missing: []};
|
|
|
|
|
}
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function searchEstimateMap(search_str) {
|
|
|
|
|
if (!search_str) return {mapPlaces: 0};
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/search/estimate?q=${encodeURIComponent(search_str)}`);
|
|
|
|
|
if (!response.ok) return {mapPlaces: 0};
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return {mapPlaces: data.map_places || 0};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function rebuildMapSearchIndex(filename) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/map/search/rebuild/${encodeURIComponent(filename)}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not rebuild search index');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
} else {
|
|
|
|
|
toast({type: 'success', title: 'Search Index', description: 'Search index build started', time: 3000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-01 16:45:59 -06:00
|
|
|
export async function clearCompletedDownloads() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/download/clear_completed`);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not clear completed downloads! See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Downloads Error', description: message, time: 5000});
|
2022-04-01 16:31:49 -06:00
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
return response
|
2022-04-01 16:31:49 -06:00
|
|
|
}
|
2022-05-01 21:03:30 -06:00
|
|
|
|
2024-04-17 11:25:26 -06:00
|
|
|
export async function deleteOnceDownloads() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/download/delete_once`);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not delete once downloads! See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Downloads Error', description: message, time: 5000});
|
2024-04-17 11:25:26 -06:00
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
return response
|
2024-04-17 11:25:26 -06:00
|
|
|
}
|
|
|
|
|
|
2024-05-08 17:02:27 -06:00
|
|
|
export async function retryOnceDownloads() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/download/retry_once`);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Could not retry once downloads! See server logs.');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Downloads Error', description: message, time: 5000});
|
2024-05-08 17:02:27 -06:00
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
return response
|
2024-05-08 17:02:27 -06:00
|
|
|
}
|
|
|
|
|
|
2025-12-26 10:16:12 -07:00
|
|
|
export async function batchDeleteDownloads(downloadIds) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/download/batch/delete`, {download_ids: downloadIds});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not delete downloads! See server logs.');
|
|
|
|
|
toast({type: 'error', title: 'Downloads Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
return response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function batchRetryDownloads(downloadIds) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/download/batch/retry`, {download_ids: downloadIds});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not retry downloads! See server logs.');
|
|
|
|
|
toast({type: 'error', title: 'Downloads Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
return response
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function batchClearDownloads(downloadIds) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/download/batch/clear`, {download_ids: downloadIds});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not clear downloads! See server logs.');
|
|
|
|
|
toast({type: 'error', title: 'Downloads Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
return response
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 11:10:01 -07:00
|
|
|
export async function getStatistics() {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${API_URI}/statistics`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
2022-12-15 11:48:46 -07:00
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to get file statistics');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, 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
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(uri);
|
|
|
|
|
if (response.ok) {
|
2022-12-23 16:04:09 -07:00
|
|
|
return await response.json();
|
|
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
// Not toasting because this happens often.
|
|
|
|
|
return response
|
2022-12-23 16:04:09 -07:00
|
|
|
}
|
2023-03-24 08:58:18 -06:00
|
|
|
|
2026-03-07 15:43:11 -07:00
|
|
|
export async function getTags(tagNames) {
|
|
|
|
|
let uri = `${API_URI}/tag`;
|
|
|
|
|
if (tagNames && tagNames.length > 0) {
|
|
|
|
|
const params = new URLSearchParams();
|
|
|
|
|
(typeof tagNames === 'string' ? [tagNames] : tagNames).forEach(name => params.append('tag_names', name));
|
|
|
|
|
uri = `${uri}?${params.toString()}`;
|
|
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(uri);
|
|
|
|
|
if (response.ok) {
|
2023-03-24 08:58:18 -06:00
|
|
|
const body = await response.json();
|
2026-03-07 15:43:11 -07:00
|
|
|
return body;
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
// Not toasting because this happens often.
|
|
|
|
|
return response
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
|
|
|
|
|
2026-03-07 10:29:05 -07:00
|
|
|
export async function getRecentTags() {
|
|
|
|
|
const uri = `${API_URI}/tag/recent`;
|
|
|
|
|
const response = await apiGet(uri);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const body = await response.json();
|
|
|
|
|
return body['tag_names'] || [];
|
|
|
|
|
}
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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`;
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(uri, body);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to add tag');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Tag Error', description: message, time: 5000});
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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`;
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(uri, body)
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to untag');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Tag Error', description: message, time: 5000});
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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}`;
|
|
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
const 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 {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Unable to save tag');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Tag Error', description: message, 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}`;
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiDelete(uri);
|
2023-03-24 08:58:18 -06:00
|
|
|
if (response.status === 400) {
|
|
|
|
|
const content = await response.json();
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Cannot delete, Tag is used');
|
2023-07-17 14:21:27 -06:00
|
|
|
if (content['code'] === 'USED_TAG') {
|
2023-03-24 08:58:18 -06:00
|
|
|
toast({
|
2024-08-15 19:32:01 -06:00
|
|
|
type: 'error', title: 'Error!', description: message, time: 5000,
|
2023-03-24 08:58:18 -06:00
|
|
|
})
|
|
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
} else if (!response.ok) {
|
2023-03-24 08:58:18 -06:00
|
|
|
console.error('Failed to delete tag');
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, `Unable to delete tag: ${name}`);
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Tag Error', description: message, time: 5000});
|
2023-03-24 08:58:18 -06:00
|
|
|
}
|
|
|
|
|
}
|
2023-04-01 11:52:41 -06:00
|
|
|
|
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 {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Your share failed to send!');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
2023-04-10 13:15:34 -06:00
|
|
|
}
|
|
|
|
|
}
|
2023-04-18 22:03:45 -06:00
|
|
|
|
2024-10-02 21:59:33 -06:00
|
|
|
export async function searchDirectories(path) {
|
|
|
|
|
const body = {path: path || ''};
|
2023-04-18 22:03:45 -06:00
|
|
|
const response = await apiPost(`${API_URI}/files/search_directories`, body);
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
return [];
|
|
|
|
|
} else if (response.status === 200) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
is_dir: content.is_dir,
|
|
|
|
|
directories: content.directories,
|
|
|
|
|
channel_directories: content.channel_directories,
|
|
|
|
|
domain_directories: content.domain_directories,
|
|
|
|
|
}
|
2023-04-18 22:03:45 -06:00
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to search directories!');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
2023-04-18 22:03:45 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to rename!');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function movePaths(destination, paths) {
|
|
|
|
|
const body = {destination, paths};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/move`, body);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to move!');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-19 13:45:41 -07:00
|
|
|
export async function ignoreDirectory(directory) {
|
|
|
|
|
const body = {path: directory};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/ignore_directory`, body);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to ignore directory!');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
2024-02-19 13:45:41 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function unignoreDirectory(directory) {
|
|
|
|
|
const body = {path: directory};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/unignore_directory`, body);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to unignore directory!');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
2024-02-19 13:45:41 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
export async function fetchZims() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/zim`);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
2023-05-29 18:04:03 -06:00
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
zims: content['zims'],
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Cannot fetch Zims');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchZimSubscriptions() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/zim/subscribe`);
|
2024-08-15 19:32:01 -06:00
|
|
|
if (response.ok) {
|
2023-05-29 18:04:03 -06:00
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
subscriptions: content['subscriptions'],
|
|
|
|
|
catalog: content['catalog'],
|
|
|
|
|
iso_639_codes: content['iso_639_codes'],
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Cannot fetch Zim Subscriptions');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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}`);
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${ZIM_API}/search/${zimId}`, body);
|
|
|
|
|
if (response.ok) {
|
2023-05-29 18:04:03 -06:00
|
|
|
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`;
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(uri, body);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to add zim tag');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
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`;
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(uri, body);
|
|
|
|
|
if (!response.ok) {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Failed to untag zim');
|
2024-08-15 19:32:01 -06:00
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2025-02-02 10:16:11 -07:00
|
|
|
export async function setZimAutoSearch(id, auto_search) {
|
|
|
|
|
const body = {auto_search};
|
|
|
|
|
const response = await apiPost(`${API_URI}/zim/${id}/auto_search`, body);
|
|
|
|
|
if (response.status !== 204) {
|
|
|
|
|
throw new Error('Failed to set Zim auto search');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2024-04-16 09:39:29 -06:00
|
|
|
export async function searchSuggestions(search_str) {
|
|
|
|
|
const body = {search_str};
|
|
|
|
|
const response = await apiPost(`${API_URI}/search_suggestions`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
channels: content.channels,
|
|
|
|
|
domains: content.domains,
|
2026-03-17 18:35:57 -06:00
|
|
|
authors: content.authors || [],
|
|
|
|
|
subjects: content.subjects || [],
|
2024-04-16 09:39:29 -06:00
|
|
|
}
|
2024-08-15 19:32:01 -06:00
|
|
|
} else {
|
|
|
|
|
console.error('Failed to get file search suggestions!');
|
2024-04-16 09:39:29 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-22 16:36:57 -06:00
|
|
|
export async function searchEstimateFiles(search_str, tagNames, mimetypes, months, dateRange, anyTag) {
|
2024-03-06 17:41:04 -07:00
|
|
|
months = months ? months.map(i => parseInt(i)) : [];
|
|
|
|
|
|
2024-07-22 16:36:57 -06:00
|
|
|
const body = {search_str, tag_names: tagNames, mimetypes, months, any_tag: anyTag};
|
2024-03-06 17:41:04 -07:00
|
|
|
if (dateRange) {
|
|
|
|
|
body['from_year'] = dateRange[0];
|
|
|
|
|
body['to_year'] = dateRange[1];
|
|
|
|
|
}
|
2024-04-16 09:39:29 -06:00
|
|
|
const response = await apiPost(`${API_URI}/search_file_estimates`, body);
|
2023-11-20 11:01:46 -07:00
|
|
|
if (response.ok) {
|
|
|
|
|
const content = await response.json();
|
2023-11-21 14:46:55 -07:00
|
|
|
|
2023-11-20 11:01:46 -07:00
|
|
|
return {
|
2024-04-16 09:39:29 -06:00
|
|
|
fileGroups: content.file_groups,
|
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries. Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.
Database:
- Migration adds the generated column and a GIN index (rewrites the
table; a few minutes on large libraries).
Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
query (COUNT FILTER on the abc subset): `file_groups` (fast) and
`file_groups_deep`.
UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
list.
- The gap is reconciled by a hint offering deep search: count-aware on
the global search ("No results in fast search. N results available in
deep search." / "N more results available..."), generic on the module
pages (no deep estimate there). The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
?deep=true.
Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside. Also skip flaky test_download_channel on
CircleCI.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:09:08 -06:00
|
|
|
fileGroupsDeep: content.file_groups_deep,
|
2023-11-20 11:01:46 -07:00
|
|
|
}
|
2024-07-22 16:36:57 -06:00
|
|
|
} else {
|
|
|
|
|
console.error('Failed to get file search estimates!');
|
2023-11-20 11:01:46 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-01 11:31:17 -07:00
|
|
|
export async function searchEstimateZims(search_str, tagNames) {
|
|
|
|
|
const body = {search_str: search_str, tag_names: tagNames};
|
|
|
|
|
const response = await apiPost(`${API_URI}/zim/search_estimates`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const content = await response.json();
|
2023-11-26 20:49:36 -07:00
|
|
|
return {
|
2024-01-01 11:31:17 -07:00
|
|
|
zimsEstimates: content.zims_estimates,
|
2023-11-26 20:49:36 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 19:32:01 -06:00
|
|
|
export async function searchEstimateOthers(tagNames) {
|
|
|
|
|
const body = {tag_names: tagNames};
|
|
|
|
|
const response = await apiPost(`${API_URI}/search_other_estimates`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
others: content.others,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function searchChannels(tagNames) {
|
|
|
|
|
const body = {tag_names: tagNames};
|
|
|
|
|
const response = await apiPost(`${API_URI}/videos/channels/search`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
channels: content.channels,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-29 18:04:03 -06:00
|
|
|
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 {
|
2024-10-02 21:59:33 -06:00
|
|
|
const message = await getErrorMessage(response, 'Cannot fetch outdated Zims. See server logs.');
|
2023-05-29 18:04:03 -06:00
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
2024-08-15 19:32:01 -06:00
|
|
|
title: 'Error',
|
|
|
|
|
description: message,
|
2023-05-29 18:04:03 -06:00
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteOutdatedZims() {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/zim/outdated`);
|
|
|
|
|
return response.status === 204;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 20:07:02 -06:00
|
|
|
export async function postShutdown() {
|
2025-12-19 17:40:43 -07:00
|
|
|
// Call Controller directly for system shutdown
|
|
|
|
|
const {shutdownSystem} = await import('./api/controller');
|
|
|
|
|
try {
|
|
|
|
|
const result = await shutdownSystem();
|
|
|
|
|
if (result.success) {
|
|
|
|
|
return null; // Success
|
|
|
|
|
}
|
|
|
|
|
return {code: 'SHUTDOWN_FAILED', error: result.error};
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return {code: 'SHUTDOWN_FAILED', error: e.message};
|
2023-08-17 20:07:02 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function postRestart() {
|
2025-12-19 17:40:43 -07:00
|
|
|
// Call Controller directly for system reboot
|
|
|
|
|
const {rebootSystem} = await import('./api/controller');
|
|
|
|
|
try {
|
|
|
|
|
const result = await rebootSystem();
|
|
|
|
|
if (result.success) {
|
|
|
|
|
return null; // Success
|
|
|
|
|
}
|
|
|
|
|
return {code: 'SHUTDOWN_FAILED', error: result.error};
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return {code: 'SHUTDOWN_FAILED', error: e.message};
|
2023-08-17 20:07:02 -06:00
|
|
|
}
|
|
|
|
|
}
|
2024-11-29 17:01:16 -07:00
|
|
|
|
|
|
|
|
export async function postVideoFileFormat(video_file_format) {
|
|
|
|
|
const body = {video_file_format};
|
|
|
|
|
return await apiPost(`${API_URI}/videos/file_format`, body);
|
2025-10-29 22:16:33 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function checkUpgrade(force = false) {
|
|
|
|
|
const url = force ? `${API_URI}/upgrade/check?force=true` : `${API_URI}/upgrade/check`;
|
|
|
|
|
const response = await apiGet(url);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function triggerUpgrade() {
|
|
|
|
|
const response = await apiPost(`${API_URI}/upgrade/start`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to start upgrade. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Upgrade Error',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return response;
|
2025-12-06 14:49:46 -07:00
|
|
|
}
|
2025-12-06 18:07:20 -07:00
|
|
|
|
|
|
|
|
export async function getBulkTagPreview(paths) {
|
|
|
|
|
const body = {paths};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/bulk_tag/preview`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to get bulk tag preview.');
|
|
|
|
|
toast({type: 'error', title: 'Bulk Tag Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function applyBulkTags(paths, addTagNames, removeTagNames) {
|
|
|
|
|
const body = {
|
|
|
|
|
paths,
|
|
|
|
|
add_tag_names: addTagNames || [],
|
|
|
|
|
remove_tag_names: removeTagNames || [],
|
|
|
|
|
};
|
|
|
|
|
const response = await apiPost(`${API_URI}/files/bulk_tag/apply`, body);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to apply bulk tags.');
|
|
|
|
|
toast({type: 'error', title: 'Bulk Tag Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getBulkTagProgress() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/files/bulk_tag/progress`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
// Not toasting because this happens often during polling.
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-02-20 14:37:58 -07:00
|
|
|
|
|
|
|
|
// Encrypted Cookies API
|
|
|
|
|
|
|
|
|
|
export async function getCookiesStatus() {
|
|
|
|
|
const response = await apiGet(`${VIDEOS_API}/cookies/status`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to get cookies status.');
|
|
|
|
|
toast({type: 'error', title: 'Cookies Error', description: message, time: 5000});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function uploadCookies(cookiesContent, password) {
|
|
|
|
|
const body = {cookies_content: cookiesContent, password};
|
|
|
|
|
const response = await apiPost(`${VIDEOS_API}/cookies`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
toast({type: 'success', title: 'Cookies Saved', description: 'Cookies encrypted and saved successfully.', time: 3000});
|
|
|
|
|
return {success: true};
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to save cookies.');
|
|
|
|
|
toast({type: 'error', title: 'Cookies Error', description: message, time: 5000});
|
|
|
|
|
return {success: false, error: message};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteCookies() {
|
|
|
|
|
const response = await apiDelete(`${VIDEOS_API}/cookies`);
|
|
|
|
|
if (response.status === 204) {
|
|
|
|
|
toast({type: 'success', title: 'Cookies Deleted', description: 'Encrypted cookies file deleted.', time: 3000});
|
|
|
|
|
return {success: true};
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to delete cookies.');
|
|
|
|
|
toast({type: 'error', title: 'Cookies Error', description: message, time: 5000});
|
|
|
|
|
return {success: false, error: message};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function unlockCookies(password) {
|
|
|
|
|
const body = {password};
|
|
|
|
|
const response = await apiPost(`${VIDEOS_API}/cookies/unlock`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
toast({type: 'success', title: 'Cookies Unlocked', description: 'Cookies decrypted and ready for downloads.', time: 3000});
|
|
|
|
|
return {success: true};
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to unlock cookies.');
|
|
|
|
|
toast({type: 'error', title: 'Cookies Error', description: message, time: 5000});
|
|
|
|
|
return {success: false, error: message};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function lockCookies() {
|
|
|
|
|
const response = await apiPost(`${VIDEOS_API}/cookies/lock`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
toast({type: 'success', title: 'Cookies Locked', description: 'Cookies cleared from memory.', time: 3000});
|
|
|
|
|
return {success: true};
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to lock cookies.');
|
|
|
|
|
toast({type: 'error', title: 'Cookies Error', description: message, time: 5000});
|
|
|
|
|
return {success: false, error: message};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchSuggestedUserAgent() {
|
|
|
|
|
const response = await apiGet(`${VIDEOS_API}/suggested-user-agent`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data?.user_agent || '';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
}
|
2026-03-17 18:35:57 -06:00
|
|
|
|
|
|
|
|
// Docs API
|
|
|
|
|
const DOCS_API = '/api/docs';
|
|
|
|
|
|
|
|
|
|
export async function getDocStatistics() {
|
|
|
|
|
return await apiGet(`${DOCS_API}/statistics`);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-20 15:53:21 -06:00
|
|
|
export async function getDoc(fileGroupId) {
|
|
|
|
|
return await apiGet(`${DOCS_API}/${fileGroupId}`);
|
2026-03-17 18:35:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries. Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.
Database:
- Migration adds the generated column and a GIN index (rewrites the
table; a few minutes on large libraries).
Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
query (COUNT FILTER on the abc subset): `file_groups` (fast) and
`file_groups_deep`.
UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
list.
- The gap is reconciled by a hint offering deep search: count-aware on
the global search ("No results in fast search. N results available in
deep search." / "N more results available..."), generic on the module
pages (no deep estimate there). The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
?deep=true.
Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside. Also skip flaky test_download_channel on
CircleCI.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:09:08 -06:00
|
|
|
export async function searchDocs(offset, limit, searchStr, order, tagNames, author, subject, mimetype, deep) {
|
2026-03-17 18:35:57 -06:00
|
|
|
offset = parseInt(offset || 0);
|
|
|
|
|
limit = parseInt(limit || DEFAULT_LIMIT);
|
|
|
|
|
let body = {offset, limit};
|
|
|
|
|
if (searchStr) {
|
|
|
|
|
body['search_str'] = searchStr;
|
|
|
|
|
}
|
|
|
|
|
if (order) {
|
|
|
|
|
body['order_by'] = order;
|
|
|
|
|
}
|
|
|
|
|
if (tagNames && tagNames.length > 0) {
|
|
|
|
|
body['tag_names'] = tagNames;
|
|
|
|
|
}
|
|
|
|
|
if (author) {
|
|
|
|
|
body['author'] = author;
|
|
|
|
|
}
|
|
|
|
|
if (subject) {
|
|
|
|
|
body['subject'] = subject;
|
|
|
|
|
}
|
2026-04-14 15:32:06 -06:00
|
|
|
if (mimetype) {
|
|
|
|
|
body['mimetype'] = mimetype;
|
|
|
|
|
}
|
Search: fast ABC mode by default, opt-in deep search
The file_group.textsearch tsvector indexes all four text columns;
d_text (captions, document text, zip contents) is ~90% of the data,
making ts_rank searches take seconds on large libraries. Add a
textsearch_abc generated column (title/author/description only, ~8x
smaller) and default all searches to it, with deep=true opting into the
full column.
Database:
- Migration adds the generated column and a GIN index (rewrites the
table; a few minutes on large libraries).
Backend:
- FilesSearchRequest, VideoSearchRequest, ArchiveSearchRequest, and
DocSearchRequest accept `deep`; each search function picks the column.
- /api/search_file_estimates returns both counts in one index-bound
query (COUNT FILTER on the abc subset): `file_groups` (fast) and
`file_groups_deep`.
UI (one coherent story across the count surfaces):
- The typing dropdown always suggests the deep count (what is findable).
- The tab badge shows the active mode's count so it matches the result
list.
- The gap is reconciled by a hint offering deep search: count-aware on
the global search ("No results in fast search. N results available in
deep search." / "N more results available..."), generic on the module
pages (no deep estimate there). The hint resets pagination.
- "Search Depth" toggle in the search filter modals, persisted as
?deep=true.
Tests that relied on d_text matches now pass deep=True, with fast-mode
assertions alongside. Also skip flaky test_download_channel on
CircleCI.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:09:08 -06:00
|
|
|
if (deep) {
|
|
|
|
|
body['deep'] = true;
|
|
|
|
|
}
|
2026-03-17 18:35:57 -06:00
|
|
|
|
|
|
|
|
console.debug('searching docs', body);
|
|
|
|
|
const response = await apiPost(`${DOCS_API}/search`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let data = await response.json();
|
|
|
|
|
return [data['file_groups'], data['totals']['file_groups']];
|
|
|
|
|
} else {
|
|
|
|
|
const message = await getErrorMessage(response, 'Cannot search docs. See server logs.');
|
|
|
|
|
toast({
|
|
|
|
|
type: 'error',
|
|
|
|
|
title: 'Unable to search docs',
|
|
|
|
|
description: message,
|
|
|
|
|
time: 5000,
|
|
|
|
|
});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
Add ordered collections (playlists): polymorphic items + item API (#475)
* Add Playlists: ordered, mixed-type collections
A playlist (Collection kind='playlist') is a manually-curated, ordered list that
mixes item types. Squash of the playlists feature branch (24 commits).
Data model & API:
- CollectionItem is polymorphic via item_kind: 'file' (FileGroup), 'zim'
(zim_id + zim_entry), or 'url' (link to anything the WROLPi browser opens,
e.g. /map?lat=&lon=&z=). CHECK constraint enforces exactly one kind; per-kind
unique constraints; migration a7b1c2d3e4f5.
- Endpoints: create playlist; add/remove/reorder items (idempotent adds: 201 new,
200 existing); GET returns the ordered items. All mutations wrol_mode_check'd.
Config (source of truth):
- playlists.yaml (PlaylistsConfig) stores each playlist's metadata AND ordered
items (file by relative path, zim by path+entry, url inline); round-trips a
DB wipe. Supports backup import (DB_CONFIG_FILE_NAMES).
- The redundant generic CollectionsConfig (collections.yaml) is deleted:
channels/domains own their configs, authors/subjects are re-derived.
On-disk sync (sync_playlists_directory switch):
- Each playlist materializes into the configurable Playlists Directory
(playlists_destination, Settings UI input, excluded from indexing) with
position-prefixed entries: NNNN_<file> hard links (copy fallback across
filesystems) and NNNN_<title>.html stubs for zim/url items.
- Tagged playlists are namespaced like channels: <playlists>/<tag>/<name>;
a tag change moves the directory and prunes the empty old tag dir.
- Deletion safety: managed files are only removed when they are our marked
stubs or still have another hard link (st_nlink > 1) -- never a last copy.
Stray loose files at the playlists root are removed; stub URLs are
scheme-allowlisted (no javascript:/data:).
Frontend:
- /playlists list page (CollectionTable, name filter, New Playlist modal, Tag
column) between Files and Zim in the nav.
- View-only detail page (Name link) and edit page (Edit button): themed table
with model icons/colors + poster thumbnails, items link to their model page
(video/archive/doc) or preview, up/down reorder, remove, add-URL form,
single-tag selector; all editing disabled in WROL Mode.
- Reusable green "Add to Playlist" button on Video/Archive/Doc detail pages,
the FilePreview toolbar, Zim search results, and Map pins (added as a /map
URL item with a map-marker icon).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Playlist edit page parity: rename, custom directory, tag modal move suggestion
Match the ChannelEditPage/DomainEditPage UX on the playlist edit page:
Back/View buttons, an edit form (name, description, directory), and the
shared CollectionTagModal with the violet "Tag" button. The tag modal now
suggests moving the playlist to its managed tag location
(playlists/<tag>/<name>); accepting the suggestion stores directory=None so
the sync keeps auto-managing the location. Tag buttons on the Channel and
Domain edit pages are now violet to match.
Backend: update_collection learns rename (with per-kind validation and
duplicate checks) and playlist custom directories (cleanup of the abandoned
directory, config round-trip, commit-before-switch to avoid the background
sync racing pre-commit state). tag_collection's duplicated untag/tag
branches are merged, and the per-kind config-save dispatch is consolidated
into _activate_config_save().
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Deduplicate Collection error handling and Tag creation
Delete the duplicate UnknownCollection in wrolpi/collections/errors.py and
re-export the canonical one from wrolpi/errors.py, which carries
status_code=NOT_FOUND (the local copy inherited 500). Replace the repeated
query/raise pattern in reorganize.py with Collection.find_by_id.
Add Tag.get_or_create_tag and use it for collection tagging; flush the new
Tag before returning so callers can read .id immediately -- previously
tagging a collection with a brand-new tag name set tag_id=None. Regression
test included.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 19:37:34 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
export async function fetchPlaylists() {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}?kind=playlist`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['collections'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to fetch playlists.');
|
|
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getPlaylist(playlistId) {
|
|
|
|
|
const response = await apiGet(`${COLLECTIONS_API}/${playlistId}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['collection'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to fetch playlist.');
|
|
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-10 15:56:20 -06:00
|
|
|
export async function createPlaylist(name, description, tagName) {
|
Add ordered collections (playlists): polymorphic items + item API (#475)
* Add Playlists: ordered, mixed-type collections
A playlist (Collection kind='playlist') is a manually-curated, ordered list that
mixes item types. Squash of the playlists feature branch (24 commits).
Data model & API:
- CollectionItem is polymorphic via item_kind: 'file' (FileGroup), 'zim'
(zim_id + zim_entry), or 'url' (link to anything the WROLPi browser opens,
e.g. /map?lat=&lon=&z=). CHECK constraint enforces exactly one kind; per-kind
unique constraints; migration a7b1c2d3e4f5.
- Endpoints: create playlist; add/remove/reorder items (idempotent adds: 201 new,
200 existing); GET returns the ordered items. All mutations wrol_mode_check'd.
Config (source of truth):
- playlists.yaml (PlaylistsConfig) stores each playlist's metadata AND ordered
items (file by relative path, zim by path+entry, url inline); round-trips a
DB wipe. Supports backup import (DB_CONFIG_FILE_NAMES).
- The redundant generic CollectionsConfig (collections.yaml) is deleted:
channels/domains own their configs, authors/subjects are re-derived.
On-disk sync (sync_playlists_directory switch):
- Each playlist materializes into the configurable Playlists Directory
(playlists_destination, Settings UI input, excluded from indexing) with
position-prefixed entries: NNNN_<file> hard links (copy fallback across
filesystems) and NNNN_<title>.html stubs for zim/url items.
- Tagged playlists are namespaced like channels: <playlists>/<tag>/<name>;
a tag change moves the directory and prunes the empty old tag dir.
- Deletion safety: managed files are only removed when they are our marked
stubs or still have another hard link (st_nlink > 1) -- never a last copy.
Stray loose files at the playlists root are removed; stub URLs are
scheme-allowlisted (no javascript:/data:).
Frontend:
- /playlists list page (CollectionTable, name filter, New Playlist modal, Tag
column) between Files and Zim in the nav.
- View-only detail page (Name link) and edit page (Edit button): themed table
with model icons/colors + poster thumbnails, items link to their model page
(video/archive/doc) or preview, up/down reorder, remove, add-URL form,
single-tag selector; all editing disabled in WROL Mode.
- Reusable green "Add to Playlist" button on Video/Archive/Doc detail pages,
the FilePreview toolbar, Zim search results, and Map pins (added as a /map
URL item with a map-marker icon).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Playlist edit page parity: rename, custom directory, tag modal move suggestion
Match the ChannelEditPage/DomainEditPage UX on the playlist edit page:
Back/View buttons, an edit form (name, description, directory), and the
shared CollectionTagModal with the violet "Tag" button. The tag modal now
suggests moving the playlist to its managed tag location
(playlists/<tag>/<name>); accepting the suggestion stores directory=None so
the sync keeps auto-managing the location. Tag buttons on the Channel and
Domain edit pages are now violet to match.
Backend: update_collection learns rename (with per-kind validation and
duplicate checks) and playlist custom directories (cleanup of the abandoned
directory, config round-trip, commit-before-switch to avoid the background
sync racing pre-commit state). tag_collection's duplicated untag/tag
branches are merged, and the per-kind config-save dispatch is consolidated
into _activate_config_save().
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Deduplicate Collection error handling and Tag creation
Delete the duplicate UnknownCollection in wrolpi/collections/errors.py and
re-export the canonical one from wrolpi/errors.py, which carries
status_code=NOT_FOUND (the local copy inherited 500). Replace the repeated
query/raise pattern in reorganize.py with Collection.find_by_id.
Add Tag.get_or_create_tag and use it for collection tagging; flush the new
Tag before returning so callers can read .id immediately -- previously
tagging a collection with a brand-new tag name set tag_id=None. Regression
test included.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 19:37:34 -06:00
|
|
|
// Trailing slash avoids Sanic's 302 redirect on the root POST route (which would drop the body).
|
2026-06-10 15:56:20 -06:00
|
|
|
const response = await apiPost(`${COLLECTIONS_API}/`,
|
|
|
|
|
{name, description, tag_name: tagName || null, kind: 'playlist'});
|
Add ordered collections (playlists): polymorphic items + item API (#475)
* Add Playlists: ordered, mixed-type collections
A playlist (Collection kind='playlist') is a manually-curated, ordered list that
mixes item types. Squash of the playlists feature branch (24 commits).
Data model & API:
- CollectionItem is polymorphic via item_kind: 'file' (FileGroup), 'zim'
(zim_id + zim_entry), or 'url' (link to anything the WROLPi browser opens,
e.g. /map?lat=&lon=&z=). CHECK constraint enforces exactly one kind; per-kind
unique constraints; migration a7b1c2d3e4f5.
- Endpoints: create playlist; add/remove/reorder items (idempotent adds: 201 new,
200 existing); GET returns the ordered items. All mutations wrol_mode_check'd.
Config (source of truth):
- playlists.yaml (PlaylistsConfig) stores each playlist's metadata AND ordered
items (file by relative path, zim by path+entry, url inline); round-trips a
DB wipe. Supports backup import (DB_CONFIG_FILE_NAMES).
- The redundant generic CollectionsConfig (collections.yaml) is deleted:
channels/domains own their configs, authors/subjects are re-derived.
On-disk sync (sync_playlists_directory switch):
- Each playlist materializes into the configurable Playlists Directory
(playlists_destination, Settings UI input, excluded from indexing) with
position-prefixed entries: NNNN_<file> hard links (copy fallback across
filesystems) and NNNN_<title>.html stubs for zim/url items.
- Tagged playlists are namespaced like channels: <playlists>/<tag>/<name>;
a tag change moves the directory and prunes the empty old tag dir.
- Deletion safety: managed files are only removed when they are our marked
stubs or still have another hard link (st_nlink > 1) -- never a last copy.
Stray loose files at the playlists root are removed; stub URLs are
scheme-allowlisted (no javascript:/data:).
Frontend:
- /playlists list page (CollectionTable, name filter, New Playlist modal, Tag
column) between Files and Zim in the nav.
- View-only detail page (Name link) and edit page (Edit button): themed table
with model icons/colors + poster thumbnails, items link to their model page
(video/archive/doc) or preview, up/down reorder, remove, add-URL form,
single-tag selector; all editing disabled in WROL Mode.
- Reusable green "Add to Playlist" button on Video/Archive/Doc detail pages,
the FilePreview toolbar, Zim search results, and Map pins (added as a /map
URL item with a map-marker icon).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* Playlist edit page parity: rename, custom directory, tag modal move suggestion
Match the ChannelEditPage/DomainEditPage UX on the playlist edit page:
Back/View buttons, an edit form (name, description, directory), and the
shared CollectionTagModal with the violet "Tag" button. The tag modal now
suggests moving the playlist to its managed tag location
(playlists/<tag>/<name>); accepting the suggestion stores directory=None so
the sync keeps auto-managing the location. Tag buttons on the Channel and
Domain edit pages are now violet to match.
Backend: update_collection learns rename (with per-kind validation and
duplicate checks) and playlist custom directories (cleanup of the abandoned
directory, config round-trip, commit-before-switch to avoid the background
sync racing pre-commit state). tag_collection's duplicated untag/tag
branches are merged, and the per-kind config-save dispatch is consolidated
into _activate_config_save().
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Deduplicate Collection error handling and Tag creation
Delete the duplicate UnknownCollection in wrolpi/collections/errors.py and
re-export the canonical one from wrolpi/errors.py, which carries
status_code=NOT_FOUND (the local copy inherited 500). Replace the repeated
query/raise pattern in reorganize.py with Collection.find_by_id.
Add Tag.get_or_create_tag and use it for collection tagging; flush the new
Tag before returning so callers can read .id immediately -- previously
tagging a collection with a brand-new tag name set tag_id=None. Regression
test included.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 19:37:34 -06:00
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['collection'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to create playlist.');
|
|
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deletePlaylist(playlistId) {
|
|
|
|
|
const response = await apiDelete(`${COLLECTIONS_API}/${playlistId}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to delete playlist.');
|
|
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addPlaylistItem(playlistId, item) {
|
|
|
|
|
// item: {item_kind, url?, title?, file_group_id?, zim_id?, zim_entry?, position?}
|
|
|
|
|
const response = await apiPost(`${COLLECTIONS_API}/${playlistId}/items`, item);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['item'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to add item.');
|
|
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function removePlaylistItem(playlistId, itemId) {
|
|
|
|
|
const response = await apiDelete(`${COLLECTIONS_API}/${playlistId}/items/${itemId}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to remove item.');
|
|
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function reorderPlaylistItems(playlistId, itemIds) {
|
|
|
|
|
const response = await apiPut(`${COLLECTIONS_API}/${playlistId}/items/order`, {item_ids: itemIds});
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['collection'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to reorder items.');
|
|
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update a playlist's name, description, and/or custom directory ('' clears the directory).
|
|
|
|
|
export async function updatePlaylist(playlistId, {name, description, directory}) {
|
|
|
|
|
const response = await apiPut(`${COLLECTIONS_API}/${playlistId}`, {name, description, directory});
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['collection'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to update playlist.');
|
|
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set (tagName) or clear (tagName='') a playlist's single tag. When `directory` is given, the
|
|
|
|
|
// playlist also moves there (the managed tag location is normalized back to auto-managed).
|
|
|
|
|
export async function setPlaylistTag(playlistId, tagName, directory) {
|
|
|
|
|
const body = {tag_name: tagName || ''};
|
|
|
|
|
if (directory !== null && directory !== undefined) {
|
|
|
|
|
body.directory = directory;
|
|
|
|
|
}
|
|
|
|
|
const response = await apiPut(`${COLLECTIONS_API}/${playlistId}`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['collection'];
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Failed to update playlist tag.');
|
|
|
|
|
toast({type: 'error', title: 'Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|