video playback and timeline playhead
This commit is contained in:
27
AZKiServer/Controllers/MediaController.cs
Normal file
27
AZKiServer/Controllers/MediaController.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using AZKiServer.Services;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace AZKiServer.Controllers;
|
||||
|
||||
[Route("/m/")]
|
||||
public class MediaController(MediaService mediaService, IConfiguration configuration) : Controller
|
||||
{
|
||||
private readonly string _basePath = configuration["SCAN_LOCATION"] ?? throw new NullReferenceException("SCAN_LOCATION is not set");
|
||||
|
||||
[HttpGet("v/{id}")]
|
||||
[ResponseCache(Duration = int.MaxValue)]
|
||||
public async Task<IActionResult> VideoAsync(ObjectId id)
|
||||
{
|
||||
var media = await mediaService.GetEntryAsync(id);
|
||||
if (media == null)
|
||||
return NotFound();
|
||||
if (media.Type != Models.MediaType.Video)
|
||||
return BadRequest();
|
||||
var filePath = Path.Combine(_basePath, media.Filepath);
|
||||
//var fs = new FileStream(, FileMode.Open);
|
||||
return PhysicalFile(filePath, "video/mp4", true);
|
||||
}
|
||||
}
|
||||
@@ -53,10 +53,10 @@ builder.Services.AddCors(o =>
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true });
|
||||
app.UseCors();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseCors();
|
||||
|
||||
|
||||
//app.UseAuthentication();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using AZKiServer.Models;
|
||||
|
||||
using MaybeError;
|
||||
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Driver;
|
||||
@@ -39,6 +41,11 @@ public class MediaService(IMongoDatabase db)
|
||||
return await _entries.Find(filter).ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<MediaEntry?> GetEntryAsync(ObjectId id, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _entries.Find(e => e.Id == id).FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
public async Task DeleteAllEntriesAsync(IEnumerable<ObjectId> ids, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await _entries.DeleteManyAsync(e => ids.Contains(e.Id), cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user