2019-12-28 12:07:26 +00:00
|
|
|
import { RequestHandler } from "../entities/RequestHandler";
|
|
|
|
import { UserHelper } from "../helpers/UserHelper";
|
|
|
|
import { GroupsHelper } from "../helpers/GroupsHelper";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual directory controller
|
|
|
|
*
|
|
|
|
* @author Pierre HUBERT
|
|
|
|
*/
|
|
|
|
|
|
|
|
export class VirtualDirectoryController {
|
|
|
|
|
2019-12-28 13:34:42 +00:00
|
|
|
/**
|
|
|
|
* Find a user by its virtual directory
|
|
|
|
*
|
|
|
|
* @param h Request handler
|
|
|
|
*/
|
|
|
|
public static async FindUser(h: RequestHandler) {
|
|
|
|
const virtualDirectory = h.postVirtualDirectory("subfolder");
|
|
|
|
|
|
|
|
const userID = await UserHelper.FindByFolder(virtualDirectory);
|
|
|
|
|
|
|
|
if(userID < 1)
|
|
|
|
h.error(404, "No user was found with this subfolder!");
|
|
|
|
|
|
|
|
h.send({
|
|
|
|
userID: userID
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-28 12:07:26 +00:00
|
|
|
/**
|
|
|
|
* Find a group / user using a given virtual directory
|
|
|
|
*
|
|
|
|
* @param h Request handler
|
|
|
|
*/
|
|
|
|
public static async Find(h: RequestHandler) {
|
|
|
|
const virtualDirectory = h.postVirtualDirectory("directory");
|
|
|
|
|
|
|
|
const userID = await UserHelper.FindByFolder(virtualDirectory);
|
|
|
|
const groupID = await GroupsHelper.FindByVirtualDirectory(virtualDirectory);
|
|
|
|
|
|
|
|
if(userID < 1 && groupID < 1)
|
|
|
|
h.error(404, "Specified user / group virtual directory not found !")
|
|
|
|
|
|
|
|
h.send({
|
|
|
|
kind: userID >= 1 ? "user" : "group",
|
|
|
|
id: userID >= 1 ? userID : groupID,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|