guoziyun 9 mesi fa
parent
commit
c175de7d5e

+ 14 - 1
oms/dist/src/app.js

@@ -7,7 +7,7 @@ exports.clickhouseService = exports.redisClient = void 0;
 // oms/src/app.ts
 const dotenv_1 = __importDefault(require("dotenv"));
 dotenv_1.default.config(); // 在读取环境变量之前加载 .env 文件
-const express_1 = __importDefault(require("express"));
+const express_1 = __importDefault(require("express")); // 导入 NextFunction
 const redis_1 = require("redis");
 const path_1 = __importDefault(require("path"));
 const apiRoutes_1 = __importDefault(require("./routes/apiRoutes"));
@@ -52,6 +52,19 @@ app.use((req, res, next) => {
     console.log(`[API Request] ${new Date().toISOString()} - ${req.method} ${req.originalUrl}`);
     next();
 });
+// --- 在这里添加全局禁用缓存的中间件 ---
+app.use("/api", (req, res, next) => {
+    // 为所有 API 路由显式禁用浏览器缓存
+    res.set({
+        "Cache-Control": "no-cache, no-store, must-revalidate",
+        Pragma: "no-cache",
+        Expires: "0",
+        ETag: null, // 移除ETag以强制浏览器重新验证
+        "Last-Modified": null, // 移除Last-Modified以强制浏览器重新验证
+    });
+    next();
+});
+// ------------------------------------
 // API routes
 app.use("/api", apiRoutes_1.default);
 // 动态设置公共目录和Angular应用路径

+ 3 - 3
oms/dist/src/scripts/active-user-daily-notify.ts.js

@@ -220,10 +220,10 @@ async function run() {
         const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
         // 性能优化:只查询需要的字段(_id, fmToken, lang, cc),避免加载整个文档
         const activeUsers = await userModel_1.User.find({
-            // lastActiveAt: { $gte: sevenDaysAgo },
+            lastActiveAt: { $gte: sevenDaysAgo },
             fmToken: { $nin: [null, ""] },
-            versionName: { $in: ["5.8.0-debug"] },
-            //   versionName: { $in: ["5.8.0", "5.8.0-debug"] },
+            //   versionName: { $in: ["5.8.0-debug"] },
+            versionName: { $in: ["5.8.0", "5.8.0-debug"] },
         })
             .select("_id uid fmToken lang cc")
             .lean();

+ 16 - 2
oms/src/app.ts

@@ -2,7 +2,7 @@
 import dotenv from "dotenv";
 dotenv.config(); // 在读取环境变量之前加载 .env 文件
 
-import express, { Request, Response } from "express";
+import express, { Request, Response, NextFunction } from "express"; // 导入 NextFunction
 import { createClient } from "redis";
 import path from "path";
 import apiRoutes from "./routes/apiRoutes";
@@ -48,11 +48,25 @@ redisClient.on("error", (err: any) => console.error("Redis connection error:", e
 app.use(express.json());
 
 // 新增中间件:为每个API请求添加日志打印
-app.use((req: Request, res: Response, next) => {
+app.use((req: Request, res: Response, next: NextFunction) => {
   console.log(`[API Request] ${new Date().toISOString()} - ${req.method} ${req.originalUrl}`);
   next();
 });
 
+// --- 在这里添加全局禁用缓存的中间件 ---
+app.use("/api", (req: Request, res: Response, next: NextFunction) => {
+  // 为所有 API 路由显式禁用浏览器缓存
+  res.set({
+    "Cache-Control": "no-cache, no-store, must-revalidate",
+    Pragma: "no-cache",
+    Expires: "0",
+    ETag: null, // 移除ETag以强制浏览器重新验证
+    "Last-Modified": null, // 移除Last-Modified以强制浏览器重新验证
+  });
+  next();
+});
+// ------------------------------------
+
 // API routes
 app.use("/api", apiRoutes);
 

+ 3 - 3
oms/src/scripts/active-user-daily-notify.ts.ts

@@ -209,10 +209,10 @@ export async function run(): Promise<void> {
 
     // 性能优化:只查询需要的字段(_id, fmToken, lang, cc),避免加载整个文档
     const activeUsers = await User.find({
-      // lastActiveAt: { $gte: sevenDaysAgo },
+      lastActiveAt: { $gte: sevenDaysAgo },
       fmToken: { $nin: [null, ""] },
-      versionName: { $in: ["5.8.0-debug"] },
-      //   versionName: { $in: ["5.8.0", "5.8.0-debug"] },
+      //   versionName: { $in: ["5.8.0-debug"] },
+      versionName: { $in: ["5.8.0", "5.8.0-debug"] },
     })
       .select("_id uid fmToken lang cc")
       .lean<IUser[]>();