Repository navigation
Expand file tree
/
Copy pathFileMakerContainersController.cs
More file actions
47 lines (42 loc) · 2.25 KB
/
Copy pathFileMakerContainersController.cs
File metadata and controls
47 lines (42 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Codeer.LowCode.Blazor.Connectors.FileMaker;
using Codeer.LowCode.Blazor.Connectors.FileMaker.Server;
using Codeer.LowCode.Blazor.Extras.Server.AuditLog;
using LowCodeApp.Server.Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace LowCodeApp.Server.Controllers
{
//FileMaker のオブジェクトフィールドのダウンロード。読めるかの判定 (レコード・フィールドの権限・オブジェクトのフィールドか) は GetContainerAsync が持つ
[Authorize, AutoValidateAntiforgeryToken]
[ApiController]
public class FileMakerContainersController : ControllerBase, IAsyncDisposable
{
readonly DataService _dataService;
readonly AuditContext _audit;
public FileMakerContainersController(DataService dataService, AuditContext audit)
{
_dataService = dataService;
_audit = audit;
}
[NonAction]
public async ValueTask DisposeAsync()
=> await _dataService.DisposeAsync();
[HttpGet(FileMakerContainerFieldDesign.DownloadUrl), Audit(AuditCategory.Export)]
public async Task<IActionResult> DownloadAsync(string? module, string? id, string? field)
{
_audit.AddTarget(module ?? string.Empty, id, $"FileMakerContainer:{field}");
var file = await FileMakerContainers.GetContainerAsync(_dataService.DbAccess, _dataService.ModuleDataIO, _dataService.Design.DesignData, module, id, field);
if (file == null) return NotFound();
//ブラウザで開かせない (保存させる)。ファイル名は File が Content-Disposition に符号化して入れる
Response.Headers.XContentTypeOptions = "nosniff";
return File(file.Content, "application/octet-stream", SafeFileName(file.FileName));
}
//パスの区切り・制御文字を外す (名前は FileMaker に保存された利用者の入力)
static string SafeFileName(string name)
{
var chars = name.Select(c => char.IsControl(c) || c is '/' or '\\' or '"' ? '_' : c).ToArray();
var safe = new string(chars).Trim().Trim('.');
return string.IsNullOrEmpty(safe) ? "download" : safe;
}
}
}