1、nfo文件优化,修复演员信息(视频作者)
2、图文视频,因版权原因无法下载的音频,系统配置新增默认音频上传入口,上传成功后,后面在遇到无法下载音频时,将用该音频进行图文视频合成的音频数据 3、增加动态视频合成配置。 4、容器重启后,手机端会连续跳转登录页很多次的bug修复 5、其他优化
This commit is contained in:
@@ -28,6 +28,18 @@ namespace dy.net.Controllers
|
||||
private readonly DouyinFollowService douyinFollowService;
|
||||
private readonly DouyinCookieService douyinCookieService;
|
||||
|
||||
// 定义允许上传的音频扩展名(小写)
|
||||
private readonly string[] _allowedAudioExtensions = { ".mp3", ".wav" };
|
||||
|
||||
// 定义允许的音频 MIME 类型(增强验证)
|
||||
private readonly string[] _allowedAudioMimeTypes = {
|
||||
"audio/mpeg", "audio/wav"
|
||||
};
|
||||
|
||||
// 最大文件大小:20MB(可根据需求调整)
|
||||
private const long _maxFileSize = 20 * 1024 * 1024;
|
||||
|
||||
|
||||
public ConfigController(DouyinCookieService dyCookieService, DouyinCommonService commonService, DouyinQuartzJobService quartzJobService, DouyinFollowService douyinFollowService, DouyinCookieService douyinCookieService)
|
||||
{
|
||||
this.dyCookieService = dyCookieService;
|
||||
@@ -374,5 +386,108 @@ namespace dy.net.Controllers
|
||||
return ApiResult.Fail("请求失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 上传音频文件接口
|
||||
/// </summary>
|
||||
/// <param name="file">要上传的音频文件</param>
|
||||
/// <returns>上传结果</returns>
|
||||
[HttpPost("UploadAudio")]
|
||||
public IActionResult UploadAudio(IFormFile file)
|
||||
{
|
||||
// 1. 验证文件是否为空
|
||||
if (file == null || file.Length == 0)
|
||||
{
|
||||
return BadRequest(new { success = false, message = "请选择要上传的音频文件" });
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 2. 验证文件大小
|
||||
if (file.Length > _maxFileSize)
|
||||
{
|
||||
return BadRequest(new { success = false, message = $"文件大小超过限制(最大允许 {_maxFileSize / 1024 / 1024}MB)" });
|
||||
}
|
||||
|
||||
// 3. 获取文件扩展名并验证
|
||||
var fileExtension = Path.GetExtension(file.FileName).ToLower();
|
||||
if (!_allowedAudioExtensions.Contains(fileExtension))
|
||||
{
|
||||
return BadRequest(new
|
||||
{
|
||||
success = false,
|
||||
message = $"不支持的音频格式,仅允许:{string.Join(", ", _allowedAudioExtensions)}"
|
||||
});
|
||||
}
|
||||
|
||||
// 4. 验证 MIME 类型(可选但推荐,防止扩展名伪造)
|
||||
var contentType = file.ContentType.ToLower();
|
||||
if (!_allowedAudioMimeTypes.Contains(contentType))
|
||||
{
|
||||
return BadRequest(new
|
||||
{
|
||||
success = false,
|
||||
message = "文件类型验证失败,请上传合法的音频文件"
|
||||
});
|
||||
}
|
||||
|
||||
//先删除
|
||||
var uploadMp3 = Directory.GetFiles(Path.Combine(AppContext.BaseDirectory, "mp3"))
|
||||
.Where(filePath => Path.GetFileNameWithoutExtension(filePath) != "silent_10")
|
||||
.FirstOrDefault();
|
||||
if (!string.IsNullOrWhiteSpace(uploadMp3) && System.IO.File.Exists(uploadMp3))
|
||||
{
|
||||
System.IO.File.Delete(uploadMp3);
|
||||
}
|
||||
|
||||
|
||||
// 5. 生成唯一文件名(避免重复)
|
||||
var uniqueFileName = $"dysync_default{fileExtension}";
|
||||
|
||||
// 6. 定义文件保存路径(建议配置在 appsettings.json 中,这里简化处理)
|
||||
var uploadPath = Path.Combine(AppContext.BaseDirectory, "mp3");
|
||||
|
||||
// 确保目录存在
|
||||
if (!Directory.Exists(uploadPath))
|
||||
{
|
||||
Directory.CreateDirectory(uploadPath);
|
||||
}
|
||||
|
||||
// 7. 保存文件
|
||||
var filePath = Path.Combine(uploadPath, uniqueFileName);
|
||||
|
||||
if (System.IO.File.Exists(filePath))
|
||||
{
|
||||
System.IO.File.Delete(filePath);
|
||||
}
|
||||
using (var stream = new FileStream(filePath, FileMode.Create))
|
||||
{
|
||||
file.CopyTo(stream);
|
||||
}
|
||||
|
||||
// 8. 返回成功结果(可根据需求返回文件路径/URL 等)
|
||||
return ApiResult.Success(new { fileName = uniqueFileName, filePath });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 捕获异常并返回错误信息
|
||||
return ApiResult.Fail(ex.Message);
|
||||
}
|
||||
}
|
||||
[AllowAnonymous]
|
||||
[HttpGet("defaudio")]
|
||||
public async Task<IActionResult> GetDefaultAudioUrl()
|
||||
{
|
||||
var uploadMp3 = Directory.GetFiles(Path.Combine(AppContext.BaseDirectory, "mp3"))
|
||||
.Where(filePath => Path.GetFileNameWithoutExtension(filePath) != "silent_10")
|
||||
.FirstOrDefault();
|
||||
if (!string.IsNullOrWhiteSpace(uploadMp3) && System.IO.File.Exists(uploadMp3))
|
||||
{
|
||||
return File(System.IO.File.ReadAllBytes(uploadMp3), "application/octet-stream", Path.GetFileName(uploadMp3));
|
||||
}
|
||||
return ApiResult.Fail("未上传音频");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ namespace dy.net.Controllers
|
||||
this.logInfoService = logInfoService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetLog(string type, string date)
|
||||
[HttpGet("/api/logs/GetLog/{type}/{date}")]
|
||||
public async Task<IActionResult> GetLog([FromRoute]string type, [FromRoute] string date)
|
||||
{
|
||||
var filePath = Path.Combine(webHostEnvironment.IsDevelopment() ? Directory.GetCurrentDirectory() : AppDomain.CurrentDomain.BaseDirectory, "logs", $"log-{type}-{date}.txt");
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
var msg = $"Log file log-{type}-{date}.txt not found.";
|
||||
var msg = $"{date},没有发现{type}的日志";
|
||||
//Serilog.Log.Error(msg);
|
||||
return Ok(msg);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using dy.net.service;
|
||||
using dy.net.utils;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
|
||||
namespace dy.net.Controllers
|
||||
{
|
||||
@@ -270,5 +271,45 @@ namespace dy.net.Controllers
|
||||
var data = await douyinVideoService.DeleteInvalidVideo();
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 所有视频重新生成nfo文件
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("renfo")]
|
||||
public async Task<IActionResult> ReCreateNfo()
|
||||
{
|
||||
var videos= await douyinVideoService.GetAllAsync();
|
||||
if (videos == null || videos.Count == 0)
|
||||
{
|
||||
return ApiResult.Success("暂无视频数据需要生成NFO文件");
|
||||
}
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var totalCount = videos.Count;
|
||||
foreach (var video in videos)
|
||||
{
|
||||
try
|
||||
{
|
||||
NfoFileGenerator.GenerateVideoNfoFile(video);
|
||||
Serilog.Log.Debug($"刮削视频(Path:{video.VideoSavePath})生成NFO成功!");
|
||||
await Task.Delay(50);
|
||||
}
|
||||
catch (Exception singleEx)
|
||||
{
|
||||
Serilog.Log.Error($"刮削视频(Path:{video.VideoSavePath})生成NFO失败:{singleEx.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Serilog.Log.Error($"NFO文件生成任务执行异常:{ex.Message}\n{ex.StackTrace}");
|
||||
}
|
||||
});
|
||||
|
||||
return ApiResult.Success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user