代码优化

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

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

@ -201,7 +201,7 @@ public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_Course
return ServiceResult<string>.OprateFailed("无效的课件ID!"); return ServiceResult<string>.OprateFailed("无效的课件ID!");
var attachments = await _ghre_CourseWareAttachmentServices.Query(x => x.CourseWareId == id); var attachments = await _ghre_CourseWareAttachmentServices.Query(x => x.CourseWareId == id);
var webRootPath = _hostingEnvironment.WebRootPath; 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(); var files = attachments.Select(x => $"{webRootPath}{"\\" + x.RelativePath}").ToArray();
if (files.Length > 0) if (files.Length > 0)
{ {

Loading…
Cancel
Save