Simplify storage configuration text
This commit is contained in:
parent
ce7aa26542
commit
3ea54b2a21
@ -7,7 +7,7 @@ import {
|
||||
cloudflareR2Client,
|
||||
cloudflareR2PutObjectCommandForKey,
|
||||
} from '@/services/storage/cloudflare-r2';
|
||||
import { STORAGE_PREFERENCE } from '@/site/config';
|
||||
import { CURRENT_STORAGE } from '@/site/config';
|
||||
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
||||
|
||||
export const runtime = 'edge';
|
||||
@ -19,10 +19,10 @@ export async function GET(
|
||||
const session = await auth();
|
||||
if (session?.user && key) {
|
||||
const url = await getSignedUrl(
|
||||
STORAGE_PREFERENCE === 'cloudflare-r2'
|
||||
CURRENT_STORAGE === 'cloudflare-r2'
|
||||
? cloudflareR2Client()
|
||||
: awsS3Client(),
|
||||
STORAGE_PREFERENCE === 'cloudflare-r2'
|
||||
CURRENT_STORAGE === 'cloudflare-r2'
|
||||
? cloudflareR2PutObjectCommandForKey(key)
|
||||
: awsS3PutObjectCommandForKey(key),
|
||||
{ expiresIn: 3600 }
|
||||
|
||||
@ -13,7 +13,7 @@ import {
|
||||
isUrlFromAwsS3,
|
||||
} from './aws-s3';
|
||||
import {
|
||||
STORAGE_PREFERENCE,
|
||||
CURRENT_STORAGE,
|
||||
HAS_AWS_S3_STORAGE,
|
||||
HAS_VERCEL_BLOB_STORAGE,
|
||||
HAS_CLOUDFLARE_R2_STORAGE,
|
||||
@ -111,15 +111,15 @@ export const uploadFromClientViaPresignedUrl = async (
|
||||
.then((response) => response.text());
|
||||
|
||||
return fetch(url, { method: 'PUT', body: file })
|
||||
.then(() => `${baseUrlForStorage(STORAGE_PREFERENCE)}/${key}`);
|
||||
.then(() => `${baseUrlForStorage(CURRENT_STORAGE)}/${key}`);
|
||||
};
|
||||
|
||||
export const uploadPhotoFromClient = async (
|
||||
file: File | Blob,
|
||||
extension = 'jpg',
|
||||
) => (
|
||||
STORAGE_PREFERENCE === 'cloudflare-r2' ||
|
||||
STORAGE_PREFERENCE === 'aws-s3'
|
||||
CURRENT_STORAGE === 'cloudflare-r2' ||
|
||||
CURRENT_STORAGE === 'aws-s3'
|
||||
)
|
||||
? uploadFromClientViaPresignedUrl(file, PREFIX_UPLOAD, extension, true)
|
||||
: vercelBlobUploadFromClient(file, `${PREFIX_UPLOAD}.${extension}`);
|
||||
|
||||
@ -27,7 +27,8 @@ export default function SiteChecklistClient({
|
||||
hasVercelBlobStorage,
|
||||
hasCloudflareR2Storage,
|
||||
hasAwsS3Storage,
|
||||
storagePreference,
|
||||
hasMultipleStorageProviders,
|
||||
currentStorage,
|
||||
hasAuth,
|
||||
hasAdminUser,
|
||||
hasTitle,
|
||||
@ -142,10 +143,11 @@ export default function SiteChecklistClient({
|
||||
and connect to project
|
||||
</ChecklistRow>
|
||||
<ChecklistRow
|
||||
title={hasStorage
|
||||
// eslint-disable-next-line max-len
|
||||
? `Setup storage (preferred: ${labelForStorage(storagePreference)})`
|
||||
: 'Setup storage (one of the following)'}
|
||||
title={!hasStorage
|
||||
? 'Setup storage (one of the following)'
|
||||
: hasMultipleStorageProviders
|
||||
? `Setup storage (current: ${labelForStorage(currentStorage)})`
|
||||
: 'Setup storage'}
|
||||
status={hasStorage}
|
||||
isPending={isPendingPage}
|
||||
>
|
||||
|
||||
@ -56,9 +56,15 @@ export const HAS_AWS_S3_STORAGE =
|
||||
(process.env.AWS_S3_ACCESS_KEY ?? '').length > 0 &&
|
||||
(process.env.AWS_S3_SECRET_ACCESS_KEY ?? '').length > 0;
|
||||
|
||||
// Storage preference relies on client-only keys
|
||||
// so that it's available in the browser when uploading
|
||||
export const STORAGE_PREFERENCE: StorageType =
|
||||
export const HAS_MULTIPLE_STORAGE_PROVIDERS = [
|
||||
HAS_VERCEL_BLOB_STORAGE,
|
||||
HAS_CLOUDFLARE_R2_STORAGE,
|
||||
HAS_AWS_S3_STORAGE,
|
||||
].filter(Boolean).length > 1;
|
||||
|
||||
// Storage preference requires client-available keys
|
||||
// so it can be reached in the browser when uploading
|
||||
export const CURRENT_STORAGE: StorageType =
|
||||
(process.env.NEXT_PUBLIC_STORAGE_PREFERENCE as StorageType | undefined) || (
|
||||
HAS_CLOUDFLARE_R2_STORAGE_CLIENT
|
||||
? 'cloudflare-r2'
|
||||
@ -94,7 +100,8 @@ export const CONFIG_CHECKLIST_STATUS = {
|
||||
HAS_VERCEL_BLOB_STORAGE ||
|
||||
HAS_CLOUDFLARE_R2_STORAGE ||
|
||||
HAS_AWS_S3_STORAGE,
|
||||
storagePreference: STORAGE_PREFERENCE,
|
||||
hasMultipleStorageProviders: HAS_MULTIPLE_STORAGE_PROVIDERS,
|
||||
currentStorage: CURRENT_STORAGE,
|
||||
hasAuth: (process.env.AUTH_SECRET ?? '').length > 0,
|
||||
hasAdminUser: (
|
||||
(process.env.ADMIN_EMAIL ?? '').length > 0 &&
|
||||
|
||||
Loading…
Reference in New Issue
Block a user