mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-03 11:04:02 +00:00 
			
		
		
		
	Can replace account image
This commit is contained in:
		@@ -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
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user