Skip to content

Commit

Permalink
return uploaded file url
Browse files Browse the repository at this point in the history
  • Loading branch information
f0x52 committed May 20, 2024
1 parent 1949981 commit 9e3dff3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions server/plugins/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,18 @@ class Uploader {
}

static afterUpload(this: void, req: Request, res: Response) {
if (req.file) {
log.info("uploaded file: '%s'", req.file.originalname);
if (req.file === undefined) {
return res.status(500).json({error: "File upload error"});
}

const relativePath = path.relative(Config.getFileUploadPath(), req.file.path);
const uploadUrl = `uploads/${relativePath}`;

log.info(`File upload by ${req._username ?? "unknown"}: ${relativePath}`);

return res.status(200).json({
url: uploadUrl
});
}

static getMaxFileSize() {
Expand Down

0 comments on commit 9e3dff3

Please sign in to comment.