mm_statics 1.7.1 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +30 -6
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -298,7 +298,7 @@ Static.prototype._sendFile = async function (ctx, path) {
298
298
  };
299
299
  }
300
300
 
301
- await send(ctx, path, config);
301
+ return await send(ctx, path, config);
302
302
  };
303
303
 
304
304
  /**
@@ -652,34 +652,58 @@ Static.prototype._handleCompiledResp = async function (url, path, body, ctx) {
652
652
  }
653
653
  };
654
654
 
655
+ /**
656
+ * 获取真实路径
657
+ * @param {string} path 文件路径
658
+ * @returns {string} 真实路径
659
+ */
660
+ Static.prototype._getRealPath = function (path) {
661
+ return path.replace(this.config.path, "/");
662
+ }
663
+
664
+ /**
665
+ * 将路由路径转换为物理路径
666
+ * @param {string} path 文件路径
667
+ * @returns {string} 根路径
668
+ */
669
+ Static.prototype._pathToRoot = function (path) {
670
+ return ("." + path).fullname(this.config.root);
671
+ }
672
+
655
673
  /**
656
674
  * 主处理函数
657
675
  * @param {object} ctx Koa上下文对象
658
676
  * @param {Function} next Koa中间件函数
659
677
  */
660
678
  Static.prototype.main = async function (ctx, next) {
661
- const url = ctx.url; // 使用完整URL(包含查询参数)
662
- const path = ctx.path; // 仅用于文件路径检查
679
+ let url = ctx.url; // 使用完整URL(包含查询参数)
680
+ if (!ctx.path.startsWith(this.config.path)) {
681
+ await next();
682
+ return '';
683
+ }
684
+
685
+ let path = this._getRealPath(ctx.path);
663
686
 
664
687
  // 检查缓存
665
688
  if (await this._handleCache(url, ctx)) {
666
- return;
689
+ return this._pathToRoot(path);
667
690
  }
668
691
 
669
692
  // 处理文件编译
670
693
  let body = await this._handleFileCompile(path);
671
694
  if (body) {
672
695
  await this._handleCompiledResp(url, path, body, ctx);
673
- return;
696
+ return this._pathToRoot(path);
674
697
  }
675
698
 
676
699
  // 直接发送文件
677
700
  try {
678
- await this._sendFile(ctx, path);
701
+ return await this._sendFile(ctx, path);
679
702
  }
680
703
  catch {
681
704
  await next();
682
705
  }
706
+ return '';
683
707
  };
684
708
 
685
709
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_statics",
3
- "version": "1.7.1",
3
+ "version": "1.7.4",
4
4
  "description": "这是超级美眉statics函数模块,用于web服务端statics缓存",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -49,8 +49,8 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "eslint": "^9.39.2",
52
- "eslint-plugin-jsdoc": "^62.4.1",
53
- "mm_eslint": "^1.5.7",
52
+ "eslint-plugin-jsdoc": "^62.5.0",
53
+ "mm_eslint": "^1.6.3",
54
54
  "mocha": "^11.7.5",
55
55
  "supertest": "^7.2.2"
56
56
  }