feat(media): support local and s3 upload providers
This commit is contained in:
@@ -2,7 +2,7 @@ import { hasPermission } from "@cms/content/rbac"
|
||||
import { createMediaAsset } from "@cms/db"
|
||||
|
||||
import { auth, resolveRoleFromAuthSession } from "@/lib/auth/server"
|
||||
import { storeUploadLocally } from "@/lib/media/local-storage"
|
||||
import { storeUpload } from "@/lib/media/storage"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
@@ -147,7 +147,7 @@ export async function POST(request: Request): Promise<Response> {
|
||||
}
|
||||
|
||||
try {
|
||||
const stored = await storeUploadLocally({
|
||||
const stored = await storeUpload({
|
||||
file: fileEntry,
|
||||
mediaType: type,
|
||||
})
|
||||
@@ -170,14 +170,17 @@ export async function POST(request: Request): Promise<Response> {
|
||||
return Response.json(
|
||||
{
|
||||
id: created.id,
|
||||
provider: stored.provider,
|
||||
notice: "Media uploaded successfully.",
|
||||
},
|
||||
{ status: 201 },
|
||||
)
|
||||
} catch {
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Upload failed. Please try again."
|
||||
|
||||
return Response.json(
|
||||
{
|
||||
message: "Upload failed. Please try again.",
|
||||
message,
|
||||
},
|
||||
{ status: 500 },
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ import { getMediaFoundationSummary, listMediaAssets } from "@cms/db"
|
||||
|
||||
import { AdminShell } from "@/components/admin-shell"
|
||||
import { MediaUploadForm } from "@/components/media/media-upload-form"
|
||||
import { resolveMediaStorageProvider } from "@/lib/media/storage"
|
||||
import { requirePermissionForRoute } from "@/lib/route-guards"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
@@ -33,6 +34,7 @@ export default async function MediaManagementPage({
|
||||
])
|
||||
const notice = readFirstValue(resolvedSearchParams.notice)
|
||||
const error = readFirstValue(resolvedSearchParams.error)
|
||||
const activeStorageProvider = resolveMediaStorageProvider(process.env.CMS_MEDIA_STORAGE_PROVIDER)
|
||||
|
||||
return (
|
||||
<AdminShell
|
||||
@@ -78,8 +80,8 @@ export default async function MediaManagementPage({
|
||||
<section className="rounded-xl border border-neutral-200 p-6">
|
||||
<h2 className="text-xl font-medium">Upload Media Asset</h2>
|
||||
<p className="mt-1 text-sm text-neutral-600">
|
||||
Files are currently stored via local adapter. S3/object storage is the next incremental
|
||||
step.
|
||||
Upload storage provider: <strong>{activeStorageProvider}</strong>. You can switch via
|
||||
`CMS_MEDIA_STORAGE_PROVIDER` (`local` or `s3`) until the admin settings toggle lands.
|
||||
</p>
|
||||
<MediaUploadForm />
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user