@blocklet/uploader-server 0.1.59 → 0.1.60
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 +5 -4
- package/lib/utils.js +5 -4
- package/package.json +1 -1
package/es/utils.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import config from "@blocklet/sdk/lib/config";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import joinUrl from "url-join";
|
|
5
4
|
import { isbot } from "isbot";
|
|
6
|
-
import AuthService from "@blocklet/sdk/service/auth";
|
|
7
|
-
const authClient = new AuthService();
|
|
8
5
|
const DEFAULT_TTL = 5 * 60 * 1e3;
|
|
6
|
+
const appUrl = process.env.BLOCKLET_APP_URL || "";
|
|
9
7
|
const trustedDomainsCache = {
|
|
10
8
|
timestamp: 0,
|
|
11
9
|
domains: []
|
|
@@ -14,13 +12,16 @@ export async function getTrustedDomainsCache({
|
|
|
14
12
|
forceUpdate = false,
|
|
15
13
|
ttl = DEFAULT_TTL
|
|
16
14
|
} = {}) {
|
|
15
|
+
if (!appUrl) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
17
18
|
const now = Date.now();
|
|
18
19
|
if (!forceUpdate && trustedDomainsCache.domains.length > 0) {
|
|
19
20
|
if (now - trustedDomainsCache.timestamp < ttl) {
|
|
20
21
|
return trustedDomainsCache.domains;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
|
-
trustedDomainsCache.domains = await axios.get(joinUrl(
|
|
24
|
+
trustedDomainsCache.domains = await axios.get(joinUrl(appUrl, "/.well-known/service/api/federated/getTrustedDomains")).then((res) => res.data);
|
|
24
25
|
trustedDomainsCache.timestamp = now;
|
|
25
26
|
return trustedDomainsCache.domains;
|
|
26
27
|
}
|
package/lib/utils.js
CHANGED
|
@@ -8,14 +8,12 @@ exports.getTrustedDomainsCache = getTrustedDomainsCache;
|
|
|
8
8
|
exports.proxyImageDownload = proxyImageDownload;
|
|
9
9
|
exports.setPDFDownloadHeader = setPDFDownloadHeader;
|
|
10
10
|
var _axios = _interopRequireDefault(require("axios"));
|
|
11
|
-
var _config = _interopRequireDefault(require("@blocklet/sdk/lib/config"));
|
|
12
11
|
var _path = _interopRequireDefault(require("path"));
|
|
13
12
|
var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
14
13
|
var _isbot = require("isbot");
|
|
15
|
-
var _auth = _interopRequireDefault(require("@blocklet/sdk/service/auth"));
|
|
16
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
-
const authClient = new _auth.default();
|
|
18
15
|
const DEFAULT_TTL = 5 * 60 * 1e3;
|
|
16
|
+
const appUrl = process.env.BLOCKLET_APP_URL || "";
|
|
19
17
|
const trustedDomainsCache = {
|
|
20
18
|
timestamp: 0,
|
|
21
19
|
domains: []
|
|
@@ -24,13 +22,16 @@ async function getTrustedDomainsCache({
|
|
|
24
22
|
forceUpdate = false,
|
|
25
23
|
ttl = DEFAULT_TTL
|
|
26
24
|
} = {}) {
|
|
25
|
+
if (!appUrl) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
27
28
|
const now = Date.now();
|
|
28
29
|
if (!forceUpdate && trustedDomainsCache.domains.length > 0) {
|
|
29
30
|
if (now - trustedDomainsCache.timestamp < ttl) {
|
|
30
31
|
return trustedDomainsCache.domains;
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
trustedDomainsCache.domains = await _axios.default.get((0, _urlJoin.default)(
|
|
34
|
+
trustedDomainsCache.domains = await _axios.default.get((0, _urlJoin.default)(appUrl, "/.well-known/service/api/federated/getTrustedDomains")).then(res => res.data);
|
|
34
35
|
trustedDomainsCache.timestamp = now;
|
|
35
36
|
return trustedDomainsCache.domains;
|
|
36
37
|
}
|