mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-18 21:47:39 +02:00
* Added user options to backup module; Fixed HTTP 500 bug
This commit is contained in:
@@ -1149,9 +1149,31 @@ export const api = {
|
||||
}),
|
||||
resetSettings: () =>
|
||||
request<AppSettings>('/settings/reset', { method: 'POST' }),
|
||||
exportBackup: async () => {
|
||||
const response = await fetch(`${API_BASE}/settings/backup`);
|
||||
return response.json();
|
||||
exportBackup: async (categories?: Record<string, boolean>): Promise<{ blob: Blob; filename: string }> => {
|
||||
const params = new URLSearchParams();
|
||||
if (categories) {
|
||||
if (categories.settings !== undefined) params.set('include_settings', String(categories.settings));
|
||||
if (categories.notifications !== undefined) params.set('include_notifications', String(categories.notifications));
|
||||
if (categories.templates !== undefined) params.set('include_templates', String(categories.templates));
|
||||
if (categories.smart_plugs !== undefined) params.set('include_smart_plugs', String(categories.smart_plugs));
|
||||
if (categories.printers !== undefined) params.set('include_printers', String(categories.printers));
|
||||
if (categories.filaments !== undefined) params.set('include_filaments', String(categories.filaments));
|
||||
if (categories.maintenance !== undefined) params.set('include_maintenance', String(categories.maintenance));
|
||||
if (categories.archives !== undefined) params.set('include_archives', String(categories.archives));
|
||||
}
|
||||
const url = `${API_BASE}/settings/backup${params.toString() ? '?' + params.toString() : ''}`;
|
||||
const response = await fetch(url);
|
||||
|
||||
// Get filename from Content-Disposition header
|
||||
const contentDisposition = response.headers.get('Content-Disposition');
|
||||
let filename = 'bambusy-backup.json';
|
||||
if (contentDisposition) {
|
||||
const match = contentDisposition.match(/filename=([^;]+)/);
|
||||
if (match) filename = match[1].trim();
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
return { blob, filename };
|
||||
},
|
||||
importBackup: async (file: File) => {
|
||||
const formData = new FormData();
|
||||
|
||||
Reference in New Issue
Block a user