Models like Archive/Video/Doc can be deleted, even if they are tagged. User is shown a warning and must confirm deletion of tagged files.

This commit is contained in:
Roland 2026-05-03 17:28:06 -06:00 • committed by lrnselfreliance
parent 513ae52a6e
commit 09a967535b
23 changed files with 689 additions and 109 deletions

View file

@ -247,7 +247,7 @@ export async function getVideoCaptions(fileGroupId) {
}
}
export async function deleteVideos(fileGroupIds) {
export async function deleteVideos(fileGroupIds, force = false) {
if (!fileGroupIds || fileGroupIds.length === 0) {
toast({
type: 'error',
@ -258,17 +258,27 @@ export async function deleteVideos(fileGroupIds) {
}
console.info(`Deleting Videos: ${fileGroupIds}`);
const i = fileGroupIds.join(',');
const response = await apiDelete(`${VIDEOS_API}/${i}`);
if (response.status !== 204) {
const message = await getErrorMessage(response, 'Failed to delete videos.');
toast({
type: 'error',
title: 'Deleting Videos failed',
description: message,
time: 5000,
});
throw Error(message);
const url = force ? `${VIDEOS_API}/${i}?force=true` : `${VIDEOS_API}/${i}`;
const response = await apiDelete(url);
if (response.ok) {
return response;
}
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.
}
const message = await getErrorMessage(response, 'Failed to delete videos.');
toast({
type: 'error',
title: 'Deleting Videos failed',
description: message,
time: 5000,
});
throw Error(message);
}
export async function downloadVideoMetadata(videoUrl) {
@ -741,7 +751,7 @@ export async function deleteItems(itemIds) {
return response
}
export async function deleteArchives(archiveIds) {
export async function deleteArchives(archiveIds, force = false) {
if (!archiveIds || archiveIds.length === 0) {
toast({
type: 'error',
@ -752,15 +762,24 @@ export async function deleteArchives(archiveIds) {
}
console.log(`Deleting Archives: ${archiveIds}`);
let i = archiveIds.join(',');
const response = await apiDelete(`${ARCHIVES_API}/${i}`);
if (!response.ok) {
const message = await getErrorMessage(response, 'Failed to delete archives');
toast({
type: 'error', title: 'Unexpected server response', description: message, time: 5000,
});
throw Error('Failed to delete archives');
const url = force ? `${ARCHIVES_API}/${i}?force=true` : `${ARCHIVES_API}/${i}`;
const response = await apiDelete(url);
if (response.ok) {
return response;
}
return response
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.
}
const message = await getErrorMessage(response, 'Failed to delete archives');
toast({
type: 'error', title: 'Unexpected server response', description: message, time: 5000,
});
throw Error('Failed to delete archives');
}
export async function searchArchives(offset, limit, domain, searchStr, order, tagNames, headline) {
@ -2234,9 +2253,29 @@ export async function getDoc(fileGroupId) {
return await apiGet(`${DOCS_API}/${fileGroupId}`);
}
export async function deleteDocs(docIds) {
export async function deleteDocs(docIds, force = false) {
const ids = Array.isArray(docIds) ? docIds.join(',') : docIds;
return await apiDelete(`${DOCS_API}/${ids}`);
const url = force ? `${DOCS_API}/${ids}?force=true` : `${DOCS_API}/${ids}`;
const response = await apiDelete(url);
if (response.ok) {
return response;
}
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.
}
const message = await getErrorMessage(response, 'Failed to delete documents.');
toast({
type: 'error',
title: 'Deleting Documents failed',
description: message,
time: 5000,
});
throw Error(message);
}
export async function searchDocs(offset, limit, searchStr, order, tagNames, author, subject, mimetype) {