Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/pages/api/v1/course/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { withMethods } from "@/lib/api-middlewares/with-method";
import { withUserAuthorized } from "@/lib/api-middlewares/with-authorized";
import { createSlug, getFileExtension } from "@/lib/utils";
import fs from "fs";
import path from "path";
import { APIResponse } from "@/types/apis";
import { readFieldWithSingleFile } from "@/lib/upload/utils";
import { ContentManagementService } from "@/services/cms/ContentManagementService";
Expand Down Expand Up @@ -59,8 +60,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
}

const extension = getFileExtension(files.file[0].originalFilename);
const sourcePath = files.file[0].filepath;
const fileBuffer = await fs.promises.readFile(`${sourcePath}`);
const sourcePath = path.resolve(files.file[0].filepath);
const safeDir = path.resolve("/var/www/uploads"); // Replace with your safe directory
if (!sourcePath.startsWith(safeDir)) {
throw new Error("Invalid file path");
}
const fileBuffer = await fs.promises.readFile(sourcePath);
//now upload the image
const newThumbnailResponse = await cms.uploadVideoThumbnail(
cmsConfig,
Expand Down
Loading