Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89f0d6a546 | ||
|
|
8bc9460989 |
44
ui/src/lib/paraglide/messages/admin_nav_import.js
Normal file
44
ui/src/lib/paraglide/messages/admin_nav_import.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/* eslint-disable */
|
||||
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
||||
|
||||
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
||||
|
||||
/** @typedef {{}} Admin_Nav_ImportInputs */
|
||||
|
||||
const en_admin_nav_import = /** @type {(inputs: Admin_Nav_ImportInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Import`)
|
||||
};
|
||||
|
||||
const ru_admin_nav_import = /** @type {(inputs: Admin_Nav_ImportInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Import`)
|
||||
};
|
||||
|
||||
const id_admin_nav_import = /** @type {(inputs: Admin_Nav_ImportInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Import`)
|
||||
};
|
||||
|
||||
const pt_admin_nav_import = /** @type {(inputs: Admin_Nav_ImportInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Import`)
|
||||
};
|
||||
|
||||
const fr_admin_nav_import = /** @type {(inputs: Admin_Nav_ImportInputs) => LocalizedString} */ () => {
|
||||
return /** @type {LocalizedString} */ (`Import`)
|
||||
};
|
||||
|
||||
/**
|
||||
* | output |
|
||||
* | --- |
|
||||
* | "Import" |
|
||||
*
|
||||
* @param {Admin_Nav_ImportInputs} inputs
|
||||
* @param {{ locale?: "en" | "ru" | "id" | "pt" | "fr" }} options
|
||||
* @returns {LocalizedString}
|
||||
*/
|
||||
export const admin_nav_import = /** @type {((inputs?: Admin_Nav_ImportInputs, options?: { locale?: "en" | "ru" | "id" | "pt" | "fr" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Admin_Nav_ImportInputs, { locale?: "en" | "ru" | "id" | "pt" | "fr" }, {}>} */ ((inputs = {}, options = {}) => {
|
||||
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
||||
if (locale === "en") return en_admin_nav_import(inputs)
|
||||
if (locale === "ru") return ru_admin_nav_import(inputs)
|
||||
if (locale === "id") return id_admin_nav_import(inputs)
|
||||
if (locale === "pt") return pt_admin_nav_import(inputs)
|
||||
return fr_admin_nav_import(inputs)
|
||||
});
|
||||
@@ -17,22 +17,41 @@ export const GET: RequestHandler = async ({ locals }) => {
|
||||
|
||||
/**
|
||||
* POST /api/admin/import
|
||||
* Create a new import task.
|
||||
* Create a new import task. Supports both multipart/form-data (file upload)
|
||||
* and application/json (object key reference).
|
||||
*/
|
||||
export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
if (!locals.user || locals.user.role !== 'admin') {
|
||||
throw error(403, 'Forbidden');
|
||||
}
|
||||
const body = await request.json();
|
||||
const res = await backendFetch('/api/admin/import', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
|
||||
const ct = request.headers.get('content-type') ?? '';
|
||||
|
||||
let res: Response;
|
||||
|
||||
if (ct.includes('multipart/form-data')) {
|
||||
// Forward the raw FormData body; let the browser-set Content-Type
|
||||
// (which includes the boundary) pass through unchanged.
|
||||
const formData = await request.formData();
|
||||
res = await backendFetch('/api/admin/import', {
|
||||
method: 'POST',
|
||||
// Do NOT set Content-Type manually — the fetch API sets it
|
||||
// automatically with the correct boundary when given a FormData body.
|
||||
body: formData
|
||||
});
|
||||
} else {
|
||||
const body = await request.json();
|
||||
res = await backendFetch('/api/admin/import', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
const err = await res.json().catch(() => ({ error: 'Failed to create import task' }));
|
||||
throw error(res.status, err.error || 'Failed to create import task');
|
||||
}
|
||||
const data = await res.json();
|
||||
return json(data);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user