1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-21 00:55:17 +00:00

Add PDF support

This commit is contained in:
2020-03-20 12:10:48 +01:00
parent 0a1626dc47
commit 5c8c3be9ae
2 changed files with 47 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import { checkVirtualDirectory } from "../utils/VirtualDirsUtils";
import { FriendsHelper } from "../helpers/FriendsHelper";
import { PostsHelper } from "../helpers/PostsHelper";
import { PostAccessLevel } from "./Post";
import { writeFileSync } from "fs";
/**
* Response to a request
@ -411,6 +412,32 @@ export class RequestHandler {
return targetFilePath;
}
/**
* Save the file uploaded by a user
*
* @param postField The name of the POST field containing the file
* @param mime_type Required mime type
* @param ext Required file extension
* @param folder The target user folder
*/
public async savePostFile(postField: string, folder: string, ext:string, mime_type: string) : Promise<string> {
const file = this.getUploadedFile(postField);
if(file == undefined)
this.error(400, "File '"+postField+"' is missing in the request !");
if(file.mimetype != mime_type)
this.error(400, "Invalid file mime type (required: " + mime_type+")")
const targetUserDataFolder = prepareFileCreation(this.getUserId(), folder);
const targetFilePath = generateNewUserDataFileName(targetUserDataFolder, ext);
const targetSysPath = pathUserData(targetFilePath, true);
writeFileSync(targetSysPath, file.data, "binary");
return targetFilePath;
}
/**
* Validate API tokens
*