uploaded file path
This commit is contained in:
+11
-1
@@ -79,8 +79,18 @@ export const adminApi = {
|
|||||||
apiFetch('/api/auth/password', { method: 'PUT', body: JSON.stringify({ currentPassword, newPassword }) }),
|
apiFetch('/api/auth/password', { method: 'PUT', body: JSON.stringify({ currentPassword, newPassword }) }),
|
||||||
|
|
||||||
upload: async (file) => {
|
upload: async (file) => {
|
||||||
|
// Try Node API first; fall back to local data URL when server is unavailable.
|
||||||
|
try {
|
||||||
const form = new FormData();
|
const form = new FormData();
|
||||||
form.append('file', file);
|
form.append('file', file);
|
||||||
return apiFetch('/api/upload', { method: 'POST', body: form });
|
return await apiFetch('/api/upload', { method: 'POST', body: form });
|
||||||
|
} catch {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = () => resolve({ url: reader.result, filename: file.name });
|
||||||
|
reader.onerror = () => reject(new Error('Failed to read file'));
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user