27 lines
687 B
TypeScript
27 lines
687 B
TypeScript
export async function uploadMissionFile({
|
|
missionId,
|
|
file,
|
|
type, // 'logo' or 'attachment'
|
|
}: {
|
|
missionId: string;
|
|
file: File;
|
|
type: 'logo' | 'attachment';
|
|
}): Promise<{ success: boolean; data?: any; error?: string }> {
|
|
const formData = new FormData();
|
|
formData.append('missionId', missionId);
|
|
formData.append('type', type);
|
|
formData.append('file', file);
|
|
|
|
const res = await fetch('/api/missions/upload', {
|
|
method: 'POST',
|
|
body: formData,
|
|
});
|
|
|
|
if (!res.ok) {
|
|
const err = await res.json().catch(() => ({}));
|
|
return { success: false, error: err.error || 'Upload failed' };
|
|
}
|
|
|
|
const data = await res.json();
|
|
return { success: true, data };
|
|
}
|