fix(web): build issues

This commit is contained in:
BennyKok 2023-12-21 00:48:27 +08:00
parent 7a60c357d8
commit a8adb59879
4 changed files with 28 additions and 28 deletions

View File

@ -5,7 +5,7 @@ import { deploymentsTable } from "@/db/schema";
import { isKeyRevoked } from "@/server/curdApiKeys";
import { getRunsData } from "@/server/getRunsOutput";
import { parseJWT } from "@/server/parseJWT";
import { replaceCDNUrl } from "@/server/resource";
import { replaceCDNUrl } from "@/server/replaceCDNUrl";
import { eq } from "drizzle-orm";
import { NextResponse } from "next/server";
import { z } from "zod";
@ -36,10 +36,9 @@ async function checkToken(request: Request) {
}
export async function GET(request: Request) {
const invalidRequest = await checkToken(request)
const invalidRequest = await checkToken(request);
if (invalidRequest) return invalidRequest;
const [data, error] = await parseDataSafe(Request2, request);
if (!data || error) return error;
@ -54,7 +53,7 @@ export async function GET(request: Request) {
for (let j = 0; j < output.data?.images.length; j++) {
const element = output.data?.images[j];
element.url = replaceCDNUrl(
`${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}/outputs/runs/${run.id}/${element.filename}`,
`${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}/outputs/runs/${run.id}/${element.filename}`
);
}
}
@ -66,7 +65,7 @@ export async function GET(request: Request) {
}
export async function POST(request: Request) {
const invalidRequest = await checkToken(request)
const invalidRequest = await checkToken(request);
if (invalidRequest) return invalidRequest;
const [data, error] = await parseDataSafe(Request, request);
@ -87,18 +86,18 @@ export async function POST(request: Request) {
origin,
deploymentData.workflow_version_id,
deploymentData.machine_id,
inputs,
inputs
);
if ('error' in run_id) throw new Error(run_id.error);
if ("error" in run_id) throw new Error(run_id.error);
return NextResponse.json(
{
run_id: ('workflow_run_id' in run_id) ? run_id.workflow_run_id : '',
run_id: "workflow_run_id" in run_id ? run_id.workflow_run_id : "",
},
{
status: 200,
},
}
);
} catch (error: any) {
return NextResponse.json(
@ -107,7 +106,7 @@ export async function POST(request: Request) {
},
{
status: 500,
},
}
);
}
}

View File

@ -1,6 +1,6 @@
'use server'
"use server";
import { replaceCDNUrl } from "@/server/resource";
import { replaceCDNUrl } from "./replaceCDNUrl";
export async function getFileDownloadUrl(file: string) {
return replaceCDNUrl(

View File

@ -0,0 +1,16 @@
export function replaceCDNUrl(url: string) {
// When using R2, we don't want to include the bucket name in the URL
if (process.env.SPACES_CDN_DONT_INCLUDE_BUCKET === "true") {
url = url.replace(
`${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}`,
process.env.SPACES_ENDPOINT_CDN!
);
} else {
url = url.replace(
process.env.SPACES_ENDPOINT!,
process.env.SPACES_ENDPOINT_CDN!
);
}
return url;
}

View File

@ -1,3 +1,4 @@
import { replaceCDNUrl } from "./replaceCDNUrl";
import type { PutObjectCommandInput } from "@aws-sdk/client-s3";
import {
DeleteObjectCommand,
@ -17,22 +18,6 @@ const s3Client = new S3({
forcePathStyle: true,
});
export function replaceCDNUrl(url: string) {
// When using R2, we don't want to include the bucket name in the URL
if (process.env.SPACES_CDN_DONT_INCLUDE_BUCKET === "true") {
url = url.replace(
`${process.env.SPACES_ENDPOINT}/${process.env.SPACES_BUCKET}`,
process.env.SPACES_ENDPOINT_CDN!
);
} else {
url = url.replace(
process.env.SPACES_ENDPOINT!,
process.env.SPACES_ENDPOINT_CDN!
);
}
return url;
}
export type ResourceObject = {
resourceBucket: string;
resourceId: string;