diff --git a/Learn.VideoAnalysis.API/Expand/HttpFilter.cs b/Learn.VideoAnalysis.API/Expand/HttpFilter.cs index e3512e6..8d75c44 100644 --- a/Learn.VideoAnalysis.API/Expand/HttpFilter.cs +++ b/Learn.VideoAnalysis.API/Expand/HttpFilter.cs @@ -253,7 +253,7 @@ namespace Learn.VideoAnalysis.API.Expand } catch (Exception ex) { - Console.WriteLine($"{DateTime.Now}=>接口规范出现异常"); + Console.WriteLine($"{DateTime.Now}=>接口出现异常"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } diff --git a/VideoAnalysis/Program.cs b/VideoAnalysis/Program.cs index c7e713d..52e96d2 100644 --- a/VideoAnalysis/Program.cs +++ b/VideoAnalysis/Program.cs @@ -28,94 +28,13 @@ namespace Learn.VideoAnalysis { public class Program { - public static void CleanHarFile(string inputPath, string outputPath) - { - try - { - // 1. 读取原始文件 - var jsonString = File.ReadAllText(inputPath); - var root = JsonNode.Parse(jsonString)!; - var entries = root["log"]?["entries"]?.AsArray(); - - if (entries == null) return; - - // 过滤关键词 - var blackList = new[] { "google", "gstatic", "doubleclick", "analytics", "facebook", "recaptcha" }; - - // 2. 逻辑清理 (从后往前) - for (int i = entries.Count - 1; i >= 0; i--) - { - var entry = entries[i]; - string url = entry?["request"]?["url"]?.GetValue().ToLower() ?? ""; - string resourceType = entry?["_resourceType"]?.GetValue().ToLower() ?? ""; - - // 判定是否保留 (必须是 API 且 不在黑名单内) - bool isApi = (resourceType == "xhr" || resourceType == "fetch"); - bool isBlacklisted = blackList.Any(k => url.Contains(k)); - - if (!isApi || isBlacklisted) - { - entries.RemoveAt(i); - continue; - } - - // 3. 结构瘦身 - if (entry?["_initiator"] is JsonObject initiator) - { - initiator.Remove("stack"); - initiator.Remove("callFrames"); - } - - // 移除所有以下划线开头的非标准扩展字段 (Chrome 专用字段) - var entryObj = entry.AsObject(); - var keysToRemove = entryObj.Where(kv => kv.Key.StartsWith("_")).Select(kv => kv.Key).ToList(); - foreach (var key in keysToRemove) entryObj.Remove(key); - } - - // 4. 极限压缩配置 - var options = new JsonSerializerOptions - { - // 核心:禁用缩进,输出单行压缩格式 - WriteIndented = false, - // 核心:防止斜杠等字符被转义成 \u002F,保持原始字符减少长度 - Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, - // 忽略值为 null 的字段,进一步减小体积 - DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull - }; - - // 5. 写入文件 - string compressedJson = root.ToJsonString(options); - File.WriteAllText(outputPath, compressedJson); - - long originalSize = new FileInfo(inputPath).Length; - long newSize = new FileInfo(outputPath).Length; - - Console.WriteLine("--- 压缩统计 ---"); - Console.WriteLine($"原始大小: {originalSize / 1024.0:F2} KB"); - Console.WriteLine($"压缩后大小: {newSize / 1024.0:F2} KB"); - Console.WriteLine($"压缩率: {(1.0 - (double)newSize / originalSize) * 100:F2}%"); - Console.WriteLine($"保留请求数: {entries.Count}"); - } - catch (Exception ex) - { - Console.WriteLine($"处理失败: {ex.Message}"); - } - } public static void Main(string[] args) { - // 调用方法 - CleanHarFile("C:\\Users\\Administrator\\Downloads\\kream.co.kr.har", "C:\\Users\\Administrator\\Downloads\\kream.co.kr.API压缩.har"); - - - - - - - - //交互式环境选择函数 AppConfigExpand.SelectEnvironment(ref args); + + var builder = WebApplication.CreateBuilder(args); //设置接口请求体最大100m builder.WebHost.ConfigureKestrel(serverOptions => diff --git a/VideoAnalysisCore/Common/RedisExpand.cs b/VideoAnalysisCore/Common/RedisExpand.cs index d8e5c8f..7eeb6bb 100644 --- a/VideoAnalysisCore/Common/RedisExpand.cs +++ b/VideoAnalysisCore/Common/RedisExpand.cs @@ -152,7 +152,14 @@ namespace VideoAnalysisCore.Common Redis = redis; } - + public void JoinQueue(string ChannelKey,params long[] taskIds) + { + if (taskIds is null || taskIds.Length == 0) + return; + // 直接批量推入,避免循环和事务开销 + var d = taskIds.Select(s => (object)s).ToArray(); + Redis.LPush(ChannelKey, d); + } /// /// 缓存GPT任务缓存 /// diff --git a/VideoAnalysisCore/Controllers/LJZK_Controller.cs b/VideoAnalysisCore/Controllers/LJZK_Controller.cs index cdad991..0059a6b 100644 --- a/VideoAnalysisCore/Controllers/LJZK_Controller.cs +++ b/VideoAnalysisCore/Controllers/LJZK_Controller.cs @@ -40,11 +40,10 @@ namespace VideoAnalysisCore.Controllers private readonly Repository videoQuestionDB; private readonly Repository videoQuestionKonwDB; private readonly RedisManager redisManager; - readonly VideoSliceWorkflowManager videoSliceWorkflowManager; public LJZK_Controller(IMapper mp, Repository nodesubscriptionDB, Repository videoTaskDB = null, Repository videoKonwPointDB = null - , Repository nodePackageInfoDB = null, Repository videoQuestionDB = null, Repository videoQuestionKonwDB = null, Repository courseInfoDB = null, RedisManager redisManager = null, Repository videoTaskStageDB = null, VideoSliceWorkflowManager videoSliceWorkflowManager = null) + , Repository nodePackageInfoDB = null, Repository videoQuestionDB = null, Repository videoQuestionKonwDB = null, Repository courseInfoDB = null, RedisManager redisManager = null, Repository videoTaskStageDB = null) { this.mp = mp; this.nodesubscriptionDB = nodesubscriptionDB; @@ -56,7 +55,6 @@ namespace VideoAnalysisCore.Controllers this.courseInfoDB = courseInfoDB; this.redisManager = redisManager; this.videoTaskStageDB = videoTaskStageDB; - this.videoSliceWorkflowManager = videoSliceWorkflowManager; } @@ -69,7 +67,6 @@ namespace VideoAnalysisCore.Controllers [HttpPost(Name = "NodePackage")] public async Task NodePackage(NodePackageReq[] reqArr) { - Console.WriteLine($"{DateTime.Now} ļ req=" + reqArr.Count()); if (reqArr is null || reqArr.Count() == 0) return BadRequest("ЧƵб"); var videos = new List(reqArr.Count()); @@ -160,7 +157,7 @@ namespace VideoAnalysisCore.Controllers if (videos is null || videos.Count == 0) return Ok(); var ids = videos.Select(s => s.Id).ToArray(); - videoSliceWorkflowManager.JoinQueue(ids); + redisManager.JoinQueue(RedisExpandKey.ChannelKey, ids); return Ok(); } diff --git a/VideoAnalysisCore/Job/NodePackageJob.cs b/VideoAnalysisCore/Job/NodePackageJob.cs index dd26621..fd101f8 100644 --- a/VideoAnalysisCore/Job/NodePackageJob.cs +++ b/VideoAnalysisCore/Job/NodePackageJob.cs @@ -113,7 +113,9 @@ namespace VideoAnalysisCore.Job else { var res = await responseMessage.Content.ReadAsStringAsync(); - Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调失败!!! {responseMessage.StatusCode} {res}"); + Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调失败!!! VideoCode{item.VideoCode}"); + Console.WriteLine($"{responseMessage.StatusCode} {postUrl}"); + Console.WriteLine(res); } } catch (Exception ex) @@ -121,7 +123,10 @@ namespace VideoAnalysisCore.Job if (responseMessage != null) { var res = (await responseMessage?.Content?.ReadAsStringAsync()) ?? string.Empty; - Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调失败!!! {responseMessage?.StatusCode} {res}"); + Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调失败!!! VideoCode{item.VideoCode}"); + Console.WriteLine($"{responseMessage.StatusCode} {ex.Message} "); + Console.WriteLine($"{ ex.StackTrace}"); + Console.WriteLine(res); } Console.WriteLine(ex); }