2024-11-02 15:14:02 -06:00
|
|
|
import {emptyToNull} from "./components/Common";
|
ui: thirty-five files off Semantic, leaving fifteen
Phase 2, part 4. Baseline 50 -> 15.
Migrated: all eight calculators, the rest of inventory and collections, the
Map/Zim/Docs cluster, Videos, Files, Search, Archive, DashboardPage,
DatesSelector, HelpModal, Events, Tags, Flasher's neighbours, admin Settings
and Status, Download, and App.
Also the three shared modules everything imports: api.js and customHooks.js
swap the Semantic toast library for the library's shim (same call shape), and
useForm.js renders the library's Message. useForm accepts both the old
`{content, header, positive|negative}` shape and the new `{kind, title}`,
because the pages building those objects migrate separately.
Two library gaps closed, both found by call sites needing them:
ActionInput is a forwardRef now. Its ref reaches the input rather than the
wrapper, because callers use it to focus or select the field -- a ref to the
surrounding div would do neither, which is why one call site had resorted to
hand-copying the component's markup.
Header takes a `color` token name. Three separate call sites had reached for
an inline style to colour a heading that carries meaning ("3 items to add"
against "2 to remove"), which is how a hex ends up in markup.
Two files needed repair after being interrupted mid-edit: MapViewer had a
Segment left in its error branch, and VideoPlayer had lost the useContext
import its own code still used. Neither jest nor tsc noticed; only
`npm run build` did, which is the whole reason that check exists.
Fifteen files remain: Archive, BulkTagModal, Channels, Docs, FileBrowser,
FilePreview, Flasher, Nav, Playlists, Theme.tsx, Upload, VideoPlayer, Zim,
ControllerPage, admin/Downloads. Theme.tsx is deliberately last -- the
unmigrated files still import its Semantic-backed wrappers, so it can only go
once they have.
2026-07-30 12:21:30 -06:00
|
|
|
import {toast} from "./components/ui";
|
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,
|
Add a Repos module that mirrors git repositories (#783)
Repos keeps local mirrors of git repositories, cloned over https and kept up to date on a schedule.
- A Repo is a Collection (kind='repo') plus a `repository` row. The new `git` downloader clones it, then updates it
(weekly by default, or Never: the clone is kept as it is and only updated on request).
- Repos are saved in `repos/<tag>/<name>` (the Repos Directory, ignored by default) or a directory the user chooses.
An existing clone can be imported where it is. repos.yaml is the source of truth.
- A GitHub-like page shows each repo's README, files, and history, with a ZIP download. READMEs are searchable
under the global search's Other tab.
- git is hardened against hostile repos and configs: https only, pinned addresses with no private addresses (for the
repo and its submodules), sanitized configs, no hooks or links, and only clones WROLPi made or imported are
updated.
- Tagging a Repo moves its clone as one directory. Repo changes wait for repos.yaml to be imported at startup.
- The file mover groups unindexed files with no primary file as one FileGroup, and never replaces a file at the
destination. A failed tag move restores the Collection's tag. A Collection's directory cannot leave the media
directory.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 15:16:40 -06:00
|
|
|
REPOS_API,
|
2025-12-06 14:49:46 -07:00
|
|
|
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();
|
|
|
|
|
const code = content['code'];
|
Sync and backup: a secondary WROLPi and a backup drive copy the library (#957)
* A secondary WROLPi copies its primary's library over HTTP
A WROLPi with role "secondary" pulls from its primary: a manifest of every
FileGroup's files (/api/sync/manifest), then each missing or changed file
from the primary's Caddy /media/ (resumable, written to a hidden partial and
renamed with the primary's mtime), a refresh, then the library configs,
imported as the primary wrote them. wrolpi.yaml contributes only its library
settings. Files deleted on the primary are kept.
A secondary never saves the synced configs and never downloads. Its API
answers 503 SYNCING while a sync runs, and every page warns that it is a
copy. It syncs in a daily window or on "Sync now"; WROL Mode stops it.
On a Pi 4 (no AES instructions) the client uses TLS 1.2 ChaCha20, which
pulls ~110 MB/s from Caddy versus ~41 MB/s for rsync over ssh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync has its own /admin tab; a sync's reads from the primary are bounded
The sync settings and progress move from Settings (and the component
gallery, which is for library components) to /admin/sync.
A download never writes past the size in the primary's manifest, and configs,
listings, and manifest pages are capped. A primary address may not carry a
user name or password (it is logged and shown). While a sync runs, the API
answers only the exact requests that show its progress or stop it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync keeps the secondary's replaced configs in today's config backup
The first copy of the day is kept, like a save, so a config backup import
undoes a sync's config changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Docker's Caddy logs every request
`docker compose logs -f web` shows each request with its status, size and
duration, e.g. a secondary's /media/ downloads during a sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync reports its progress as it downloads, and refuses quietly
The status updated only when a page of 500 FileGroups finished, so a page of
large files looked stuck; it now updates every 2 seconds. Requests refused
while syncing are answered by the middleware instead of raised, so the UI's
polling no longer logs an error each time. The primary's version is stored
without its trailing newline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A WROLPi can back up to a second drive; sync settings live in sync.yaml
The Sync tab's Backup Drive copies the media directory to a second mounted
drive with rsync during the sync window (hourly), or on "Back Up Now".
Nothing on the backup drive is deleted. The Tags and playlists directories
are left out (WROLPi rebuilds them from the configs), and the database is
written as an SQLite snapshot rather than copied as files, so the drive can be
mounted as the media directory and start. A backup is written only while the
chosen drive (by UUID) is mounted where it was chosen, and is not the media or
system drive; rsync is stopped if the drive disappears. Not in Docker, which
cannot reach other drives.
Role, primary, window and backup drive move from wrolpi.yaml to sync.yaml:
they belong to this machine, and are never copied from a primary.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The Sync tab shows the configured backup drive
getSettings copies each setting by name and did not list the backup drive,
so the Sync tab showed "None" while one was configured. It also dropped
`version`. A test now fails for any setting the API sends that getSettings
drops.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup can go to a folder on its drive, and remembers its last success
The Backup Drive panel takes a folder on the chosen drive. The drive is
checked through the folder's mount point: the folder is written only when the
drive with the saved UUID is mounted there, so a folder left on the system
drive by an unplugged drive, or on another drive mounted inside the chosen
one, is refused. A missing folder is created once the drive is checked.
When the last backup succeeded is saved in sync.yaml, so it is known after a
restart. "Stop Backup" is disabled while the database snapshot is written (it
runs to the end), and a finished backup clears the request to stop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The backup drive has its own window
The sync window was shown in the Sync panel but also scheduled the backup
drive. The Backup Drive panel now has its own window (sync.yaml
backup_window_start/end), saved with the drive; the sync window is shown,
and used, only for a secondary's sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync and the backup drive can each exclude folders
A secondary or a backup drive may be smaller than the primary's library.
Each Sync tab panel has its own excluded folders in sync.yaml, chosen in
a folder browser: a secondary browses its primary's folders (through
Caddy), the backup drive browses this WROLPi's media directory. Excluded
folders are never copied; what was copied before is kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The folder browser does not offer lost+found
Every ext4 drive has a root-only lost+found folder; a sync and a backup
never copy it, so it is not offered for exclusion.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync never writes into config or tags, whatever their case
On a media drive that ignores case (exFAT, NTFS, macOS), a manifest path
like Config/wrolpi.db is the real config folder. The protected and
unlisted top-level folders are now compared case-insensitively in the
manifest, in resolve_destination, in excluded-folder validation, and in
both folder listings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup writes the database snapshot only when the database changed
Every backup rewrote the whole database snapshot (2.5 GB on a busy
WROLPi), even on the window's idle hourly runs. The snapshot is now
skipped when the live database (its size and mtime, and those of a
non-empty WAL) and the drive's copy are both unchanged since the last
snapshot. The record is in memory, so the first backup after a restart
writes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove the unused save_sync_config switch
Nothing activated it; SyncConfig saves directly. The test server's
log_message override is called by http.server, so it goes in the
vulture baseline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 10:53:34 -07:00
|
|
|
console.error('API error response json', content);
|
2023-07-17 14:21:27 -06:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2026-11-11 19:21:06 -07:00
|
|
|
export async function searchVideos(offset, limit, channelId, searchStr, order_by, tagNames, headline, censored, deep, anyTag) {
|
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;
|
|
|
|
|
}
|
2026-11-11 19:21:06 -07:00
|
|
|
if (anyTag) {
|
|
|
|
|
body['any_tag'] = 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
|
|
|
}
|
|
|
|
|
|
Jobs queue, video Edit dropdown: transcode/remux, edit title & description (#711)
* Jobs queue and video transcode from the video page
Add an in-memory FIFO Job queue (wrolpi/jobs.py): functions register by
name, callers enqueue by name with JSON kwargs, and the perpetual-tasks
owner runs them one at a time. Logging emitted inside a Job and the
output of its subprocesses are captured into a per-Job log; Jobs report
progress and can be cancelled (a running Job's subprocess is killed).
Jobs are not persisted; an API restart forgets them.
Add a transcode Job and POST /api/videos/<id>/transcode. ffmpeg reports
progress via -progress pipe:1. The existing FileGroup is pointed at the
new file before the refresh so tags and history survive a container
change.
Replace the video page Refresh button with an Edit dropdown (Refresh,
Transcode). The Transcode modal pre-fills from the preferred codecs in
the Videos settings and shows the Job's progress, log tail and Cancel.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Video page: move Delete into the Edit dropdown
The Edit dropdown now holds Refresh, Transcode and Delete, so the action
row is Download / Edit / Add to Playlist. Delete keeps its confirmation
(a Confirm dialog) and the tagged-files prompt, and is disabled in WROL
Mode like the other items.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Video page: Edit > Edit to change a video's title
PUT /api/videos/<file_group_id> writes the title (and fulltitle) into the
Video's info json, creating the file when the video has none, then
validates the Video again so its title and search text follow. Files
stay the source of truth: the edit survives a refresh, and a re-download
of the metadata replaces it (the modal says so).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Video page: edit the description in Edit > Edit
PUT /api/videos/<file_group_id> now takes optional title and description
and changes only the fields given; an empty description clears it. The
modal sends only what changed and refetches the description after saving.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Transcode modal: allow a container-only remux
Keeping both streams is no longer refused: ffmpeg copies them into the
chosen container with fast start. The container select starts at the
file's own container, the hint explains what a remux does, and the button
reads Remux when nothing is re-encoded.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* WROL Mode: refuse video edits and transcodes past the API
The routes already returned 403, but a transcode Job queued before WROL
Mode was enabled still ran, update_video could be called from anywhere,
and the Edit modal's Save button stayed live. The Job now fails before
ffmpeg starts, update_video carries wrol_mode_check, and the modal
disables Save with a notice.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Transcode: verify the output before replacing the original
After ffmpeg exits, the output is probed and compared with the source
(container, presence of video/audio streams, codec per stream, duration
within 1s or 1%) and its last 30 seconds are decoded to a null output.
Any failure removes the output and keeps the original.
The tail decode replaces the download-time completeness check, which
grabbed a single frame near the end: one ffmpeg_video_complete (sync for
the downloader, async for Jobs) now serves both, and is stricter, since
every frame of the tail plus the audio must decode.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Jobs: claim atomically, cap pending, own-session subprocesses; retarget before delete
Review fixes. The worker read a Job's status and wrote RUNNING as two
steps, so a cancel landing between them was overwritten and the Job ran;
_claim_job now does both under the lock. enqueue_job refuses past
JOB_PENDING_LIMIT pending Jobs. JobContext.run_command starts the
subprocess in its own session and raises CancelledError when the command
was killed, so a handler cannot mistake it for a normal exit.
The transcode Job now retargets the FileGroup (committed) while the
original file still exists, and deletes the original afterwards
(transcode_video_file gained keep_original). A crash in between leaves
both files with the database pointing at a real one.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Video page: the Edit menu owns the transcode Job; polling survives Close and errors
Review fixes. The transcode Job's id and polling (useJob) move from the
modal to VideoEditMenu, so closing the modal no longer stops the page
from learning the Job finished (and refetching the video, whose path may
have changed). While a Job runs the menu shows Transcoding..., reopening
shows its progress instead of the form, and Delete waits. A failed poll
request is retried instead of ending the polling. getJobs checks the
response like its siblings. Design narration trimmed from comments.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Transcode: audio files, and Remove video to turn a video into an audio file
video_codec 'none' (REMOVE_VIDEO) drops the video stream (-vn, audio
required); an audio-only source is audio-only output whatever the video
target says, and a video target on it is refused. Audio output gets an
audio container (m4a/ogg/mp3) checked against the codec it will hold, and
a video container asked for audio output is replaced by the codec's
natural one. faststart only for mp4/m4a. Verification learned the
audio-only shape and ffprobe's container names (mkv reports matroska).
The modal offers 'Remove video (audio only)', switches to audio
containers and follows the audio codec, reads Extract Audio, and opens
for audio files (no video codec select).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Video page: yellow Edit button
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Transcode: remove the temp output on cancel; tell the user when a closed-modal Job fails or is lost
Review fixes. The temp output was only removed on Exception, but a
cancelled Job's run_command raises CancelledError (a BaseException), so a
cancel left the partial file for a refresh to index. Closing the modal
during a Job that then failed showed nothing; it now toasts the error
(and a cancellation). Polling gives up on a 404 or five failures in a
row (the API restarted and forgot its Jobs), warning the user and
unlocking Transcode and Delete instead of reading Transcoding... forever.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Jobs: _claim_job docstring states the invariant, not the old race
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Transcode: fragmented mp4 option for very long videos
A whole-file mp4 index grows with the frame count; for a many-hour video
it reaches tens of MB, which a phone must fetch and parse before the
first frame, and every seek walks it. `fragmented` writes the file with
-movflags +frag_keyframe+empty_moov+default_base_moof+global_sidx and
10s fragments: a ~1 KB moov plus a global seek index, so playback starts
and seeks quickly. mp4/m4a only; a remux, so it takes seconds per GB.
Measured on an 11-hour h264/aac file: moov 40 MB -> 1.4 KB, seek index
2 x 120 KB, 10k fragments, duration and codecs unchanged, remux in 25s.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Transcode modal: the Fragmented label says audio for audio output
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Video edits keep the original: custom_title/custom_description in the info json's wrolpi section
Editing a title or description no longer overwrites yt-dlp's keys. The
values go into the info json's `wrolpi` section (custom_title,
custom_description); the modeler prefers them when deriving the Video, so
a refresh keeps the edit while the original title and description stay in
the file. An empty custom description means none.
Both re-download paths carry the wrolpi section over: the metadata-only
refresh merges it into the fresh info json, and a full re-download
snapshots it before yt-dlp overwrites the file and restores it (then
re-validates) in finalize_download. FileGroup.get_wrolpi_json reads it.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 19:25:23 -06:00
|
|
|
export async function updateVideo(fileGroupId, {title, description}) {
|
|
|
|
|
// Edits the Video's details (written to its info json). Only the fields given are changed.
|
|
|
|
|
// Returns the updated video file group.
|
|
|
|
|
const response = await apiPut(`${VIDEOS_API}/${fileGroupId}`, {title, description});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to save the video. See server logs.');
|
|
|
|
|
toast({type: 'error', title: 'Failed to save', description: message, time: 5000});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data['file_group'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function transcodeVideo(fileGroupId, {
|
|
|
|
|
video_codec = null, audio_codec = null, container = 'mp4', fragmented = false,
|
|
|
|
|
}) {
|
|
|
|
|
// Queues a transcode Job; returns the job id. Watch it with `getJob`.
|
|
|
|
|
const body = {video_codec, audio_codec, container, fragmented};
|
|
|
|
|
const response = await apiPost(`${VIDEOS_API}/${fileGroupId}/transcode`, body);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to queue the transcode. See server logs.');
|
|
|
|
|
toast({type: 'error', title: 'Failed to transcode', description: message, time: 5000});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data['job_id'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getJobs() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/jobs`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(await getErrorMessage(response, 'Unable to get the jobs'));
|
|
|
|
|
}
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data['jobs'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getJob(jobId) {
|
|
|
|
|
const response = await apiGet(`${API_URI}/jobs/${jobId}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const error = new Error(await getErrorMessage(response, 'Unable to get the job'));
|
|
|
|
|
error.status = response.status;
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data['job'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function cancelJob(jobId) {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/jobs/${jobId}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to cancel the job');
|
|
|
|
|
toast({type: 'error', title: 'Failed to cancel', description: message, time: 5000});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
return data['job'];
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Fix API stalls: non-blocking switch worker, threaded searches, indexed Videos page (#678)
* Fix API stalls: non-blocking switch worker, threaded searches, indexed Videos page
Three response-time fixes found by benchmarking the read-only API endpoints
hot and cold on real libraries:
* `switch_worker` runs on the Sanic worker's event loop every 0.1s and called
the blocking `multiprocessing.Event.wait(timeout=1)`. With no switch pending
(the normal state) this froze the loop for a second at a time; about a third
of all requests, including trivial ones, took ~1,000 ms. It now polls
`is_set()` and returns immediately.
* The search handlers (videos, files, archives, docs, zims) and `/api/statistics`
ran synchronous SQLite queries on the event loop, so one slow search stalled
every other request on that worker. They now run via `asyncio.to_thread`.
* The unfiltered Videos page (`POST /api/videos/search` with only an order)
used `mimetype LIKE 'video/%' OR ...` plus `COUNT(*) OVER()`, which visits
every video's index entry before LIMIT applies: seconds cold on a large
library on a spinning disk, and ~10 s hot for a deep page. It now seeks each
exact mimetype on the (mimetype, effective_datetime) index for `limit + offset`
rows and merges them, with the total from a separate count cached for 60 s.
Results are identical to the generic query.
Also adds `scripts/api_perf.py` (times every read-only endpoint against a host,
optionally restarting the API over SSH for cold numbers) and
`scripts/api_perf_compare.py` (merges per-host results). Host profiles live in a
gitignored JSON file; an example is included.
Measured on an 8-core docker host with a 10 GB library: median hot request
1,007 ms -> 22 ms; Videos page 1 hot 287 -> 108 ms, page 50 1,345 -> 120 ms.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Serve the video description from its own endpoint instead of Video.__json__
`Video.__json__` computed `description` as `c_text or get_video_description()`,
where the fallback opens and parses the video's info json from disk. The list
endpoints serialize every result with `__json__`, so any page containing videos
without an indexed description (common: many videos have none) read their info
json files on every request, cold, for a field the list never displays. The
description is not part of search either: search runs against the FTS copy of
`c_text`, so the fallback never fed the index.
Drop `description` from `__json__` and serve it from
`GET /api/videos/<id>/description`, like comments and captions. The endpoint
returns the indexed `c_text`, falling back to the info json only there, for a
row indexed before descriptions were stored. The player page fetches it through
`useVideoExtras` alongside the comments.
Tests assert the list and detail responses never touch the info json, and cover
the endpoint's indexed, fallback, and not-found cases.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Address review: thread-local zim sessions, fast-path equivalence test, comments
* Zim search, single-zim search, and search estimates run libzim off the event
loop, each opening its own session inside the worker thread rather than
passing the request's SQLAlchemy Session across threads.
* The Videos fast-path test now runs the same requests through the generic
query and asserts identical rows and paging for both date orders. The one
intentional difference is documented: past the end, the fast path still
reports the true total.
* switch_worker returns before its try block so the empty path does not clear
the event; its comment states the invariant only. The copied "synchronous
SQLite" comments are reduced to one line in one place.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-29 16:17:41 -06:00
|
|
|
export async function getVideoDescription(fileGroupId) {
|
|
|
|
|
const response = await apiGet(`${VIDEOS_API}/${fileGroupId}/description`);
|
|
|
|
|
let data = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
description: data.description,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
The backup drive keeps deleted files for 30 days, then removes them (#999)
* The backup drive keeps deleted files for 30 days, then removes them
The fifth part of replacing the sync. A backup drive never deleted anything, so it grew forever and kept every file
the media directory had ever held. Now, like a secondary:
- A file deleted from the media directory, or the old version of one that changed, is moved to a dated folder in
.backup-trash on the backup drive. Folders older than backup_delete_after_days (sync.yaml; 30 by default, also
for drives set up before this; none never deletes) are removed, before and after each backup, and the oldest go
sooner when the drive is nearly full.
- A backup refuses a media directory that is not mounted, or has no config/wrolpi.yaml: copied with deletes, an
empty folder would move the whole backup drive to the trash.
- The Backup Drive panel has the same "Delete after N days / Never delete them" control as the Sync panel, now one
component, and refuses an empty number of days.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A nearly full drive keeps the trash it just filled, and makes room for the database
Review found, in the backup drive's trash and in the secondary's sync, which share its shape:
- Below 1 GiB free, the purge after a copy removed the newest trash folder too. Moving a file to the trash is a
rename, which frees nothing, so on a nearly full drive a deleted file was gone at the end of the same run instead
of 30 days later. The newest folder is now only removed by age (0 days still deletes at once).
- The purge made room only down to 1 GiB, so a database larger than the free space failed to be copied every time
while the trash was full. Before the database is written (the backup's snapshot, the secondary's copy of its
primary's), the trash now makes room for the whole database.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 16:50:21 -07:00
|
|
|
backup_delete_after_days: content.backup_delete_after_days,
|
Sync and backup: a secondary WROLPi and a backup drive copy the library (#957)
* A secondary WROLPi copies its primary's library over HTTP
A WROLPi with role "secondary" pulls from its primary: a manifest of every
FileGroup's files (/api/sync/manifest), then each missing or changed file
from the primary's Caddy /media/ (resumable, written to a hidden partial and
renamed with the primary's mtime), a refresh, then the library configs,
imported as the primary wrote them. wrolpi.yaml contributes only its library
settings. Files deleted on the primary are kept.
A secondary never saves the synced configs and never downloads. Its API
answers 503 SYNCING while a sync runs, and every page warns that it is a
copy. It syncs in a daily window or on "Sync now"; WROL Mode stops it.
On a Pi 4 (no AES instructions) the client uses TLS 1.2 ChaCha20, which
pulls ~110 MB/s from Caddy versus ~41 MB/s for rsync over ssh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync has its own /admin tab; a sync's reads from the primary are bounded
The sync settings and progress move from Settings (and the component
gallery, which is for library components) to /admin/sync.
A download never writes past the size in the primary's manifest, and configs,
listings, and manifest pages are capped. A primary address may not carry a
user name or password (it is logged and shown). While a sync runs, the API
answers only the exact requests that show its progress or stop it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync keeps the secondary's replaced configs in today's config backup
The first copy of the day is kept, like a save, so a config backup import
undoes a sync's config changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Docker's Caddy logs every request
`docker compose logs -f web` shows each request with its status, size and
duration, e.g. a secondary's /media/ downloads during a sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync reports its progress as it downloads, and refuses quietly
The status updated only when a page of 500 FileGroups finished, so a page of
large files looked stuck; it now updates every 2 seconds. Requests refused
while syncing are answered by the middleware instead of raised, so the UI's
polling no longer logs an error each time. The primary's version is stored
without its trailing newline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A WROLPi can back up to a second drive; sync settings live in sync.yaml
The Sync tab's Backup Drive copies the media directory to a second mounted
drive with rsync during the sync window (hourly), or on "Back Up Now".
Nothing on the backup drive is deleted. The Tags and playlists directories
are left out (WROLPi rebuilds them from the configs), and the database is
written as an SQLite snapshot rather than copied as files, so the drive can be
mounted as the media directory and start. A backup is written only while the
chosen drive (by UUID) is mounted where it was chosen, and is not the media or
system drive; rsync is stopped if the drive disappears. Not in Docker, which
cannot reach other drives.
Role, primary, window and backup drive move from wrolpi.yaml to sync.yaml:
they belong to this machine, and are never copied from a primary.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The Sync tab shows the configured backup drive
getSettings copies each setting by name and did not list the backup drive,
so the Sync tab showed "None" while one was configured. It also dropped
`version`. A test now fails for any setting the API sends that getSettings
drops.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup can go to a folder on its drive, and remembers its last success
The Backup Drive panel takes a folder on the chosen drive. The drive is
checked through the folder's mount point: the folder is written only when the
drive with the saved UUID is mounted there, so a folder left on the system
drive by an unplugged drive, or on another drive mounted inside the chosen
one, is refused. A missing folder is created once the drive is checked.
When the last backup succeeded is saved in sync.yaml, so it is known after a
restart. "Stop Backup" is disabled while the database snapshot is written (it
runs to the end), and a finished backup clears the request to stop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The backup drive has its own window
The sync window was shown in the Sync panel but also scheduled the backup
drive. The Backup Drive panel now has its own window (sync.yaml
backup_window_start/end), saved with the drive; the sync window is shown,
and used, only for a secondary's sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync and the backup drive can each exclude folders
A secondary or a backup drive may be smaller than the primary's library.
Each Sync tab panel has its own excluded folders in sync.yaml, chosen in
a folder browser: a secondary browses its primary's folders (through
Caddy), the backup drive browses this WROLPi's media directory. Excluded
folders are never copied; what was copied before is kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The folder browser does not offer lost+found
Every ext4 drive has a root-only lost+found folder; a sync and a backup
never copy it, so it is not offered for exclusion.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync never writes into config or tags, whatever their case
On a media drive that ignores case (exFAT, NTFS, macOS), a manifest path
like Config/wrolpi.db is the real config folder. The protected and
unlisted top-level folders are now compared case-insensitively in the
manifest, in resolve_destination, in excluded-folder validation, and in
both folder listings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup writes the database snapshot only when the database changed
Every backup rewrote the whole database snapshot (2.5 GB on a busy
WROLPi), even on the window's idle hourly runs. The snapshot is now
skipped when the live database (its size and mtime, and those of a
non-empty WAL) and the drive's copy are both unchanged since the last
snapshot. The record is in memory, so the first backup after a restart
writes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove the unused save_sync_config switch
Nothing activated it; SyncConfig saves directly. The test server's
log_message override is called by http.server, so it goes in the
vulture baseline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 10:53:34 -07:00
|
|
|
backup_device_uuid: content.backup_device_uuid,
|
|
|
|
|
backup_directory: content.backup_directory,
|
|
|
|
|
backup_excluded_directories: content.backup_excluded_directories,
|
|
|
|
|
backup_window_end: content.backup_window_end,
|
|
|
|
|
backup_window_start: content.backup_window_start,
|
2024-10-03 13:35:06 -06:00
|
|
|
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,
|
Add a Repos module that mirrors git repositories (#783)
Repos keeps local mirrors of git repositories, cloned over https and kept up to date on a schedule.
- A Repo is a Collection (kind='repo') plus a `repository` row. The new `git` downloader clones it, then updates it
(weekly by default, or Never: the clone is kept as it is and only updated on request).
- Repos are saved in `repos/<tag>/<name>` (the Repos Directory, ignored by default) or a directory the user chooses.
An existing clone can be imported where it is. repos.yaml is the source of truth.
- A GitHub-like page shows each repo's README, files, and history, with a ZIP download. READMEs are searchable
under the global search's Other tab.
- git is hardened against hostile repos and configs: https only, pinned addresses with no private addresses (for the
repo and its submodules), sanitized configs, no hooks or links, and only clones WROLPi made or imported are
updated.
- Tagging a Repo moves its clone as one directory. Repo changes wait for repos.yaml to be imported at startup.
- The file mover groups unindexed files with no primary file as one FileGroup, and never replaces a file at the
destination. A failed tag move restores the Collection's tag. A Collection's directory cannot leave the media
directory.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 15:16:40 -06:00
|
|
|
repos_destination: content.repos_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,
|
Sync and backup: a secondary WROLPi and a backup drive copy the library (#957)
* A secondary WROLPi copies its primary's library over HTTP
A WROLPi with role "secondary" pulls from its primary: a manifest of every
FileGroup's files (/api/sync/manifest), then each missing or changed file
from the primary's Caddy /media/ (resumable, written to a hidden partial and
renamed with the primary's mtime), a refresh, then the library configs,
imported as the primary wrote them. wrolpi.yaml contributes only its library
settings. Files deleted on the primary are kept.
A secondary never saves the synced configs and never downloads. Its API
answers 503 SYNCING while a sync runs, and every page warns that it is a
copy. It syncs in a daily window or on "Sync now"; WROL Mode stops it.
On a Pi 4 (no AES instructions) the client uses TLS 1.2 ChaCha20, which
pulls ~110 MB/s from Caddy versus ~41 MB/s for rsync over ssh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync has its own /admin tab; a sync's reads from the primary are bounded
The sync settings and progress move from Settings (and the component
gallery, which is for library components) to /admin/sync.
A download never writes past the size in the primary's manifest, and configs,
listings, and manifest pages are capped. A primary address may not carry a
user name or password (it is logged and shown). While a sync runs, the API
answers only the exact requests that show its progress or stop it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync keeps the secondary's replaced configs in today's config backup
The first copy of the day is kept, like a save, so a config backup import
undoes a sync's config changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Docker's Caddy logs every request
`docker compose logs -f web` shows each request with its status, size and
duration, e.g. a secondary's /media/ downloads during a sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync reports its progress as it downloads, and refuses quietly
The status updated only when a page of 500 FileGroups finished, so a page of
large files looked stuck; it now updates every 2 seconds. Requests refused
while syncing are answered by the middleware instead of raised, so the UI's
polling no longer logs an error each time. The primary's version is stored
without its trailing newline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A WROLPi can back up to a second drive; sync settings live in sync.yaml
The Sync tab's Backup Drive copies the media directory to a second mounted
drive with rsync during the sync window (hourly), or on "Back Up Now".
Nothing on the backup drive is deleted. The Tags and playlists directories
are left out (WROLPi rebuilds them from the configs), and the database is
written as an SQLite snapshot rather than copied as files, so the drive can be
mounted as the media directory and start. A backup is written only while the
chosen drive (by UUID) is mounted where it was chosen, and is not the media or
system drive; rsync is stopped if the drive disappears. Not in Docker, which
cannot reach other drives.
Role, primary, window and backup drive move from wrolpi.yaml to sync.yaml:
they belong to this machine, and are never copied from a primary.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The Sync tab shows the configured backup drive
getSettings copies each setting by name and did not list the backup drive,
so the Sync tab showed "None" while one was configured. It also dropped
`version`. A test now fails for any setting the API sends that getSettings
drops.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup can go to a folder on its drive, and remembers its last success
The Backup Drive panel takes a folder on the chosen drive. The drive is
checked through the folder's mount point: the folder is written only when the
drive with the saved UUID is mounted there, so a folder left on the system
drive by an unplugged drive, or on another drive mounted inside the chosen
one, is refused. A missing folder is created once the drive is checked.
When the last backup succeeded is saved in sync.yaml, so it is known after a
restart. "Stop Backup" is disabled while the database snapshot is written (it
runs to the end), and a finished backup clears the request to stop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The backup drive has its own window
The sync window was shown in the Sync panel but also scheduled the backup
drive. The Backup Drive panel now has its own window (sync.yaml
backup_window_start/end), saved with the drive; the sync window is shown,
and used, only for a secondary's sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync and the backup drive can each exclude folders
A secondary or a backup drive may be smaller than the primary's library.
Each Sync tab panel has its own excluded folders in sync.yaml, chosen in
a folder browser: a secondary browses its primary's folders (through
Caddy), the backup drive browses this WROLPi's media directory. Excluded
folders are never copied; what was copied before is kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The folder browser does not offer lost+found
Every ext4 drive has a root-only lost+found folder; a sync and a backup
never copy it, so it is not offered for exclusion.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync never writes into config or tags, whatever their case
On a media drive that ignores case (exFAT, NTFS, macOS), a manifest path
like Config/wrolpi.db is the real config folder. The protected and
unlisted top-level folders are now compared case-insensitively in the
manifest, in resolve_destination, in excluded-folder validation, and in
both folder listings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup writes the database snapshot only when the database changed
Every backup rewrote the whole database snapshot (2.5 GB on a busy
WROLPi), even on the window's idle hourly runs. The snapshot is now
skipped when the live database (its size and mtime, and those of a
non-empty WAL) and the drive's copy are both unchanged since the last
snapshot. The record is in memory, so the first backup after a restart
writes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove the unused save_sync_config switch
Nothing activated it; SyncConfig saves directly. The test server's
log_message override is called by http.server, so it goes in the
vulture baseline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 10:53:34 -07:00
|
|
|
role: content.role,
|
2026-02-07 18:40:56 -07:00
|
|
|
save_ffprobe_json: content.save_ffprobe_json,
|
The Controller can make a secondary a copy of its primary with rsync (#992)
* The Controller can make a secondary a copy of its primary with rsync
The second part of replacing the sync. The Controller runs it, because the secondary's API is stopped while its
library is replaced: checks, a database snapshot on the primary, stop the API, rsync every file from the primary's
daemon (ignored directories included), fetch the snapshot and put it in the database's place, start the API, purge.
- Files the primary deleted or changed are moved to a dated folder in .sync-trash, and removed after
delete_after_days (a new sync.yaml setting, 30 by default; none never deletes), or sooner when the drive is nearly
full.
- A primary of another version or database migration, or with its media unmounted, is refused before anything is
touched. The database is replaced last, so a sync that stops earlier leaves one that works.
- On a Raspberry Pi and Debian rsync runs as the wrolpi user; in Docker in a helper container made from the api
container. A Controller that starts after an interrupted sync starts the API.
- When a secondary's API starts it takes the library settings of the primary's wrolpi.yaml, which the sync left.
Reached only through the Controller's /api/sync/run for now; the existing sync and its schedule are unchanged.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* The sync copies no link that leaves the library, and root follows none in the media directory
Security review of the Controller's sync:
- An exclusion that ends in a slash matches only a directory. A file or link named config/ssl, tags or
config/backup on the primary would have replaced this machine's directory of that name. The exclusions now match
whatever has the name.
- Links were copied as they are. One that points outside the primary's library would, on the secondary, point at
the secondary's own files, which the web server then serves. Only links that stay inside the library are copied,
and no device files.
- The Controller is root, in a media directory that belongs to another user. It no longer writes, reads, replaces
or purges through a symbolic link there.
Found on the way: the directory the Controller made for the incoming database belonged to root, so rsync, which
runs as the library's owner, could not have written into it. It now belongs to the media directory's owner.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A sync ends when its primary stops answering, and makes room before it copies
Review found:
- rsync waits forever by default. A primary that lost power or its link during a copy left the secondary's API
stopped until someone cancelled. rsync now gives up after 30 seconds without a connection and 5 minutes without
data, which ends the run and starts the API.
- The trash was only purged after a run that succeeded. The trash is what fills the drive, and a full drive fails
every run, so it never got its turn. It is now also purged before the copy.
- A value in sync.yaml that could not be used raised after the run lock was taken and before the handlers that
release it, leaving "A sync is already running" until the Controller restarted.
- The playlists directory left out of the copy was this machine's, not the primary's, whose hard links would have
arrived as full copies. The primary's wrolpi.yaml is now fetched before the copy, and both are left out.
- A primary whose media directory is elsewhere is refused: its database names every file by its full path.
- In Docker rsync is its own container, which outlives a Controller that stops. A Controller that starts after an
interrupted sync now removes it before it starts the API.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-18 20:12:20 -07:00
|
|
|
sync_delete_after_days: content.sync_delete_after_days,
|
Sync and backup: a secondary WROLPi and a backup drive copy the library (#957)
* A secondary WROLPi copies its primary's library over HTTP
A WROLPi with role "secondary" pulls from its primary: a manifest of every
FileGroup's files (/api/sync/manifest), then each missing or changed file
from the primary's Caddy /media/ (resumable, written to a hidden partial and
renamed with the primary's mtime), a refresh, then the library configs,
imported as the primary wrote them. wrolpi.yaml contributes only its library
settings. Files deleted on the primary are kept.
A secondary never saves the synced configs and never downloads. Its API
answers 503 SYNCING while a sync runs, and every page warns that it is a
copy. It syncs in a daily window or on "Sync now"; WROL Mode stops it.
On a Pi 4 (no AES instructions) the client uses TLS 1.2 ChaCha20, which
pulls ~110 MB/s from Caddy versus ~41 MB/s for rsync over ssh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync has its own /admin tab; a sync's reads from the primary are bounded
The sync settings and progress move from Settings (and the component
gallery, which is for library components) to /admin/sync.
A download never writes past the size in the primary's manifest, and configs,
listings, and manifest pages are capped. A primary address may not carry a
user name or password (it is logged and shown). While a sync runs, the API
answers only the exact requests that show its progress or stop it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync keeps the secondary's replaced configs in today's config backup
The first copy of the day is kept, like a save, so a config backup import
undoes a sync's config changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Docker's Caddy logs every request
`docker compose logs -f web` shows each request with its status, size and
duration, e.g. a secondary's /media/ downloads during a sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync reports its progress as it downloads, and refuses quietly
The status updated only when a page of 500 FileGroups finished, so a page of
large files looked stuck; it now updates every 2 seconds. Requests refused
while syncing are answered by the middleware instead of raised, so the UI's
polling no longer logs an error each time. The primary's version is stored
without its trailing newline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A WROLPi can back up to a second drive; sync settings live in sync.yaml
The Sync tab's Backup Drive copies the media directory to a second mounted
drive with rsync during the sync window (hourly), or on "Back Up Now".
Nothing on the backup drive is deleted. The Tags and playlists directories
are left out (WROLPi rebuilds them from the configs), and the database is
written as an SQLite snapshot rather than copied as files, so the drive can be
mounted as the media directory and start. A backup is written only while the
chosen drive (by UUID) is mounted where it was chosen, and is not the media or
system drive; rsync is stopped if the drive disappears. Not in Docker, which
cannot reach other drives.
Role, primary, window and backup drive move from wrolpi.yaml to sync.yaml:
they belong to this machine, and are never copied from a primary.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The Sync tab shows the configured backup drive
getSettings copies each setting by name and did not list the backup drive,
so the Sync tab showed "None" while one was configured. It also dropped
`version`. A test now fails for any setting the API sends that getSettings
drops.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup can go to a folder on its drive, and remembers its last success
The Backup Drive panel takes a folder on the chosen drive. The drive is
checked through the folder's mount point: the folder is written only when the
drive with the saved UUID is mounted there, so a folder left on the system
drive by an unplugged drive, or on another drive mounted inside the chosen
one, is refused. A missing folder is created once the drive is checked.
When the last backup succeeded is saved in sync.yaml, so it is known after a
restart. "Stop Backup" is disabled while the database snapshot is written (it
runs to the end), and a finished backup clears the request to stop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The backup drive has its own window
The sync window was shown in the Sync panel but also scheduled the backup
drive. The Backup Drive panel now has its own window (sync.yaml
backup_window_start/end), saved with the drive; the sync window is shown,
and used, only for a secondary's sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync and the backup drive can each exclude folders
A secondary or a backup drive may be smaller than the primary's library.
Each Sync tab panel has its own excluded folders in sync.yaml, chosen in
a folder browser: a secondary browses its primary's folders (through
Caddy), the backup drive browses this WROLPi's media directory. Excluded
folders are never copied; what was copied before is kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The folder browser does not offer lost+found
Every ext4 drive has a root-only lost+found folder; a sync and a backup
never copy it, so it is not offered for exclusion.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync never writes into config or tags, whatever their case
On a media drive that ignores case (exFAT, NTFS, macOS), a manifest path
like Config/wrolpi.db is the real config folder. The protected and
unlisted top-level folders are now compared case-insensitively in the
manifest, in resolve_destination, in excluded-folder validation, and in
both folder listings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup writes the database snapshot only when the database changed
Every backup rewrote the whole database snapshot (2.5 GB on a busy
WROLPi), even on the window's idle hourly runs. The snapshot is now
skipped when the live database (its size and mtime, and those of a
non-empty WAL) and the drive's copy are both unchanged since the last
snapshot. The record is in memory, so the first backup after a restart
writes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove the unused save_sync_config switch
Nothing activated it; SyncConfig saves directly. The test server's
log_message override is called by http.server, so it goes in the
vulture baseline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 10:53:34 -07:00
|
|
|
sync_excluded_directories: content.sync_excluded_directories,
|
|
|
|
|
sync_primary_url: content.sync_primary_url,
|
|
|
|
|
sync_window_end: content.sync_window_end,
|
|
|
|
|
sync_window_start: content.sync_window_start,
|
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,
|
Sync and backup: a secondary WROLPi and a backup drive copy the library (#957)
* A secondary WROLPi copies its primary's library over HTTP
A WROLPi with role "secondary" pulls from its primary: a manifest of every
FileGroup's files (/api/sync/manifest), then each missing or changed file
from the primary's Caddy /media/ (resumable, written to a hidden partial and
renamed with the primary's mtime), a refresh, then the library configs,
imported as the primary wrote them. wrolpi.yaml contributes only its library
settings. Files deleted on the primary are kept.
A secondary never saves the synced configs and never downloads. Its API
answers 503 SYNCING while a sync runs, and every page warns that it is a
copy. It syncs in a daily window or on "Sync now"; WROL Mode stops it.
On a Pi 4 (no AES instructions) the client uses TLS 1.2 ChaCha20, which
pulls ~110 MB/s from Caddy versus ~41 MB/s for rsync over ssh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync has its own /admin tab; a sync's reads from the primary are bounded
The sync settings and progress move from Settings (and the component
gallery, which is for library components) to /admin/sync.
A download never writes past the size in the primary's manifest, and configs,
listings, and manifest pages are capped. A primary address may not carry a
user name or password (it is logged and shown). While a sync runs, the API
answers only the exact requests that show its progress or stop it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync keeps the secondary's replaced configs in today's config backup
The first copy of the day is kept, like a save, so a config backup import
undoes a sync's config changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Docker's Caddy logs every request
`docker compose logs -f web` shows each request with its status, size and
duration, e.g. a secondary's /media/ downloads during a sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync reports its progress as it downloads, and refuses quietly
The status updated only when a page of 500 FileGroups finished, so a page of
large files looked stuck; it now updates every 2 seconds. Requests refused
while syncing are answered by the middleware instead of raised, so the UI's
polling no longer logs an error each time. The primary's version is stored
without its trailing newline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A WROLPi can back up to a second drive; sync settings live in sync.yaml
The Sync tab's Backup Drive copies the media directory to a second mounted
drive with rsync during the sync window (hourly), or on "Back Up Now".
Nothing on the backup drive is deleted. The Tags and playlists directories
are left out (WROLPi rebuilds them from the configs), and the database is
written as an SQLite snapshot rather than copied as files, so the drive can be
mounted as the media directory and start. A backup is written only while the
chosen drive (by UUID) is mounted where it was chosen, and is not the media or
system drive; rsync is stopped if the drive disappears. Not in Docker, which
cannot reach other drives.
Role, primary, window and backup drive move from wrolpi.yaml to sync.yaml:
they belong to this machine, and are never copied from a primary.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The Sync tab shows the configured backup drive
getSettings copies each setting by name and did not list the backup drive,
so the Sync tab showed "None" while one was configured. It also dropped
`version`. A test now fails for any setting the API sends that getSettings
drops.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup can go to a folder on its drive, and remembers its last success
The Backup Drive panel takes a folder on the chosen drive. The drive is
checked through the folder's mount point: the folder is written only when the
drive with the saved UUID is mounted there, so a folder left on the system
drive by an unplugged drive, or on another drive mounted inside the chosen
one, is refused. A missing folder is created once the drive is checked.
When the last backup succeeded is saved in sync.yaml, so it is known after a
restart. "Stop Backup" is disabled while the database snapshot is written (it
runs to the end), and a finished backup clears the request to stop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The backup drive has its own window
The sync window was shown in the Sync panel but also scheduled the backup
drive. The Backup Drive panel now has its own window (sync.yaml
backup_window_start/end), saved with the drive; the sync window is shown,
and used, only for a secondary's sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync and the backup drive can each exclude folders
A secondary or a backup drive may be smaller than the primary's library.
Each Sync tab panel has its own excluded folders in sync.yaml, chosen in
a folder browser: a secondary browses its primary's folders (through
Caddy), the backup drive browses this WROLPi's media directory. Excluded
folders are never copied; what was copied before is kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The folder browser does not offer lost+found
Every ext4 drive has a root-only lost+found folder; a sync and a backup
never copy it, so it is not offered for exclusion.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync never writes into config or tags, whatever their case
On a media drive that ignores case (exFAT, NTFS, macOS), a manifest path
like Config/wrolpi.db is the real config folder. The protected and
unlisted top-level folders are now compared case-insensitively in the
manifest, in resolve_destination, in excluded-folder validation, and in
both folder listings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup writes the database snapshot only when the database changed
Every backup rewrote the whole database snapshot (2.5 GB on a busy
WROLPi), even on the window's idle hourly runs. The snapshot is now
skipped when the live database (its size and mtime, and those of a
non-empty WAL) and the drive's copy are both unchanged since the last
snapshot. The record is in memory, so the first backup after a restart
writes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove the unused save_sync_config switch
Nothing activated it; SyncConfig saves directly. The test server's
log_message override is called by http.server, so it goes in the
vulture baseline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 10:53:34 -07:00
|
|
|
version: content.version,
|
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
|
|
|
}
|
|
|
|
|
|
Sync and backup: a secondary WROLPi and a backup drive copy the library (#957)
* A secondary WROLPi copies its primary's library over HTTP
A WROLPi with role "secondary" pulls from its primary: a manifest of every
FileGroup's files (/api/sync/manifest), then each missing or changed file
from the primary's Caddy /media/ (resumable, written to a hidden partial and
renamed with the primary's mtime), a refresh, then the library configs,
imported as the primary wrote them. wrolpi.yaml contributes only its library
settings. Files deleted on the primary are kept.
A secondary never saves the synced configs and never downloads. Its API
answers 503 SYNCING while a sync runs, and every page warns that it is a
copy. It syncs in a daily window or on "Sync now"; WROL Mode stops it.
On a Pi 4 (no AES instructions) the client uses TLS 1.2 ChaCha20, which
pulls ~110 MB/s from Caddy versus ~41 MB/s for rsync over ssh.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync has its own /admin tab; a sync's reads from the primary are bounded
The sync settings and progress move from Settings (and the component
gallery, which is for library components) to /admin/sync.
A download never writes past the size in the primary's manifest, and configs,
listings, and manifest pages are capped. A primary address may not carry a
user name or password (it is logged and shown). While a sync runs, the API
answers only the exact requests that show its progress or stop it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync keeps the secondary's replaced configs in today's config backup
The first copy of the day is kept, like a save, so a config backup import
undoes a sync's config changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Docker's Caddy logs every request
`docker compose logs -f web` shows each request with its status, size and
duration, e.g. a secondary's /media/ downloads during a sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync reports its progress as it downloads, and refuses quietly
The status updated only when a page of 500 FileGroups finished, so a page of
large files looked stuck; it now updates every 2 seconds. Requests refused
while syncing are answered by the middleware instead of raised, so the UI's
polling no longer logs an error each time. The primary's version is stored
without its trailing newline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A WROLPi can back up to a second drive; sync settings live in sync.yaml
The Sync tab's Backup Drive copies the media directory to a second mounted
drive with rsync during the sync window (hourly), or on "Back Up Now".
Nothing on the backup drive is deleted. The Tags and playlists directories
are left out (WROLPi rebuilds them from the configs), and the database is
written as an SQLite snapshot rather than copied as files, so the drive can be
mounted as the media directory and start. A backup is written only while the
chosen drive (by UUID) is mounted where it was chosen, and is not the media or
system drive; rsync is stopped if the drive disappears. Not in Docker, which
cannot reach other drives.
Role, primary, window and backup drive move from wrolpi.yaml to sync.yaml:
they belong to this machine, and are never copied from a primary.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The Sync tab shows the configured backup drive
getSettings copies each setting by name and did not list the backup drive,
so the Sync tab showed "None" while one was configured. It also dropped
`version`. A test now fails for any setting the API sends that getSettings
drops.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup can go to a folder on its drive, and remembers its last success
The Backup Drive panel takes a folder on the chosen drive. The drive is
checked through the folder's mount point: the folder is written only when the
drive with the saved UUID is mounted there, so a folder left on the system
drive by an unplugged drive, or on another drive mounted inside the chosen
one, is refused. A missing folder is created once the drive is checked.
When the last backup succeeded is saved in sync.yaml, so it is known after a
restart. "Stop Backup" is disabled while the database snapshot is written (it
runs to the end), and a finished backup clears the request to stop.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The backup drive has its own window
The sync window was shown in the Sync panel but also scheduled the backup
drive. The Backup Drive panel now has its own window (sync.yaml
backup_window_start/end), saved with the drive; the sync window is shown,
and used, only for a secondary's sync.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Sync and the backup drive can each exclude folders
A secondary or a backup drive may be smaller than the primary's library.
Each Sync tab panel has its own excluded folders in sync.yaml, chosen in
a folder browser: a secondary browses its primary's folders (through
Caddy), the backup drive browses this WROLPi's media directory. Excluded
folders are never copied; what was copied before is kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The folder browser does not offer lost+found
Every ext4 drive has a root-only lost+found folder; a sync and a backup
never copy it, so it is not offered for exclusion.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A sync never writes into config or tags, whatever their case
On a media drive that ignores case (exFAT, NTFS, macOS), a manifest path
like Config/wrolpi.db is the real config folder. The protected and
unlisted top-level folders are now compared case-insensitively in the
manifest, in resolve_destination, in excluded-folder validation, and in
both folder listings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A backup writes the database snapshot only when the database changed
Every backup rewrote the whole database snapshot (2.5 GB on a busy
WROLPi), even on the window's idle hourly runs. The snapshot is now
skipped when the live database (its size and mtime, and those of a
non-empty WAL) and the drive's copy are both unchanged since the last
snapshot. The record is in memory, so the first backup after a restart
writes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Remove the unused save_sync_config switch
Nothing activated it; SyncConfig saves directly. The test server's
log_message override is called by http.server, so it goes in the
vulture baseline.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 10:53:34 -07:00
|
|
|
// Sync: a secondary WROLPi copies its library from its primary.
|
|
|
|
|
|
|
|
|
|
export async function saveSyncSettings(settings) {
|
|
|
|
|
const response = await apiPut(`${API_URI}/sync/settings`, settings);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not save sync settings.');
|
|
|
|
|
toast({type: 'error', title: 'Saving Sync Settings Failed', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class PrimaryUnreachableError extends Error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The folders directly inside `path`; `source` is 'local' (this WROLPi) or 'primary' (its primary). */
|
|
|
|
|
export async function getSyncDirectories(path, source) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/sync/directories`, {path: path || '', source});
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const {directories} = await response.json();
|
|
|
|
|
return directories;
|
|
|
|
|
}
|
|
|
|
|
if (response.status === 502) {
|
|
|
|
|
const {error} = await response.json();
|
|
|
|
|
throw new PrimaryUnreachableError(error || 'The primary did not answer');
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not list the folders.');
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function runBackup() {
|
|
|
|
|
const response = await apiPost(`${API_URI}/sync/backup/run`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not start the backup.');
|
|
|
|
|
toast({type: 'error', title: 'Backup Failed', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function cancelBackup() {
|
|
|
|
|
return await apiPost(`${API_URI}/sync/backup/cancel`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function testSync() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/sync/test`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not reach the primary.');
|
|
|
|
|
return {ok: false, error: message};
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2026-09-26 17:47:32 -06:00
|
|
|
// Undefined, not {dates: []}, so the modal can tell a failed fetch from having no backups.
|
2026-03-09 16:11:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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'];
|
|
|
|
|
}
|
2026-09-26 17:47:32 -06:00
|
|
|
// Undefined, not [], so the modal can tell a failed fetch from having no backups.
|
2026-06-19 16:13:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-11-11 19:21:06 -07:00
|
|
|
export async function searchArchives(offset, limit, domain, searchStr, order, tagNames, headline, deep, anyTag) {
|
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;
|
|
|
|
|
}
|
2026-11-11 19:21:06 -07:00
|
|
|
if (anyTag) {
|
|
|
|
|
body['any_tag'] = 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Add a Repos module that mirrors git repositories (#783)
Repos keeps local mirrors of git repositories, cloned over https and kept up to date on a schedule.
- A Repo is a Collection (kind='repo') plus a `repository` row. The new `git` downloader clones it, then updates it
(weekly by default, or Never: the clone is kept as it is and only updated on request).
- Repos are saved in `repos/<tag>/<name>` (the Repos Directory, ignored by default) or a directory the user chooses.
An existing clone can be imported where it is. repos.yaml is the source of truth.
- A GitHub-like page shows each repo's README, files, and history, with a ZIP download. READMEs are searchable
under the global search's Other tab.
- git is hardened against hostile repos and configs: https only, pinned addresses with no private addresses (for the
repo and its submodules), sanitized configs, no hooks or links, and only clones WROLPi made or imported are
updated.
- Tagging a Repo moves its clone as one directory. Repo changes wait for repos.yaml to be imported at startup.
- The file mover groups unindexed files with no primary file as one FileGroup, and never replaces a file at the
destination. A failed tag move restores the Collection's tag. A Collection's directory cannot leave the media
directory.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 15:16:40 -06:00
|
|
|
// Tag any Collection (and optionally move its directory).
|
|
|
|
|
export async function tagCollection(collectionId, tagName, directory) {
|
|
|
|
|
const body = {tag_name: tagName};
|
|
|
|
|
if (directory) {
|
|
|
|
|
body['directory'] = directory;
|
|
|
|
|
}
|
|
|
|
|
const response = await apiPost(`${COLLECTIONS_API}/${collectionId}/tag`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Unable to tag. See server logs.');
|
|
|
|
|
toast({type: 'error', title: 'Tag Error', description: message, time: 5000});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-29 22:16:33 -06:00
|
|
|
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() {
|
2026-09-26 17:47:32 -06:00
|
|
|
// Not toasting because this will happen often. Undefined on any failure, not an empty list, so
|
|
|
|
|
// the form can say the downloaders could not be fetched.
|
2022-02-04 13:55:13 -07:00
|
|
|
try {
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiGet(`${API_URI}/downloaders`);
|
2026-09-26 17:47:32 -06:00
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
2022-02-04 13:55:13 -07:00
|
|
|
} catch (e) {
|
2026-09-26 17:47:32 -06:00
|
|
|
// The API is down; reported as undefined below.
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Resume videos and audio where the user left off; show progress on cards (#791)
* Resume videos and audio where the user left off; show progress on cards
Videos and audio resume where the user left off, on the video page and in
the file preview, and keep playing. `?t=` starts at an explicit time
instead.
useFileProgress saves how far the user is through a file: every 15 seconds
while it changes, and a final save (a beacon, which survives the page
closing) on pause, end, hiding the page, leaving it, or switching files.
Each save is also kept in sessionStorage; on open the newer of that and the
server's position wins, so coming straight back resumes exactly even if the
final save is still in flight.
Cards show a progress bar along the bottom of their poster. The dashboard's
Recently Viewed Files gains All / Continue; Continue uses the new
`in_progress` file search filter.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Progress review fixes: in_progress totals, latest dashboard request, preview viewed
- The in_progress search filter skips the uncounted fast path and is part of
the totals cache key, so Continue never reports All's (or the library's)
count.
- The dashboard's Recently Viewed hook applies only its latest response, and
clears the list when switching All/Continue until the new files arrive.
- POST /api/files/file returns `viewed`, so a preview can tell a file
finished elsewhere from an older position this tab holds.
- The progress hook tests restore Blob, fetch and sendBeacon.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 17:29:12 -06:00
|
|
|
export async function filesSearch(offset, limit, searchStr, mimetypes, model, tagNames, headline, months, fromYear, toYear, anyTag, order, suffix, path, deep, inProgress) {
|
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;
|
|
|
|
|
}
|
Resume videos and audio where the user left off; show progress on cards (#791)
* Resume videos and audio where the user left off; show progress on cards
Videos and audio resume where the user left off, on the video page and in
the file preview, and keep playing. `?t=` starts at an explicit time
instead.
useFileProgress saves how far the user is through a file: every 15 seconds
while it changes, and a final save (a beacon, which survives the page
closing) on pause, end, hiding the page, leaving it, or switching files.
Each save is also kept in sessionStorage; on open the newer of that and the
server's position wins, so coming straight back resumes exactly even if the
final save is still in flight.
Cards show a progress bar along the bottom of their poster. The dashboard's
Recently Viewed Files gains All / Continue; Continue uses the new
`in_progress` file search filter.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Progress review fixes: in_progress totals, latest dashboard request, preview viewed
- The in_progress search filter skips the uncounted fast path and is part of
the totals cache key, so Continue never reports All's (or the library's)
count.
- The dashboard's Recently Viewed hook applies only its latest response, and
clears the list when switching All/Continue until the new files arrive.
- POST /api/files/file returns `viewed`, so a preview can tell a file
finished elsewhere from an older position this tab holds.
- The progress hook tests restore Blob, fetch and sendBeacon.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 17:29:12 -06:00
|
|
|
if (inProgress) {
|
|
|
|
|
body['in_progress'] = 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});
|
2026-09-26 17:47:32 -06:00
|
|
|
// Undefined, not [null, null], so the picker can tell a failed search from finding nothing.
|
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 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'] || [];
|
|
|
|
|
}
|
2026-09-26 17:05:02 -06:00
|
|
|
// Undefined, not [], so the page can tell a failed fetch from an empty list.
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not get saved firmware configurations');
|
|
|
|
|
toast({type: 'error', title: 'Flasher Error', description: message, time: 5000});
|
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 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
|
|
|
}
|
|
|
|
|
|
The map draws any PMTiles file as an overlay, in any sub-directory (#962)
Any PMTiles file under the map directory, at any depth, can be shown. The API reads each file's header and metadata and says what it is (basemap, terrain, overlay, unreadable). Overlays are offered in the layer control under the name the file gives itself, hidden until turned on, with a checkbox per vector layer, and are drawn generically.
Map files are named by their path within the map directory everywhere, and unfinished downloads are no longer listed. A file can be ignored from the Manage page; ignored files are kept in a new maps.yaml config.
PMTiles metadata is not decompressed past its size limit, and the standalone viewer encodes map file paths.
2026-11-13 15:11:01 -07:00
|
|
|
// A map file is named by its path within the map directory; it may be in a sub-directory.
|
|
|
|
|
function encodeMapPath(mapPath) {
|
|
|
|
|
return String(mapPath).split('/').map(encodeURIComponent).join('/');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteMapFile(mapPath) {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/map/files/${encodeMapPath(mapPath)}`);
|
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});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
The map draws any PMTiles file as an overlay, in any sub-directory (#962)
Any PMTiles file under the map directory, at any depth, can be shown. The API reads each file's header and metadata and says what it is (basemap, terrain, overlay, unreadable). Overlays are offered in the layer control under the name the file gives itself, hidden until turned on, with a checkbox per vector layer, and are drawn generically.
Map files are named by their path within the map directory everywhere, and unfinished downloads are no longer listed. A file can be ignored from the Manage page; ignored files are kept in a new maps.yaml config.
PMTiles metadata is not decompressed past its size limit, and the standalone viewer encodes map file paths.
2026-11-13 15:11:01 -07:00
|
|
|
// Show a map file on the map, or ignore it.
|
|
|
|
|
export async function setMapFileVisible(mapPath, visible) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/map/files/visible`, {map_path: mapPath, visible});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not change the map file');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
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});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
A fallout simulator on the map: nuclear mode, targets, live winds aloft (#1007)
* A fallout model, checked against six Nevada tests
The local fallout of a surface burst lands where layered winds carry particles of every size
from the stabilized cloud. Cloud and particle sizes come from DNAF-1, WSEG-10 and DELFIC;
the air is the 1976 standard atmosphere. The six shots' wind profiles, measured contour
areas and plume bearings are in nts-shots.json with their sources, alongside HPAC's
predictions of the same contours.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A prototype fallout panel on the map
Right-click "Simulate Fallout Here" draws the dose rate at H+1 of one surface burst, in one
wind or in the winds aloft of one of the six Nevada tests. Nothing is saved.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fallout lands where it meets the ground
A particle stops falling at the first level where it is at or below the ground under it, not
at a plane at the height of ground zero: early on a ridge in its way, later in a valley. The
map panel reads the ground from the terrain files the user has downloaded; the Nevada tests
are checked against a small elevation grid of Mapterhorn terrain, as WROLPi publishes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fallout falls from the cloud's cap, skirt and stem
The cloud of a surface burst holds 77.5% of its activity in the cap, 15% in a skirt below it
and 7.5% in the stem (Philippe et al.); the stem starts as narrow as the early fireball at the
ground and widens up to the cap (DNAF-1). More of the fallout lands near ground zero: a 1 Mt
burst now draws a 1000 R/hr contour.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Close-in fallout measured after three Nevada surface bursts
Jangle Sugar, Small Boy and Johnie Boy, from DNAF-1's Table 3: the area, hotline length and
azimuth of each contour from 35 to 1000 R/hr, as observed and as DNAF-1, DELFIC and WSEG-10
predicted them, with each shot's winds. The deposition grid can look closely at part of the
fallout, and measures hotlines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fallout rises with the cloud, and heavy particles drop out low
All of the activity starts in the early fireball and rises with the cloud, whose base and top
climb with the square root of time (SIMFIC). Each particle rises with the air less its own
settling speed, so a heavy one leaves the cloud low and early and lands near ground zero, and a
light one rides to the top. A burst above the ground puts down less, by its scaled height.
Against the close-in fallout of Jangle Sugar and Small Boy this is within 2.4x in area and 1.7x
in hotline length (it was 100x short); across the six Nevada tests, 4.2x a priori (it was 8.9x).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel offers the weapons in service today
Weapons deployed or stockpiled by each country, each with its yield quoted from the 2025-2026
Nuclear Notebook or SIPRI Yearbook, and the improvised devices FEMA plans for; no retired or
historical weapons, and none whose yield no source gives. Variable-yield weapons have one entry
for each published setting. Fission shares are not public; they are assumed as Glasstone and
Dolan plan for, and the user may change them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel's dropdowns open above it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A variable-yield weapon is named once, with each setting's yield beside it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel uses the forecast winds aloft
WROLPi fetches, on request, Open-Meteo's hourly forecast of the wind at nineteen pressure levels
(about 100 m to 24 km) and the rain, for the whole degree around the burst: the place is rounded
before it is sent. The forecast is kept, so the panel can use it offline. The panel picks the
hour nearest now, gives the forecast's age, and warns of rain, which brings fallout down in places
the map does not show.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A nuclear mode on the map: targets, and fallout
A radiation button under the print button turns nuclear mode on and off. In it, targets (likely
detonation sites) are shown alongside the pins, a pin added is saved as a target, and fallout can
be simulated at a target or anywhere on the map. A pin's kind is kept in map_pins.yaml; a pin
without one is a plain pin, as every pin was.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Targets keep their weapon, and nuclear mode shows the fallout of all of them
A target keeps the weapon chosen for it (or a yield of the user's own) and its fission share in
map_pins.yaml. Nuclear mode opens on the fallout of every saved target at once, in the forecast
winds aloft fetched most recently; a burst tried out from the map can be saved as a target.
A whole-degree latitude or longitude, which a browser sends as an integer, is a valid pin, and a
pin's label and color may be left out of an update.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* An improvised device is named once, with each yield beside it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fallout of many targets is calculated in seconds, and shown as it goes
A particle size's settling speed is read from a table by altitude rather than solved again for
every fall of every burst (a burst: 40 ms to 6 ms). The view yields to the page only every 40 ms,
through a message channel, which a browser does not hold back in a hidden tab as it does timers;
it says how far it has got, and draws the fallout on flat ground while the terrain is read.
A target in the list shows its weapon, and is given a weapon picker when asked; one picker sets
every target's weapon.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout grid covers where fallout shows, not past the poles
The faintest particles of a burst are carried thousands of km in two days; with many targets the
grid stretched past 90 degrees and the map refused the image ("Invalid LngLat latitude"). The grid
now covers the spots which can reach the faintest band drawn, the image's corners stay within
Web Mercator's 85 degrees, and so does the area whose terrain is read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fallout across a continent is drawn where it lands
The map stretches an image evenly in Web Mercator between its corners, but the fallout grid's rows
are evenly apart in latitude; over tens of degrees (targets across a country) they part ways, and
the southern part of the image was drawn far from its targets. Each image row now takes the grid
row at its own latitude. A burst far from the first target keeps its plume as wide, east to west,
as at its own latitude.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Terrain across the antimeridian, and ground with no number, do not break the fallout
Targets in Alaska and Hawaii carry fallout west of 180 degrees, where the terrain's tile arithmetic
read past the tile's pixels; one sample with no number made every target's lowest ground NaN and
every spot fall off the map, and the grid's size Infinity. Longitudes wrap, a sample with no number
is left out (of the lowest ground, and of the elevation between samples), and a spot not on the map
is left out of the grid rather than breaking it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Every target's weapon is set in one change
Setting it target by target, eight at once, lost most of the changes: each request wrote the whole
pin list, undoing the others (QA: 47 of 156 changed). PUT /api/map/pins/targets/weapon gives
every target the weapon in one change of the config.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The every-target weapon picker starts empty and always applies
It showed the first target's weapon, so choosing that weapon for all of them did nothing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fallout is carried by the winds where it is, region by region
A field of forecasts on a grid over the targets replaces the one forecast for
all of them. Each particle rises and falls through the wind at its place,
height and hour, read between the surrounding grid points, hours and heights.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The winds aloft are fetched as a Job, ninety places a minute
The free forecast service allows 600 calls a minute and a place costs six, so
a field of up to 540 points is fetched in paced batches by a Job, which the
fallout panel follows, instead of inside one request.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A small burst's hot fallout is kept on a grid over many, and the panel says what it shows
- Each burst's narrow close-in fallout is also put on a fine grid, so the
lethal zone of a small target is not averaged away in the cells kilometers
wide of a grid over targets far apart.
- The legend says the dose rate is as at one hour, with all the fallout down,
and what R/hr is; the error quoted is the unscaled model's.
- The TNA's yield is 150 kt: its source gives only an upper bound below 300.
- Weapons show their fission share beside their yield.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout can be watched landing, hour by hour
A timeline under the legend plays, or steps through, the 48 hours after the
bursts: each hour shows only the fallout which has landed by then, at its
dose rate then (t^-1.2 from H+1), on the same cells as the whole of it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The map can show the total dose of someone outdoors, hour by hour
A "Show" picker switches from the dose rate to the total dose (R) someone
outdoors gets from when the fallout arrives: t^-1.2 added up from each spot's
arrival to the hour on the timeline, or over the first two weeks. Its bands
say what each dose does to a person.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The model is checked against the Army's fallout manuals
- FM 3-3-1's worked decay and dose problems are tests.
- FM 3-11.3's cloud and Zone I nomograms, read from their images, are a
fixture; the model's cloud top is within 10% of them from 1 kt to 10 Mt,
and its Zone I within 0.7-1.7 times from 10 kt to 1 Mt, the yields of
modern weapons, which the test shots do not reach.
- The legend says real fallout may decay faster or slower than usual.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The model is checked against two megaton bursts in the Pacific
Redwing Zuni (3.5 Mt), whose winds were measured above its cloud: the hot
fallout goes where it went and about as far. Castle Bravo (15 Mt), whose
winds were measured only below its cloud: its fallout arrives when it did,
and its hot fallout reaching a third as far is kept in view as a known gap.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Winds are read from the right points at every spacing, and cover the landing
- A field's points were filed by rounding (lat + 90) / spacing but looked up
by flooring it: at 4 and 8 degrees, which do not divide 90, every point read
half its neighbor's wind. Both now count whole spacings from the equator.
- The forecast starts at midnight UTC, so two days could end before the
fallout of a burst this hour was down; three are fetched (the same call
weight), and the panel says when the last hour's winds are held.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Bravo's known gap is not its unmeasured upper winds
Reanalysis winds above the 1954 sounding turn the plume to within 10 degrees
of the measured one but do not lengthen its hot contours; the fixture's caveat
and the test's explanation said otherwise, and now say what was found.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Rain takes fallout out of the air where it falls
A falling particle in rain loses a share of its activity every step: fast
inside the rain cloud ("rainout"), slower below it, by how hard it rains
("washout"), at Glasstone and Dolan's rates (Tables 9.74a and b), and none
above it. What is taken out comes down where the particle was. The forecast
now asks for relative humidity at 14 levels, and each hour's rain cloud is
taken as HYSPLIT takes it: from the lowest level 80% humid to the first above
it less than 60%.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* With no forecast, the fallout of 30 past days of the month
- wrolpi/scripts/build_fallout_climatology.py builds, from NOAA's reanalysis,
the winds aloft of 30 days of each month (one from each year 1991-2020) over
the whole world: a gzip file a month, about 4 MB, for the release download
location.
- WROLPi fetches the months it lacks once, while there is the Internet, each
checked against a sha256 pinned in modules/map/climatology.py (none pinned
until the files are published), and serves them to the panel.
- The panel's "Past days of a month" wind runs the bursts in each day and shows
on what share of the days each place had the chosen dose rate; it is chosen
for us when there is no forecast, or it has run out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The climatology's months are published, and their sha256 pinned
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The climatology worker waits for the Internet and the drive on startup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Counting the past days says flat ground at once, not the forecast's terrain
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Past days' fallout reuses each yield's paths, about 10 times faster
On flat ground in a day's held winds, how each parcel rises with the cloud
and falls does not depend on the wind, so it is worked out once per yield
and kept for every burst and day. The rising cloud is carried by the winds
over ground zero (it drifts about 10 km); the fall still reads the winds
where the particle is. A field of one hour is read without its hours, and
the nearest point to a cell past the field is kept.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The rising cloud reads the winds over ground zero from arrays, by level
Each parcel's rise is kept as the levels of the column it passes through
(steps in the same level as one) and their seconds, so a burst reads the
column once and sums.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel shows a progress bar while it calculates
At the top of the panel, filled as far as the bursts are done, or moving
without a count until there is one. A calculation stopped by removing the
last target no longer leaves the panel busy.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Past days' fallout runs in Web Workers, with a Cancel button
The days are spread over workers, one for each core but one (left for the
page), at most 6, and at most 2 where the browser says it has 2 GB or less.
A worker is given the next day as it finishes one, and sends back only the
cells reached. Where workers cannot be made, or fail, the days are
calculated on the page as before.
The days are counted on cells as wide as the coarsest day's grid, so the
count does not depend on which day finishes first.
Cancel, beside the progress bar, stops a calculation (and its workers) at
once; Calculate starts it again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The forecast's bursts are spread over Web Workers too
The workers now take any task: a past day, or a burst. The page and the
workers build each burst's winds and terrain with the same functions
(work.js), so the fallout is the same either way; the flat pass and the
terrain pass each run on their own workers, and Cancel stops them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The bursts' grid is made in parts by the Web Workers
The grid is a sum over the bursts' spots, sharpened by the most any burst
raises a cell, so it is made in a fixed number of parts (a burst's spots
in one) on one frame, and joined on the page. The page makes the same
parts when there are no workers, so the grid is the same either way.
The forecast's warnings (bursts outside the winds, rain) are no longer
worked out again on every progress update.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The forecast's hours are labeled once an hour, not on every progress update
Writing each hour's label (toLocaleString) took most of the page's time
while the workers calculated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Faster forecast fallout: the nearest point outside the field, progress, and what workers are sent
- Outside the forecast's field, the nearest point is looked for only
among the points which can be nearest somewhere in the grid cell (kept
for each cell); the same point as looking through them all. Longitudes
are wrapped however far round the world a particle is carried.
- The progress is shown at most ten times a second.
- The workers are sent the forecast's arrays, not the forecast as fetched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel in steps: the targets, then the fallout hour by hour or in total
Nuclear mode opens on the targets; nothing is calculated until the user goes on.
The winds and terrain wait under Options, with what is used said beside it.
The timeline runs from the first hour to two weeks, saying how much the fallout
has weakened since H+1; the view of all the fallout as if landed at H+1 is gone.
Going back and on again with nothing changed draws what was calculated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel's winds: the forecast, past days, or one wind; no test shots' winds
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel's wind is a step of its own, between the targets and the fallout
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel says it is an estimate; how it compares with the test bursts goes in the help
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Targets are tried out until saved; the saved ones are loaded first, and saved all at once
Nuclear mode starts with no targets. Targets added are tried out, and the saved
targets join them when the user loads them. Saving replaces the saved targets
with the list, in one change, and is refused until they were loaded (or there are
none), so none are lost unseen. A target can be taken out of the list. The
burst tried out from the map's menu is gone: a target tried out does the same.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Nuclear targets are kept in their own config, map_nuclear.yaml, and listed apart from the pins
The pins are plain pins again. The targets have their own endpoints, and their
own table on the Pins tab, where one can be deleted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The rest of keeping nuclear targets in map_nuclear.yaml: the config, its endpoints, and the table
The commit before this one was missing these files.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel's wind is the forecast when it has the winds until the fallout is down, else one wind
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The weather is a subscription: a forecast around the saved targets, downloaded every day
The Open-Meteo fetch is a recurring Download (daily) instead of a Job the panel
starts. The Manage tab has a Weather section: turning it on or off, what it
downloads, how its downloads went, and the forecast kept. Only the newest
forecast is kept, and it covers four days. The wind step asks the user to turn
the download on, and warns, there and beside the fallout, when the forecast runs
out before the fallout is down.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The forecast service may take three minutes to answer, and a timeout says so
A batch of four days' forecasts took 43 seconds, near the old 60-second limit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The fallout panel's targets step has an Add a target button: the next click on the map places it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 12:01:13 -07:00
|
|
|
// Which months of the fallout climatology are kept: {version, months, missing, published}, or null.
|
|
|
|
|
export async function getFalloutClimatology() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/fallout/climatology`);
|
|
|
|
|
return response.ok ? await response.json() : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// One month of the fallout climatology, as kept (gzip bytes), or null.
|
|
|
|
|
export async function getFalloutClimatologyMonth(month) {
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/fallout/climatology/${month}`);
|
|
|
|
|
return response.ok ? await response.arrayBuffer() : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The field of forecast winds aloft fetched most recently (the fallout simulator), or null.
|
|
|
|
|
export async function getLatestFalloutWinds() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/fallout/winds/latest`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json()).winds;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The saved nuclear targets ([{id, lat, lon, label, created, weapon, yield_kt?, fission_fraction?}]), or
|
|
|
|
|
// undefined when they could not be fetched.
|
|
|
|
|
export async function getMapTargets() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/nuclear/targets`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json()).targets;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteMapTarget(targetId) {
|
|
|
|
|
const response = await apiDelete(`${API_URI}/map/nuclear/targets/${targetId}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not delete the target');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
}
|
|
|
|
|
return response.ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save `targets` ([{lat, lon, label, weapon, yield_kt?, fission_fraction?, id?}]) in place of the
|
|
|
|
|
// saved targets, which are those of `loadedIds` (refused if they are not): the saved targets, or null.
|
|
|
|
|
export async function saveMapTargets(targets, loadedIds) {
|
|
|
|
|
const response = await apiPut(`${API_URI}/map/nuclear/targets`, {targets, loaded_ids: loadedIds});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not save the targets');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return (await response.json()).targets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The weather subscription (a forecast around the nuclear targets, downloaded every day): {enabled,
|
|
|
|
|
// download, targets, spacing, points, seconds, field}, or undefined when it could not be fetched.
|
|
|
|
|
export async function getWeather() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/weather`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Subscribe to the weather, or not: the subscription as it is then, or null.
|
|
|
|
|
export async function setWeatherSubscription(enabled) {
|
|
|
|
|
const response = await apiPut(`${API_URI}/map/weather`, {enabled});
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not change the weather download');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Download the weather now, rather than when it is next due: the subscription as it is then, or null.
|
|
|
|
|
export async function downloadWeatherNow() {
|
|
|
|
|
const response = await apiPost(`${API_URI}/map/weather/download`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, 'Could not download the weather');
|
|
|
|
|
toast({type: 'error', title: 'Map Error', description: message, time: 5000});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 18:58:31 -06:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
A map is exported as a PDF: a 1:24,000 quadrangle, in layers, on a sheet, which says where it is (#1006)
* The map can choose a 1:24,000 quadrangle to export (#971)
The first part of exporting a map as a PDF: a grid of 7.5-minute quadrangles is drawn over the
map, and a click chooses one. The grid is arithmetic, so it needs no data. Exporting itself is
not here yet; the button is disabled.
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* A quadrangle of the map is exported as a PDF with a layer for each map layer (#972)
* A quadrangle of the map is exported as a PDF with a layer for each map layer
The browser draws the quadrangle off the screen at the size of a 1:24,000 sheet, once for each
layer which is on, and the API puts the images in a PDF, each in a layer of its own which a
reader can show and hide. A layer in which nothing is drawn is left out.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* The exported map's canvas keeps what was drawn, and an export's memory is bounded
- The drawing buffer is asked for where this MapLibre reads it (canvasContextAttributes); as an
option of the map it was ignored, so the canvas could be read after it was cleared.
- Each layer's pixels are compressed in the PDF as the layer is added. PyMuPDF kept them
uncompressed until the PDF was written: about 90 MB a layer of a quadrangle, all at once.
- The pixels of all the layers together are limited, before any image is decoded.
- pymupdf is imported when a PDF is made, not when the API starts.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An exported map says where on the Earth it is (#973)
* An exported map says where on the Earth it is
The PDF's page has a geospatial viewport (ISO 32000-2): the page is the map in Web Mercator,
with the latitude and longitude of each corner. The corners are the edges of the picture the
browser drew, read from the map which drew it.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A map whose edge is the antimeridian can be exported
The map's arithmetic puts the east edge of the last quadrangle before the antimeridian a rounding error past
180 degrees, and the export was refused. An edge within 1e-8 of a degree of 180 is at 180 (it is not wrapped
to -180); a map which is really across the antimeridian is still refused.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An exported map is on a sheet: a margin, a grid, scale bars and notes (#974)
* An exported map is on a sheet: a margin, a grid, scale bars and notes
The map is put on a larger page with what a topographic map has around it: a title, the latitude and longitude
of its corners and of ticks between them, scale bars (kilometers, miles, feet), and notes of the projection, the
grid and where the map's data is from. Over the map is a 1,000 meter UTM grid, each line named in the margin.
The grid and the margin are PDF layers of their own. The PDF says where the map is, not where the page is. The
picker has a box to export the map alone.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* The scale of a narrow map is written under its name, not over it
A quadrangle near a pole is two inches wide, which is not room for its name and its scale on one line.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An exported map says where a compass points (#975)
* An exported map says where a compass points
The sheet has a diagram of the three norths (true, grid and magnetic) beside its scale bars, and a note of how
far magnetic north is from true north on the day the map was made, and how fast it moves.
The declination is from the World Magnetic Model 2025 (NOAA NCEI and the British Geological Survey; public
domain), whose coefficient file is shipped: nothing is downloaded. The model is good until 2030; outside its
years nothing is said of a compass.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A corner of an exported map is not also a tick
The edges of the picture the browser draws are a hair outside the quadrangle's, so the quadrangle's own edges
were taken for ticks inside the map, and each was written over the coordinate of its corner.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A compass which passes due south has moved a little, not most of the way around
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* A map can be exported at 400 DPI (#976)
The picker has a choice of 300 or 400 DPI. A map is drawn less sharp than was asked for, rather than refused,
when it would be more pixels than the API makes a PDF of: a quadrangle near the equator, or one with many layers
on. The picker says so while it draws.
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An exported quadrangle goes by the name the USGS gives it (#977)
* An exported quadrangle goes by the name the USGS gives it
The picker says what the chosen quadrangle is called, and the sheet's title, the PDF's title and the file's
name have it. Where the USGS has no name, which is most of the world, a quadrangle goes by where it is, as
before.
The names are an index of the 65,600 7.5 minute quadrangles of The National Map (U.S. Geological Survey; public
domain), which is shipped: nothing is downloaded. In Alaska a USGS quadrangle is wider than 7.5 minutes, so a
quadrangle of the picker's grid there is "Part of" the one which has its middle.
The places the tests of the map export are of are changed for others.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* An area half of which is the last quadrangle of the land is a part of it
The middle of such an area is on the quadrangle's east or north edge, with no quadrangle beyond it, and it was
given no name.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* The PDF of a map is made by a Job, which the browser watches (#978)
* The PDF of a map is made by a Job, which the browser watches
A PDF of a quadrangle is a minute or two of work on a Raspberry Pi 4, and the request which waited for it was
cut off after a minute: only the smallest quadrangles could be exported there.
Now the browser describes the map, sends the image of each layer in a request of its own, and starts a Job; it
watches the Job, shows how far along it is, and fetches the PDF when the Job is done. Cancel stops the Job.
The images are kept on disk until the PDF is made of them, and an export is removed when it is an hour old.
The credits on the sheet are no longer cut off: an attribution which names many sources is each of them.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A cancelled map export stops, and is removed
- A cancelled Job is not over until the thread making the PDF has stopped, so the next Job does not start beside
it; the work can also be stopped while the sheet is drawn and the PDF written.
- DELETE /api/map/export/<id> stops an export at any step and removes what was sent; the browser calls it when
the person exporting cancels, while layers are sent as well as while the PDF is made.
- An export whose Job is waiting or running is not removed for being old; one whose Job was cancelled is removed
at once.
- Cancel while the map is drawn stops the drawing between two layers.
- Exports are kept in a directory made for this user alone, which is refused when it is a link or is another
user's; only what is an export there is removed.
- A request for the finished PDF which is lost is made again.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An overlay's areas and lines go under the map's labels, and its own labels over them (#979)
An overlay was drawn whole over the basemap, so an area it filled covered the names of what is in it. Labels are
now always on top: the areas, lines and pictures of every overlay are under the basemap's labels, and the text,
icons and points of every overlay are over them. It is so in the map, the standalone viewer, and an exported PDF,
where an overlay with both is two layers ("Towers" and "Towers (labels)").
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An overlay's ground is over the ground of every basemap file (#980)
* An overlay's ground is over the ground of every basemap file
On a map of several basemap files, the ground of an overlay was put before the first label of the first file,
which is under the land, water and roads of every file after it: an overlay's areas and lines were hidden, and
in an exported PDF its layer was just above the background. It goes where the basemap's labels begin: the first
of the labels which are over all of the basemap's ground.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* The labels of every basemap file are over the ground of every file
A map of several basemap files was their layers one file after another, so only the labels of the last file were
on top: the labels of the others were under the land, water and roads of the files after them, and under the
ground of an overlay. Both viewers now draw the ground of every file and then the labels of every file.
The contour lines are drawn after the basemap's labels and are not of the basemap: an overlay's ground goes under
the basemap's labels, not under the contours instead.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* Contours are drawn from as deep as the terrain file goes (#981)
The map read a terrain file to zoom 8, which is how deep the terrain WROLPi offers goes, however deep the file
was. It now reads a file as deep as the file says it goes, in both viewers, and draws finer contour lines from a
deeper file: every 40 feet (or 20 meters) from zoom 11, as a 1:24,000 sheet has. A file which goes to zoom 8 is
drawn as it was.
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An exported map names its small roads (#982)
* An exported map names its small roads
A quadrangle is drawn at about zoom 13. The basemap's style names small roads
from zoom 15, and its tiles have no names for them below zoom 14, so the streets
of a town were printed as lines with no names.
Before the map is drawn, the tiles of zoom 14 which the quadrangle is in are
read, and the roads in them which have a name are given to the export map as a
source of its own. The layer which names small roads draws from that source, as
its style says to.
At the scale of a sheet most streets are shorter than their names, and a map
writes a name along a line only where the line is longer. Such a road is named
over its middle, turned as the road goes; a road in pieces is named once.
A source whose tiles can not be read is exported as before.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* The names of small roads are placed by the export, at every latitude
A quadrangle nearer the equator is drawn at a little over zoom 14, where the
names were not read and the style still kept them for zoom 15: such a map had
no names of small roads. They are now read wherever a layer would not name
roads.
Every name of a small road is now a point: over the middle of its road, turned
as the road goes under it, again every 400 pixels of a long road. Before, a
road long enough was left for the map to name along its line, which the map
often does not (the line bends, or is in pieces), and a short piece beside it
was named too. One place decides where a road is named, so a road in pieces is
named once, and a piece of another kind of road does not take the name.
Reading the names can be cancelled.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* A sheet has a bar of meters, its norths in mils, and how far apart its contour lines are (#983)
Under the map are bars of kilometers, meters, miles and feet.
How far the grid's north and a compass's north are from true north is written in
mils as well as in degrees, in the diagram and in the notes: a compass may be
marked in either.
A map which is exported with its contour lines says how far apart they are
(CONTOUR INTERVAL 40 FEET), under the bars. The browser knows: it is the
interval of the tiles the lines are made for at the zoom of the sheet, in the
unit the map measures in. It says so with the sheet, and what is not an
interval is not written.
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* A sheet says what the quadrangles around it are called (#984)
* A sheet says what the quadrangles around it are called
Under the scale bars is a diagram of nine squares, the map the middle one, and
beside it what the USGS calls each of the eight around it: the sheets to print
to carry on off the edge of this one.
The names are from the index of quadrangles which names the sheet itself. A
quadrangle with no name (out to sea, or over a border) has no number; a map of
where the USGS names nothing, and a map too narrow for the diagram, go without.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A sheet is never beside itself
Where a quadrangle of the USGS is wider than the map (Alaska), the area the
size of the map to its east or west is often more of the quadrangle the map is
in, and the diagram named the sheet as its own neighbor. The quadrangle on a
side is now the next one which is not the map's own.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* A sheet has a legend of the lines of its map (#985)
* A sheet has a legend of the lines of its map
Under the scale bars is what each kind of line of the map is: highway, major
road, minor road, path, railway, boundary, contour and index contour, each a
piece of the line as the map draws it, on the color of the map's land.
The map's style says how a line is drawn at each zoom, and a sheet is drawn at
one. The browser, which has the style, says what each line's color, width,
dashes and edges are at that zoom; the API draws them. A line is in the legend
when its layer is exported and draws something at that zoom.
What the browser sends is made into lines before it is kept: what is not a line
is left out, and the map is exported.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A legend has no line too thin to see, and no name longer than its room
A style brings a line in from nothing as the map is zoomed in: a path is a few
hundredths of a point wide on a quadrangle near the equator. It was in the
legend, drawn several times wider than on the map. A line under a tenth of a
point is now left out, by the browser and by the API.
What a line is called is cut to the room beside its line, as the name of an
adjoining quadrangle is.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* Fixes to the map PDF export: wrong neighbors, leftover exports, exports which outlive the map (#989)
* A sheet names what is around it, and its edges, by where they are and not a hair from there
The edges the browser gives of a map are a hair outside its quadrangle. The quadrangles around a map whose
middle is on the edge two share (every other map of Alaska) were those around the map west of it, and one of
them was the map itself. An edge a hair south of the equator was 0 degrees south, a map which ended where the
UTM zones do had no grid, and a sheet dated in the last year there is could not be made.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* An export is removed when it is over, and its work stops when the API does
The images and the PDF of an export were kept until the next export began, however long that was. The browser
now has the export removed however it ends, and old exports are removed when a PDF is made too. The work of a
Job which ended because the API was stopping went on to the end of the PDF, with the API waiting for it. What
is said of an export, and each image, is written whole. Text which is no text is taken out when an export
begins, not found by the Job.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* An export stops with its map, and waits for a page which can not be seen
Leaving the map while it was exported left the export going, to fail or to hand a PDF to another page; so did
closing the picker, which is now left open. A PDF which arrives after the export was stopped is not saved.
The time a page is behind another tab is not counted against a map which is drawing. The name of a road is
one line. A photograph which ends a little inside the map is not made a JPEG with a black strip. An accent
in the name of a quadrangle is not a gap in the name of its file.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A PDF is not kept from who made it by a server slow to remove the export
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An exported map has its water over its parks (#990)
* A sheet names what is around it, and its edges, by where they are and not a hair from there
The edges the browser gives of a map are a hair outside its quadrangle. The quadrangles around a map whose
middle is on the edge two share (every other map of Alaska) were those around the map west of it, and one of
them was the map itself. An edge a hair south of the equator was 0 degrees south, a map which ended where the
UTM zones do had no grid, and a sheet dated in the last year there is could not be made.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* An export is removed when it is over, and its work stops when the API does
The images and the PDF of an export were kept until the next export began, however long that was. The browser
now has the export removed however it ends, and old exports are removed when a PDF is made too. The work of a
Job which ended because the API was stopping went on to the end of the PDF, with the API waiting for it. What
is said of an export, and each image, is written whole. Text which is no text is taken out when an export
begins, not found by the Job.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* An export stops with its map, and waits for a page which can not be seen
Leaving the map while it was exported left the export going, to fail or to hand a PDF to another page; so did
closing the picker, which is now left open. A PDF which arrives after the export was stopped is not saved.
The time a page is behind another tab is not counted against a map which is drawing. The name of a road is
one line. A photograph which ends a little inside the map is not made a JPEG with a black strip. An accent
in the name of a quadrangle is not a gap in the name of its file.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* An exported map has its water over its parks
A layer of the PDF was one image, drawn where the topmost of its layers is. The parks of Land Cover are under
the water on the map and its piers are over it, so all of Land Cover was drawn over the water: a lake in a
park, or among houses, was not on the PDF. A second basemap file put its water over the first's buildings.
A layer is now as many images as it must be, each where it is on the map, in one layer of the PDF: a part
which fills an area stays where it is, and a part which is only lines is drawn with the next.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A PDF is not kept from who made it by a server slow to remove the export
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A map file which is of somewhere else is not drawn when a map is exported
Each basemap file is several images of an exported map, and most files of a library are of other places: each
was an image of nothing, counted against how many images an export may be and how sharp it may be. A file
whose own edges are outside the quadrangle is now left out before the layers are counted.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An exported map has its streams (#991)
A basemap draws streams from zoom 14, and service roads and taxiways from 13. A quadrangle is drawn a little
short of that (zoom 13.8 at 40 degrees, 13.2 at 61), from tiles which have them: none were on the PDF. What
is drawn from a zoom no deeper than a quadrangle's detail is drawn. Names are left as they are.
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An export which is cancelled stops at once, in the middle of a request (#993)
* An export which is cancelled stops at once, in the middle of a request
An export was stopped between two requests. The image of a layer is tens of megabytes, which is a long request
on a slow connection, and a request to a server which has stopped answering never ends: the export said it was
stopping until then. Cancel, and leaving the map, now end the request.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* The requests an export makes after its layers are sent are seen to be stopped too
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* A map is exported as it is printed: on white, in dark lines (#996)
* A map is exported as it is printed: on white, in dark lines
The light and dark maps are made for a screen. On paper their roads are white on pale gray and their streams
half a pixel of pale blue. The printed map is a third look, of the map's own: white ground, dark road edges
and names, blue streams wide enough to see, paths drawn, brown contours.
It is what a map is exported in unless Light or Dark is chosen where the quadrangle is, and the choice is
remembered in the browser. While a quadrangle is chosen the map is shown in the look it will be exported in.
The light and dark maps are as they were.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* Changing the look of the map does not move it
What is done when a new style is in place was asked for after the style was set. A style which only differs
from the one the map has is in place before that, so it was done at the next change of style instead, with
where the map had been at this one: the map went back there when a quadrangle was chosen, and again when it was
not. It is asked for first, and the map is not moved at all. An export no longer waits for the map to be
still, which it need not and which nothing ended.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* The colors of the printed map are chosen where its layers are (#997)
* The colors of the printed map are chosen where its layers are
While a quadrangle is chosen and the map is shown as it is printed, each layer of the layer control has its
color beside it, to be changed: one for most, three for the land (what grows, what was built, sand and ice)
and two for names (the name, and what is around it). A basemap has several colors where one is chosen, which
are shades of it. The edge of a road stays dark. What is chosen is remembered in the browser, and can be put
back. The map on the screen is as it was.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A ramp on a bridge is the color of a major road, as it is off one
A basemap draws a ramp on a bridge in the color of a minor road on a bridge: on the printed map it was white
where the rest of the ramp is yellow, and followed the color chosen for minor roads. What puts the colors
back is a button, which a keyboard reaches.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* A layer with nothing in it does not make an exported map less sharp (#1001)
* A layer with nothing in it does not make an exported map less sharp
How sharp a map may be depends on how many images it is, and every group of layers was counted: a basemap
file with no runway, highway or boundary in the quadrangle was images of nothing, drawn, sent, and counted
against the rest. A map of 23 images asked for at 400 DPI was made at 330. The groups are now looked at
first, on a small map, and only those with something in them are drawn, as sharp as that many may be.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* An image which arrives after its export was removed is not kept, and one mil is a mil
Stopping an export while an image was on its way left the image behind it, in a directory nothing would
remove for an hour. An angle of one mil was "1 mils" on the sheet.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* The map which is exported from is made as sharp as it is to be (#1002)
* The map which is exported from is made as sharp as it is to be
The groups of a map are looked at on a small map, which was then made larger to draw them. A browser lets
a canvas be larger when it is made than it lets one be made larger afterwards: a quadrangle asked for at
400 DPI was 33 million pixels, 288 DPI at 40 degrees, less than before the groups were looked at first. The
small map is now removed, and the map which is exported from is made in its place.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* A canvas the browser stopped drawing on is not a layer with nothing in it
A canvas whose drawing was taken away by the browser reads as clear, and a group looked at then was left out
of the PDF without a word: the export fails instead. An export stopped as the last group is looked at does
not make the map it would have been drawn on.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* An exported map says where it is in a projection Adobe Acrobat knows (#1003)
* An exported map says where it is in a projection Adobe Acrobat knows
The page was said to be in Web Mercator, which it is drawn in. Acrobat does not know Web Mercator, in the
words of the standard or in Esri's: it took the page for a map, and put every place on it at 0, 0. The page
is now said to be Mercator on the WGS 84 ellipsoid, which it reads, with the same corners. Between the corners
the two differ by under three centimeters on the ground.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
* How well a page is said to be where it is, is measured from what the PDF says
The test of it measured two formulas of its own. It now reads the corners and the projection from the PDF and
does a reader's sum with them. The few centimeters are of a quadrangle: a taller page is less well said, by
the square of how tall it is, which the comment now says and a test measures.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
* The help says how a map is exported as a PDF (#1004)
The help of the map is five pages, one of them the PDF export.
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-20 17:22:21 -07:00
|
|
|
// Make a PDF of a map from the images of its layers ({name, blob}, from the bottom up). Returns the
|
|
|
|
|
// PDF (a Blob); throws an Error which says what went wrong.
|
|
|
|
|
// `bounds` is the west, south, east and north edges of the images, in degrees.
|
|
|
|
|
// What exportMapPdf throws when the person exporting stopped it: not a failure to be told of.
|
|
|
|
|
export class ExportCancelled extends Error {
|
|
|
|
|
constructor() {
|
|
|
|
|
super('The export was cancelled');
|
|
|
|
|
this.name = 'ExportCancelled';
|
|
|
|
|
this.cancelled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// How many times in a row the server may not answer, while the PDF of an export is made or fetched,
|
|
|
|
|
// before the export is given up on: the API is busy while it makes a PDF, and a Raspberry Pi more so.
|
|
|
|
|
const EXPORT_POLL_FAILURES = 10;
|
|
|
|
|
|
|
|
|
|
// Make the PDF of a map from the images of its layers (see modules/map/export_job.py). The PDF is a
|
|
|
|
|
// minute or two of work on a Raspberry Pi, so it is a Job: the map is described, the image of each
|
|
|
|
|
// layer is sent, the Job is started and watched, and the PDF is fetched when the Job is done.
|
|
|
|
|
//
|
|
|
|
|
// onStatus(text): told how far along it is. isCancelled(): asked, between steps, whether to stop;
|
|
|
|
|
// signal: an AbortSignal which stops it at once, in the middle of a request (an image of a layer
|
|
|
|
|
// is tens of megabytes, and a request to a server which has stopped answering never ends);
|
|
|
|
|
// the server is then told to stop the export and remove what was sent. Rejects with
|
|
|
|
|
// ExportCancelled when it was stopped.
|
|
|
|
|
//
|
|
|
|
|
// However it ends, the server is told to remove what it has of the export: the images are a hundred
|
|
|
|
|
// megabytes and the PDF tens, on a disk which may be an SD card.
|
|
|
|
|
export async function exportMapPdf(
|
|
|
|
|
{width, height, dpi, title, bounds, layers, sheet},
|
|
|
|
|
{onStatus = () => undefined, isCancelled = () => false, signal = undefined, pollMs = 1000} = {},
|
|
|
|
|
) {
|
|
|
|
|
const exports = `${API_URI}/map/export`;
|
|
|
|
|
let exportId = null;
|
|
|
|
|
// Best effort: the server removes old exports itself, later. An export which is stopped while
|
|
|
|
|
// it is being described has no id yet to remove it by: what the server made of it is one small
|
|
|
|
|
// file, which it removes with the old ones.
|
|
|
|
|
const remove = async () => {
|
|
|
|
|
if (exportId) await fetch(`${exports}/${exportId}`, {method: 'DELETE'}).catch(() => undefined);
|
|
|
|
|
};
|
|
|
|
|
try {
|
|
|
|
|
return await sendAndFetch();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// A request which was stopped because the export was is not a failure to be told of.
|
|
|
|
|
throw signal?.aborted ? new ExportCancelled() : e;
|
|
|
|
|
} finally {
|
|
|
|
|
// Not waited for: a server which is slow to answer is not to keep a PDF from who made it.
|
|
|
|
|
remove();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function sendAndFetch() {
|
|
|
|
|
const send = async (url, init, fallback) => {
|
|
|
|
|
let response;
|
|
|
|
|
try {
|
|
|
|
|
response = await fetch(url, {...init, signal});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
throw new Error('Could not reach the server');
|
|
|
|
|
}
|
|
|
|
|
if (!response.ok) throw new Error(await getErrorMessage(response, fallback));
|
|
|
|
|
return response;
|
|
|
|
|
};
|
|
|
|
|
const pause = () => new Promise(resolve => setTimeout(resolve, pollMs));
|
|
|
|
|
// Stopped by the person exporting: removing the export cancels its Job.
|
|
|
|
|
const stopIfCancelled = async () => {
|
|
|
|
|
if (isCancelled() || signal?.aborted) throw new ExportCancelled();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await stopIfCancelled();
|
|
|
|
|
onStatus('Sending the map…');
|
|
|
|
|
const created = await send(exports, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
|
body: JSON.stringify({width, height, dpi, title, bounds, sheet, layers: layers.map(i => i.name)}),
|
|
|
|
|
}, 'Could not export the map');
|
|
|
|
|
exportId = (await created.json()).export_id;
|
|
|
|
|
|
|
|
|
|
// One layer a request: together they are more than a request may be, and more than a slow
|
|
|
|
|
// connection sends in the time a request is given.
|
|
|
|
|
for (const [index, layer] of layers.entries()) {
|
|
|
|
|
await stopIfCancelled();
|
|
|
|
|
onStatus(`Sending ${layer.name} (${index + 1} of ${layers.length})…`);
|
|
|
|
|
await send(`${exports}/${exportId}/layer/${index}`, {method: 'POST', body: layer.blob},
|
|
|
|
|
`Could not send ${layer.name}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await stopIfCancelled();
|
|
|
|
|
const started = await send(`${exports}/${exportId}/start`, {method: 'POST'}, 'Could not make the PDF');
|
|
|
|
|
const {job_id: jobId} = await started.json();
|
|
|
|
|
|
|
|
|
|
let failures = 0;
|
|
|
|
|
let waited = 0;
|
|
|
|
|
while (true) {
|
|
|
|
|
await stopIfCancelled();
|
|
|
|
|
let job;
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_URI}/jobs/${jobId}`, {signal});
|
|
|
|
|
if (response.status === 404) throw Object.assign(new Error('The server forgot the export'), {final: true});
|
|
|
|
|
if (!response.ok) throw new Error('Could not ask how the PDF is coming');
|
|
|
|
|
job = (await response.json()).job;
|
|
|
|
|
failures = 0;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e.final || ++failures >= EXPORT_POLL_FAILURES) {
|
|
|
|
|
throw e.final ? e : new Error('Could not reach the server');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (job?.status === 'complete') break;
|
|
|
|
|
if (job?.status === 'failed') throw new Error(job.error || 'The PDF could not be made');
|
|
|
|
|
if (job?.status === 'cancelled') throw new ExportCancelled();
|
|
|
|
|
if (job?.status === 'pending') {
|
|
|
|
|
// A Job is taken up within a moment, unless another (a video being transcoded) is in its way.
|
|
|
|
|
onStatus(++waited > 3 ? 'Waiting for another job to finish…' : 'Starting the PDF…');
|
|
|
|
|
} else if (job) {
|
|
|
|
|
onStatus(`Making the PDF (${Math.round(job.progress || 0)}%)…`);
|
|
|
|
|
}
|
|
|
|
|
await pause();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The PDF is made, and kept for an hour. A request which is lost now is asked again: not to be
|
|
|
|
|
// the reason all of it is done again.
|
|
|
|
|
onStatus('Fetching the PDF…');
|
|
|
|
|
for (failures = 0; ; ) {
|
|
|
|
|
await stopIfCancelled();
|
|
|
|
|
let response;
|
|
|
|
|
try {
|
|
|
|
|
response = await fetch(`${exports}/${exportId}/pdf`, {signal});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
response = null;
|
|
|
|
|
}
|
|
|
|
|
if (response?.ok) return await response.blob();
|
|
|
|
|
// What the server refuses, it will refuse again.
|
|
|
|
|
if (response && response.status < 500) {
|
|
|
|
|
throw new Error(await getErrorMessage(response, 'Could not fetch the PDF'));
|
|
|
|
|
}
|
|
|
|
|
if (++failures >= EXPORT_POLL_FAILURES) throw new Error('Could not fetch the PDF');
|
|
|
|
|
await pause();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// What the USGS calls a quadrangle: {name, state, exact}, or null where it has no name (most of the
|
|
|
|
|
// world), and when it can not be asked. A map is exported without its name as well as with it.
|
|
|
|
|
export async function getMapQuadName({west, south, east, north}) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await apiGet(
|
|
|
|
|
`${API_URI}/map/quad?west=${west}&south=${south}&east=${east}&north=${north}`);
|
|
|
|
|
if (!response.ok) return null;
|
|
|
|
|
return (await response.json()).quad || null;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2026-09-26 17:47:32 -06:00
|
|
|
// Undefined, not {results: []}, so a failed search is not shown as finding nothing.
|
|
|
|
|
return undefined;
|
2026-04-11 20:09:30 -06:00
|
|
|
}
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getMapSearchStatus() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/map/search/status`);
|
|
|
|
|
if (!response.ok) {
|
2026-09-26 17:47:32 -06:00
|
|
|
// Undefined, not {indexed: [], missing: []}, which read as "no maps are installed".
|
|
|
|
|
return undefined;
|
2026-04-11 20:09:30 -06:00
|
|
|
}
|
|
|
|
|
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};
|
|
|
|
|
}
|
|
|
|
|
|
The map draws any PMTiles file as an overlay, in any sub-directory (#962)
Any PMTiles file under the map directory, at any depth, can be shown. The API reads each file's header and metadata and says what it is (basemap, terrain, overlay, unreadable). Overlays are offered in the layer control under the name the file gives itself, hidden until turned on, with a checkbox per vector layer, and are drawn generically.
Map files are named by their path within the map directory everywhere, and unfinished downloads are no longer listed. A file can be ignored from the Manage page; ignored files are kept in a new maps.yaml config.
PMTiles metadata is not decompressed past its size limit, and the standalone viewer encodes map file paths.
2026-11-13 15:11:01 -07:00
|
|
|
export async function rebuildMapSearchIndex(mapPath) {
|
|
|
|
|
const response = await apiPost(`${API_URI}/map/search/rebuild/${encodeMapPath(mapPath)}`);
|
2026-04-11 20:09:30 -06:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
A directory rename is finished by the file worker, not the request (#950)
* A directory rename is finished by the file worker, not the request
A directory rename queued a move, waited for it, then removed the old
directory and updated nested Collections itself. A rename that outlasted
Sanic's RESPONSE_TIMEOUT (60 s) was cancelled while waiting: the move still
finished, but the old directory and its emptied subdirectories were left
behind, nested Collections kept their old directories, and the browser was
told the rename failed.
The move job now finishes the rename (nested Collections, then removing the
old directory, empty directories only), and the request returns once the
move is queued. A failure is reported by the job's event. An empty
directory can be renamed (it raised before). The worker status carries
`rename_from`, so the Files page progress bar labels the rename, and the
file browser fetches again when the file worker is done.
A directory rename no longer queues a refresh of its parent: the file
worker runs the newest task first, so it scanned the directory before the
rename.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A queued rename returns its job, and the file browser waits for it
Review fixes:
- The cancellation test patched `wait_for_job`, which this path no longer
calls, so it cancelled nothing. It now asserts the invariant: the
request only queues the rename (it never waits, and nothing has moved
when it returns), and the file worker alone finishes it.
- The file browser inferred the end of a rename from the file worker's
polled status. A short job can start and finish between two polls, and
the first idle poll (before the job started) spent the "fetch once"
token, so the table could keep the old name. POST /api/files/rename now
returns `{"job_id": ...}` (null when the rename is already done), GET
/api/files/jobs/<job_id> reports pending/complete/failed, and the file
browser polls that job before fetching.
- useBrowseFiles ignores a fetch that settles after a newer one, so a
listing requested before a rename cannot replace the one after it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 13:09:33 -07:00
|
|
|
/**
|
|
|
|
|
* Returns the file worker job id of a queued rename (a directory), or null when the rename is already done.
|
|
|
|
|
*/
|
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});
|
A directory rename is finished by the file worker, not the request (#950)
* A directory rename is finished by the file worker, not the request
A directory rename queued a move, waited for it, then removed the old
directory and updated nested Collections itself. A rename that outlasted
Sanic's RESPONSE_TIMEOUT (60 s) was cancelled while waiting: the move still
finished, but the old directory and its emptied subdirectories were left
behind, nested Collections kept their old directories, and the browser was
told the rename failed.
The move job now finishes the rename (nested Collections, then removing the
old directory, empty directories only), and the request returns once the
move is queued. A failure is reported by the job's event. An empty
directory can be renamed (it raised before). The worker status carries
`rename_from`, so the Files page progress bar labels the rename, and the
file browser fetches again when the file worker is done.
A directory rename no longer queues a refresh of its parent: the file
worker runs the newest task first, so it scanned the directory before the
rename.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A queued rename returns its job, and the file browser waits for it
Review fixes:
- The cancellation test patched `wait_for_job`, which this path no longer
calls, so it cancelled nothing. It now asserts the invariant: the
request only queues the rename (it never waits, and nothing has moved
when it returns), and the file worker alone finishes it.
- The file browser inferred the end of a rename from the file worker's
polled status. A short job can start and finish between two polls, and
the first idle poll (before the job started) spent the "fetch once"
token, so the table could keep the old name. POST /api/files/rename now
returns `{"job_id": ...}` (null when the rename is already done), GET
/api/files/jobs/<job_id> reports pending/complete/failed, and the file
browser polls that job before fetching.
- useBrowseFiles ignores a fetch that settles after a newer one, so a
listing requested before a rename cannot replace the one after it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 13:09:33 -07:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
const json = await response.json();
|
|
|
|
|
return json['job_id'] || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a file worker job's status ('pending', 'complete', or 'failed'), or null if it is unknown.
|
|
|
|
|
*/
|
|
|
|
|
export async function fetchFileWorkerJobStatus(jobId) {
|
|
|
|
|
const response = await apiGet(`${API_URI}/files/jobs/${encodeURIComponent(jobId)}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
return null;
|
2023-05-29 18:04:03 -06:00
|
|
|
}
|
A directory rename is finished by the file worker, not the request (#950)
* A directory rename is finished by the file worker, not the request
A directory rename queued a move, waited for it, then removed the old
directory and updated nested Collections itself. A rename that outlasted
Sanic's RESPONSE_TIMEOUT (60 s) was cancelled while waiting: the move still
finished, but the old directory and its emptied subdirectories were left
behind, nested Collections kept their old directories, and the browser was
told the rename failed.
The move job now finishes the rename (nested Collections, then removing the
old directory, empty directories only), and the request returns once the
move is queued. A failure is reported by the job's event. An empty
directory can be renamed (it raised before). The worker status carries
`rename_from`, so the Files page progress bar labels the rename, and the
file browser fetches again when the file worker is done.
A directory rename no longer queues a refresh of its parent: the file
worker runs the newest task first, so it scanned the directory before the
rename.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* A queued rename returns its job, and the file browser waits for it
Review fixes:
- The cancellation test patched `wait_for_job`, which this path no longer
calls, so it cancelled nothing. It now asserts the invariant: the
request only queues the rename (it never waits, and nothing has moved
when it returns), and the file worker alone finishes it.
- The file browser inferred the end of a rename from the file worker's
polled status. A short job can start and finish between two polls, and
the first idle poll (before the job started) spent the "fetch once"
token, so the table could keep the old name. POST /api/files/rename now
returns `{"job_id": ...}` (null when the rename is already done), GET
/api/files/jobs/<job_id> reports pending/complete/failed, and the file
browser polls that job before fetching.
- useBrowseFiles ignores a fetch that settles after a newer one, so a
listing requested before a rename cannot replace the one after it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 13:09:33 -07:00
|
|
|
const json = await response.json();
|
|
|
|
|
return json['status'];
|
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 || [],
|
Add a Repos module that mirrors git repositories (#783)
Repos keeps local mirrors of git repositories, cloned over https and kept up to date on a schedule.
- A Repo is a Collection (kind='repo') plus a `repository` row. The new `git` downloader clones it, then updates it
(weekly by default, or Never: the clone is kept as it is and only updated on request).
- Repos are saved in `repos/<tag>/<name>` (the Repos Directory, ignored by default) or a directory the user chooses.
An existing clone can be imported where it is. repos.yaml is the source of truth.
- A GitHub-like page shows each repo's README, files, and history, with a ZIP download. READMEs are searchable
under the global search's Other tab.
- git is hardened against hostile repos and configs: https only, pinned addresses with no private addresses (for the
repo and its submodules), sanitized configs, no hooks or links, and only clones WROLPi made or imported are
updated.
- Tagging a Repo moves its clone as one directory. Repo changes wait for repos.yaml to be imported at startup.
- The file mover groups unindexed files with no primary file as one FileGroup, and never replaces a file at the
destination. A failed tag move restores the Collection's tag. A Collection's directory cannot leave the media
directory.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 15:16:40 -06:00
|
|
|
repos: content.repos || [],
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Add a Repos module that mirrors git repositories (#783)
Repos keeps local mirrors of git repositories, cloned over https and kept up to date on a schedule.
- A Repo is a Collection (kind='repo') plus a `repository` row. The new `git` downloader clones it, then updates it
(weekly by default, or Never: the clone is kept as it is and only updated on request).
- Repos are saved in `repos/<tag>/<name>` (the Repos Directory, ignored by default) or a directory the user chooses.
An existing clone can be imported where it is. repos.yaml is the source of truth.
- A GitHub-like page shows each repo's README, files, and history, with a ZIP download. READMEs are searchable
under the global search's Other tab.
- git is hardened against hostile repos and configs: https only, pinned addresses with no private addresses (for the
repo and its submodules), sanitized configs, no hooks or links, and only clones WROLPi made or imported are
updated.
- Tagging a Repo moves its clone as one directory. Repo changes wait for repos.yaml to be imported at startup.
- The file mover groups unindexed files with no primary file as one FileGroup, and never replaces a file at the
destination. A failed tag move restores the Collection's tag. A Collection's directory cannot leave the media
directory.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 15:16:40 -06:00
|
|
|
export async function searchEstimateOthers(tagNames, searchStr) {
|
|
|
|
|
const body = {tag_names: tagNames, search_str: searchStr || null};
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/search_other_estimates`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
others: content.others,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-07 18:22:05 -06:00
|
|
|
export async function searchChannels(tagNames, searchStr) {
|
|
|
|
|
const body = {tag_names: tagNames, search_str: searchStr};
|
2024-08-15 19:32:01 -06:00
|
|
|
const response = await apiPost(`${API_URI}/videos/channels/search`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return {
|
|
|
|
|
channels: content.channels,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-07 18:22:05 -06:00
|
|
|
// Collections of `kind` whose name matches `searchStr` and/or which have any of the tags.
|
|
|
|
|
export async function searchCollections(kind, tagNames, searchStr) {
|
|
|
|
|
const body = {kind, tag_names: tagNames, search_str: searchStr};
|
|
|
|
|
const response = await apiPost(`${COLLECTIONS_API}/search`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return {collections: content.collections};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-08 08:48:58 -07:00
|
|
|
// `branch` upgrades from that branch; without it the current branch is upgraded.
|
|
|
|
|
export async function triggerUpgrade(branch = null) {
|
|
|
|
|
const body = branch ? {branch} : undefined;
|
|
|
|
|
const response = await apiPost(`${API_URI}/upgrade/start`, body);
|
2025-10-29 22:16:33 -06:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-11-11 19:21:06 -07:00
|
|
|
export async function searchDocs(offset, limit, searchStr, order, tagNames, author, subject, mimetype, deep, anyTag) {
|
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-11-11 19:21:06 -07:00
|
|
|
if (anyTag) {
|
|
|
|
|
body['any_tag'] = 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);
|
|
|
|
|
}
|
Bookmarks: a nav menu of user links, stored in bookmarks.yaml (#729)
* bookmarks: user bookmarks in the navigation bar, stored in bookmarks.yaml
A "Bookmarks" tab between Calculators and Flasher opens on hover or click and
lists the user's bookmarks, with directories as flyout submenus (Menu.Sub).
The mobile hamburger shows directories as labelled groups instead. The tab
always shows, with an "Edit bookmarks" item, so the feature can be found
before any bookmark exists.
Bookmarks live in a new config-only bookmarks.yaml: a nested tree where a
node with `children` is a directory and a node with `url` is a bookmark.
Every node carries an integer id so the API can rename, move and delete
without relying on names. A URL may be a path on this WROLPi, a port on this
host (`:8096/` or `http://:8096/`, resolved against whatever hostname the
browser used, so it works over LAN IP, mDNS and the hotspot alike), or an
absolute URL. Each bookmark chooses whether to open in a new tab.
The editor at /more/bookmarks follows the playlist items table: numbered rows,
up/down/edit/delete, and inline "Add a bookmark" / "Add a directory" forms
with a Location picker. Deleting a directory asks first, since its contents
go with it. The menu and the editor are in the component gallery.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* bookmarks: mark More current when the editor is folded inside it; rem indents in the mobile menu
Found on the QA Pi at a width where Bookmarks overflows into More: the More
button carried no mark on /more/bookmarks, because the bookmarks link has no
`to` for isLinkActive to match. isLinkActive now knows the bookmarks link owns
its editor page, and the Bookmarks tab uses the same rule.
The mobile menu's directory labels sat a few pixels left of the labels around
them: the indent was in em, and a Menu.Label is set smaller than a Menu.Item.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* bookmarks: parse URLs instead of matching a prefix; validate the whole tree on every write
The URL contract was checked by prefix on both sides, and a prefix is not a
form: `//evil.com` starts like a path and `:8096@evil.com` starts like a port,
and a browser takes both off this host. A path is now a single leading slash
that resolves to this origin, a port form is an optional scheme, `:`, digits
and then only a path, query or fragment (no `@`, no backslash, no control
characters), and anything else must parse as http(s). The same rules live in
wrolpi/bookmarks.py and BookmarksContext.js, with the same bypass strings in
both test suites.
The config's dataclass validator only saw that `bookmarks` was a list, so a
hand-edited file or the generic config API could store a `javascript:` URL
that the bookmarks API would refuse, and the nav rendered it. The config now
validates the tree itself on every write and import: URL forms, exactly one of
url/children, unique integer ids, boolean new_tab, and no cycles (a YAML
anchor can build one). An invalid file is not imported and, since it was never
successfully imported, is never overwritten.
On the page, a stored URL that does not resolve is rendered as text, never as
an href. A refused add keeps what was typed instead of clearing the form, and
an edit whose move is refused still refreshes the nav (the rename was
committed) and keeps the modal open. An IPv6 host is bracketed before a port.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* help: document Bookmarks
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-26 13:11:24 -06:00
|
|
|
|
|
|
|
|
// Bookmarks: a tree of nodes, a node with `children` being a directory.
|
|
|
|
|
export async function getBookmarks() {
|
|
|
|
|
const response = await apiGet(`${API_URI}/bookmarks`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['bookmarks'];
|
|
|
|
|
}
|
|
|
|
|
throw new Error('Could not fetch bookmarks');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function bookmarksModify(request, fallbackMessage) {
|
|
|
|
|
const response = await request;
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return response.status === 204 ? null : await response.json();
|
|
|
|
|
}
|
|
|
|
|
const message = await getErrorMessage(response, fallbackMessage);
|
|
|
|
|
toast({type: 'error', title: 'Bookmarks Error', description: message, time: 5000});
|
|
|
|
|
throw new Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addBookmark({name, url, new_tab = false, parent_id = null, position = null}) {
|
|
|
|
|
const body = {name, url, new_tab, parent_id, position};
|
|
|
|
|
return await bookmarksModify(apiPost(`${API_URI}/bookmarks`, body), 'Could not add bookmark');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function addBookmarkDirectory({name, parent_id = null, position = null}) {
|
|
|
|
|
const body = {name, parent_id, position};
|
|
|
|
|
return await bookmarksModify(apiPost(`${API_URI}/bookmarks/directory`, body), 'Could not add directory');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateBookmark(nodeId, {name, url, new_tab}) {
|
|
|
|
|
const body = {name, url, new_tab};
|
|
|
|
|
return await bookmarksModify(apiPut(`${API_URI}/bookmarks/${nodeId}`, body), 'Could not update bookmark');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function moveBookmark(nodeId, parent_id, position = null) {
|
|
|
|
|
const body = {parent_id, position};
|
|
|
|
|
return await bookmarksModify(apiPost(`${API_URI}/bookmarks/${nodeId}/move`, body), 'Could not move bookmark');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteBookmark(nodeId) {
|
|
|
|
|
return await bookmarksModify(apiDelete(`${API_URI}/bookmarks/${nodeId}`), 'Could not delete bookmark');
|
|
|
|
|
}
|
Add a Repos module that mirrors git repositories (#783)
Repos keeps local mirrors of git repositories, cloned over https and kept up to date on a schedule.
- A Repo is a Collection (kind='repo') plus a `repository` row. The new `git` downloader clones it, then updates it
(weekly by default, or Never: the clone is kept as it is and only updated on request).
- Repos are saved in `repos/<tag>/<name>` (the Repos Directory, ignored by default) or a directory the user chooses.
An existing clone can be imported where it is. repos.yaml is the source of truth.
- A GitHub-like page shows each repo's README, files, and history, with a ZIP download. READMEs are searchable
under the global search's Other tab.
- git is hardened against hostile repos and configs: https only, pinned addresses with no private addresses (for the
repo and its submodules), sanitized configs, no hooks or links, and only clones WROLPi made or imported are
updated.
- Tagging a Repo moves its clone as one directory. Repo changes wait for repos.yaml to be imported at startup.
- The file mover groups unindexed files with no primary file as one FileGroup, and never replaces a file at the
destination. A failed tag move restores the Collection's tag. A Collection's directory cannot leave the media
directory.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 15:16:40 -06:00
|
|
|
|
|
|
|
|
async function reposError(response, fallbackMessage) {
|
|
|
|
|
const message = await getErrorMessage(response, fallbackMessage);
|
|
|
|
|
toast({type: 'error', title: 'Repos Error', description: message, time: 5000});
|
|
|
|
|
throw Error(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchRepos() {
|
|
|
|
|
const response = await apiGet(REPOS_API);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['repos'];
|
|
|
|
|
}
|
|
|
|
|
await reposError(response, 'Failed to fetch repos.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getRepo(repoId) {
|
|
|
|
|
const response = await apiGet(`${REPOS_API}/${repoId}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['repo'];
|
|
|
|
|
}
|
|
|
|
|
await reposError(response, 'Failed to fetch repo.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// `repo`: {url, directory?, name?, tag_name?, frequency?, mode?, branch?, description?}
|
|
|
|
|
export async function createRepo(repo) {
|
|
|
|
|
const response = await apiPost(REPOS_API, repo);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['repo'];
|
|
|
|
|
}
|
|
|
|
|
await reposError(response, 'Failed to add repo.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// `changes`: {description?, frequency?, mode?, branch?}. An empty branch follows the remote's default branch.
|
|
|
|
|
export async function updateRepo(repoId, changes) {
|
|
|
|
|
const response = await apiPut(`${REPOS_API}/${repoId}`, changes);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['repo'];
|
|
|
|
|
}
|
|
|
|
|
await reposError(response, 'Failed to update repo.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteRepo(repoId, deleteFiles = false) {
|
|
|
|
|
const response = await apiDelete(`${REPOS_API}/${repoId}?delete_files=${deleteFiles ? 'true' : 'false'}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
await reposError(response, 'Failed to delete repo.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Download the repo's updates now.
|
|
|
|
|
export async function updateRepoNow(repoId) {
|
|
|
|
|
const response = await apiPost(`${REPOS_API}/${repoId}/update`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
await reposError(response, 'Failed to start the repo update.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// One directory of a repo's files: {path, entries: [{name, path, is_dir, size}], readme_path}.
|
|
|
|
|
export async function getRepoTree(repoId, path) {
|
|
|
|
|
const query = path ? `?path=${encodeURIComponent(path)}` : '';
|
|
|
|
|
const response = await apiGet(`${REPOS_API}/${repoId}/tree${query}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
await reposError(response, 'Failed to list the repo files.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Repos matching the search (name and README) and/or the tags. Each has an escaped `readme_headline`.
|
|
|
|
|
export async function searchRepos(searchStr, tagNames) {
|
|
|
|
|
const body = {search_str: searchStr || null, tag_names: tagNames || []};
|
|
|
|
|
const response = await apiPost(`${REPOS_API}/search`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const content = await response.json();
|
|
|
|
|
return {repos: content.repos, total: content.totals.repos};
|
|
|
|
|
}
|
|
|
|
|
await reposError(response, 'Failed to search repos.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The commits of a repo's checked out branch, newest first: {commits: [{sha, author, date, message}], total}.
|
|
|
|
|
export async function getRepoLog(repoId, offset = 0, limit = 50) {
|
|
|
|
|
const response = await apiGet(`${REPOS_API}/${repoId}/log?limit=${limit}&offset=${offset}`);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return await response.json();
|
|
|
|
|
}
|
|
|
|
|
await reposError(response, 'Failed to fetch the repo history.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A ZIP of a repo's checked out files; the browser downloads it.
|
|
|
|
|
export function repoArchiveURL(repoId) {
|
|
|
|
|
return `${REPOS_API}/${repoId}/archive.zip`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// What importing the git clone in `directory` (relative to the media directory) would do. Changes nothing.
|
|
|
|
|
export async function inspectRepoImport(directory, name, tagName, url) {
|
|
|
|
|
const body = {directory, name: name || null, tag_name: tagName || null, url: url || null};
|
|
|
|
|
const response = await apiPost(`${REPOS_API}/import/inspect`, body);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return {inspection: (await response.json())['inspection']};
|
|
|
|
|
}
|
|
|
|
|
return {error: await getErrorMessage(response, 'Cannot import this directory.')};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Import an existing git clone as a Repo; it stays where it is. `repo`: {directory, confirm, url?, name?, ...}
|
|
|
|
|
export async function importRepo(repo) {
|
|
|
|
|
const response = await apiPost(`${REPOS_API}/import`, repo);
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
return (await response.json())['repo'];
|
|
|
|
|
}
|
|
|
|
|
await reposError(response, 'Failed to import the repo.');
|
|
|
|
|
}
|