|
5 | 5 | using System.Text.RegularExpressions;
|
6 | 6 | using Microsoft.AspNetCore.Authorization;
|
7 | 7 | using Microsoft.AspNetCore.Mvc;
|
| 8 | +using Microsoft.AspNetCore.StaticFiles; |
8 | 9 | using Shoko.Models.Enums;
|
9 | 10 | using Shoko.Server.API.Annotations;
|
10 | 11 | using Shoko.Server.API.ModelBinders;
|
@@ -160,6 +161,31 @@ public ActionResult<File> GetFileByAnidbFileID([FromRoute] int anidbFileID, [Fro
|
160 | 161 | return new File(HttpContext, file, includeXRefs, includeDataFrom, includeMediaInfo);
|
161 | 162 | }
|
162 | 163 |
|
| 164 | + /// <summary> |
| 165 | + /// Returns a file stream for the specified file ID. |
| 166 | + /// </summary> |
| 167 | + /// <param name="fileID">Shoko ID</param> |
| 168 | + /// <returns>A file stream for the specified file.</returns> |
| 169 | + [HttpGet("{fileID}/Stream")] |
| 170 | + public ActionResult GetFileStream([FromRoute] int fileID) |
| 171 | + { |
| 172 | + var file = RepoFactory.VideoLocal.GetByID(fileID); |
| 173 | + if (file == null) |
| 174 | + return NotFound(FileNotFoundWithFileID); |
| 175 | + |
| 176 | + var bestLocation = file.GetBestVideoLocalPlace(); |
| 177 | + |
| 178 | + var fileInfo = bestLocation.GetFile(); |
| 179 | + if (fileInfo == null) |
| 180 | + return InternalError("Unable to find physical file for reading the stream data."); |
| 181 | + |
| 182 | + var provider = new FileExtensionContentTypeProvider(); |
| 183 | + if (!provider.TryGetContentType(fileInfo.FullName, out var contentType)) |
| 184 | + contentType = "application/octet-stream"; |
| 185 | + |
| 186 | + return PhysicalFile(fileInfo.FullName, contentType, enableRangeProcessing: true); |
| 187 | + } |
| 188 | + |
163 | 189 | /// <summary>
|
164 | 190 | /// Get the MediaInfo model for file with VideoLocal ID
|
165 | 191 | /// </summary>
|
|
0 commit comments