✨ File index
This commit is contained in:
@@ -14,7 +14,7 @@ public class CloudFileUnusedRecyclingJob(
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
logger.LogInformation("Cleaning tus cloud files...");
|
||||
var storePath = configuration["Tus:StorePath"];
|
||||
var storePath = configuration["Storage:Uploads"];
|
||||
if (Directory.Exists(storePath))
|
||||
{
|
||||
var oneHourAgo = SystemClock.Instance.GetCurrentInstant() - Duration.FromHours(1);
|
||||
@@ -39,6 +39,7 @@ public class CloudFileUnusedRecyclingJob(
|
||||
var processedCount = 0;
|
||||
var markedCount = 0;
|
||||
var totalFiles = await db.Files
|
||||
.Where(f => f.FileIndexes.Count == 0)
|
||||
.Where(f => f.PoolId.HasValue && recyclablePools.Contains(f.PoolId.Value))
|
||||
.Where(f => !f.IsMarkedRecycle)
|
||||
.CountAsync();
|
||||
|
||||
@@ -76,7 +76,7 @@ public class FileController(
|
||||
}
|
||||
|
||||
// Fallback for tus uploads
|
||||
var tusStorePath = configuration.GetValue<string>("Tus:StorePath");
|
||||
var tusStorePath = configuration.GetValue<string>("Storage:Uploads");
|
||||
if (!string.IsNullOrEmpty(tusStorePath))
|
||||
{
|
||||
var tusFilePath = Path.Combine(env.ContentRootPath, tusStorePath, file.Id);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using DysonNetwork.Drive.Billing;
|
||||
using DysonNetwork.Drive.Index;
|
||||
using DysonNetwork.Drive.Storage.Model;
|
||||
using DysonNetwork.Shared.Auth;
|
||||
using DysonNetwork.Shared.Http;
|
||||
@@ -24,6 +25,7 @@ public class FileUploadController(
|
||||
PermissionService.PermissionServiceClient permission,
|
||||
QuotaService quotaService,
|
||||
PersistentTaskService persistentTaskService,
|
||||
FileIndexService fileIndexService,
|
||||
ILogger<FileUploadController> logger
|
||||
)
|
||||
: ControllerBase
|
||||
@@ -260,10 +262,26 @@ public class FileUploadController(
|
||||
persistentTask.ExpiredAt
|
||||
);
|
||||
|
||||
// Update task status to "processing" - background processing is now happening
|
||||
// Create the file index if a path is provided
|
||||
if (!string.IsNullOrEmpty(persistentTask.Path))
|
||||
{
|
||||
try
|
||||
{
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
await fileIndexService.CreateAsync(persistentTask.Path, fileId, accountId);
|
||||
logger.LogInformation("Created file index for file {FileId} at path {Path}", fileId, persistentTask.Path);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning(ex, "Failed to create file index for file {FileId} at path {Path}", fileId, persistentTask.Path);
|
||||
// Don't fail the upload if index creation fails, just log it
|
||||
}
|
||||
}
|
||||
|
||||
// Update the task status to "processing" - background processing is now happening
|
||||
await persistentTaskService.UpdateTaskProgressAsync(taskId, 0.95, "Processing file in background...");
|
||||
|
||||
// Send upload completion notification (file is uploaded, but processing continues)
|
||||
// Send upload completion notification (a file is uploaded, but processing continues)
|
||||
await persistentTaskService.SendUploadCompletedNotificationAsync(persistentTask, fileId);
|
||||
|
||||
return Ok(cloudFile);
|
||||
|
||||
@@ -22,6 +22,7 @@ public class FileUploadParameters
|
||||
public string? EncryptPassword { get; set; }
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
public List<int> UploadedChunks { get; set; } = [];
|
||||
public string? Path { get; set; }
|
||||
}
|
||||
|
||||
// File Move Task Parameters
|
||||
@@ -93,6 +94,7 @@ public class CreateUploadTaskRequest
|
||||
public string? EncryptPassword { get; set; }
|
||||
public Instant? ExpiredAt { get; set; }
|
||||
public long? ChunkSize { get; set; }
|
||||
public string? Path { get; set; }
|
||||
}
|
||||
|
||||
public class CreateUploadTaskResponse
|
||||
@@ -301,6 +303,17 @@ public class PersistentUploadTask : PersistentTask
|
||||
TypedParameters = parameters;
|
||||
}
|
||||
}
|
||||
|
||||
public string? Path
|
||||
{
|
||||
get => TypedParameters.Path;
|
||||
set
|
||||
{
|
||||
var parameters = TypedParameters;
|
||||
parameters.Path = value;
|
||||
TypedParameters = parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum TaskType
|
||||
@@ -654,4 +667,4 @@ public enum UploadTaskStatus
|
||||
Completed = TaskStatus.Completed,
|
||||
Failed = TaskStatus.Failed,
|
||||
Expired = TaskStatus.Expired
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,7 +615,14 @@ public class PersistentTaskService(
|
||||
var chunkSize = request.ChunkSize ?? 1024 * 1024 * 5; // 5MB default
|
||||
var chunksCount = (int)Math.Ceiling((double)request.FileSize / chunkSize);
|
||||
|
||||
// Use the default pool if no pool is specified, or find first available pool
|
||||
// If the second chunk is too small (less than 1MB), merge it with the first chunk
|
||||
if (chunksCount == 2 && (request.FileSize - chunkSize) < 1024 * 1024)
|
||||
{
|
||||
chunksCount = 1;
|
||||
chunkSize = request.FileSize;
|
||||
}
|
||||
|
||||
// Use the default pool if no pool is specified, or find the first available pool
|
||||
var poolId = request.PoolId ?? await GetFirstAvailablePoolIdAsync();
|
||||
|
||||
var uploadTask = new PersistentUploadTask
|
||||
@@ -632,6 +639,7 @@ public class PersistentTaskService(
|
||||
EncryptPassword = request.EncryptPassword,
|
||||
ExpiredAt = request.ExpiredAt,
|
||||
Hash = request.Hash,
|
||||
Path = request.Path,
|
||||
AccountId = accountId,
|
||||
Status = TaskStatus.InProgress,
|
||||
UploadedChunks = [],
|
||||
@@ -1132,4 +1140,4 @@ public class RecentActivity
|
||||
public double Progress { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user