1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 00:25:17 +00:00

Can replace account image

This commit is contained in:
2020-03-22 15:00:08 +01:00
parent d02eb7afce
commit 34b0a29e77
4 changed files with 51 additions and 6 deletions

View File

@ -1,5 +1,5 @@
import { pathUserData } from "../utils/UserDataUtils";
import { existsSync, readFileSync } from "fs";
import { existsSync, readFileSync, unlinkSync, writeFileSync } from "fs";
import { AccountImage, AccountImageVisibilityLevel } from "../entities/AccountImage";
/**
@ -24,6 +24,22 @@ export class AccountImageHelper {
return new AccountImage(userID, accountImageFileContent, level);
}
/**
* Set a new account image for a user
*
* @param userID Target user ID
* @param path The path for the account image
*/
public static async Set(userID: number, path: string) {
// First, delete any previous account image
const currInfo = await this.Get(userID);
if(currInfo.hasImage)
unlinkSync(currInfo.sysPath);
writeFileSync(this.GetPathMetadataFile(userID), path.replace("avatars/", ""));
}
/**
* Get the content of the file associated to the user account image, if any
*