|
|
@@ -1,4 +1,5 @@
|
|
1
|
1
|
using System.ComponentModel.DataAnnotations;
|
|
|
2
|
+using System.IO;
|
|
2
|
3
|
using Luticate2.Utils.Dbo.Basic;
|
|
3
|
4
|
using Luticate2.Utils.Dbo.FsFiles;
|
|
4
|
5
|
using Luticate2.Utils.Dbo.PaginatedRequest;
|
|
|
@@ -6,20 +7,47 @@ using Luticate2.Utils.Interfaces;
|
|
6
|
7
|
using Luticate2.Utils.Utils;
|
|
7
|
8
|
using Microsoft.AspNetCore.Http;
|
|
8
|
9
|
using Microsoft.AspNetCore.Mvc;
|
|
|
10
|
+using Microsoft.AspNetCore.StaticFiles;
|
|
9
|
11
|
using Microsoft.Extensions.Options;
|
|
10
|
12
|
|
|
11
|
13
|
namespace Luticate2.Utils.Controllers
|
|
12
|
14
|
{
|
|
13
|
|
- public class LuFsFilesCrudController<TBusiness> : LuController
|
|
|
15
|
+ public abstract class LuFsFilesCrudController<TBusiness> : LuController
|
|
14
|
16
|
where TBusiness : ILuCrudInterface<LuFsFilesAddDbo, LuFsFilesDbo, LuFsFilesAddDbo, string>
|
|
15
|
17
|
{
|
|
16
|
18
|
protected readonly TBusiness Business;
|
|
17
|
19
|
|
|
18
|
|
- public LuFsFilesCrudController(IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo, TBusiness business) : base(luUtilsOptionsDbo)
|
|
|
20
|
+ protected LuFsFilesCrudController(IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo, TBusiness business) : base(luUtilsOptionsDbo)
|
|
19
|
21
|
{
|
|
20
|
22
|
Business = business;
|
|
21
|
23
|
}
|
|
22
|
24
|
|
|
|
25
|
+ protected abstract string GetBasePath();
|
|
|
26
|
+
|
|
|
27
|
+ [HttpGet]
|
|
|
28
|
+ [Route("[controller]/{id}/raw")]
|
|
|
29
|
+ public virtual IActionResult GetSingleByIdRaw([Required]string id, bool forceDownload = false)
|
|
|
30
|
+ {
|
|
|
31
|
+ var get = Business.GetSingleById(id);
|
|
|
32
|
+ if (!get)
|
|
|
33
|
+ {
|
|
|
34
|
+ throw new LuResultException(get.To<object>());
|
|
|
35
|
+ }
|
|
|
36
|
+ string type;
|
|
|
37
|
+ var contentTypeProvider = new FileExtensionContentTypeProvider();
|
|
|
38
|
+ if (!contentTypeProvider.TryGetContentType(id, out type))
|
|
|
39
|
+ {
|
|
|
40
|
+ type = "application/octet-stream";
|
|
|
41
|
+ }
|
|
|
42
|
+ var fullPath = Path.Combine(new FileInfo(GetBasePath()).FullName, get.Data.Path);
|
|
|
43
|
+ var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
|
|
|
44
|
+ if (forceDownload)
|
|
|
45
|
+ {
|
|
|
46
|
+ return File(stream, type, get.Data.Path);
|
|
|
47
|
+ }
|
|
|
48
|
+ return new FileStreamResult(stream, type);
|
|
|
49
|
+ }
|
|
|
50
|
+
|
|
23
|
51
|
[HttpGet]
|
|
24
|
52
|
[Route("[controller]/{id}")]
|
|
25
|
53
|
public virtual LuApiWrapperDbo<LuFsFilesDbo> GetSingleById([Required]string id)
|