Skip to content

Commit

Permalink
✂️
Browse files Browse the repository at this point in the history
  • Loading branch information
flvndvd committed Apr 4, 2024
1 parent 21620f8 commit a86e7f9
Showing 1 changed file with 1 addition and 27 deletions.
28 changes: 1 addition & 27 deletions front/pages/api/w/[wId]/assistant/agent_configurations/avatar.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
import { Storage } from "@google-cloud/storage";
import { IncomingForm } from "formidable";
import type { NextApiRequest, NextApiResponse } from "next";

import { uploadToBucket } from "@app/lib/dfs";
import { withLogging } from "@app/logger/withlogging";

const { DUST_UPLOAD_BUCKET = "", SERVICE_ACCOUNT } = process.env;
const { DUST_UPLOAD_BUCKET = "" } = process.env;

export const config = {
api: {
bodyParser: false, // Disabling Next.js's body parser as formidable has its own
},
};

export async function assertIsSelfHostedPictureUrl(pictureUrl: string) {
const isSelfHosted = pictureUrl.startsWith(
`https://storage.googleapis.com/${DUST_UPLOAD_BUCKET}/`
);

const storage = new Storage({
keyFilename: SERVICE_ACCOUNT,
});

const filename = pictureUrl.split("/").at(-1);
if (!filename) {
return false;
}

const bucket = storage.bucket(DUST_UPLOAD_BUCKET);
const gcsFile = await bucket.file(filename);

const [metadata] = await gcsFile.getMetadata();

const isImageContentType =
metadata.contentType && metadata.contentType.includes("image");

return isSelfHosted && isImageContentType;
}

async function handler(
req: NextApiRequest,
res: NextApiResponse
Expand Down

0 comments on commit a86e7f9

Please sign in to comment.