🗑️ Remove the fast upload endpoint
This commit is contained in:
@@ -348,110 +348,4 @@ public class FileController(
|
||||
var count = await fs.DeleteAllRecycledFilesAsync();
|
||||
return Ok(new { Count = count });
|
||||
}
|
||||
|
||||
public class CreateFastFileRequest
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
public long Size { get; set; }
|
||||
public string Hash { get; set; } = null!;
|
||||
public string? MimeType { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public Dictionary<string, object?>? UserMeta { get; set; }
|
||||
public Dictionary<string, object?>? FileMeta { get; set; }
|
||||
public List<Shared.Models.ContentSensitiveMark>? SensitiveMarks { get; set; }
|
||||
public Guid PoolId { get; set; }
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost("fast")]
|
||||
[RequiredPermission("global", "files.create")]
|
||||
public async Task<ActionResult<SnCloudFile>> CreateFastFile([FromBody] CreateFastFileRequest request)
|
||||
{
|
||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
|
||||
var pool = await db.Pools.FirstOrDefaultAsync(p => p.Id == request.PoolId);
|
||||
if (pool is null) return BadRequest();
|
||||
if (!currentUser.IsSuperuser && pool.AccountId != accountId)
|
||||
return StatusCode(403, "You don't have permission to create files in this pool.");
|
||||
|
||||
if (!pool.PolicyConfig.EnableFastUpload)
|
||||
return StatusCode(
|
||||
403,
|
||||
"This pool does not allow fast upload"
|
||||
);
|
||||
|
||||
if (pool.PolicyConfig.RequirePrivilege > 0)
|
||||
{
|
||||
if (currentUser.PerkSubscription is null)
|
||||
{
|
||||
return StatusCode(
|
||||
403,
|
||||
$"You need to have join the Stellar Program to use this pool"
|
||||
);
|
||||
}
|
||||
|
||||
var privilege =
|
||||
PerkSubscriptionPrivilege.GetPrivilegeFromIdentifier(currentUser.PerkSubscription.Identifier);
|
||||
if (privilege < pool.PolicyConfig.RequirePrivilege)
|
||||
{
|
||||
return StatusCode(
|
||||
403,
|
||||
$"You need Stellar Program tier {pool.PolicyConfig.RequirePrivilege} to use this pool, you are tier {privilege}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (request.Size > pool.PolicyConfig.MaxFileSize)
|
||||
{
|
||||
return StatusCode(
|
||||
403,
|
||||
$"File size {request.Size} is larger than the pool's maximum file size {pool.PolicyConfig.MaxFileSize}"
|
||||
);
|
||||
}
|
||||
|
||||
var (ok, billableUnit, quota) = await qs.IsFileAcceptable(
|
||||
accountId,
|
||||
pool.BillingConfig.CostMultiplier ?? 1.0,
|
||||
request.Size
|
||||
);
|
||||
if (!ok)
|
||||
{
|
||||
return StatusCode(
|
||||
403,
|
||||
$"File size {billableUnit} is larger than the user's quota {quota}"
|
||||
);
|
||||
}
|
||||
|
||||
await using var transaction = await db.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
var file = new SnCloudFile
|
||||
{
|
||||
Name = request.Name,
|
||||
Size = request.Size,
|
||||
Hash = request.Hash,
|
||||
MimeType = request.MimeType,
|
||||
Description = request.Description,
|
||||
AccountId = accountId,
|
||||
UserMeta = request.UserMeta,
|
||||
FileMeta = request.FileMeta,
|
||||
SensitiveMarks = request.SensitiveMarks,
|
||||
PoolId = request.PoolId
|
||||
};
|
||||
db.Files.Add(file);
|
||||
await db.SaveChangesAsync();
|
||||
await fs._PurgeCacheAsync(file.Id);
|
||||
await transaction.CommitAsync();
|
||||
|
||||
file.FastUploadLink = await fs.CreateFastUploadLinkAsync(file);
|
||||
|
||||
return file;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user