Add Vercel deploy support alongside Coolify
Storage now picks Vercel Blob when a store is connected (BLOB_STORE_ID or BLOB_READ_WRITE_TOKEN), falling back to local disk for self-hosted runs. Adds vercel.json cron schedule for the existing cron routes (ig-publisher capped to once/day on Hobby plan). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { putLocalBlob } from "@/lib/storage/local-blob";
|
||||
import { putBlob } from "@/lib/storage/blob";
|
||||
import { requirePageAction } from "@/lib/auth/user";
|
||||
import { errorResponse } from "@/lib/http";
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function POST(req: Request) {
|
||||
try {
|
||||
const ext = file.type === "image/png" ? "png" : "jpg";
|
||||
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || new URL(req.url).origin;
|
||||
const blob = await putLocalBlob(`posts/${pageId}/image.${ext}`, file, { contentType: file.type }, baseUrl);
|
||||
const blob = await putBlob(`posts/${pageId}/image.${ext}`, file, { contentType: file.type }, baseUrl);
|
||||
return NextResponse.json({ url: blob.url });
|
||||
} catch (e) {
|
||||
return errorResponse(e, "upload");
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { putLocalBlob } from "./local-blob";
|
||||
|
||||
/**
|
||||
* Picks the storage driver by env: Vercel Blob when a store is connected
|
||||
* (`BLOB_STORE_ID` from OIDC-mode `vercel storage connect`, or a static
|
||||
* `BLOB_READ_WRITE_TOKEN`), local disk otherwise (Coolify self-host, see
|
||||
* local-blob.ts).
|
||||
*/
|
||||
export async function putBlob(
|
||||
key: string,
|
||||
file: File,
|
||||
opts: { contentType: string },
|
||||
baseUrl: string
|
||||
): Promise<{ url: string }> {
|
||||
if (process.env.BLOB_STORE_ID || process.env.BLOB_READ_WRITE_TOKEN) {
|
||||
const { put } = await import("@vercel/blob");
|
||||
const blob = await put(key, file, {
|
||||
access: "public",
|
||||
contentType: opts.contentType,
|
||||
addRandomSuffix: true,
|
||||
});
|
||||
return { url: blob.url };
|
||||
}
|
||||
return putLocalBlob(key, file, opts, baseUrl);
|
||||
}
|
||||
Reference in New Issue
Block a user