feat: Enhance avatar management with detailed logging and error handling
This commit is contained in:
@@ -31,15 +31,23 @@ object AvatarFileManager {
|
||||
* @return Путь к файлу (формат: "a/md5hash")
|
||||
*/
|
||||
fun saveAvatar(context: Context, base64Image: String, entityId: String): String {
|
||||
android.util.Log.d("AvatarFileManager", "💾 saveAvatar called")
|
||||
android.util.Log.d("AvatarFileManager", "📊 Base64 length: ${base64Image.length}")
|
||||
android.util.Log.d("AvatarFileManager", "👤 Entity ID: ${entityId.take(16)}...")
|
||||
|
||||
// Генерируем путь как в desktop версии
|
||||
val filePath = generateMd5Path(base64Image, entityId)
|
||||
android.util.Log.d("AvatarFileManager", "🔗 Generated file path: $filePath")
|
||||
|
||||
// Шифруем данные с паролем "rosetta-a"
|
||||
android.util.Log.d("AvatarFileManager", "🔐 Encrypting with password...")
|
||||
val encrypted = CryptoManager.encryptWithPassword(base64Image, AVATAR_PASSWORD)
|
||||
android.util.Log.d("AvatarFileManager", "✅ Encrypted length: ${encrypted.length}")
|
||||
|
||||
// Сохраняем в файловую систему
|
||||
val dir = File(context.filesDir, AVATAR_DIR)
|
||||
dir.mkdirs()
|
||||
android.util.Log.d("AvatarFileManager", "📁 Base dir: ${dir.absolutePath}")
|
||||
|
||||
// Путь формата "a/md5hash" -> создаем подпапку "a"
|
||||
val parts = filePath.split("/")
|
||||
@@ -48,11 +56,14 @@ object AvatarFileManager {
|
||||
subDir.mkdirs()
|
||||
val file = File(subDir, parts[1])
|
||||
file.writeText(encrypted)
|
||||
android.util.Log.d("AvatarFileManager", "💾 Saved to: ${file.absolutePath}")
|
||||
} else {
|
||||
val file = File(dir, filePath)
|
||||
file.writeText(encrypted)
|
||||
android.util.Log.d("AvatarFileManager", "💾 Saved to: ${file.absolutePath}")
|
||||
}
|
||||
|
||||
android.util.Log.d("AvatarFileManager", "✅ Avatar saved successfully")
|
||||
return filePath
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user