30060fe29c
基于 upstream/master (c5922f9) 新建分支,移植以下功能:
1. 扫码登录(DyQrCodeService + ConfigController 3个接口)
2. 视频预览组件(VideoPlayer.vue)
3. 下载配置服务(DownloadConfigService + AppConfig 6个扩展字段)
4. Gitea CI/CD(.gitea/workflows/deploy.yml)
5. 生产 Dockerfile(Dockerfile.prod,含中国镜像源配置)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
122 lines
4.4 KiB
C#
122 lines
4.4 KiB
C#
using dy.net.model.entity;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace dy.net.service
|
|
{
|
|
/// <summary>
|
|
/// 下载配置服务,用于判断是否应该下载视频
|
|
/// </summary>
|
|
public class DownloadConfigService
|
|
{
|
|
private readonly DouyinCommonService _commonService;
|
|
|
|
public DownloadConfigService(DouyinCommonService commonService)
|
|
{
|
|
_commonService = commonService;
|
|
}
|
|
|
|
private AppConfig GetConfig()
|
|
{
|
|
return _commonService.GetConfig();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断是否应该下载视频
|
|
/// </summary>
|
|
/// <param name="videoType">视频类型:"1"=喜欢,"2"=收藏</param>
|
|
/// <param name="authorId">作者ID</param>
|
|
/// <param name="authorName">作者名称</param>
|
|
/// <param name="createTime">视频创建时间</param>
|
|
/// <returns>true=应该下载,false=不应该下载</returns>
|
|
public bool ShouldDownload(string videoType, string authorId, string authorName, DateTime createTime)
|
|
{
|
|
var config = GetConfig();
|
|
if (config == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// 如果未启用自动下载,直接返回false
|
|
if (config.EnableAutoDownload != true)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// 检查视频类型是否允许下载
|
|
if (videoType == "1" && config.DownloadFavorite != true)
|
|
{
|
|
return false; // 喜欢类型但未启用下载
|
|
}
|
|
|
|
if (videoType == "2" && config.DownloadCollect != true)
|
|
{
|
|
return false; // 收藏类型但未启用下载
|
|
}
|
|
|
|
// 检查时间范围
|
|
if (config.DownloadDaysRange.HasValue && config.DownloadDaysRange.Value > 0)
|
|
{
|
|
var daysDiff = (DateTime.Now - createTime).TotalDays;
|
|
if (daysDiff > config.DownloadDaysRange.Value)
|
|
{
|
|
return false; // 超出时间范围
|
|
}
|
|
}
|
|
|
|
// 检查作者白名单
|
|
if (!string.IsNullOrWhiteSpace(config.AuthorWhitelist))
|
|
{
|
|
try
|
|
{
|
|
var whitelist = JsonConvert.DeserializeObject<List<string>>(config.AuthorWhitelist);
|
|
if (whitelist != null && whitelist.Any())
|
|
{
|
|
// 如果配置了白名单,只有白名单中的作者才下载
|
|
var isInWhitelist = whitelist.Any(a =>
|
|
(!string.IsNullOrWhiteSpace(authorId) && a.Equals(authorId, StringComparison.OrdinalIgnoreCase)) ||
|
|
(!string.IsNullOrWhiteSpace(authorName) && a.Equals(authorName, StringComparison.OrdinalIgnoreCase))
|
|
);
|
|
if (!isInWhitelist)
|
|
{
|
|
return false; // 不在白名单中
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Serilog.Log.Warning($"解析作者白名单失败:{ex.Message}");
|
|
}
|
|
}
|
|
|
|
// 检查作者黑名单
|
|
if (!string.IsNullOrWhiteSpace(config.AuthorBlacklist))
|
|
{
|
|
try
|
|
{
|
|
var blacklist = JsonConvert.DeserializeObject<List<string>>(config.AuthorBlacklist);
|
|
if (blacklist != null && blacklist.Any())
|
|
{
|
|
// 如果配置了黑名单,黑名单中的作者不下载
|
|
var isInBlacklist = blacklist.Any(a =>
|
|
(!string.IsNullOrWhiteSpace(authorId) && a.Equals(authorId, StringComparison.OrdinalIgnoreCase)) ||
|
|
(!string.IsNullOrWhiteSpace(authorName) && a.Equals(authorName, StringComparison.OrdinalIgnoreCase))
|
|
);
|
|
if (isInBlacklist)
|
|
{
|
|
return false; // 在黑名单中
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Serilog.Log.Warning($"解析作者黑名单失败:{ex.Message}");
|
|
}
|
|
}
|
|
|
|
// 所有检查都通过,可以下载
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|