👔 No longer create permission for owner
This commit is contained in:
@@ -321,7 +321,7 @@ public class FileController(
|
|||||||
string? overrideMimeType
|
string? overrideMimeType
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var client = fs.CreateMinioClient(dest);
|
var client = FileService.CreateMinioClient(dest);
|
||||||
if (client is null)
|
if (client is null)
|
||||||
return BadRequest("Failed to configure client for remote destination, file got an invalid storage remote.");
|
return BadRequest("Failed to configure client for remote destination, file got an invalid storage remote.");
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class FileObjectCleanupJob(AppDatabase db, FileService fileService, ILogg
|
|||||||
{
|
{
|
||||||
var dest = await fileService.GetRemoteStorageConfig(replica.PoolId!.Value);
|
var dest = await fileService.GetRemoteStorageConfig(replica.PoolId!.Value);
|
||||||
if (dest == null) continue;
|
if (dest == null) continue;
|
||||||
var client = fileService.CreateMinioClient(dest);
|
var client = FileService.CreateMinioClient(dest);
|
||||||
if (client == null) continue;
|
if (client == null) continue;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -257,19 +257,10 @@ public class FileService(
|
|||||||
IsPrimary = true
|
IsPrimary = true
|
||||||
};
|
};
|
||||||
|
|
||||||
var permission = new SnFilePermission
|
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
FileId = file.Id,
|
|
||||||
SubjectType = SnFilePermissionType.Someone,
|
|
||||||
SubjectId = file.AccountId.ToString(),
|
|
||||||
Permission = SnFilePermissionLevel.Write
|
|
||||||
};
|
|
||||||
|
|
||||||
db.Files.Add(file);
|
db.Files.Add(file);
|
||||||
db.FileObjects.Add(fileObject);
|
db.FileObjects.Add(fileObject);
|
||||||
db.FileReplicas.Add(replica);
|
db.FileReplicas.Add(replica);
|
||||||
db.FilePermissions.Add(permission);
|
|
||||||
|
|
||||||
await db.SaveChangesAsync();
|
await db.SaveChangesAsync();
|
||||||
file.ObjectId = file.Id;
|
file.ObjectId = file.Id;
|
||||||
@@ -700,7 +691,7 @@ public class FileService(
|
|||||||
return await GetRemoteStorageConfig(id);
|
return await GetRemoteStorageConfig(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMinioClient? CreateMinioClient(RemoteStorageConfig dest)
|
public static IMinioClient? CreateMinioClient(RemoteStorageConfig dest)
|
||||||
{
|
{
|
||||||
var client = new MinioClient()
|
var client = new MinioClient()
|
||||||
.WithEndpoint(dest.Endpoint)
|
.WithEndpoint(dest.Endpoint)
|
||||||
@@ -717,76 +708,12 @@ public class FileService(
|
|||||||
await cache.RemoveAsync(cacheKey);
|
await cache.RemoveAsync(cacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task _PurgeCacheRangeAsync(IEnumerable<string> fileIds)
|
private async Task _PurgeCacheRangeAsync(IEnumerable<string> fileIds)
|
||||||
{
|
{
|
||||||
var tasks = fileIds.Select(_PurgeCacheAsync);
|
var tasks = fileIds.Select(_PurgeCacheAsync);
|
||||||
await Task.WhenAll(tasks);
|
await Task.WhenAll(tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<SnCloudFile?>> LoadFromReference(List<SnCloudFileReferenceObject> references)
|
|
||||||
{
|
|
||||||
var cachedFiles = new Dictionary<string, SnCloudFile>();
|
|
||||||
var uncachedIds = new List<string>();
|
|
||||||
|
|
||||||
foreach (var reference in references)
|
|
||||||
{
|
|
||||||
var cacheKey = string.Concat(CacheKeyPrefix, reference.Id);
|
|
||||||
var cachedFile = await cache.GetAsync<SnCloudFile>(cacheKey);
|
|
||||||
|
|
||||||
if (cachedFile != null)
|
|
||||||
{
|
|
||||||
cachedFiles[reference.Id] = cachedFile;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uncachedIds.Add(reference.Id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uncachedIds.Count > 0)
|
|
||||||
{
|
|
||||||
var dbFiles = await db.Files
|
|
||||||
.Where(f => uncachedIds.Contains(f.Id))
|
|
||||||
.Include(f => f.Object)
|
|
||||||
.ThenInclude(o => o.FileReplicas)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
foreach (var file in dbFiles)
|
|
||||||
{
|
|
||||||
var cacheKey = string.Concat(CacheKeyPrefix, file.Id);
|
|
||||||
await cache.SetAsync(cacheKey, file, CacheDuration);
|
|
||||||
cachedFiles[file.Id] = file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
[
|
|
||||||
.. references
|
|
||||||
.Select(r => cachedFiles.GetValueOrDefault(r.Id))
|
|
||||||
.Where(f => f != null)
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<int> GetReferenceCountAsync(string fileId)
|
|
||||||
{
|
|
||||||
var file = await db.Files.FirstOrDefaultAsync(f => f.Id == fileId);
|
|
||||||
if (file == null || file.ObjectId == null) return 0;
|
|
||||||
|
|
||||||
return await db.Files
|
|
||||||
.Where(f => f.ObjectId == file.ObjectId && f.Id != fileId)
|
|
||||||
.CountAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<bool> IsReferencedAsync(string fileId)
|
|
||||||
{
|
|
||||||
var file = await db.Files.FirstOrDefaultAsync(f => f.Id == fileId);
|
|
||||||
if (file == null || file.ObjectId == null) return false;
|
|
||||||
|
|
||||||
return await db.Files
|
|
||||||
.Where(f => f.ObjectId == file.ObjectId && f.Id != fileId)
|
|
||||||
.AnyAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsIgnoredField(string fieldName)
|
private static bool IsIgnoredField(string fieldName)
|
||||||
{
|
{
|
||||||
var gpsFields = new[]
|
var gpsFields = new[]
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ public static class FileUploadedEvent
|
|||||||
public record FileUploadedEventPayload(
|
public record FileUploadedEventPayload(
|
||||||
string FileId,
|
string FileId,
|
||||||
Guid RemoteId,
|
Guid RemoteId,
|
||||||
string StorageId,
|
string? StorageId,
|
||||||
string ContentType,
|
string? ContentType,
|
||||||
string ProcessingFilePath,
|
string ProcessingFilePath,
|
||||||
bool IsTempFile
|
bool IsTempFile
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user