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

View File

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

View File

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

View File

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