✨ Still don't know what I am doing
This commit is contained in:
@ -3,6 +3,7 @@ using FFMpegCore;
|
||||
using System.Security.Cryptography;
|
||||
using DysonNetwork.Shared.Cache;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Minio;
|
||||
using Minio.DataModel.Args;
|
||||
@ -344,6 +345,68 @@ public class FileService(
|
||||
return file;
|
||||
}
|
||||
|
||||
public async Task<CloudFile> UpdateFileAsync(CloudFile file, FieldMask updateMask)
|
||||
{
|
||||
var existingFile = await db.Files.FirstOrDefaultAsync(f => f.Id == file.Id);
|
||||
if (existingFile == null)
|
||||
{
|
||||
throw new InvalidOperationException($"File with ID {file.Id} not found.");
|
||||
}
|
||||
|
||||
foreach (var path in updateMask.Paths)
|
||||
{
|
||||
switch (path)
|
||||
{
|
||||
case "name":
|
||||
existingFile.Name = file.Name;
|
||||
break;
|
||||
case "description":
|
||||
existingFile.Description = file.Description;
|
||||
break;
|
||||
case "file_meta":
|
||||
existingFile.FileMeta = file.FileMeta;
|
||||
break;
|
||||
case "user_meta":
|
||||
existingFile.UserMeta = file.UserMeta;
|
||||
break;
|
||||
case "mime_type":
|
||||
existingFile.MimeType = file.MimeType;
|
||||
break;
|
||||
case "hash":
|
||||
existingFile.Hash = file.Hash;
|
||||
break;
|
||||
case "size":
|
||||
existingFile.Size = file.Size;
|
||||
break;
|
||||
case "uploaded_at":
|
||||
existingFile.UploadedAt = file.UploadedAt;
|
||||
break;
|
||||
case "uploaded_to":
|
||||
existingFile.UploadedTo = file.UploadedTo;
|
||||
break;
|
||||
case "has_compression":
|
||||
existingFile.HasCompression = file.HasCompression;
|
||||
break;
|
||||
case "is_marked_recycle":
|
||||
existingFile.IsMarkedRecycle = file.IsMarkedRecycle;
|
||||
break;
|
||||
case "storage_id":
|
||||
existingFile.StorageId = file.StorageId;
|
||||
break;
|
||||
case "storage_url":
|
||||
existingFile.StorageUrl = file.StorageUrl;
|
||||
break;
|
||||
default:
|
||||
logger.LogWarning("Attempted to update unknown field: {Field}", path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
await _PurgeCacheAsync(file.Id);
|
||||
return existingFile;
|
||||
}
|
||||
|
||||
public async Task DeleteFileAsync(CloudFile file)
|
||||
{
|
||||
await DeleteFileDataAsync(file);
|
||||
|
@ -15,19 +15,11 @@ namespace DysonNetwork.Drive.Storage
|
||||
|
||||
public override async Task<Shared.Proto.CloudFile> UpdateFile(UpdateFileRequest request, ServerCallContext context)
|
||||
{
|
||||
// Assuming UpdateFileAsync exists in FileService and handles the update_mask
|
||||
// This is a placeholder, as the current FileService.cs doesn't have a direct UpdateFile method
|
||||
// You might need to implement this logic in FileService based on your needs.
|
||||
// For now, we'll just return the requested file.
|
||||
var file = await fileService.GetFileAsync(request.File.Id);
|
||||
if (file == null)
|
||||
{
|
||||
throw new RpcException(new Status(StatusCode.NotFound, "File not found"));
|
||||
}
|
||||
|
||||
// Apply updates from request.File to 'file' based on request.UpdateMask
|
||||
// This part requires more detailed implementation based on how you want to handle partial updates.
|
||||
return file.ToProtoValue();
|
||||
var updatedFile = await fileService.UpdateFileAsync(file, request.UpdateMask);
|
||||
return updatedFile.ToProtoValue();
|
||||
}
|
||||
|
||||
public override async Task<Empty> DeleteFile(DeleteFileRequest request, ServerCallContext context)
|
||||
|
Reference in New Issue
Block a user