mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 20:59:56 -05:00
repos: add the Repos UI
* Repos table (CollectionTable), New Repo and Edit pages (frequency, mode, branch, description, tag, delete with an optional "also delete its files"). * A GitHub-like repo page: upstream, branch, latest commit, a status message when not yet downloaded or the last update failed, the file tree (directories through ?path=, files in the file preview), and each directory's README. * Global search: a Repos section under Other with escaped README headlines, Repos in the suggestions, and the search text sent to the Other estimate. * Settings: the Repos Directory field. * CollectionTable columns may `render` their cell. * Theme gallery: the repo summary, tree, and status icons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5506dc0a88
commit
0d1a988fa6
17 changed files with 1362 additions and 33 deletions
|
|
@ -7,6 +7,7 @@ import {
|
|||
COLLECTIONS_API,
|
||||
DEFAULT_LIMIT,
|
||||
Downloaders,
|
||||
REPOS_API,
|
||||
VIDEOS_API,
|
||||
ZIM_API
|
||||
} from "./components/Vars";
|
||||
|
|
@ -406,6 +407,7 @@ export async function getSettings() {
|
|||
nav_color: content.nav_color,
|
||||
media_directory: content.media_directory,
|
||||
playlists_destination: content.playlists_destination,
|
||||
repos_destination: content.repos_destination,
|
||||
require_cookies_unlocked: content.require_cookies_unlocked,
|
||||
require_media_mounted: content.require_media_mounted,
|
||||
save_ffprobe_json: content.save_ffprobe_json,
|
||||
|
|
@ -927,6 +929,21 @@ export async function getCollectionTagInfo(collectionId, tagName) {
|
|||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
export async function tagDomain(domainId, tagName, directory) {
|
||||
const body = {
|
||||
tag_name: tagName,
|
||||
|
|
@ -2051,6 +2068,7 @@ export async function searchSuggestions(search_str) {
|
|||
domains: content.domains,
|
||||
authors: content.authors || [],
|
||||
subjects: content.subjects || [],
|
||||
repos: content.repos || [],
|
||||
}
|
||||
} else {
|
||||
console.error('Failed to get file search suggestions!');
|
||||
|
|
@ -2089,8 +2107,8 @@ export async function searchEstimateZims(search_str, tagNames) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function searchEstimateOthers(tagNames) {
|
||||
const body = {tag_names: tagNames};
|
||||
export async function searchEstimateOthers(tagNames, searchStr) {
|
||||
const body = {tag_names: tagNames, search_str: searchStr || null};
|
||||
const response = await apiPost(`${API_URI}/search_other_estimates`, body);
|
||||
if (response.ok) {
|
||||
const content = await response.json();
|
||||
|
|
@ -2488,3 +2506,79 @@ export async function moveBookmark(nodeId, parent_id, position = null) {
|
|||
export async function deleteBookmark(nodeId) {
|
||||
return await bookmarksModify(apiDelete(`${API_URI}/bookmarks/${nodeId}`), 'Could not delete bookmark');
|
||||
}
|
||||
|
||||
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, 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.');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue