Revert "Добавил кастомизацию+, убрал жесты потому что они мне жизнь сломали"

This reverts commit 9ca9f0c2d4.
This commit is contained in:
jganenok
2025-12-05 18:44:22 +07:00
parent dd6e9107f4
commit ca8fd20796
7 changed files with 261 additions and 1235 deletions

View File

@@ -40,12 +40,7 @@ class AvatarCacheService {
final timestamp = _imageCacheTimestamps[cacheKey];
if (timestamp != null && !_isExpired(timestamp, _imageTTL)) {
final imageData = _imageMemoryCache[cacheKey]!;
if (_isValidImageData(imageData)) {
return MemoryImage(imageData);
} else {
_imageMemoryCache.remove(cacheKey);
_imageCacheTimestamps.remove(cacheKey);
}
return MemoryImage(imageData);
} else {
_imageMemoryCache.remove(cacheKey);
_imageCacheTimestamps.remove(cacheKey);
@@ -57,25 +52,20 @@ class AvatarCacheService {
customKey: cacheKey,
);
if (cachedFile != null && await cachedFile.exists()) {
try {
final imageData = await cachedFile.readAsBytes();
if (_isValidImageData(imageData)) {
_imageMemoryCache[cacheKey] = imageData;
_imageCacheTimestamps[cacheKey] = DateTime.now();
final imageData = await cachedFile.readAsBytes();
if (_imageMemoryCache.length > _maxMemoryImages) {
await _evictOldestImages();
}
_imageMemoryCache[cacheKey] = imageData;
_imageCacheTimestamps[cacheKey] = DateTime.now();
return MemoryImage(imageData);
}
} catch (e) {
print('Ошибка чтения кешированного файла аватарки: $e');
if (_imageMemoryCache.length > _maxMemoryImages) {
await _evictOldestImages();
}
return MemoryImage(imageData);
}
final imageData = await _downloadImage(avatarUrl);
if (imageData != null && _isValidImageData(imageData)) {
if (imageData != null) {
await _cacheService.cacheFile(avatarUrl, customKey: cacheKey);
_imageMemoryCache[cacheKey] = imageData;
@@ -83,8 +73,6 @@ class AvatarCacheService {
return MemoryImage(imageData);
}
return NetworkImage(avatarUrl);
} catch (e) {
print('Ошибка получения аватарки: $e');
}
@@ -123,11 +111,6 @@ class AvatarCacheService {
return null;
}
if (!_isValidImageData(imageData)) {
print('Невалидные данные изображения для $url');
return null;
}
return imageData;
}
} catch (e) {
@@ -136,34 +119,6 @@ class AvatarCacheService {
return null;
}
bool _isValidImageData(Uint8List data) {
if (data.isEmpty) return false;
if (data.length < 4) return false;
final header = data.sublist(0, 4);
final pngHeader = [0x89, 0x50, 0x4E, 0x47];
final jpegHeader = [0xFF, 0xD8, 0xFF];
final gifHeader = [0x47, 0x49, 0x46, 0x38];
final webpHeader = [0x52, 0x49, 0x46, 0x46];
bool isValid = false;
if (header[0] == pngHeader[0] && header[1] == pngHeader[1] &&
header[2] == pngHeader[2] && header[3] == pngHeader[3]) {
isValid = true;
} else if (header[0] == jpegHeader[0] && header[1] == jpegHeader[1] &&
header[2] == jpegHeader[2]) {
isValid = true;
} else if (header[0] == gifHeader[0] && header[1] == gifHeader[1] &&
header[2] == gifHeader[2] && header[3] == gifHeader[3]) {
isValid = true;
} else if (header[0] == webpHeader[0] && header[1] == webpHeader[1] &&
header[2] == webpHeader[2] && header[3] == webpHeader[3]) {
isValid = true;
}
return isValid;
}
String _generateCacheKey(String url, int? userId) {
if (userId != null) {
return 'avatar_${userId}_${_hashUrl(url)}';