Fix Stuffbox popup completion and preflight storage before file selection

Hop-State: A_06FP87Y83XVM00YY2RB0X2G
Hop-Proposal: R_06FP87XN1TX5B0CW1ZFDEK8
Hop-Task: T_06FP86NZGXSMEX63FZDAS70
Hop-Attempt: AT_06FP86NZGYZEGPH937G3WK8
This commit is contained in:
2026-07-14 21:53:52 -07:00
committed by Hop
parent 270d5437f0
commit 67b96d6725
9 changed files with 224 additions and 70 deletions
+16 -8
View File
@@ -28,10 +28,23 @@ interface JsonResponse extends Record<string, unknown> {
provider?: string | null;
}
export type StorageProvider = 'stuffbox' | 's3' | null;
async function json(response: Response): Promise<JsonResponse> {
return response.json().catch(() => ({})) as Promise<JsonResponse>;
}
export async function getStorageProvider(): Promise<StorageProvider> {
const response = await fetch('/api/storage/configuration', { cache: 'no-store' });
const configuration = await json(response);
if (!response.ok) {
throw new MediaUploadError(configuration.error || 'Unable to load storage configuration', undefined, response.status);
}
return configuration.provider === 'stuffbox' || configuration.provider === 's3'
? configuration.provider
: null;
}
function directPut(
uploadUrl: string,
file: File,
@@ -105,13 +118,8 @@ export async function uploadMediaFile(
file: File,
onProgress?: (progress: number) => void,
): Promise<UploadedMedia> {
const configurationResponse = await fetch('/api/storage/configuration', { cache: 'no-store' });
const configuration = await json(configurationResponse);
if (!configurationResponse.ok) {
throw new MediaUploadError(configuration.error || 'Unable to load storage configuration', undefined, configurationResponse.status);
}
if (configuration.provider === 'stuffbox') return uploadToStuffbox(file, onProgress);
if (configuration.provider === 's3') return uploadToS3(file);
const provider = await getStorageProvider();
if (provider === 'stuffbox') return uploadToStuffbox(file, onProgress);
if (provider === 's3') return uploadToS3(file);
throw new MediaUploadError('Connect media storage before uploading.', 'STORAGE_NOT_CONFIGURED', 409);
}