1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 13:29:22 +00:00

Can create a directory to contain user data

This commit is contained in:
Pierre HUBERT 2019-11-30 18:28:27 +01:00
parent 4a280e312c
commit 6736dec599

View File

@ -1,5 +1,6 @@
import { conf } from "../helpers/ConfigHelper"; import { conf } from "../helpers/ConfigHelper";
import { join } from "path"; import { join } from "path";
import { existsSync, mkdirSync, writeFileSync } from "fs";
/** /**
* User data utilities * User data utilities
@ -19,4 +20,36 @@ export function pathUserData(uri: string = "", sysPath: boolean = false) : strin
return join(conf().storageURL, uri).replace(":/", "://"); return join(conf().storageURL, uri).replace(":/", "://");
else else
return join(conf().storagePath, uri); return join(conf().storagePath, uri);
}
/**
* Prepare file creation
*
* @param userID Target user ID
* @param folderName The file directory (based on user_data folder)
*/
export function prepareFileCreation(userID: number, folderName: string) : string {
// Determine subfolder name
let subfolder : string;
if(userID != 0)
subfolder = join(folderName, userID.toString());
else
subfolder = folderName;
const subfolderPath = pathUserData(subfolder, true);
// Check if the path exists
if(!existsSync(subfolderPath)) {
// Create the directory
mkdirSync(subfolderPath, {
recursive: true
});
// Block directory listing
writeFileSync(join(subfolderPath, "index.html"), "");
}
return subfolder;
} }