mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Can change account image visibility
This commit is contained in:
parent
95af444741
commit
bd83a77fb2
@ -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)},
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user