Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e6b0b21a6 | |||
| 19274d444d |
2
.github/workflows/release.yaml
vendored
2
.github/workflows/release.yaml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkou code
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Build
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace AobaServer.Controllers;
|
||||
public class MediaController(AobaService aobaService, ILogger<MediaController> logger) : Controller
|
||||
{
|
||||
[HttpGet("{id}")]
|
||||
[HttpGet("{id}/*")]
|
||||
[HttpGet("{id}/{*fn}")]
|
||||
[ResponseCache(Duration = int.MaxValue)]
|
||||
public async Task<IActionResult> MediaAsync(ObjectId id, [FromServices] MongoClient client, CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -29,6 +29,22 @@ public class MediaController(AobaService aobaService, ILogger<MediaController> l
|
||||
return File(file, mime, true);
|
||||
}
|
||||
|
||||
[HttpGet("{id}/dl")]
|
||||
[HttpGet("{id}/dl/{*fn}")]
|
||||
[ResponseCache(Duration = int.MaxValue)]
|
||||
public async Task<IActionResult> DownloadMediaAsync(ObjectId id, [FromServices] MongoClient client, [FromQuery] string? fn = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var file = await aobaService.GetFileStreamAsync(id, seekable: true, cancellationToken: cancellationToken);
|
||||
if (file.HasError)
|
||||
{
|
||||
logger.LogError(file.Error.Exception, "Failed to load media stream");
|
||||
return NotFound();
|
||||
}
|
||||
var mime = MimeTypesMap.GetMimeType(file.Value.FileInfo.Filename);
|
||||
_ = aobaService.IncrementViewCountAsync(id, cancellationToken);
|
||||
return File(file, mime, fn ?? file.Value.FileInfo.Filename, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirect legacy media urls to the new url
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user