🐛 Fix issues in getting file
This commit is contained in:
@@ -30,7 +30,7 @@ public class FileService(
|
|||||||
|
|
||||||
public async Task<SnCloudFile?> GetFileAsync(string fileId)
|
public async Task<SnCloudFile?> GetFileAsync(string fileId)
|
||||||
{
|
{
|
||||||
var cacheKey = $"{CacheKeyPrefix}{fileId}";
|
var cacheKey = string.Concat(CacheKeyPrefix, fileId);
|
||||||
|
|
||||||
var cachedFile = await cache.GetAsync<SnCloudFile>(cacheKey);
|
var cachedFile = await cache.GetAsync<SnCloudFile>(cacheKey);
|
||||||
if (cachedFile is not null)
|
if (cachedFile is not null)
|
||||||
@@ -57,7 +57,7 @@ public class FileService(
|
|||||||
|
|
||||||
foreach (var fileId in fileIds)
|
foreach (var fileId in fileIds)
|
||||||
{
|
{
|
||||||
var cacheKey = $"{CacheKeyPrefix}{fileId}";
|
var cacheKey = string.Concat(CacheKeyPrefix, fileId);
|
||||||
var cachedFile = await cache.GetAsync<SnCloudFile>(cacheKey);
|
var cachedFile = await cache.GetAsync<SnCloudFile>(cacheKey);
|
||||||
|
|
||||||
if (cachedFile != null)
|
if (cachedFile != null)
|
||||||
@@ -77,7 +77,7 @@ public class FileService(
|
|||||||
|
|
||||||
foreach (var file in dbFiles)
|
foreach (var file in dbFiles)
|
||||||
{
|
{
|
||||||
var cacheKey = $"{CacheKeyPrefix}{file.Id}";
|
var cacheKey = string.Concat(CacheKeyPrefix, file.Id);
|
||||||
await cache.SetAsync(cacheKey, file, CacheDuration);
|
await cache.SetAsync(cacheKey, file, CacheDuration);
|
||||||
cachedFiles[file.Id] = file;
|
cachedFiles[file.Id] = file;
|
||||||
}
|
}
|
||||||
@@ -295,6 +295,8 @@ public class FileService(
|
|||||||
|
|
||||||
private async Task ExtractMetadataAsync(SnCloudFile file, string filePath)
|
private async Task ExtractMetadataAsync(SnCloudFile file, string filePath)
|
||||||
{
|
{
|
||||||
|
if (file.Object == null) return;
|
||||||
|
|
||||||
switch (file.MimeType?.Split('/')[0])
|
switch (file.MimeType?.Split('/')[0])
|
||||||
{
|
{
|
||||||
case "image":
|
case "image":
|
||||||
@@ -340,11 +342,11 @@ public class FileService(
|
|||||||
if (orientation is 6 or 8) (width, height) = (height, width);
|
if (orientation is 6 or 8) (width, height) = (height, width);
|
||||||
meta["exif"] = exif;
|
meta["exif"] = exif;
|
||||||
meta["ratio"] = height != 0 ? (double)width / height : 0;
|
meta["ratio"] = height != 0 ? (double)width / height : 0;
|
||||||
file.Object!.Meta = meta;
|
file.Object.Meta = meta;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
file.Object!.Meta = new Dictionary<string, object?>();
|
file.Object.Meta = new Dictionary<string, object?>();
|
||||||
logger.LogError(ex, "Failed to analyze image file {FileId}", file.Id);
|
logger.LogError(ex, "Failed to analyze image file {FileId}", file.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,7 +357,7 @@ public class FileService(
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var mediaInfo = await FFProbe.AnalyseAsync(filePath);
|
var mediaInfo = await FFProbe.AnalyseAsync(filePath);
|
||||||
file.Object!.Meta = new Dictionary<string, object?>
|
file.Object.Meta = new Dictionary<string, object?>
|
||||||
{
|
{
|
||||||
["width"] = mediaInfo.PrimaryVideoStream?.Width,
|
["width"] = mediaInfo.PrimaryVideoStream?.Width,
|
||||||
["height"] = mediaInfo.PrimaryVideoStream?.Height,
|
["height"] = mediaInfo.PrimaryVideoStream?.Height,
|
||||||
@@ -391,7 +393,7 @@ public class FileService(
|
|||||||
.ToList(),
|
.ToList(),
|
||||||
};
|
};
|
||||||
if (mediaInfo.PrimaryVideoStream is not null)
|
if (mediaInfo.PrimaryVideoStream is not null)
|
||||||
file.Object!.Meta["ratio"] = (double)mediaInfo.PrimaryVideoStream.Width /
|
file.Object.Meta["ratio"] = (double)mediaInfo.PrimaryVideoStream.Width /
|
||||||
mediaInfo.PrimaryVideoStream.Height;
|
mediaInfo.PrimaryVideoStream.Height;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -711,7 +713,7 @@ public class FileService(
|
|||||||
|
|
||||||
internal async Task _PurgeCacheAsync(string fileId)
|
internal async Task _PurgeCacheAsync(string fileId)
|
||||||
{
|
{
|
||||||
var cacheKey = $"{CacheKeyPrefix}{fileId}";
|
var cacheKey = string.Concat(CacheKeyPrefix, fileId);
|
||||||
await cache.RemoveAsync(cacheKey);
|
await cache.RemoveAsync(cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -728,7 +730,7 @@ public class FileService(
|
|||||||
|
|
||||||
foreach (var reference in references)
|
foreach (var reference in references)
|
||||||
{
|
{
|
||||||
var cacheKey = $"{CacheKeyPrefix}{reference.Id}";
|
var cacheKey = string.Concat(CacheKeyPrefix, reference.Id);
|
||||||
var cachedFile = await cache.GetAsync<SnCloudFile>(cacheKey);
|
var cachedFile = await cache.GetAsync<SnCloudFile>(cacheKey);
|
||||||
|
|
||||||
if (cachedFile != null)
|
if (cachedFile != null)
|
||||||
@@ -751,7 +753,7 @@ public class FileService(
|
|||||||
|
|
||||||
foreach (var file in dbFiles)
|
foreach (var file in dbFiles)
|
||||||
{
|
{
|
||||||
var cacheKey = $"{CacheKeyPrefix}{file.Id}";
|
var cacheKey = string.Concat(CacheKeyPrefix, file.Id);
|
||||||
await cache.SetAsync(cacheKey, file, CacheDuration);
|
await cache.SetAsync(cacheKey, file, CacheDuration);
|
||||||
cachedFiles[file.Id] = file;
|
cachedFiles[file.Id] = file;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class JsonCacheSerializer : ICacheSerializer
|
|||||||
{
|
{
|
||||||
Modifiers = { JsonExtensions.UnignoreAllProperties() },
|
Modifiers = { JsonExtensions.UnignoreAllProperties() },
|
||||||
},
|
},
|
||||||
ReferenceHandler = ReferenceHandler.Preserve,
|
ReferenceHandler = ReferenceHandler.IgnoreCycles,
|
||||||
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals,
|
||||||
Converters = { new ByteStringConverter() }
|
Converters = { new ByteStringConverter() }
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user