fix: export every prompt and model from the workspace, not only the page on screen (#30187)

This commit is contained in:
G30
2026-09-19 10:03:17 -05:00
committed by GitHub
parent 9e293a58ea
commit 621ed6de7f
3 changed files with 17 additions and 9 deletions
+4 -4
View File
@@ -1,10 +1,10 @@
import { WEBUI_API_BASE_URL } from '$lib/constants';
export const exportModels = async (token: string, ids: string[]) => {
export const exportModels = async (token: string, ids?: string[]) => {
const query = new URLSearchParams();
ids.forEach((id) => query.append('ids', id));
if (!ids.length) return [];
const response = await fetch(`${WEBUI_API_BASE_URL}/models/export?${query}`, {
(ids ?? []).forEach((id) => query.append('ids', id));
if (ids && !ids.length) return [];
const response = await fetch(`${WEBUI_API_BASE_URL}/models/export${ids ? `?${query}` : ''}`, {
headers: { authorization: `Bearer ${token}` }
});
if (!response.ok) throw await response.json();
+3 -3
View File
@@ -114,7 +114,7 @@
id: 'models-export',
label: $i18n.t('Export JSON'),
onClick: async () => {
await downloadModels(models);
await downloadModels();
},
visible: $user?.role === 'admin' || $user?.permissions?.workspace?.models_export
}
@@ -283,11 +283,11 @@
}
};
const downloadModels = async (models) => {
const downloadModels = async (models = null) => {
try {
models = await exportModels(
localStorage.token,
models.map((model: { id: string }) => model.id)
models ? models.map((model: { id: string }) => model.id) : undefined
);
} catch (error: any) {
toast.error(`${error?.detail ?? error}`);
+10 -2
View File
@@ -19,7 +19,8 @@
deletePromptById,
togglePromptById,
getPromptItems,
getPromptTags
getPromptTags,
getPrompts
} from '$lib/apis/prompts';
import { capitalizeFirstLetter, slugify, copyToClipboard } from '$lib/utils';
@@ -108,7 +109,14 @@
id: 'prompts-export',
label: $i18n.t('Export JSON'),
onClick: async () => {
let blob = new Blob([JSON.stringify(prompts)], {
const _prompts = await getPrompts(localStorage.token).catch((error) => {
toast.error(`${error}`);
return null;
});
if (!_prompts) {
return;
}
let blob = new Blob([JSON.stringify(_prompts)], {
type: 'application/json'
});
saveAs(blob, `prompts-export-${Date.now()}.json`);