代码优化

master
xiaochanghai 8 months ago
parent f1a8bbee88
commit 9f21b5dad7
  1. 11
      Tiobon.Core.Api/Controllers/FileController.cs
  2. 17
      Tiobon.Core.Services/Ghre/Ghre_AttachmentServices.cs
  3. 2
      Tiobon.Core.Services/Ghre/Ghre_CourseWareServices.cs

@ -155,10 +155,10 @@ public class FileController : BaseApiController
AttachFileName = fileAttachment.AttachFileName,
AttachmentName = fileName,
AttachmentNo = fileAttachment.AttachmentNo,
FileURL = fileAttachment.FileURL,
PhysicsPath = fileAttachment.PhysicsPath,
RelativePath = fileAttachment.RelativePath,
ThumbnailPath = fileAttachment.ThumbnailPath,
FileURL = "/Advanced" + fileAttachment.FileURL,
PhysicsPath = "/Advanced" + fileAttachment.PhysicsPath,
RelativePath = "/Advanced" + fileAttachment.RelativePath,
ThumbnailPath = "/Advanced" + fileAttachment.ThumbnailPath,
AttachFileSize = fileAttachment.AttachFileSize,
});
@ -226,12 +226,13 @@ public class FileController : BaseApiController
/// </summary>
/// <param name="path">主键ID</param>
/// <returns></returns>
[HttpGet("DownloadByPath/{path}"), AllowAnonymous]
[HttpGet("DownloadByPath"), AllowAnonymous]
public async Task<IActionResult> DownloadByPath(string path)
{
try
{
path = WebUtility.UrlDecode(path);
path = path.Replace("/Advanced", null);
var file = await _ghre_AttachmentServices.QuerySingle(x => x.RelativePath == path);
return await Download(file.Id);

@ -39,16 +39,17 @@ namespace Tiobon.Core.Services
if (upload.chunkIndex == upload.totalChunks - 1)
{
var id = SnowFlakeSingle.Instance.NextId();
await FileMerge(upload.id, ".mp4", id);
using var _context = ContextFactory.CreateContext();
var ext = string.Empty;
if (string.IsNullOrEmpty(file.FileName) == false)
{
var dotPos = upload.fileName.LastIndexOf('.');
ext = upload.fileName.Substring(dotPos + 1);
}
var id = SnowFlakeSingle.Instance.NextId();
await FileMerge(upload.id, "."+ ext, id);
using var _context = ContextFactory.CreateContext();
var filePath = $"/files/upload/{id}.{ext}";
var fileAttachment = new Ghre_Attachment();
fileAttachment.Id = SnowFlakeSingle.Instance.NextId();
@ -74,10 +75,10 @@ namespace Tiobon.Core.Services
AttachFileName = fileAttachment.AttachFileName,
AttachmentName = fileAttachment.AttachmentName,
AttachmentNo = fileAttachment.AttachmentNo,
FileURL = fileAttachment.FileURL,
PhysicsPath = fileAttachment.PhysicsPath,
RelativePath = fileAttachment.RelativePath,
ThumbnailPath = fileAttachment.ThumbnailPath,
FileURL = "/Advanced" + fileAttachment.FileURL,
PhysicsPath = "/Advanced" + fileAttachment.PhysicsPath,
RelativePath = "/Advanced" + fileAttachment.RelativePath,
ThumbnailPath = "/Advanced" + fileAttachment.ThumbnailPath,
AttachFileSize = fileAttachment.AttachFileSize,
});
}

@ -201,7 +201,7 @@ public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_Course
return ServiceResult<string>.OprateFailed("无效的课件ID!");
var attachments = await _ghre_CourseWareAttachmentServices.Query(x => x.CourseWareId == id);
var webRootPath = _hostingEnvironment.WebRootPath;
var outPath = $"/files/upload/{result.CourseWareName}_{result.VersionNo}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
var outPath = $"/Advanced/files/upload/{result.CourseWareName}_{result.VersionNo}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip";
var files = attachments.Select(x => $"{webRootPath}{"\\" + x.RelativePath}").ToArray();
if (files.Length > 0)
{

Loading…
Cancel
Save