@abtnode/blocklet-services 1.16.19-beta-e6aac665 → 1.16.19-beta-7b2db880

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.
@@ -66,11 +66,7 @@ module.exports = (node, opts) => {
66
66
 
67
67
  const handlerOpts = {
68
68
  authenticator,
69
- tokenStorage: new DynamicStorage({
70
- dbPath: path.join(opts.dataDir, 'connections.db'),
71
- model: 'Connection',
72
- primaryKey: 'token',
73
- }),
69
+ tokenStorage: new DynamicStorage({ dbPath: path.join(opts.dataDir, 'connections.db') }),
74
70
  sendNotificationFn: async (connectedDid, message, { req }) => {
75
71
  const { wallet } = await req.getBlockletInfo();
76
72
  return sendToUser(
@@ -22,11 +22,7 @@ module.exports = (node, opts) => {
22
22
  const handlers = createHandlers({
23
23
  logger,
24
24
  authenticator,
25
- storage: new DynamicStorage({
26
- dbPath: path.join(opts.dataDir, 'connections.db'),
27
- model: 'ConnectionV2',
28
- primaryKey: 'sessionId',
29
- }),
25
+ storage: new DynamicStorage({ dbPath: path.join(opts.dataDir, 'connections.db'), v2: true }),
30
26
  socketPathname: `${WELLKNOWN_SERVICE_PATH_PREFIX}/api/connect/relay/websocket`,
31
27
  sendNotificationFn: async (connectedDid, message, { request }) => {
32
28
  const { wallet } = await request.getBlockletInfo();
package/api/libs/image.js CHANGED
@@ -130,68 +130,6 @@ const isImageRequest = (req) => {
130
130
 
131
131
  const getImageContentType = (extension) => (extension === 'svg' ? 'image/svg+xml' : `image/${extension}`);
132
132
 
133
- const tasks = {};
134
- const processAndRespond = (req, res, cacheDir, getSrc, ext, sendOptions = { maxAge: '356d', immutable: true }) => {
135
- if (fs.existsSync(cacheDir) === false) {
136
- fs.mkdirSync(cacheDir, { recursive: true });
137
- }
138
-
139
- const params = req.imageFilter;
140
- const extension = toLower(ext || path.extname(req.path).slice(1));
141
-
142
- // NOTE: 不要使用 `req.accepts('image/webp')`,这里需要排除掉 `Accept: */*` 和 `Accept: image/*` 的情况
143
- const acceptWebp = req.accepts().includes('image/webp');
144
- if (!acceptWebp) {
145
- if (params.f === 'webp') {
146
- params.f = undefined;
147
- }
148
- if ((!extension || extension === 'webp') && !params.f) {
149
- params.f = 'png';
150
- }
151
- }
152
- if (!extension && !params.f) {
153
- params.f = 'png';
154
- }
155
-
156
- if (!extension && !params.f) {
157
- res.status(400).send('Image filter failed: either extension or format must be specified');
158
- return;
159
- }
160
-
161
- const cacheKey = md5(stringify({ target: req.target, path: req.originalUrl, params }));
162
- const destPath = getCacheFilePath(cacheDir, `${cacheKey}.${params.f || extension}`);
163
- if (fs.existsSync(destPath)) {
164
- res.header('Content-Type', getImageContentType(params.f || extension));
165
- res.sendFile(destPath, sendOptions);
166
- return;
167
- }
168
-
169
- // do the convert
170
- tasks[cacheKey] ??= getSrc(req)
171
- .then(([src, _extension]) => processImage(src, toLower(_extension), destPath, params))
172
- .finally(() => {
173
- setTimeout(() => {
174
- delete tasks[cacheKey];
175
- }, 1000);
176
- });
177
-
178
- tasks[cacheKey]
179
- .then(() => {
180
- logger.info('image filter succeed', { params, url: req.originalUrl, destPath });
181
- res.header('Content-Type', getImageContentType(params.f || extension));
182
- res.sendFile(destPath, sendOptions);
183
- })
184
- .catch((err) => {
185
- logger.error('image filter failed', { error: err, params, url: req.url });
186
- if (params.e) {
187
- res.status(500).send(`Image service error: ${err.message}`);
188
- } else {
189
- res.status(500);
190
- res.sendFile(errorImage, { maxAge: 0 });
191
- }
192
- });
193
- };
194
-
195
133
  const processImage = (src, extension, dest, params) => {
196
134
  return new Promise((resolve, reject) => {
197
135
  // output stream
@@ -282,6 +220,68 @@ const processImage = (src, extension, dest, params) => {
282
220
  });
283
221
  };
284
222
 
223
+ const tasks = {};
224
+ const processAndRespond = (req, res, cacheDir, getSrc, ext, sendOptions = { maxAge: '356d', immutable: true }) => {
225
+ if (fs.existsSync(cacheDir) === false) {
226
+ fs.mkdirSync(cacheDir, { recursive: true });
227
+ }
228
+
229
+ const params = req.imageFilter;
230
+ const extension = toLower(ext || path.extname(req.path).slice(1));
231
+
232
+ // NOTE: 不要使用 `req.accepts('image/webp')`,这里需要排除掉 `Accept: */*` 和 `Accept: image/*` 的情况
233
+ const acceptWebp = req.accepts().includes('image/webp');
234
+ if (!acceptWebp) {
235
+ if (params.f === 'webp') {
236
+ params.f = undefined;
237
+ }
238
+ if ((!extension || extension === 'webp') && !params.f) {
239
+ params.f = 'png';
240
+ }
241
+ }
242
+ if (!extension && !params.f) {
243
+ params.f = 'png';
244
+ }
245
+
246
+ if (!extension && !params.f) {
247
+ res.status(400).send('Image filter failed: either extension or format must be specified');
248
+ return;
249
+ }
250
+
251
+ const cacheKey = md5(stringify({ target: req.target, path: req.originalUrl, params }));
252
+ const destPath = getCacheFilePath(cacheDir, `${cacheKey}.${params.f || extension}`);
253
+ if (fs.existsSync(destPath)) {
254
+ res.header('Content-Type', getImageContentType(params.f || extension));
255
+ res.sendFile(destPath, sendOptions);
256
+ return;
257
+ }
258
+
259
+ // do the convert
260
+ tasks[cacheKey] ??= getSrc(req)
261
+ .then(([src, _extension]) => processImage(src, toLower(_extension), destPath, params))
262
+ .finally(() => {
263
+ setTimeout(() => {
264
+ delete tasks[cacheKey];
265
+ }, 1000);
266
+ });
267
+
268
+ tasks[cacheKey]
269
+ .then(() => {
270
+ logger.info('image filter succeed', { params, url: req.originalUrl, destPath });
271
+ res.header('Content-Type', getImageContentType(params.f || extension));
272
+ res.sendFile(destPath, sendOptions);
273
+ })
274
+ .catch((err) => {
275
+ logger.error('image filter failed', { error: err, params, url: req.url });
276
+ if (params.e) {
277
+ res.status(500).send(`Image service error: ${err.message}`);
278
+ } else {
279
+ res.status(500);
280
+ res.sendFile(errorImage, { maxAge: 0 });
281
+ }
282
+ });
283
+ };
284
+
285
285
  module.exports = {
286
286
  isImageAccepted,
287
287
  isImageRequest,
@@ -5,8 +5,6 @@ const fetch = require('node-fetch').default;
5
5
  const U200D = String.fromCharCode(8205); // zero-width joiner
6
6
  const UFE0Fg = /\uFE0F/g; // variation selector regex
7
7
 
8
- const getIconCode = (char) => toCodePoint(char.indexOf(U200D) < 0 ? char.replace(UFE0Fg, '') : char);
9
-
10
8
  const toCodePoint = (unicodeSurrogates) => {
11
9
  const r = [];
12
10
  let c = 0;
@@ -26,6 +24,8 @@ const toCodePoint = (unicodeSurrogates) => {
26
24
  return r.join('-');
27
25
  };
28
26
 
27
+ const getIconCode = (char) => toCodePoint(char.indexOf(U200D) < 0 ? char.replace(UFE0Fg, '') : char);
28
+
29
29
  const apis = {
30
30
  twemoji: (code) => `https://cdn.jsdelivr.net/gh/twitter/twemoji@14.0.2/assets/svg/${code.toLowerCase()}.svg`,
31
31
  openmoji: 'https://cdn.jsdelivr.net/npm/@svgmoji/openmoji@2.0.0/svg/',
@@ -107,6 +107,7 @@ const getOgImage = ({ input, info, cacheDir, format, tmpDir }) => {
107
107
  return destPath;
108
108
  }
109
109
 
110
+ // eslint-disable-next-line no-use-before-define
110
111
  generateTasks[cacheKey] ??= generateOgImage(params, tmpDir).finally(() => {
111
112
  setTimeout(() => {
112
113
  delete generateTasks[cacheKey];
@@ -75,6 +75,7 @@ async function login(req, node, options) {
75
75
  throw new ApiError(400, t('oauthCantBeOwner', locale));
76
76
  }
77
77
  const { did: teamDid, wallet: blockletWallet, secret, appUrl } = await req.getBlockletInfo();
78
+
78
79
  let userWallet;
79
80
  let oauthInfo;
80
81
 
@@ -94,6 +95,7 @@ async function login(req, node, options) {
94
95
  oauthInfo = await authClient.getProfile(token);
95
96
  userWallet = fromAppDid(oauthInfo.sub, blockletWallet.secretKey);
96
97
  }
98
+
97
99
  const userDid = userWallet.address;
98
100
  const userPk = userWallet.publicKey;
99
101
 
@@ -275,6 +277,8 @@ async function invite(req, node, options) {
275
277
  let userWallet;
276
278
  let oauthInfo;
277
279
 
280
+ const { did: teamDid, wallet: blockletWallet, secret } = await req.getBlockletInfo();
281
+
278
282
  // NOTICE: 如果是统一登录,则向 master 站点发起 oauth 登录请求,auth0 的账户信息必须由 master 来生成
279
283
  if (sourceAppPid) {
280
284
  const data = await getOAuthUserInfo({
@@ -292,7 +296,7 @@ async function invite(req, node, options) {
292
296
  oauthInfo = await authClient.getProfile(token);
293
297
  userWallet = fromAppDid(oauthInfo.sub, blockletWallet.secretKey);
294
298
  }
295
- const { did: teamDid, wallet: blockletWallet, secret } = await req.getBlockletInfo();
299
+
296
300
  const nodeInfo = await req.getNodeInfo();
297
301
  let userDid = userWallet.address;
298
302
  let userPk = userWallet.publicKey;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "/.well-known/service/static/static/css/main.7ea79dc8.css",
4
- "main.js": "/.well-known/service/static/static/js/main.6f748ae5.js",
4
+ "main.js": "/.well-known/service/static/static/js/main.09227d84.js",
5
5
  "static/js/9314.f0add972.chunk.js": "/.well-known/service/static/static/js/9314.f0add972.chunk.js",
6
6
  "static/js/6218.4f3036a7.chunk.js": "/.well-known/service/static/static/js/6218.4f3036a7.chunk.js",
7
7
  "static/js/4076.8055ce74.chunk.js": "/.well-known/service/static/static/js/4076.8055ce74.chunk.js",
@@ -12,7 +12,7 @@
12
12
  "static/js/779.73350f02.chunk.js": "/.well-known/service/static/static/js/779.73350f02.chunk.js",
13
13
  "static/js/8622.6aa0a4d4.chunk.js": "/.well-known/service/static/static/js/8622.6aa0a4d4.chunk.js",
14
14
  "static/js/1148.5ccba08e.chunk.js": "/.well-known/service/static/static/js/1148.5ccba08e.chunk.js",
15
- "static/js/8944.939de854.chunk.js": "/.well-known/service/static/static/js/8944.939de854.chunk.js",
15
+ "static/js/8944.5b8c231c.chunk.js": "/.well-known/service/static/static/js/8944.5b8c231c.chunk.js",
16
16
  "static/js/5468.21a861b9.chunk.js": "/.well-known/service/static/static/js/5468.21a861b9.chunk.js",
17
17
  "static/js/9982.4f1ebb7f.chunk.js": "/.well-known/service/static/static/js/9982.4f1ebb7f.chunk.js",
18
18
  "static/js/1359.add26d23.chunk.js": "/.well-known/service/static/static/js/1359.add26d23.chunk.js",
@@ -92,7 +92,7 @@
92
92
  "static/js/9107.7f32925d.chunk.js": "/.well-known/service/static/static/js/9107.7f32925d.chunk.js",
93
93
  "static/css/3154.e954fcda.chunk.css": "/.well-known/service/static/static/css/3154.e954fcda.chunk.css",
94
94
  "static/js/8016.3ef64a2c.chunk.js": "/.well-known/service/static/static/js/8016.3ef64a2c.chunk.js",
95
- "static/js/8181.6c2a7dcb.chunk.js": "/.well-known/service/static/static/js/8181.6c2a7dcb.chunk.js",
95
+ "static/js/8181.bc510ea3.chunk.js": "/.well-known/service/static/static/js/8181.bc510ea3.chunk.js",
96
96
  "static/js/9657.b03b88e5.chunk.js": "/.well-known/service/static/static/js/9657.b03b88e5.chunk.js",
97
97
  "static/js/468.bbc69bbf.chunk.js": "/.well-known/service/static/static/js/468.bbc69bbf.chunk.js",
98
98
  "static/media/ubuntu-mono-all-400-normal.woff": "/.well-known/service/static/static/media/ubuntu-mono-all-400-normal.c879328bc62e9c68268f.woff",
@@ -119,7 +119,7 @@
119
119
  "index.html": "/.well-known/service/static/index.html",
120
120
  "static/media/space-connected.svg": "/.well-known/service/static/static/media/space-connected.9a4e18fd2bc7d065191b0d241a131c28.svg",
121
121
  "main.7ea79dc8.css.map": "/.well-known/service/static/static/css/main.7ea79dc8.css.map",
122
- "main.6f748ae5.js.map": "/.well-known/service/static/static/js/main.6f748ae5.js.map",
122
+ "main.09227d84.js.map": "/.well-known/service/static/static/js/main.09227d84.js.map",
123
123
  "9314.f0add972.chunk.js.map": "/.well-known/service/static/static/js/9314.f0add972.chunk.js.map",
124
124
  "6218.4f3036a7.chunk.js.map": "/.well-known/service/static/static/js/6218.4f3036a7.chunk.js.map",
125
125
  "4076.8055ce74.chunk.js.map": "/.well-known/service/static/static/js/4076.8055ce74.chunk.js.map",
@@ -130,7 +130,7 @@
130
130
  "779.73350f02.chunk.js.map": "/.well-known/service/static/static/js/779.73350f02.chunk.js.map",
131
131
  "8622.6aa0a4d4.chunk.js.map": "/.well-known/service/static/static/js/8622.6aa0a4d4.chunk.js.map",
132
132
  "1148.5ccba08e.chunk.js.map": "/.well-known/service/static/static/js/1148.5ccba08e.chunk.js.map",
133
- "8944.939de854.chunk.js.map": "/.well-known/service/static/static/js/8944.939de854.chunk.js.map",
133
+ "8944.5b8c231c.chunk.js.map": "/.well-known/service/static/static/js/8944.5b8c231c.chunk.js.map",
134
134
  "5468.21a861b9.chunk.js.map": "/.well-known/service/static/static/js/5468.21a861b9.chunk.js.map",
135
135
  "9982.4f1ebb7f.chunk.js.map": "/.well-known/service/static/static/js/9982.4f1ebb7f.chunk.js.map",
136
136
  "1359.add26d23.chunk.js.map": "/.well-known/service/static/static/js/1359.add26d23.chunk.js.map",
@@ -210,12 +210,12 @@
210
210
  "9107.7f32925d.chunk.js.map": "/.well-known/service/static/static/js/9107.7f32925d.chunk.js.map",
211
211
  "3154.e954fcda.chunk.css.map": "/.well-known/service/static/static/css/3154.e954fcda.chunk.css.map",
212
212
  "8016.3ef64a2c.chunk.js.map": "/.well-known/service/static/static/js/8016.3ef64a2c.chunk.js.map",
213
- "8181.6c2a7dcb.chunk.js.map": "/.well-known/service/static/static/js/8181.6c2a7dcb.chunk.js.map",
213
+ "8181.bc510ea3.chunk.js.map": "/.well-known/service/static/static/js/8181.bc510ea3.chunk.js.map",
214
214
  "9657.b03b88e5.chunk.js.map": "/.well-known/service/static/static/js/9657.b03b88e5.chunk.js.map",
215
215
  "468.bbc69bbf.chunk.js.map": "/.well-known/service/static/static/js/468.bbc69bbf.chunk.js.map"
216
216
  },
217
217
  "entrypoints": [
218
218
  "static/css/main.7ea79dc8.css",
219
- "static/js/main.6f748ae5.js"
219
+ "static/js/main.09227d84.js"
220
220
  ]
221
221
  }
package/build/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico?imageFilter=resize&w=32"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"/><meta name="theme-color" content="#000000"/><title>Blocklet Service</title><link rel="manifest" href="/.well-known/service/manifest.json"/><script src="/.well-known/service/api/env"></script><script src="/__blocklet__.js"></script><script defer="defer" src="/.well-known/service/static/static/js/main.6f748ae5.js"></script><link href="/.well-known/service/static/static/css/main.7ea79dc8.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico?imageFilter=resize&w=32"/><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"/><meta name="theme-color" content="#000000"/><title>Blocklet Service</title><link rel="manifest" href="/.well-known/service/manifest.json"/><script src="/.well-known/service/api/env"></script><script src="/__blocklet__.js"></script><script defer="defer" src="/.well-known/service/static/static/js/main.09227d84.js"></script><link href="/.well-known/service/static/static/css/main.7ea79dc8.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>