@blocklet/uploader-server 0.2.4 → 0.2.6

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/es/utils.js CHANGED
@@ -3,6 +3,7 @@ import path from "path";
3
3
  import joinUrl from "url-join";
4
4
  import { isbot } from "isbot";
5
5
  import component from "@blocklet/sdk/lib/component";
6
+ import Auth from "@blocklet/sdk/service/auth";
6
7
  import { ImageBinDid } from "./constants.js";
7
8
  import crypto from "crypto";
8
9
  import { getSignData } from "@blocklet/sdk/lib/util/verify-sign";
@@ -14,6 +15,8 @@ import { existsSync, readdirSync, renameSync, statSync, unlinkSync, createReadSt
14
15
  import { join } from "path";
15
16
  import ExifTransformer from "exif-be-gone";
16
17
  export let logger = console;
18
+ const isProduction = process.env.NODE_ENV === "production" || process.env.ABT_NODE_SERVICE_ENV === "production";
19
+ const client = new Auth();
17
20
  if (process.env.BLOCKLET_LOG_DIR) {
18
21
  try {
19
22
  const initLogger = require("@blocklet/logger");
@@ -41,11 +44,26 @@ export async function getTrustedDomainsCache({
41
44
  return trustedDomainsCache.domains;
42
45
  }
43
46
  }
44
- trustedDomainsCache.domains = await axios.get(joinUrl(appUrl, "/.well-known/service/api/federated/getTrustedDomains")).then((res) => res.data);
45
- trustedDomainsCache.timestamp = now;
47
+ try {
48
+ if (!trustedDomainsCache?.domains?.length) {
49
+ trustedDomainsCache.domains = await client.getTrustedDomains().then((res) => res.data);
50
+ trustedDomainsCache.timestamp = now;
51
+ }
52
+ } catch (error) {
53
+ }
54
+ try {
55
+ if (!trustedDomainsCache?.domains?.length) {
56
+ trustedDomainsCache.domains = await axios.get(joinUrl(appUrl, "/.well-known/service/api/federated/getTrustedDomains")).then((res) => res.data);
57
+ trustedDomainsCache.timestamp = now;
58
+ }
59
+ } catch (error) {
60
+ }
46
61
  return trustedDomainsCache.domains;
47
62
  }
48
63
  export async function checkTrustedReferer(req, res, next) {
64
+ if (!isProduction) {
65
+ return next?.();
66
+ }
49
67
  if (isbot(req.get("user-agent"))) {
50
68
  return next?.();
51
69
  }
package/lib/utils.js CHANGED
@@ -21,6 +21,7 @@ var _path = _interopRequireWildcard(require("path"));
21
21
  var _urlJoin = _interopRequireDefault(require("url-join"));
22
22
  var _isbot = require("isbot");
23
23
  var _component = _interopRequireDefault(require("@blocklet/sdk/lib/component"));
24
+ var _auth = _interopRequireDefault(require("@blocklet/sdk/service/auth"));
24
25
  var _constants = require("./constants");
25
26
  var _crypto = _interopRequireDefault(require("crypto"));
26
27
  var _verifySign = require("@blocklet/sdk/lib/util/verify-sign");
@@ -34,6 +35,8 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
34
35
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
35
36
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
36
37
  let logger = exports.logger = console;
38
+ const isProduction = process.env.NODE_ENV === "production" || process.env.ABT_NODE_SERVICE_ENV === "production";
39
+ const client = new _auth.default();
37
40
  if (process.env.BLOCKLET_LOG_DIR) {
38
41
  try {
39
42
  const initLogger = require("@blocklet/logger");
@@ -60,11 +63,24 @@ async function getTrustedDomainsCache({
60
63
  return trustedDomainsCache.domains;
61
64
  }
62
65
  }
63
- trustedDomainsCache.domains = await _axios.default.get((0, _urlJoin.default)(appUrl, "/.well-known/service/api/federated/getTrustedDomains")).then(res => res.data);
64
- trustedDomainsCache.timestamp = now;
66
+ try {
67
+ if (!trustedDomainsCache?.domains?.length) {
68
+ trustedDomainsCache.domains = await client.getTrustedDomains().then(res => res.data);
69
+ trustedDomainsCache.timestamp = now;
70
+ }
71
+ } catch (error) {}
72
+ try {
73
+ if (!trustedDomainsCache?.domains?.length) {
74
+ trustedDomainsCache.domains = await _axios.default.get((0, _urlJoin.default)(appUrl, "/.well-known/service/api/federated/getTrustedDomains")).then(res => res.data);
75
+ trustedDomainsCache.timestamp = now;
76
+ }
77
+ } catch (error) {}
65
78
  return trustedDomainsCache.domains;
66
79
  }
67
80
  async function checkTrustedReferer(req, res, next) {
81
+ if (!isProduction) {
82
+ return next?.();
83
+ }
68
84
  if ((0, _isbot.isbot)(req.get("user-agent"))) {
69
85
  return next?.();
70
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/uploader-server",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "blocklet upload server",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -49,10 +49,10 @@
49
49
  "axios": "^1.7.8"
50
50
  },
51
51
  "dependencies": {
52
- "@abtnode/cron": "^1.16.47",
53
- "@blocklet/constant": "^1.16.47",
54
- "@blocklet/logger": "^1.16.47",
55
- "@blocklet/sdk": "^1.16.47",
52
+ "@abtnode/cron": "^1.16.48",
53
+ "@blocklet/constant": "^1.16.48",
54
+ "@blocklet/logger": "^1.16.48",
55
+ "@blocklet/sdk": "^1.16.48",
56
56
  "@tus/file-store": "1.0.0",
57
57
  "@tus/server": "1.0.0",
58
58
  "@uppy/companion": "4.15.1",