@blocklet/uploader-server 0.1.70 → 0.1.72

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.
@@ -85,16 +85,16 @@ export const initStaticResourceMiddleware = ({
85
85
  }
86
86
  mappingResource();
87
87
  return (req, res, next) => {
88
- const urlPath = new URL(`http://localhost${req.url}`).pathname;
88
+ const fileName = basename(req.url);
89
89
  const matchCanUseResourceItem = canUseResources.find((item) => {
90
- if (!existsSync(join(item.dir, urlPath))) {
90
+ const { whitelist, blacklist } = item;
91
+ if (whitelist?.length && !whitelist.some((ext) => fileName.endsWith(ext))) {
91
92
  return false;
92
93
  }
93
- const { whitelist, blacklist } = item;
94
- if (whitelist?.length && !whitelist.some((ext) => urlPath.endsWith(ext))) {
94
+ if (blacklist?.length && blacklist.some((ext) => fileName.endsWith(ext))) {
95
95
  return false;
96
96
  }
97
- if (blacklist?.length && blacklist.some((ext) => urlPath.endsWith(ext))) {
97
+ if (!existsSync(join(item.dir, fileName))) {
98
98
  return false;
99
99
  }
100
100
  return true;
@@ -117,11 +117,9 @@ export const initProxyToMediaKitUploadsMiddleware = ({ options, express } = {})
117
117
  if (!mediaKitInfo?.webEndpoint) {
118
118
  return next();
119
119
  }
120
- const filename = basename(req.url);
121
- req.url = joinUrl("/uploads/", filename);
122
120
  setPDFDownloadHeader(req, res);
123
121
  proxy.once("proxyRes", (proxyRes, req2, res2) => {
124
- if (proxyRes.statusCode >= 200 && proxyRes.statusCode < 300) {
122
+ if (proxyRes.statusCode >= 200 && proxyRes.statusCode < 400) {
125
123
  res2.writeHead(proxyRes.statusCode, proxyRes.headers);
126
124
  proxyRes.pipe(res2);
127
125
  } else {
@@ -135,7 +133,7 @@ export const initProxyToMediaKitUploadsMiddleware = ({ options, express } = {})
135
133
  req,
136
134
  res,
137
135
  {
138
- target: mediaKitInfo.webEndpoint,
136
+ target: joinUrl(mediaKitInfo.webEndpoint, "/uploads", basename(req.url)),
139
137
  changeOrigin: true,
140
138
  selfHandleResponse: true,
141
139
  ...options
@@ -102,19 +102,19 @@ const initStaticResourceMiddleware = ({
102
102
  }
103
103
  mappingResource();
104
104
  return (req, res, next) => {
105
- const urlPath = new URL(`http://localhost${req.url}`).pathname;
105
+ const fileName = basename(req.url);
106
106
  const matchCanUseResourceItem = canUseResources.find(item => {
107
- if (!existsSync(join(item.dir, urlPath))) {
108
- return false;
109
- }
110
107
  const {
111
108
  whitelist,
112
109
  blacklist
113
110
  } = item;
114
- if (whitelist?.length && !whitelist.some(ext => urlPath.endsWith(ext))) {
111
+ if (whitelist?.length && !whitelist.some(ext => fileName.endsWith(ext))) {
112
+ return false;
113
+ }
114
+ if (blacklist?.length && blacklist.some(ext => fileName.endsWith(ext))) {
115
115
  return false;
116
116
  }
117
- if (blacklist?.length && blacklist.some(ext => urlPath.endsWith(ext))) {
117
+ if (!existsSync(join(item.dir, fileName))) {
118
118
  return false;
119
119
  }
120
120
  return true;
@@ -142,11 +142,9 @@ const initProxyToMediaKitUploadsMiddleware = ({
142
142
  if (!mediaKitInfo?.webEndpoint) {
143
143
  return next();
144
144
  }
145
- const filename = basename(req.url);
146
- req.url = joinUrl("/uploads/", filename);
147
145
  setPDFDownloadHeader(req, res);
148
146
  proxy.once("proxyRes", (proxyRes, req2, res2) => {
149
- if (proxyRes.statusCode >= 200 && proxyRes.statusCode < 300) {
147
+ if (proxyRes.statusCode >= 200 && proxyRes.statusCode < 400) {
150
148
  res2.writeHead(proxyRes.statusCode, proxyRes.headers);
151
149
  proxyRes.pipe(res2);
152
150
  } else {
@@ -157,7 +155,7 @@ const initProxyToMediaKitUploadsMiddleware = ({
157
155
  next(err);
158
156
  });
159
157
  proxy.web(req, res, {
160
- target: mediaKitInfo.webEndpoint,
158
+ target: joinUrl(mediaKitInfo.webEndpoint, "/uploads", basename(req.url)),
161
159
  changeOrigin: true,
162
160
  selfHandleResponse: true,
163
161
  ...options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/uploader-server",
3
- "version": "0.1.70",
3
+ "version": "0.1.72",
4
4
  "description": "blocklet upload server",
5
5
  "publishConfig": {
6
6
  "access": "public"