Controllers/DownloadController.cs
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using HeyRed.Mime;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Tmp.Models;
namespace Tmp.Controllers;
[Route("download")]
public class DownloadController : Controller
{
private readonly Configuration Configuration;
public DownloadController(IOptions<Configuration> options)
{
Configuration = options.Value;
}
[HttpHead("file/{cipher}/{filePath}")]
public IActionResult HttpHead(string filePath, string cipher)
{
// 构建文件的完整路径
var fullPath = Path.Combine(Configuration.UploadPath, $"{cipher}", filePath);
// 检查文件是否存在
if (!System.IO.File.Exists(fullPath))
{
return NotFound();
}
Response.Headers.Add("Accept-Ranges", "bytes");
return Ok();
}
[HttpGet("file/{cipher}/{filePath}")]
public IActionResult Download(string filePath, string cipher)
{
// 构建文件的完整路径
var fullPath = Path.Combine(Configuration.UploadPath, $"{cipher}", filePath);
// 检查文件是否存在
if (!System.IO.File.Exists(fullPath))
{
return NotFound();
}
// 获取文件信息
var fileInfo = new FileInfo(fullPath);
var fileSize = fileInfo.Length;
// 检查是否支持断点续传
var isRangeRequest = Request.Headers.ContainsKey("Range");
if (isRangeRequest)
{
// 解析 Range 头部,获取断点续传的起始位置和结束位置
var rangeHeader = Request.Headers["Range"].ToString();
var (startByte, endByte) = GetRange(rangeHeader, fileSize);
// 设置响应头部
Response.StatusCode = 206; // Partial Content
后面还有 56 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
