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

Can change account image visibility

This commit is contained in:
Pierre HUBERT 2020-03-22 15:15:12 +01:00
parent 95af444741
commit bd83a77fb2
3 changed files with 43 additions and 0 deletions

View File

@ -103,6 +103,8 @@ export const Routes : Route[] = [
{path: "/settings/delete_account_image", cb: (h) => SettingsController.DeleteAccountImage(h)},
{path: "/settings/set_account_image_visibility", cb: (h) => SettingsController.SetAccountImageVisibility(h)},
// Friends controller
{path: "/friends/getList", cb: (h) => FriendsController.GetList(h)},

View File

@ -12,6 +12,7 @@ import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/Virt
import { AccountHelper } from "../helpers/AccountHelper";
import { AccountImageVisibilityLevel } from "../entities/AccountImage";
import { AccountImageHelper } from "../helpers/AccountImageHelper";
import { findKey } from "../utils/ArrayUtils";
/**
* API account image visibility levels
@ -242,4 +243,21 @@ export class SettingsController {
await AccountImageHelper.Delete(h.getUserId());
h.success();
}
/**
* Change account image visibility level
*
* @param h Request handler
*/
public static async SetAccountImageVisibility(h: RequestHandler) {
const visibilityLevel = findKey(ACCOUNT_IMAGE_VISIBLITY_LEVELS, h.postString("visibility"));
if(visibilityLevel == null)
h.error(400, "Account image visibility level not understood!");
await AccountImageHelper.SetVisibilityLevel(
h.getUserId(), <AccountImageVisibilityLevel>Number(visibilityLevel));
h.success();
}
}

View File

@ -55,6 +55,29 @@ export class AccountImageHelper {
}
}
/**
* Change account image visiblity level
*
* @param userID Target user ID
* @param level New level for account image
*/
public static async SetVisibilityLevel(userID: number, level: AccountImageVisibilityLevel) {
const file = this.GetPathVisibilityFile(userID);
// If the visiblity is set to everyone, we do not
// need to have a visibility file
if(level == AccountImageVisibilityLevel.EVERYONE) {
if(existsSync(file))
unlinkSync(file);
return;
}
else
writeFileSync(file, level);
}
/**
* Get the content of the file associated to the user account image, if any
*