@seayoo-web/finder 2.0.7 → 2.0.9

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.
package/dist/index.cjs CHANGED
@@ -73,7 +73,7 @@ async function request({
73
73
  reqHeaders.set(key, value);
74
74
  });
75
75
  }
76
- const requestInit = { method };
76
+ const requestInit = { method, headers: reqHeaders };
77
77
  try {
78
78
  if (data) {
79
79
  if (hasFileUpload) {
@@ -90,12 +90,7 @@ async function request({
90
90
  requestInit.headers = reqHeaders;
91
91
  requestInit.body = formData;
92
92
  } else {
93
- if (headers) {
94
- reqHeaders.set("Content-Type", "application/json");
95
- Object.entries(headers).forEach(([key, value]) => {
96
- reqHeaders.set(key, value);
97
- });
98
- }
93
+ reqHeaders.set("content-type", reqHeaders.get("content-type") || "application/json");
99
94
  requestInit.headers = reqHeaders;
100
95
  requestInit.body = JSON.stringify(data);
101
96
  }
@@ -181,7 +176,7 @@ async function upload(option) {
181
176
  }
182
177
  const filename = path.basename(target);
183
178
  const deployTarget = path.dirname(pure(target));
184
- const { status, message, data } = await request({
179
+ const { status, data } = await request({
185
180
  url: `${getFinderServerFullPath(targetServer)}${FinderApiPaths.upload}?target=${encodeURIComponent(deployTarget)}`,
186
181
  method: "POST",
187
182
  headers: { user, key },
@@ -191,13 +186,10 @@ async function upload(option) {
191
186
  }
192
187
  });
193
188
  if (status !== 200) {
194
- throw `${`上传接口错误(${status})`.bgRed} ${message || ""}.red`;
189
+ throw `上传接口错误(status ${status})`.red;
195
190
  }
196
- if (!data || typeof data !== "object") {
197
- throw `上传接口响应错误,请自行检查是否上传成功。`.bgRed + JSON.stringify(data).red;
198
- }
199
- if ("err" in data || !("data" in data) || typeof data.data !== "string") {
200
- throw `上传接口错误。`.bgRed + JSON.stringify(data).red;
191
+ if (!data || typeof data !== "object" || "err" in data && data.err || !("data" in data) || typeof data.data !== "string") {
192
+ throw `上传接口响应错误。 ${JSON.stringify(data)}`.red;
201
193
  }
202
194
  return { previewUrl: `https://${pure(target)}` };
203
195
  }
package/dist/index.js CHANGED
@@ -71,7 +71,7 @@ async function request({
71
71
  reqHeaders.set(key, value);
72
72
  });
73
73
  }
74
- const requestInit = { method };
74
+ const requestInit = { method, headers: reqHeaders };
75
75
  try {
76
76
  if (data) {
77
77
  if (hasFileUpload) {
@@ -88,12 +88,7 @@ async function request({
88
88
  requestInit.headers = reqHeaders;
89
89
  requestInit.body = formData;
90
90
  } else {
91
- if (headers) {
92
- reqHeaders.set("Content-Type", "application/json");
93
- Object.entries(headers).forEach(([key, value]) => {
94
- reqHeaders.set(key, value);
95
- });
96
- }
91
+ reqHeaders.set("content-type", reqHeaders.get("content-type") || "application/json");
97
92
  requestInit.headers = reqHeaders;
98
93
  requestInit.body = JSON.stringify(data);
99
94
  }
@@ -179,7 +174,7 @@ async function upload(option) {
179
174
  }
180
175
  const filename = basename(target);
181
176
  const deployTarget = dirname(pure(target));
182
- const { status, message, data } = await request({
177
+ const { status, data } = await request({
183
178
  url: `${getFinderServerFullPath(targetServer)}${FinderApiPaths.upload}?target=${encodeURIComponent(deployTarget)}`,
184
179
  method: "POST",
185
180
  headers: { user, key },
@@ -189,13 +184,10 @@ async function upload(option) {
189
184
  }
190
185
  });
191
186
  if (status !== 200) {
192
- throw `${`上传接口错误(${status})`.bgRed} ${message || ""}.red`;
187
+ throw `上传接口错误(status ${status})`.red;
193
188
  }
194
- if (!data || typeof data !== "object") {
195
- throw `上传接口响应错误,请自行检查是否上传成功。`.bgRed + JSON.stringify(data).red;
196
- }
197
- if ("err" in data || !("data" in data) || typeof data.data !== "string") {
198
- throw `上传接口错误。`.bgRed + JSON.stringify(data).red;
189
+ if (!data || typeof data !== "object" || "err" in data && data.err || !("data" in data) || typeof data.data !== "string") {
190
+ throw `上传接口响应错误。 ${JSON.stringify(data)}`.red;
199
191
  }
200
192
  return { previewUrl: `https://${pure(target)}` };
201
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seayoo-web/finder",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "agent for web finder",
5
5
  "type": "module",
6
6
  "source": "index.ts",