1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-29 16:56:29 +00:00
comunicapiv2/src/utils/VirtualDirsUtils.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-12-26 12:49:17 +00:00
import { AccountHelper } from "../helpers/AccountHelper";
import { GroupsHelper } from "../helpers/GroupsHelper";
/**
* Virtual directories utilities
*
* @author Pierre HUBERT
*/
export enum VirtualDirType {
USER,
GROUP
}
/**
* Check out whether a virtual directory is valid or not
*
* @param dir The virtual directory to check
*/
export function checkVirtualDirectory(dir: string) : boolean {
if(dir.length < 4 || dir.length > 30) return false;
2019-12-26 12:49:17 +00:00
for(let el of [".html", ".txt", ".php", "à", "â", "é", "ê", "@", "/", "\"", "'", '"', "<", ">", "?", "&", "#"])
if(dir.includes(el))
return false;
return true;
}
/**
* Check the availability of a virtual directory
*
* @param dir Directory to check
* @param id The ID of the element to check
* @param type The type of the element
*/
export async function checkVirtualDirectoryAvailability(dir: string, id: number, type: VirtualDirType) : Promise<boolean> {
if(!checkVirtualDirectory(dir)) return false;
if(type == VirtualDirType.USER) {
return await AccountHelper.CheckUserDirectoryAvailability(dir, id)
&& await GroupsHelper.CheckDirectoryAvailability(dir);
}
else {
return await AccountHelper.CheckUserDirectoryAvailability(dir)
&& await GroupsHelper.CheckDirectoryAvailability(dir, id);
}
}