1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 21:39:22 +00:00
comunicapiv2/src/entities/AccountImage.ts

61 lines
1.2 KiB
TypeScript

import { pathUserData } from "../utils/UserDataUtils";
/**
* Single user account image
*
* @author Pierre HUBERT
*/
const defaultAccountImage = "0Reverse.png";
const errorAccountImage = "0Red.png";
export enum AccountImageVisibilityLevel {
FRIENDS = 1,
COMUNIC_USERS = 2,
EVERYONE = 3
}
export class AccountImage {
public constructor(
public userID: number,
public path : string,
public level: AccountImageVisibilityLevel
) {}
/**
* Get account image URL
*/
get url() : string {
if(this.path.length < 1)
return AccountImage.pathForFile(defaultAccountImage);
return AccountImage.pathForFile(this.path);
}
/**
* Get account image sys path
*/
get sysPath() : string {
if(this.path.length < 1)
throw new Error("This user has no account image!");
return AccountImage.pathForFile(this.path, true);
}
/**
* Check out whether the user has an account image
* or if it is the default account image
*/
get hasImage() : boolean {
return this.path.length > 0;
}
static get errorURL() : string {
return this.pathForFile(errorAccountImage);
}
private static pathForFile(file : string, sysPath = false) : string {
return pathUserData("avatars/" + file, sysPath);
}
}