badmfck-api-server 4.1.43 → 4.1.45

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.
@@ -156,6 +156,7 @@ export declare class ConfigService extends BaseService {
156
156
  private busy;
157
157
  private retake;
158
158
  private watchDebounceTimer;
159
+ private _lastConfigHash;
159
160
  constructor(dir: string);
160
161
  init(): Promise<void>;
161
162
  configurationDelete(name: string): Promise<IError | boolean>;
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.ConfigService = exports.S_CONFIG_UPDATED = exports.REQ_DEPLOYMENT_CONFIG_DELETE = exports.REQ_DEPLOYMENT_CONFIG_ADD = exports.REQ_DEPLOYMENT_CONFIG = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const path_1 = __importDefault(require("path"));
32
+ const crypto_1 = __importDefault(require("crypto"));
32
33
  const badmfck_signal_1 = __importStar(require("badmfck-signal"));
33
34
  const BaseService_1 = require("../BaseService");
34
35
  const Validator_1 = require("../helper/Validator");
@@ -99,6 +100,7 @@ class ConfigService extends BaseService_1.BaseService {
99
100
  busy = false;
100
101
  retake = false;
101
102
  watchDebounceTimer = null;
103
+ _lastConfigHash = null;
102
104
  constructor(dir) {
103
105
  super("ConfigService");
104
106
  this.dir = dir;
@@ -174,9 +176,15 @@ class ConfigService extends BaseService_1.BaseService {
174
176
  }
175
177
  }
176
178
  if (!isError) {
177
- this.configurations = temp;
178
- exports.S_CONFIG_UPDATED.invoke();
179
- (0, LogService_1.logWarn)("Configurations updated");
179
+ const hash = crypto_1.default.createHash("md5")
180
+ .update(JSON.stringify(Array.from(temp.entries())))
181
+ .digest("hex");
182
+ if (hash !== this._lastConfigHash) {
183
+ this._lastConfigHash = hash;
184
+ this.configurations = temp;
185
+ exports.S_CONFIG_UPDATED.invoke();
186
+ (0, LogService_1.logWarn)("Configurations updated");
187
+ }
180
188
  }
181
189
  }
182
190
  catch (e) {
@@ -155,12 +155,35 @@ async function Deploy(opt) {
155
155
  headersTimeout: 5 * 60 * 1000,
156
156
  bodyTimeout: 5 * 60 * 1000,
157
157
  });
158
- const uploadResponse = await __1.Http.post(opt.host, formData, {
159
- headers: { authorization: `Bearer ${authToken}` },
160
- dispatcher: uploadAgent,
161
- timeoutMs: 5 * 60 * 1000,
162
- retry: { enabled: false },
163
- });
158
+ const abortController = new AbortController();
159
+ const abortTimer = setTimeout(() => abortController.abort(), 5 * 60 * 1000);
160
+ let uploadResponse;
161
+ try {
162
+ const res = await fetch(opt.host, {
163
+ method: "POST",
164
+ headers: { authorization: `Bearer ${authToken}` },
165
+ body: formData,
166
+ signal: abortController.signal,
167
+ ...{ dispatcher: uploadAgent },
168
+ });
169
+ const rawText = await res.text();
170
+ let parsed;
171
+ try {
172
+ parsed = rawText.length > 0 ? JSON.parse(rawText) : null;
173
+ }
174
+ catch {
175
+ parsed = rawText;
176
+ }
177
+ uploadResponse = res.ok
178
+ ? { ok: true, status: res.status, data: parsed }
179
+ : { ok: false, status: res.status, error: parsed };
180
+ }
181
+ catch (err) {
182
+ uploadResponse = { ok: false, error: err };
183
+ }
184
+ finally {
185
+ clearTimeout(abortTimer);
186
+ }
164
187
  const elapsedMs = Date.now() - startedAt;
165
188
  const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
166
189
  const c = (code, t) => useColor ? `\x1b[${code}m${t}\x1b[0m` : t;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "4.1.43",
3
+ "version": "4.1.45",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",