From e92e290a4e27a6069b095003b698b31c1479718b Mon Sep 17 00:00:00 2001 From: jianzhichu Date: Sat, 24 Jan 2026 15:51:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/ConfigController.cs | 2 +- Program.cs | 26 ++++++++++++------- Properties/PublishProfiles/docker.pubxml.user | 2 +- app/src/pages/workplace/statics.vue | 2 +- job/DouyinBasicSyncJob.cs | 4 +-- job/DouyinFollowsAndCollnectsSyncJob.cs | 20 +++++++------- repository/DouyinCookieRepository.cs | 20 +++++++++++++- service/DouyinCommonService.cs | 2 +- service/DouyinCookieService.cs | 7 ++++- utils/NfoFileGenerator.cs | 6 ++--- 10 files changed, 60 insertions(+), 31 deletions(-) diff --git a/Controllers/ConfigController.cs b/Controllers/ConfigController.cs index f35cfd9..a53aed4 100644 --- a/Controllers/ConfigController.cs +++ b/Controllers/ConfigController.cs @@ -196,7 +196,7 @@ namespace dy.net.Controllers return saved ? ApiResult.Success() : ApiResult.Fail("添加失败"); } - private (bool Success, string Message) ValidatePaths(DouyinCookie cookie) + private static (bool Success, string Message) ValidatePaths(DouyinCookie cookie) { var pathsToCheck = new Dictionary { diff --git a/Program.cs b/Program.cs index 62875ef..872f983 100644 --- a/Program.cs +++ b/Program.cs @@ -217,21 +217,29 @@ namespace dy.net //commonService.UpdateCollectViedoType(); // 重置博主作品同步状态为未同步 //commonService.UpdateAllCookieSyncedToZero(); - // 初始化配置 - var config = commonService.InitConfig(); - if (!isDevelopment) - { - // 启动定时任务 - var quartzJobService = services.GetRequiredService(); - quartzJobService.InitOrReStartAllJobs(config?.Cron <= 0 ? "30" : config.Cron.ToString()); - } + // 初始化Cookie + var cookieService = services.GetRequiredService(); var deploy = Appsettings.Get("deploy"); if (deploy != null && deploy == "docker")//docker环境直接初始化一个默认的配置 { - var cookieService = services.GetRequiredService(); cookieService.InitCookie(); } + // 初始化配置 + var config = commonService.InitConfig(); + + //Serilog.Log.Debug("isRestart1=" + config.IsFirstRunning); + + //if (!isDevelopment) + { + var cookie = cookieService.GetOpendCookies(); + if (cookie != null && cookie.Any()) + { + // 启动定时任务 + var quartzJobService = services.GetRequiredService(); + quartzJobService.InitOrReStartAllJobs(config?.Cron <= 0 ? "30" : config.Cron.ToString()); + } + } } catch (Exception ex) { diff --git a/Properties/PublishProfiles/docker.pubxml.user b/Properties/PublishProfiles/docker.pubxml.user index 2ca2218..93c3872 100644 --- a/Properties/PublishProfiles/docker.pubxml.user +++ b/Properties/PublishProfiles/docker.pubxml.user @@ -3,7 +3,7 @@ <_PublishTargetUrl>E:\code\dysync\bin\Release\net6.0\publish\ - True|2026-01-23T14:14:26.8066324Z||;True|2026-01-23T13:36:48.4086406+08:00||;True|2026-01-23T13:30:27.2924204+08:00||;True|2026-01-23T13:02:53.3219368+08:00||;True|2026-01-23T13:01:54.3466638+08:00||;True|2026-01-23T13:01:28.8560809+08:00||;True|2026-01-22T23:18:32.0400436+08:00||;True|2026-01-22T22:29:29.5746209+08:00||;True|2026-01-22T21:32:21.7284081+08:00||;True|2026-01-22T21:20:26.5985955+08:00||;False|2026-01-22T21:20:21.1372539+08:00||;True|2026-01-22T21:11:18.3771739+08:00||;True|2026-01-22T20:58:55.9862778+08:00||;True|2026-01-22T20:51:48.6699461+08:00||;False|2026-01-22T20:51:42.2079210+08:00||;True|2026-01-22T20:50:34.7280114+08:00||;True|2026-01-22T20:50:11.1588492+08:00||;True|2026-01-22T16:11:14.0626037+08:00||;True|2026-01-22T15:53:16.6377347+08:00||;True|2026-01-22T15:45:34.0935091+08:00||;True|2026-01-22T12:44:28.1577014+08:00||;True|2026-01-22T12:40:45.7449335+08:00||;True|2026-01-22T12:39:07.0683214+08:00||;True|2026-01-22T09:55:49.7086190+08:00||;True|2026-01-22T01:37:53.6972395+08:00||;True|2026-01-22T01:34:14.2142463+08:00||;True|2026-01-22T01:32:50.9228911+08:00||;True|2026-01-22T01:29:43.8871986+08:00||;True|2026-01-22T01:29:40.7838709+08:00||;True|2026-01-22T01:27:34.4763970+08:00||;True|2026-01-22T01:26:55.0117367+08:00||;True|2026-01-22T01:23:19.4789587+08:00||;True|2026-01-19T10:19:44.8997385+08:00||;True|2026-01-19T10:11:10.2305307+08:00||;True|2026-01-17T00:52:08.8180346+08:00||;False|2026-01-17T00:52:03.1829000+08:00||;True|2026-01-17T00:45:04.0498090+08:00||;True|2026-01-16T21:00:57.7239379+08:00||;True|2026-01-16T21:00:03.3912989+08:00||;True|2026-01-16T20:56:08.5505592+08:00||;True|2026-01-16T20:46:32.3067302+08:00||;True|2026-01-15T22:18:57.9835738+08:00||;True|2026-01-15T22:07:25.4753938+08:00||;True|2026-01-15T22:07:14.8243754+08:00||;True|2026-01-15T21:40:13.2613927+08:00||;True|2026-01-15T20:57:56.6291682+08:00||;True|2026-01-15T20:57:47.1363536+08:00||;True|2026-01-15T20:08:44.4710883+08:00||;True|2026-01-15T20:04:51.8284314+08:00||;False|2026-01-15T20:04:45.3258155+08:00||;True|2026-01-15T19:59:11.7907672+08:00||;True|2026-01-15T01:10:48.9066941+08:00||;True|2026-01-15T01:03:23.6216975+08:00||;True|2026-01-15T01:03:16.3364591+08:00||;False|2026-01-15T01:03:10.5654436+08:00||;True|2026-01-15T00:49:21.6559622+08:00||;True|2026-01-15T00:10:42.7288439+08:00||;True|2026-01-15T00:06:28.4241682+08:00||;True|2026-01-13T22:34:15.2372411+08:00||;True|2026-01-13T22:26:46.4522947+08:00||;True|2026-01-13T22:15:56.9735179+08:00||;True|2026-01-13T22:15:51.8250677+08:00||;False|2026-01-13T22:15:46.6608690+08:00||;True|2026-01-13T22:03:06.4683237+08:00||;False|2026-01-13T22:03:01.2036027+08:00||;True|2026-01-13T21:36:05.8776209+08:00||;True|2026-01-13T21:33:02.0766289+08:00||;False|2026-01-13T21:32:57.1976141+08:00||;True|2026-01-13T19:14:35.2519439+08:00||;True|2026-01-13T15:07:50.0836745+08:00||;False|2026-01-13T15:06:35.5929685+08:00||;True|2026-01-13T10:21:41.6012776+08:00||;True|2026-01-13T09:57:25.4788847+08:00||;True|2026-01-13T09:53:14.4900360+08:00||;True|2026-01-13T09:23:53.6465295+08:00||;True|2026-01-12T22:04:14.5886955+08:00||;False|2026-01-12T22:04:08.2008101+08:00||;True|2026-01-12T21:53:46.9947176+08:00||;True|2026-01-12T21:11:15.8358024+08:00||;True|2026-01-12T21:09:51.8663228+08:00||;True|2026-01-11T21:25:07.5052845+08:00||;False|2026-01-11T21:24:27.5744557+08:00||;True|2026-01-11T19:59:15.4734611+08:00||;False|2026-01-11T19:59:04.9543339+08:00||;True|2026-01-11T18:51:30.6649269+08:00||;True|2026-01-08T21:07:57.5094466+08:00||;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-24T07:47:01.6934638Z||;True|2026-01-24T15:32:35.6316009+08:00||;True|2026-01-24T15:16:28.7216639+08:00||;True|2026-01-23T22:14:26.8066324+08:00||;True|2026-01-23T13:36:48.4086406+08:00||;True|2026-01-23T13:30:27.2924204+08:00||;True|2026-01-23T13:02:53.3219368+08:00||;True|2026-01-23T13:01:54.3466638+08:00||;True|2026-01-23T13:01:28.8560809+08:00||;True|2026-01-22T23:18:32.0400436+08:00||;True|2026-01-22T22:29:29.5746209+08:00||;True|2026-01-22T21:32:21.7284081+08:00||;True|2026-01-22T21:20:26.5985955+08:00||;False|2026-01-22T21:20:21.1372539+08:00||;True|2026-01-22T21:11:18.3771739+08:00||;True|2026-01-22T20:58:55.9862778+08:00||;True|2026-01-22T20:51:48.6699461+08:00||;False|2026-01-22T20:51:42.2079210+08:00||;True|2026-01-22T20:50:34.7280114+08:00||;True|2026-01-22T20:50:11.1588492+08:00||;True|2026-01-22T16:11:14.0626037+08:00||;True|2026-01-22T15:53:16.6377347+08:00||;True|2026-01-22T15:45:34.0935091+08:00||;True|2026-01-22T12:44:28.1577014+08:00||;True|2026-01-22T12:40:45.7449335+08:00||;True|2026-01-22T12:39:07.0683214+08:00||;True|2026-01-22T09:55:49.7086190+08:00||;True|2026-01-22T01:37:53.6972395+08:00||;True|2026-01-22T01:34:14.2142463+08:00||;True|2026-01-22T01:32:50.9228911+08:00||;True|2026-01-22T01:29:43.8871986+08:00||;True|2026-01-22T01:29:40.7838709+08:00||;True|2026-01-22T01:27:34.4763970+08:00||;True|2026-01-22T01:26:55.0117367+08:00||;True|2026-01-22T01:23:19.4789587+08:00||;True|2026-01-19T10:19:44.8997385+08:00||;True|2026-01-19T10:11:10.2305307+08:00||;True|2026-01-17T00:52:08.8180346+08:00||;False|2026-01-17T00:52:03.1829000+08:00||;True|2026-01-17T00:45:04.0498090+08:00||;True|2026-01-16T21:00:57.7239379+08:00||;True|2026-01-16T21:00:03.3912989+08:00||;True|2026-01-16T20:56:08.5505592+08:00||;True|2026-01-16T20:46:32.3067302+08:00||;True|2026-01-15T22:18:57.9835738+08:00||;True|2026-01-15T22:07:25.4753938+08:00||;True|2026-01-15T22:07:14.8243754+08:00||;True|2026-01-15T21:40:13.2613927+08:00||;True|2026-01-15T20:57:56.6291682+08:00||;True|2026-01-15T20:57:47.1363536+08:00||;True|2026-01-15T20:08:44.4710883+08:00||;True|2026-01-15T20:04:51.8284314+08:00||;False|2026-01-15T20:04:45.3258155+08:00||;True|2026-01-15T19:59:11.7907672+08:00||;True|2026-01-15T01:10:48.9066941+08:00||;True|2026-01-15T01:03:23.6216975+08:00||;True|2026-01-15T01:03:16.3364591+08:00||;False|2026-01-15T01:03:10.5654436+08:00||;True|2026-01-15T00:49:21.6559622+08:00||;True|2026-01-15T00:10:42.7288439+08:00||;True|2026-01-15T00:06:28.4241682+08:00||;True|2026-01-13T22:34:15.2372411+08:00||;True|2026-01-13T22:26:46.4522947+08:00||;True|2026-01-13T22:15:56.9735179+08:00||;True|2026-01-13T22:15:51.8250677+08:00||;False|2026-01-13T22:15:46.6608690+08:00||;True|2026-01-13T22:03:06.4683237+08:00||;False|2026-01-13T22:03:01.2036027+08:00||;True|2026-01-13T21:36:05.8776209+08:00||;True|2026-01-13T21:33:02.0766289+08:00||;False|2026-01-13T21:32:57.1976141+08:00||;True|2026-01-13T19:14:35.2519439+08:00||;True|2026-01-13T15:07:50.0836745+08:00||;False|2026-01-13T15:06:35.5929685+08:00||;True|2026-01-13T10:21:41.6012776+08:00||;True|2026-01-13T09:57:25.4788847+08:00||;True|2026-01-13T09:53:14.4900360+08:00||;True|2026-01-13T09:23:53.6465295+08:00||;True|2026-01-12T22:04:14.5886955+08:00||;False|2026-01-12T22:04:08.2008101+08:00||;True|2026-01-12T21:53:46.9947176+08:00||;True|2026-01-12T21:11:15.8358024+08:00||;True|2026-01-12T21:09:51.8663228+08:00||;True|2026-01-11T21:25:07.5052845+08:00||;False|2026-01-11T21:24:27.5744557+08:00||;True|2026-01-11T19:59:15.4734611+08:00||;False|2026-01-11T19:59:04.9543339+08:00||;True|2026-01-11T18:51:30.6649269+08:00||;True|2026-01-08T21:07:57.5094466+08:00||;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||; \ No newline at end of file diff --git a/app/src/pages/workplace/statics.vue b/app/src/pages/workplace/statics.vue index ff1adf0..4b6961b 100644 --- a/app/src/pages/workplace/statics.vue +++ b/app/src/pages/workplace/statics.vue @@ -478,7 +478,7 @@ const initFullChart = async () => { try { // 初始化全屏图表 fullChartInstance = echarts.init(fullChartRef.value); - const option = getChartOption(syncData.value); + const option = getChartOption(syncFullData.value); // 调整全屏图表的网格和字号,优化显示效果 option.grid = { left: '4%', diff --git a/job/DouyinBasicSyncJob.cs b/job/DouyinBasicSyncJob.cs index 8db944d..0c28434 100644 --- a/job/DouyinBasicSyncJob.cs +++ b/job/DouyinBasicSyncJob.cs @@ -264,7 +264,7 @@ namespace dy.net.job { var tag = cate?.Name ?? followed?.UperName ?? string.Empty; tag = !string.IsNullOrWhiteSpace(tag) ? $"-[{tag}]" : tag; - Log.Debug($"[{VideoType.GetDesc()}][{cookie.UserName}]{tag},本次成功同步{syncCount}条视频"); + Log.Debug($"[{cookie.UserName}][{VideoType.GetDesc()}]{tag},本次成功同步{syncCount}条视频"); if (cate != null) { @@ -487,7 +487,7 @@ namespace dy.net.job var videos = new List(); foreach (var item in data.AwemeList) { - //if (item.AwemeId != "7440444948844956985") + //if (item.AwemeId != "7586278721292733722") //{ // continue; //} diff --git a/job/DouyinFollowsAndCollnectsSyncJob.cs b/job/DouyinFollowsAndCollnectsSyncJob.cs index 5257be0..e6e5963 100644 --- a/job/DouyinFollowsAndCollnectsSyncJob.cs +++ b/job/DouyinFollowsAndCollnectsSyncJob.cs @@ -53,9 +53,7 @@ namespace dy.net.job foreach (var ck in cookies) { - Log.Information($"开始处理Cookie用户:[{ck.UserName}](ID:{ck.Id})"); - // 调用通用方法,传入差异化参数(无委托,参数直观) if (ck.UseCollectFolder) { await SyncCollectGenericAsync(ck, VideoTypeEnum.dy_custom_collect, @@ -116,7 +114,7 @@ namespace dy.net.job } await SyncFollowListAsync(ck, conf); - Log.Debug($"完成[{ck.UserName}] [列表]同步, 包括 [自定义收藏夹、关注、合集、短剧] "); + Log.Debug($"[{ck.UserName}]所有[基础数据(list)]同步完成,包括 [收藏列表、关注列表、合集列表、短剧列表] "); } } @@ -163,7 +161,7 @@ namespace dy.net.job if (currentItems?.Any() == true) { collectDataList.AddRange(currentItems.Select(entityConvertFunc)); - Log.Debug($"[{cookie.UserName}] - {logTag}:获取{currentItems.Count}条,累计{collectDataList.Count}条"); + Log.Debug($"[{cookie.UserName}][{logTag}]:获取{currentItems.Count}条,累计{collectDataList.Count}条"); } } @@ -171,16 +169,16 @@ namespace dy.net.job if (collectDataList.Any()) { var (add, update, delete, succ) = await _douyinCollectCateService.Sync(collectDataList, cookie.Id, cateType); - Log.Debug($"[{cookie.UserName}] - {logTag}:同步完成 新增:{add} 更新:{update} 删除:{delete} 成功:{succ}"); + Log.Debug($"[{cookie.UserName}][{logTag}]:同步完成 新增:{add} 更新:{update} 删除:{delete} 成功:{succ}"); } else { - Log.Debug($"[{cookie.UserName}] - {logTag}:无有效数据"); + Log.Debug($"[{cookie.UserName}][{logTag}]:无有效数据"); } } catch (Exception ex) { - Log.Error(ex, $"[{cookie.UserName}] - {logTag}:同步失败"); + Log.Error(ex, $"[{cookie.UserName}][{logTag}]:同步失败"); } } #endregion @@ -190,7 +188,7 @@ namespace dy.net.job { if (string.IsNullOrWhiteSpace(cookie.SecUserId)) { - Log.Debug($"[{cookie.UserName}] - {LOG_TAG_FOLLOW}:未设置SecUserId,跳过"); + Log.Debug($"[{cookie.UserName}][{LOG_TAG_FOLLOW}]:未设置SecUserId,跳过"); return; } @@ -237,20 +235,20 @@ namespace dy.net.job followList.AddRange(data.Followings); //Log.Debug($"[{cookie.UserName}] - {LOG_TAG_FOLLOW}:获取{data.Followings.Count}条,累计{followList.Count}条"); } - + //Serilog.Log.Debug("isRestart2=" + config.IsFirstRunning); if (!config.IsFirstRunning) hasMore = false; } if (followList.Any()) { var (add, update, succ) = await _followService.Sync(followList, cookie); - Log.Information($"[{cookie.UserName}] - {LOG_TAG_FOLLOW}:同步完成 新增:{add} 更新:{update} 成功:{succ} 总关注数:{total}"); + Log.Debug($"[{cookie.UserName}][{LOG_TAG_FOLLOW}]:同步完成 新增:{add} 更新:{update} 成功:{succ} 总关注数:{total}"); } await _douyinCommonService.SetConfigNotFirstRunning(); } catch (Exception ex) { - Log.Error(ex, $"[{cookie.UserName}] - {LOG_TAG_FOLLOW}:同步失败"); + Log.Error(ex, $"[{cookie.UserName}][{LOG_TAG_FOLLOW}]:同步失败"); } } #endregion diff --git a/repository/DouyinCookieRepository.cs b/repository/DouyinCookieRepository.cs index a43197a..fe78e16 100644 --- a/repository/DouyinCookieRepository.cs +++ b/repository/DouyinCookieRepository.cs @@ -12,7 +12,7 @@ namespace dy.net.repository { } - public async Task> GetAllCookies(Expression> whereExpression = null) + public async Task> GetAllCookiesAsync(Expression> whereExpression = null) { // 1. 初始化查询:先加固定条件 Status == 1 var query = Db.Queryable() @@ -29,6 +29,24 @@ namespace dy.net.repository return await query.ToListAsync(); } + public List GetAllCookies(Expression> whereExpression = null) + { + // 1. 初始化查询:先加固定条件 Status == 1 + var query = Db.Queryable() + .Where(x => x.Status == 1) + .Where(x => !string.IsNullOrWhiteSpace(x.Cookies)); // 固定条件(必选) + + // 2. 若传入自定义条件,叠加 Where(自动 AND 组合) + if (whereExpression != null) + { + query = query.Where(whereExpression); // 自定义条件(可选) + } + + // 3. 执行查询(SqlSugar 自动合并所有 Where 条件) + return query.ToList(); + } + + public async Task<(List list, int totalCount)> GetPagedAsync(int pageIndex, int pageSize) { var where = this.Db.Queryable(); diff --git a/service/DouyinCommonService.cs b/service/DouyinCommonService.cs index 933f084..4a8d4ac 100644 --- a/service/DouyinCommonService.cs +++ b/service/DouyinCommonService.cs @@ -97,7 +97,7 @@ namespace dy.net.service else { - int update = await sqlSugarClient.Updateable(config).ExecuteCommandAsync(); + int update = await sqlSugarClient.Updateable(config).IgnoreColumns(x => new { x.IsFirstRunning }).ExecuteCommandAsync(); return update > 0; } diff --git a/service/DouyinCookieService.cs b/service/DouyinCookieService.cs index 12269a0..8dae712 100644 --- a/service/DouyinCookieService.cs +++ b/service/DouyinCookieService.cs @@ -18,9 +18,14 @@ namespace dy.net.service public Task> GetOpendCookiesAsync(Expression> whereExpression = null) { - return _cookieRepository.GetAllCookies(whereExpression); + return _cookieRepository.GetAllCookiesAsync(whereExpression); } + + public List GetOpendCookies() + { + return _cookieRepository.GetAllCookies(); + } public Task> GetAllAsync() { return _cookieRepository.GetAllAsync(); diff --git a/utils/NfoFileGenerator.cs b/utils/NfoFileGenerator.cs index de4d8de..368ea13 100644 --- a/utils/NfoFileGenerator.cs +++ b/utils/NfoFileGenerator.cs @@ -42,7 +42,7 @@ namespace dy.net.utils { Directory.CreateDirectory(actorsDir); } - var nfoActorFullPath = Path.Combine(actorsDir, $"{video.Author}{fileExt}"); + var nfoActorFullPath = Path.Combine(actorsDir, $"{DouyinFileNameHelper.SanitizeLinuxFileName(video.Author,"",true)}{fileExt}"); if (!File.Exists(nfoActorFullPath)) { @@ -59,11 +59,11 @@ namespace dy.net.utils Actors = new List { new() { - Name = video.Author, + Name = DouyinFileNameHelper.SanitizeLinuxFileName(video.Author,"",true), Role = "主演", } }, - Author = video.Author, + Author = DouyinFileNameHelper.SanitizeLinuxFileName(video.Author, "", true), Poster = "poster.jpg", Title = video.VideoTitle, Thumbnail = "poster.jpg",// 使用poster作为缩略图