feat: 视频预览/数据看板/下载配置 三项业务功能
- 新增视频预览:VideoPlayer 组件、VideoController/DyCollectVideoService/Repository、VideoPageRequestDTO 对应后端改动 - 新增数据看板:workplace/statics.vue、RecordTable、相关 store/http/axios 改动 - 新增下载配置:DownloadConfigService、ConfigController、AppSet.vue、AppConfig - 其他:DyHttpClientService / 同步 Job(Collect, Favorit) / Cookie 表 / CommonService / ServiceExtension 的配套调整 - 仓库卫生:.gitignore 追加 feiniu 过滤;运维脚本归档到 docs/scripts/
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
using dy.net.model;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace dy.net.service
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载配置服务,用于判断是否应该下载视频
|
||||
/// </summary>
|
||||
public class DownloadConfigService
|
||||
{
|
||||
private readonly CommonService _commonService;
|
||||
|
||||
public DownloadConfigService(CommonService 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user