优化,去掉原来兼容考虑的逻辑

This commit is contained in:
jianzhichu
2026-01-08 21:24:53 +08:00
parent a943a13347
commit 00e28fc334
6 changed files with 39 additions and 77 deletions
+13 -53
View File
@@ -3,10 +3,7 @@ using dy.net.service;
using dy.net.utils;
using dy.sync.lib;
using Serilog;
using System.Drawing;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime;
using System.Text;
namespace dy.net
@@ -24,31 +21,22 @@ namespace dy.net
/// </summary>
public static void Main(string[] args)
{
// 初始化编码提供器
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// 构建Web应用
var builder = WebApplication.CreateBuilder(args);
var isDevelopment = builder.Environment.IsDevelopment();
// 配置主机
ConfigureHost(builder, isDevelopment);
// 配置服务--数据库保存路径从命令行参数传入的第一个参数
ConfigureServices(builder.Services, builder.Configuration, builder.Environment, args.Length > 0 ? args[0] : "");
// 构建应用
var app = builder.Build();
// 配置中间件
ConfigureMiddleware(app, builder.Environment);
Log.Debug($"dy.sync app is started successfully on {DefaultListenUrl}");
// 初始化应用服务
InitApplicationServices(app, isDevelopment);
//Log.Debug($"同步任务执行顺序:collect → favorite → followed → follow_user-->默认30分钟执行一次...");
Console.WriteLine();
app.Run();
}
@@ -58,24 +46,17 @@ namespace dy.net
/// </summary>
private static void ConfigureHost(WebApplicationBuilder builder, bool isDevelopment)
{
InitAppsettings(builder);
//from docker yaml file 环境变量 或者 dockerfile 或appsettings.json
DefaultListenUrl = $"http://*:{builder.Configuration.GetValue<string>(SystemStaticUtil.APP_PORT) ?? DefaultListenUrl}";
// 设置监听地址
builder.WebHost.UseUrls(DefaultListenUrl);
// 配置日志
builder.ConfigureLogging();
}
//// 配置配置文件
//builder.Host.ConfigureAppConfiguration((context, config) =>
//{
// //config.SetBasePath(Directory.GetCurrentDirectory())
// // .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
// // .AddEnvironmentVariables();
// // 关键:获取程序集所在的物理目录(而非当前工作目录)
// var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
// // 兜底:如果获取失败,回退到当前目录(可选)
// var basePath = string.IsNullOrEmpty(assemblyPath) ? Directory.GetCurrentDirectory() : assemblyPath;
// config.SetBasePath(basePath) // 使用程序集目录作为基础路径
// .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
// .AddEnvironmentVariables();
//});
private static void InitAppsettings(WebApplicationBuilder builder)
{
// 配置配置文件
builder.Host.ConfigureAppConfiguration((context, config) =>
{
@@ -131,16 +112,6 @@ namespace dy.net
configFileName);
}
});
//from docker yaml file 环境变量 或者 dockerfile 或appsettings.json
DefaultListenUrl = $"http://*:{builder.Configuration.GetValue<string>(SystemStaticUtil.APP_PORT) ?? DefaultListenUrl}";
// 设置监听地址
builder.WebHost.UseUrls(DefaultListenUrl);
// 配置日志
builder.Host.ConfigureLogging(logging => logging.ClearProviders())
.UseSerilog();
builder.ConfigureLogging();
}
/// <summary>
@@ -156,9 +127,6 @@ namespace dy.net
// 雪花ID生成器
services.AddSnowFlakeId(options => options.WorkId = new Random().Next(1, 100));
// MVC控制器+异常拦截器
services.AddControllers().AddGlobalExceptionFilter();
@@ -243,15 +211,13 @@ namespace dy.net
{
// 初始化用户
var userService = services.GetRequiredService<AdminUserService>();
userService.InitUser();
userService.InitUser("douyin","douyin2026");
var commonService = services.GetRequiredService<DouyinCommonService>();
// 更新视频类型--兼容老版本
commonService.UpdateCollectViedoType();
// 更新视频类型--兼容老版本--不再需要
//commonService.UpdateCollectViedoType();
// 重置博主作品同步状态为未同步
commonService.UpdateAllCookieSyncedToZero();
// 初始化配置
var config = commonService.InitConfig();
if (!isDevelopment)
@@ -259,8 +225,6 @@ namespace dy.net
// 启动定时任务
var quartzJobService = services.GetRequiredService<DouyinQuartzJobService>();
quartzJobService.InitOrReStartAllJobs(config?.Cron <= 0 ? "30" : config.Cron.ToString());
DouyinHttpHelper.GetTenImage(Appsettings.Get("tagName"));//查询镜像版本
}
// 初始化Cookie
@@ -270,10 +234,6 @@ namespace dy.net
var cookieService = services.GetRequiredService<DouyinCookieService>();
cookieService.InitCookie();
}
}
catch (Exception ex)
{
@@ -3,7 +3,7 @@
<Project>
<PropertyGroup>
<_PublishTargetUrl>E:\code\dysync\bin\Release\net6.0\publish\</_PublishTargetUrl>
<History>True|2026-01-08T06:51:18.2266231Z||;True|2026-01-08T14:31:55.1137120+08:00||;True|2026-01-08T00:16:24.4451490+08:00||;True|2026-01-08T00:14:20.7430793+08:00||;True|2026-01-08T00:07:46.7228194+08:00||;True|2026-01-07T23:52:13.3290082+08:00||;True|2026-01-07T23:49:28.4838650+08:00||;True|2026-01-07T23:47:45.1936189+08:00||;True|2026-01-07T23:35:09.7818611+08:00||;True|2026-01-07T23:20:43.7462863+08:00||;True|2026-01-07T23:04:39.5140429+08:00||;False|2026-01-07T23:04:36.5367611+08:00||;True|2026-01-07T22:53:14.6013449+08:00||;True|2026-01-07T22:49:59.9549006+08:00||;True|2026-01-07T22:36:40.0254856+08:00||;False|2026-01-07T22:36:28.8275903+08:00||;True|2026-01-07T21:59:51.4355171+08:00||;True|2026-01-03T21:38:51.4307034+08:00||;True|2026-01-02T19:09:16.9668906+08:00||;False|2026-01-02T19:09:11.7496369+08:00||;True|2026-01-02T15:42:08.2215697+08:00||;True|2026-01-02T09:46:56.1654861+08:00||;True|2026-01-02T09:35:28.0211225+08:00||;True|2026-01-01T23:07:01.9022045+08:00||;False|2026-01-01T23:06:56.0537216+08:00||;True|2026-01-01T22:16:10.2974067+08:00||;True|2026-01-01T22:16:06.2123787+08:00||;False|2026-01-01T22:15:33.3626979+08:00||;True|2026-01-01T22:01:30.7161900+08:00||;True|2026-01-01T21:10:19.3664263+08:00||;True|2026-01-01T21:09:38.6071080+08:00||;True|2025-12-30T11:45:54.5543034+08:00||;True|2025-12-30T09:19:08.3178124+08:00||;True|2025-12-29T18:57:29.7032246+08:00||;True|2025-12-27T14:52:24.4780776+08:00||;False|2025-12-27T14:52:19.5635794+08:00||;True|2025-12-27T14:48:01.6252748+08:00||;False|2025-12-27T14:47:55.7976192+08:00||;True|2025-12-27T14:38:23.9723838+08:00||;True|2025-12-27T13:00:29.8583858+08:00||;True|2025-12-26T22:18:42.4015637+08:00||;True|2025-12-26T22:10:58.5274572+08:00||;True|2025-12-26T22:06:26.3129600+08:00||;True|2025-12-26T22:03:55.6718618+08:00||;False|2025-12-26T22:03:48.3809954+08:00||;True|2025-12-26T22:02:33.1840390+08:00||;True|2025-12-26T22:01:16.1660100+08:00||;True|2025-12-25T00:50:26.1116465+08:00||;True|2025-12-25T00:48:27.3087708+08:00||;True|2025-12-25T00:47:38.4835720+08:00||;</History>
<History>True|2026-01-08T13:07:57.5094466Z||;True|2026-01-08T14:51:18.2266231+08:00||;True|2026-01-08T14:31:55.1137120+08:00||;True|2026-01-08T00:16:24.4451490+08:00||;True|2026-01-08T00:14:20.7430793+08:00||;True|2026-01-08T00:07:46.7228194+08:00||;True|2026-01-07T23:52:13.3290082+08:00||;True|2026-01-07T23:49:28.4838650+08:00||;True|2026-01-07T23:47:45.1936189+08:00||;True|2026-01-07T23:35:09.7818611+08:00||;True|2026-01-07T23:20:43.7462863+08:00||;True|2026-01-07T23:04:39.5140429+08:00||;False|2026-01-07T23:04:36.5367611+08:00||;True|2026-01-07T22:53:14.6013449+08:00||;True|2026-01-07T22:49:59.9549006+08:00||;True|2026-01-07T22:36:40.0254856+08:00||;False|2026-01-07T22:36:28.8275903+08:00||;True|2026-01-07T21:59:51.4355171+08:00||;True|2026-01-03T21:38:51.4307034+08:00||;True|2026-01-02T19:09:16.9668906+08:00||;False|2026-01-02T19:09:11.7496369+08:00||;True|2026-01-02T15:42:08.2215697+08:00||;True|2026-01-02T09:46:56.1654861+08:00||;True|2026-01-02T09:35:28.0211225+08:00||;True|2026-01-01T23:07:01.9022045+08:00||;False|2026-01-01T23:06:56.0537216+08:00||;True|2026-01-01T22:16:10.2974067+08:00||;True|2026-01-01T22:16:06.2123787+08:00||;False|2026-01-01T22:15:33.3626979+08:00||;True|2026-01-01T22:01:30.7161900+08:00||;True|2026-01-01T21:10:19.3664263+08:00||;True|2026-01-01T21:09:38.6071080+08:00||;True|2025-12-30T11:45:54.5543034+08:00||;True|2025-12-30T09:19:08.3178124+08:00||;True|2025-12-29T18:57:29.7032246+08:00||;True|2025-12-27T14:52:24.4780776+08:00||;False|2025-12-27T14:52:19.5635794+08:00||;True|2025-12-27T14:48:01.6252748+08:00||;False|2025-12-27T14:47:55.7976192+08:00||;True|2025-12-27T14:38:23.9723838+08:00||;True|2025-12-27T13:00:29.8583858+08:00||;True|2025-12-26T22:18:42.4015637+08:00||;True|2025-12-26T22:10:58.5274572+08:00||;True|2025-12-26T22:06:26.3129600+08:00||;True|2025-12-26T22:03:55.6718618+08:00||;False|2025-12-26T22:03:48.3809954+08:00||;True|2025-12-26T22:02:33.1840390+08:00||;True|2025-12-26T22:01:16.1660100+08:00||;True|2025-12-25T00:50:26.1116465+08:00||;True|2025-12-25T00:48:27.3087708+08:00||;True|2025-12-25T00:47:38.4835720+08:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
+2
View File
@@ -490,6 +490,8 @@ namespace dy.net.extension
/// </summary>
public static void ConfigureLogging(this WebApplicationBuilder builder)
{
builder.Host.ConfigureLogging(logging => logging.ClearProviders())
.UseSerilog();
string dateFile = "";// DateTime.Now.ToString("yyyyMMdd");
Log.Logger = new LoggerConfiguration()
+1 -1
View File
@@ -23,7 +23,7 @@ namespace dy.net.job
var now = DateTime.Now;
if (now.Hour == 1 && now.Minute < 30)
{
douyinCommonService.UpdateAllCookieSyncedToZero();
//douyinCommonService.UpdateAllCookieSyncedToZero();
//顺手清理下日志文件
LogFileCleaner.CleanOldLogFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs"), 1);
await Task.Delay(200);
+3 -3
View File
@@ -30,12 +30,12 @@ namespace dy.net.service
return await _userRepository.UpdateAvatar(avatar);
}
public (int code, string erro) InitUser()
public (int code, string erro) InitUser(string UserName,string Password)
{
AdminUserInfo userInfo = new AdminUserInfo
{
UserName = "douyin",
Password = "douyin2026",
UserName = UserName,
Password = Password,
CreateTime = DateTime.Now
};
return _userRepository.InitUser(userInfo);