mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 05:19:22 +00:00
Start account image migration
This commit is contained in:
parent
327418697c
commit
622ea0099e
@ -10,7 +10,7 @@ import { GeneralSettings, UserPageStatus, SupportedLanguages, LangSettings, Secu
|
|||||||
import { removeHTMLNodes, checkURL, fixEncoding } from "../utils/StringUtils";
|
import { removeHTMLNodes, checkURL, fixEncoding } from "../utils/StringUtils";
|
||||||
import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils";
|
import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils";
|
||||||
import { AccountHelper } from "../helpers/AccountHelper";
|
import { AccountHelper } from "../helpers/AccountHelper";
|
||||||
import { AccountImageVisibilityLevel } from "../entities/AccountImage";
|
import { AccountImageVisibilityLevel } from "../entities/User";
|
||||||
import { AccountImageHelper } from "../helpers/AccountImageHelper";
|
import { AccountImageHelper } from "../helpers/AccountImageHelper";
|
||||||
import { findKey } from "../utils/ArrayUtils";
|
import { findKey } from "../utils/ArrayUtils";
|
||||||
import { CustomEmojisHelper } from "../helpers/CustomEmojisHelper";
|
import { CustomEmojisHelper } from "../helpers/CustomEmojisHelper";
|
||||||
@ -223,12 +223,12 @@ export class SettingsController {
|
|||||||
* @param h Request handler
|
* @param h Request handler
|
||||||
*/
|
*/
|
||||||
public static async GetAccountImageSettings(h: RequestHandler) {
|
public static async GetAccountImageSettings(h: RequestHandler) {
|
||||||
const imageInfo = (await UserHelper.GetUserInfo(h.getUserId())).accountImage;
|
const user = await UserHelper.GetUserInfo(h.getUserId());
|
||||||
|
|
||||||
h.send({
|
h.send({
|
||||||
has_image: imageInfo.hasImage,
|
has_image: user.hasAccountImage,
|
||||||
image_url: imageInfo.url,
|
image_url: user.accountImageURL,
|
||||||
visibility: ACCOUNT_IMAGE_VISIBLITY_LEVELS[imageInfo.level]
|
visibility: ACCOUNT_IMAGE_VISIBLITY_LEVELS[user.accountImageVisibilityLevel]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ export class SettingsController {
|
|||||||
h.error(400, "Account image visibility level not understood!");
|
h.error(400, "Account image visibility level not understood!");
|
||||||
|
|
||||||
await AccountImageHelper.SetVisibilityLevel(
|
await AccountImageHelper.SetVisibilityLevel(
|
||||||
h.getUserId(), <AccountImageVisibilityLevel>Number(visibilityLevel));
|
h.getUserId(), <AccountImageVisibilityLevel>String(visibilityLevel));
|
||||||
|
|
||||||
h.success();
|
h.success();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { RequestHandler } from "../entities/RequestHandler";
|
import { RequestHandler } from "../entities/RequestHandler";
|
||||||
import { UserHelper } from "../helpers/UserHelper";
|
import { UserHelper } from "../helpers/UserHelper";
|
||||||
import { User, UserPageStatus } from "../entities/User";
|
import { User, UserPageStatus, AccountImageVisibilityLevel } from "../entities/User";
|
||||||
import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountImage";
|
|
||||||
import { BackgroundImageHelper } from "../helpers/BackgroundImageHelper";
|
import { BackgroundImageHelper } from "../helpers/BackgroundImageHelper";
|
||||||
import { LikesHelper, LikesType } from "../helpers/LikesHelper";
|
import { LikesHelper, LikesType } from "../helpers/LikesHelper";
|
||||||
import { FriendsHelper } from "../helpers/FriendsHelper";
|
import { FriendsHelper } from "../helpers/FriendsHelper";
|
||||||
@ -78,7 +77,7 @@ export class UserController {
|
|||||||
"publicPage": user.pageStatus == UserPageStatus.PUBLIC,
|
"publicPage": user.pageStatus == UserPageStatus.PUBLIC,
|
||||||
"openPage": user.pageStatus == UserPageStatus.OPEN,
|
"openPage": user.pageStatus == UserPageStatus.OPEN,
|
||||||
"virtualDirectory": user.hasVirtualDirectory ? user.virtualDirectory : "",
|
"virtualDirectory": user.hasVirtualDirectory ? user.virtualDirectory : "",
|
||||||
"accountImage": await this.GetAccountImageURL(user.accountImage, h),
|
"accountImage": await this.GetAccountImageURL(user, h),
|
||||||
"customEmojis": (await CustomEmojisHelper.GetListUser(user.id)).map(SettingsController.CustomEmojiToAPI)
|
"customEmojis": (await CustomEmojisHelper.GetListUser(user.id)).map(SettingsController.CustomEmojiToAPI)
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -101,20 +100,20 @@ export class UserController {
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async GetAccountImageURL(image : AccountImage, handler: RequestHandler) {
|
private static async GetAccountImageURL(user : User, handler: RequestHandler) {
|
||||||
|
|
||||||
if(image.level == AccountImageVisibilityLevel.EVERYONE
|
if(user.accountImageVisibilityLevel == AccountImageVisibilityLevel.EVERYONE
|
||||||
|| (handler.signedIn && handler.getUserId() == image.userID))
|
|| (handler.signedIn && handler.getUserId() == user.id))
|
||||||
return image.url;
|
return user.accountImageURL;
|
||||||
|
|
||||||
if(!handler.signedIn)
|
if(!handler.signedIn)
|
||||||
return AccountImage.errorURL;
|
return User.errorAccountImageURL;
|
||||||
|
|
||||||
if(image.level == AccountImageVisibilityLevel.COMUNIC_USERS
|
if(user.accountImageVisibilityLevel == AccountImageVisibilityLevel.COMUNIC_USERS
|
||||||
|| await FriendsHelper.AreFriend(image.userID, handler.getUserId())) {
|
|| await FriendsHelper.AreFriend(user.id, handler.getUserId())) {
|
||||||
return image.url;
|
return user.accountImageURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return AccountImage.errorURL;
|
return User.errorAccountImageURL;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,13 +1,23 @@
|
|||||||
import { AccountImage } from "./AccountImage";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User information
|
* User information
|
||||||
*
|
*
|
||||||
* @author Pierre HUBERT
|
* @author Pierre HUBERT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { pathUserData } from "../utils/UserDataUtils";
|
||||||
|
|
||||||
export const SupportedLanguages = ["fr", "en"]
|
export const SupportedLanguages = ["fr", "en"]
|
||||||
|
|
||||||
|
export enum AccountImageVisibilityLevel {
|
||||||
|
FRIENDS = "friends",
|
||||||
|
COMUNIC_USERS = "comunic_users",
|
||||||
|
EVERYONE = "everyone"
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultAccountImage = "0Reverse.png";
|
||||||
|
const errorAccountImage = "0Red.png";
|
||||||
|
|
||||||
|
|
||||||
export enum UserPageStatus {
|
export enum UserPageStatus {
|
||||||
PRIVATE,
|
PRIVATE,
|
||||||
PUBLIC,
|
PUBLIC,
|
||||||
@ -21,7 +31,8 @@ export interface UserInfo {
|
|||||||
timeCreate: number,
|
timeCreate: number,
|
||||||
virtualDirectory: string,
|
virtualDirectory: string,
|
||||||
pageStatus: UserPageStatus,
|
pageStatus: UserPageStatus,
|
||||||
accountImage: AccountImage,
|
accountImagePath: string,
|
||||||
|
accountImageVisibilityLevel: AccountImageVisibilityLevel,
|
||||||
friendsListPublic: boolean,
|
friendsListPublic: boolean,
|
||||||
personnalWebsite ?: string,
|
personnalWebsite ?: string,
|
||||||
publicNote ?: string,
|
publicNote ?: string,
|
||||||
@ -70,7 +81,6 @@ export class User implements UserBuilder {
|
|||||||
timeCreate: number;
|
timeCreate: number;
|
||||||
virtualDirectory: string;
|
virtualDirectory: string;
|
||||||
pageStatus: UserPageStatus;
|
pageStatus: UserPageStatus;
|
||||||
accountImage: AccountImage;
|
|
||||||
friendsListPublic: boolean;
|
friendsListPublic: boolean;
|
||||||
personnalWebsite?: string;
|
personnalWebsite?: string;
|
||||||
publicNote?: string;
|
publicNote?: string;
|
||||||
@ -78,6 +88,8 @@ export class User implements UserBuilder {
|
|||||||
allowPostsFromFriends: boolean;
|
allowPostsFromFriends: boolean;
|
||||||
allowMails: boolean;
|
allowMails: boolean;
|
||||||
lang: string;
|
lang: string;
|
||||||
|
accountImagePath: string;
|
||||||
|
accountImageVisibilityLevel: AccountImageVisibilityLevel;
|
||||||
security_question_1?: string;
|
security_question_1?: string;
|
||||||
security_answer_1?: string;
|
security_answer_1?: string;
|
||||||
security_question_2?: string;
|
security_question_2?: string;
|
||||||
@ -93,6 +105,46 @@ export class User implements UserBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get account image URL
|
||||||
|
*/
|
||||||
|
get accountImageURL() : string {
|
||||||
|
if(this.accountImagePath.length < 1)
|
||||||
|
return User.pathForAccountImageFile(defaultAccountImage);
|
||||||
|
|
||||||
|
return User.pathForAccountImageFile(this.accountImagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get account image sys path
|
||||||
|
*/
|
||||||
|
get accountImageSysPath() : string {
|
||||||
|
if(this.accountImagePath.length < 1)
|
||||||
|
throw new Error("This user has no account image!");
|
||||||
|
|
||||||
|
return User.pathForAccountImageFile(this.accountImagePath, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check out whether the user has an account image
|
||||||
|
* or if it is the default account image
|
||||||
|
*/
|
||||||
|
get hasAccountImage() : boolean {
|
||||||
|
return this.accountImagePath.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fallback account image URL
|
||||||
|
*/
|
||||||
|
static get errorAccountImageURL() : string {
|
||||||
|
return this.pathForAccountImageFile(errorAccountImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static pathForAccountImageFile(file : string, sysPath = false) : string {
|
||||||
|
return pathUserData("avatars/" + file, sysPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
get isPublic() : boolean {
|
get isPublic() : boolean {
|
||||||
return this.pageStatus != UserPageStatus.PRIVATE;
|
return this.pageStatus != UserPageStatus.PRIVATE;
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,8 @@ export class UserHelper {
|
|||||||
timeCreate: new Date(row.date_creation).getTime()/1000,
|
timeCreate: new Date(row.date_creation).getTime()/1000,
|
||||||
virtualDirectory: row.sous_repertoire,
|
virtualDirectory: row.sous_repertoire,
|
||||||
pageStatus: row.pageouverte == 1 ? UserPageStatus.OPEN : (row.public == 1 ? UserPageStatus.PUBLIC : UserPageStatus.PRIVATE),
|
pageStatus: row.pageouverte == 1 ? UserPageStatus.OPEN : (row.public == 1 ? UserPageStatus.PUBLIC : UserPageStatus.PRIVATE),
|
||||||
accountImage: await AccountImageHelper.Get(row.ID),
|
accountImagePath: row.account_image_path,
|
||||||
|
accountImageVisibilityLevel: row.account_image_visibility,
|
||||||
friendsListPublic: row.liste_amis_publique == 1,
|
friendsListPublic: row.liste_amis_publique == 1,
|
||||||
personnalWebsite: row.site_web,
|
personnalWebsite: row.site_web,
|
||||||
publicNote: row.public_note,
|
publicNote: row.public_note,
|
||||||
|
Loading…
Reference in New Issue
Block a user