Compare commits

..

No commits in common. "3812a46e2f85602392b7620dd9085d9875e444ca" and "69cd60000e91a03acae244eb3c38b544e773212a" have entirely different histories.

4 changed files with 8 additions and 21 deletions

View File

@ -53,10 +53,10 @@ public class FileController : ControllerBase {
return Ok();
}
[HttpPost("complete")]
public async Task<IActionResult> FilePostComplete(string fileId, [FromForm] CompleteFileDto dto) {
[HttpPost("complete/{ticket}")]
public async Task<IActionResult> FilePostComplete(string fileId, string ticket) {
var metadata = await _knowledgeFileHandler.GetFileMetadata(fileId);
if (metadata.Ticket != dto.Ticket) {
if (metadata.Ticket != ticket) {
return this.ProblemFromCode(ErrorCodes.TicketMismatch);
}
@ -80,10 +80,6 @@ public record UploadFileDto(
IFormFile File
);
public record CompleteFileDto(
string Ticket
);
internal record FileStatus(
bool IsCompleted,
string Md5,

View File

@ -38,8 +38,8 @@ public class KnowledgeFileHandler {
return $"{FilePath}/{fileId}.part.{rangeStart}-{rangeEnd}";
}
public string GetFileName(string fileId, string suffix) {
return $"{FilePath}/{fileId}.{suffix}";
public string GetFileName(string fileId) {
return $"{FilePath}/{fileId}";
}
public async Task SaveFileSlice(string fileId, IFormFile file, ulong rangeStart, ulong rangeEnd) {
@ -69,7 +69,7 @@ public class KnowledgeFileHandler {
}
}
var fileStream = File.Create(GetFileName(fileId, metadata.Suffix));
var fileStream = File.Create($"{FilePath}/{fileId}");
foreach (var slice in slices) {
var sliceStream = File.OpenRead(GetSliceFileName(fileId, slice.Item1, slice.Item2));
await sliceStream.CopyToAsync(fileStream);
@ -79,13 +79,10 @@ public class KnowledgeFileHandler {
}
fileStream.Close();
metadata.IsCompleted = true;
await SaveFileMetadata(fileId, metadata);
}
public async Task<Memory<byte>> ReadRanged(string fileId, ulong rangeStart, ulong rangeEnd) {
var metadata = await GetFileMetadata(fileId);
var fileStream = File.OpenRead(GetFileName(fileId, metadata.Suffix));
var fileStream = File.OpenRead($"{FilePath}/{fileId}");
var buffer = new Memory<byte>(new byte[rangeEnd - rangeStart]);
await fileStream.ReadExactlyAsync(buffer);
fileStream.Close();

View File

@ -29,7 +29,7 @@ public class TencentCosHandler {
public async Task UploadFile(string fileId, string fileSuffix) {
var uploadTask = new COSXMLUploadTask(_tencentCosOptions.Bucket, $"{fileId}.{fileSuffix}");
uploadTask.SetSrcPath(_knowledgeFileHandler.GetFileName(fileId, fileSuffix));
uploadTask.SetSrcPath(_knowledgeFileHandler.GetFileName(fileId));
await _transferManager.UploadAsync(uploadTask);
}
}

View File

@ -2,7 +2,6 @@ using System.Text.Json;
using AicsKnowledgeBase_file.Handlers;
using AicsKnowledgeBase_file.Models;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.FileProviders;
Directory.CreateDirectory("./files");
@ -42,11 +41,6 @@ if (app.Environment.IsDevelopment()) {
app.MapGet("/hello", () => "hello");
app.UseStaticFiles(new StaticFileOptions {
FileProvider = new PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "files")),
RequestPath = "/static"
});
app.UseHttpsRedirection();
app.MapControllers();