whistle.pastekitlab 1.8.3 → 1.8.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 +41 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -86,6 +86,41 @@ function shouldIntercept(url) {
86
86
  }
87
87
  }
88
88
 
89
+ // ==================== 资源类型过滤 ====================
90
+ function isResourceRequest(url, headers = {}) {
91
+ // 检查文件扩展名
92
+ const resourceExtensions = [
93
+ '.jpg', '.jpeg', '.png', '.gif', '.svg', '.webp', '.ico', // 图片
94
+ '.css', '.scss', '.less', // 样式
95
+ '.js', '.mjs', '.ts', // 脚本
96
+ '.woff', '.woff2', '.ttf', '.eot', '.otf', // 字体
97
+ '.mp3', '.mp4', '.avi', '.mov', '.wmv', '.flv', // 视频
98
+ '.pdf', '.zip', '.rar', '.7z', '.tar', '.gz' // 文档和压缩
99
+ ];
100
+
101
+ const urlLower = url.toLowerCase();
102
+ if (resourceExtensions.some(ext => urlLower.includes(ext))) {
103
+ return true;
104
+ }
105
+
106
+ // 检查 Content-Type(如果有)
107
+ const contentType = headers['content-type'] || '';
108
+ const resourceTypes = [
109
+ 'image/',
110
+ 'text/css',
111
+ 'application/javascript',
112
+ 'font/',
113
+ 'video/',
114
+ 'audio/'
115
+ ];
116
+
117
+ if (resourceTypes.some(type => contentType.includes(type))) {
118
+ return true;
119
+ }
120
+
121
+ return false;
122
+ }
123
+
89
124
  // ==================== WebSocket ====================
90
125
  function startWebSocketServer() {
91
126
  if (wss) return;
@@ -190,6 +225,12 @@ module.exports = (server, options) => {
190
225
  const url = req.fullUrl || req.url;
191
226
  console.log('>>> [GLOBAL]', url);
192
227
 
228
+ // 过滤资源类请求(图片、CSS、JS等)
229
+ if (isResourceRequest(url, req.headers)) {
230
+ log(`跳过资源请求: ${url}`);
231
+ return forwardRequest(req, res, url);
232
+ }
233
+
193
234
  // 域名过滤:如果不匹配则直接放行,不转发也不通知
194
235
  if (!shouldIntercept(url)) {
195
236
  log(`跳过未配置的域名: ${url}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whistle.pastekitlab",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "description": "Whistle plugin for PasteKit Lab - Intercepts requests and sends them to requestlistviewer via WebSocket",
5
5
  "main": "index.js",
6
6
  "scripts": {