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

Check files before deleting them

This commit is contained in:
Pierre HUBERT 2020-04-16 19:05:25 +02:00
parent 0944a99a71
commit 3058069a7d

View File

@ -34,7 +34,7 @@ export class AccountImageHelper {
// First, delete any previous account image // First, delete any previous account image
const currInfo = await this.Get(userID); const currInfo = await this.Get(userID);
if(currInfo.hasImage) if(currInfo.hasImage && existsSync(currInfo.sysPath))
unlinkSync(currInfo.sysPath); unlinkSync(currInfo.sysPath);
writeFileSync(this.GetPathMetadataFile(userID), path.replace("avatars/", "")); writeFileSync(this.GetPathMetadataFile(userID), path.replace("avatars/", ""));
@ -48,10 +48,12 @@ export class AccountImageHelper {
public static async Delete(userID: number) { public static async Delete(userID: number) {
const currInfo = await this.Get(userID); const currInfo = await this.Get(userID);
if(currInfo.hasImage) { if(currInfo.hasImage) {
unlinkSync(currInfo.sysPath); if(existsSync(currInfo.sysPath))
unlinkSync(currInfo.sysPath);
// Delete meta file // Delete meta file
unlinkSync(this.GetPathMetadataFile(userID)); if(existsSync(this.GetPathMetadataFile(userID)))
unlinkSync(this.GetPathMetadataFile(userID));
// Delete visiblity file (if any) // Delete visiblity file (if any)
const visibilityFile = this.GetPathVisibilityFile(userID); const visibilityFile = this.GetPathVisibilityFile(userID);