mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-27 09:46:07 -04:00
fix: export every prompt and model from the workspace, not only the page on screen (#30187)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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}`);
|
||||
|
||||
@@ -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`);
|
||||
|
||||
Reference in New Issue
Block a user