moeralib 0.18.3 → 0.18.7

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.
@@ -84,6 +84,9 @@ function encodeBodies(data) {
84
84
  return data.map(item => encodeBodies(item));
85
85
  }
86
86
  const encoded = (0, lodash_clonedeep_1.default)(data);
87
+ if (data.mediaCaptions != null) {
88
+ encoded.mediaCaptions = data.mediaCaptions.map((item) => encodeBodies(item));
89
+ }
87
90
  if (data.body != null) {
88
91
  encoded.body = encodeBody(data.body, data.bodyFormat);
89
92
  }
@@ -93,6 +96,9 @@ function encodeBodies(data) {
93
96
  if (data.bodySrc != null) {
94
97
  encoded.bodySrc = encodeBody(data.bodySrc, data.bodySrcFormat);
95
98
  }
99
+ if (data.captionSrc != null) {
100
+ encoded.captionSrc = encodeBody(data.captionSrc, data.captionSrcFormat);
101
+ }
96
102
  return encoded;
97
103
  }
98
104
  function decodeBody(name, encoded, format) {
@@ -126,6 +132,9 @@ function decodeBodies(name, data) {
126
132
  if (data.comments != null) {
127
133
  decoded.comments = data.comments.map((item) => decodeBodies(name, item));
128
134
  }
135
+ if (data.mediaCaptions != null) {
136
+ decoded.mediaCaptions = data.mediaCaptions.map((item) => decodeBodies(name, item));
137
+ }
129
138
  if (data.comment != null) {
130
139
  decoded.comment = decodeBodies(name, data.comment);
131
140
  }
@@ -141,6 +150,9 @@ function decodeBodies(name, data) {
141
150
  if (data.bodySrc != null) {
142
151
  decoded.bodySrc = decodeBody(name, data.bodySrc, data.bodySrcFormat);
143
152
  }
153
+ if (data.captionSrc != null) {
154
+ decoded.captionSrc = decodeBody(name, data.captionSrc, data.captionSrcFormat);
155
+ }
144
156
  return decoded;
145
157
  }
146
158
  /**
@@ -8,6 +8,8 @@ exports.createCarteFingerprint1 = createCarteFingerprint1;
8
8
  exports.createCarteFingerprint0 = createCarteFingerprint0;
9
9
  exports.createCommentFingerprint1 = createCommentFingerprint1;
10
10
  exports.createCommentFingerprint0 = createCommentFingerprint0;
11
+ exports.createMediaGrantFingerprint1 = createMediaGrantFingerprint1;
12
+ exports.createMediaGrantFingerprint0 = createMediaGrantFingerprint0;
11
13
  exports.createNotificationPacketFingerprint1 = createNotificationPacketFingerprint1;
12
14
  exports.createNotificationPacketFingerprint0 = createNotificationPacketFingerprint0;
13
15
  exports.createPostingFingerprint1 = createPostingFingerprint1;
@@ -120,6 +122,35 @@ function createCommentFingerprint0(ownerName, postingFingerprint, repliedToFinge
120
122
  return (0, crypto_1.fingerprintBytes)({ "version": 0, "objectType": "COMMENT", ownerName, postingFingerprint, repliedToFingerprint, bodySrcHash,
121
123
  bodySrcFormat, body, bodyFormat, createdAt, permissions, attachments }, COMMENT_FINGERPRINT0_SCHEMA);
122
124
  }
125
+ const MEDIA_GRANT_FINGERPRINT1_SCHEMA = [
126
+ ["version", "number"],
127
+ ["objectType", "string"],
128
+ ["nodeName", "string"],
129
+ ["mediaId", "string"],
130
+ ["expires", "number"],
131
+ ["download", "boolean"],
132
+ ["fileName", "string"],
133
+ ["salt", "bytes"],
134
+ ];
135
+ function createMediaGrantFingerprint1(nodeName, mediaId, expires, download, fileName, salt) {
136
+ return (0, crypto_1.fingerprintBytes)({ "version": 1, "objectType": "MEDIA_GRANT", nodeName, mediaId, expires, download, fileName, salt }, MEDIA_GRANT_FINGERPRINT1_SCHEMA);
137
+ }
138
+ const MEDIA_GRANT_FINGERPRINT0_SCHEMA = [
139
+ ["version", "number"],
140
+ ["objectType", "string"],
141
+ ["nodeName", "string"],
142
+ ["postingId", "string"],
143
+ ["commentId", "string"],
144
+ ["mediaId", "string"],
145
+ ["expires", "number"],
146
+ ["download", "boolean"],
147
+ ["fileName", "string"],
148
+ ["salt", "bytes"],
149
+ ];
150
+ function createMediaGrantFingerprint0(nodeName, postingId, commentId, mediaId, expires, download, fileName, salt) {
151
+ return (0, crypto_1.fingerprintBytes)({ "version": 0, "objectType": "MEDIA_GRANT", nodeName, postingId, commentId, mediaId, expires, download, fileName,
152
+ salt }, MEDIA_GRANT_FINGERPRINT0_SCHEMA);
153
+ }
123
154
  const NOTIFICATION_PACKET_FINGERPRINT1_SCHEMA = [
124
155
  ["version", "number"],
125
156
  ["objectType", "string"],
package/lib/node/node.js CHANGED
@@ -1360,33 +1360,40 @@ class MoeraNode extends caller_1.Caller {
1360
1360
  });
1361
1361
  }
1362
1362
  /**
1363
- * Upload a new media file owned by the node admin. The content of the file is passed in the request body.
1363
+ * Parse the page located at the URL and return the title, the description and the picture that may be used to
1364
+ * build a preview of the page.
1364
1365
  *
1365
- * @param {Buffer} body
1366
- * @param {string} contentType - content-type of ``body``
1367
- * @return {Promise<API.PrivateMediaFileInfo>}
1366
+ * @param {string} url
1367
+ * @return {Promise<API.LinkPreviewInfo>}
1368
1368
  */
1369
- uploadAdminMedia(body, contentType) {
1369
+ createLinkPreview(url) {
1370
1370
  return __awaiter(this, void 0, void 0, function* () {
1371
- const location = "/media/private";
1372
- return yield this.call("uploadAdminMedia", location, {
1373
- method: "POST", body, contentType, schema: "PrivateMediaFileInfo"
1371
+ const location = (0, util_1.ut) `/link-preview`;
1372
+ const params = { url };
1373
+ return yield this.call("createLinkPreview", location, {
1374
+ method: "GET", params, schema: "LinkPreviewInfo"
1374
1375
  });
1375
1376
  });
1376
1377
  }
1377
1378
  /**
1378
- * Upload a new media file owned by the given node. The content of the file is passed in the request body.
1379
+ * Upload a new private media file. The content of the file is passed in the request body. Alternatively, the file
1380
+ * can be uploaded using Media upload API and its ID passed in the `upload` query parameter. The second alternative
1381
+ * is to pass the URL of the media in the `url` query parameter, the media will be downloaded to the node.
1379
1382
  *
1380
- * @param {string} clientName - name of the node owning the media file
1381
- * @param {Buffer} body
1382
- * @param {string} contentType - content-type of ``body``
1383
+ * @param {string | null} upload - ID of the media upload to be used instead of the request body
1384
+ * @param {string | null} url - URL of the media to be used instead of the request body
1385
+ * @param {boolean | null} downsize - `true` to scale the uploaded image down to the size recommended by the node,
1386
+ * if possible; the default is `false`
1387
+ * @param {Buffer | null} body - optional
1388
+ * @param {string | null} contentType - optional content-type of ``body``
1383
1389
  * @return {Promise<API.PrivateMediaFileInfo>}
1384
1390
  */
1385
- uploadPrivateMedia(clientName, body, contentType) {
1386
- return __awaiter(this, void 0, void 0, function* () {
1387
- const location = (0, util_1.ut) `/media/private/${clientName}`;
1391
+ uploadPrivateMedia() {
1392
+ return __awaiter(this, arguments, void 0, function* (body = null, contentType = null, upload = null, url = null, downsize = null) {
1393
+ const location = (0, util_1.ut) `/media/private`;
1394
+ const params = { upload, url, downsize };
1388
1395
  return yield this.call("uploadPrivateMedia", location, {
1389
- method: "POST", body, contentType, schema: "PrivateMediaFileInfo"
1396
+ method: "POST", params, body, contentType, schema: "PrivateMediaFileInfo"
1390
1397
  });
1391
1398
  });
1392
1399
  }
@@ -1398,14 +1405,15 @@ class MoeraNode extends caller_1.Caller {
1398
1405
  * the smallest in size, but the best in quality variant of the media, according to the width provided
1399
1406
  * @param {boolean | null} download - if ``true``, the node will add ``Content-Disposition: attachment`` header to
1400
1407
  * the output
1408
+ * @param {string | null} grant - media grant allowing access to the media file
1401
1409
  * @param {boolean | null} ignoremalware - if ``true``, the node will ignore malware detection and return the media
1402
1410
  * file; only admin may use this option
1403
1411
  * @return {Promise<Blob>}
1404
1412
  */
1405
1413
  getPrivateMedia(id_1) {
1406
- return __awaiter(this, arguments, void 0, function* (id, width = null, download = null, ignoremalware = null) {
1414
+ return __awaiter(this, arguments, void 0, function* (id, width = null, download = null, grant = null, ignoremalware = null) {
1407
1415
  const location = (0, util_1.ut) `/media/private/${id}/data`;
1408
- const params = { width, download, ignoremalware };
1416
+ const params = { width, download, grant, ignoremalware };
1409
1417
  return yield this.call("getPrivateMedia", location, {
1410
1418
  method: "GET", params, schema: "blob"
1411
1419
  });
@@ -1415,13 +1423,15 @@ class MoeraNode extends caller_1.Caller {
1415
1423
  * Get media file details.
1416
1424
  *
1417
1425
  * @param {string} id - media file ID
1426
+ * @param {string | null} grant - media grant allowing access to the media file
1418
1427
  * @return {Promise<API.PrivateMediaFileInfo>}
1419
1428
  */
1420
- getPrivateMediaInfo(id) {
1421
- return __awaiter(this, void 0, void 0, function* () {
1429
+ getPrivateMediaInfo(id_1) {
1430
+ return __awaiter(this, arguments, void 0, function* (id, grant = null) {
1422
1431
  const location = (0, util_1.ut) `/media/private/${id}/info`;
1432
+ const params = { grant };
1423
1433
  return yield this.call("getPrivateMediaInfo", location, {
1424
- method: "GET", schema: "PrivateMediaFileInfo"
1434
+ method: "GET", params, schema: "PrivateMediaFileInfo"
1425
1435
  });
1426
1436
  });
1427
1437
  }
@@ -1440,20 +1450,6 @@ class MoeraNode extends caller_1.Caller {
1440
1450
  });
1441
1451
  });
1442
1452
  }
1443
- /**
1444
- * Get the list of all postings and comments the media file is attached to.
1445
- *
1446
- * @param {string} id - media file ID
1447
- * @return {Promise<API.EntryInfo[]>}
1448
- */
1449
- getPrivateMediaParentEntry(id) {
1450
- return __awaiter(this, void 0, void 0, function* () {
1451
- const location = (0, util_1.ut) `/media/private/${id}/parent`;
1452
- return yield this.call("getPrivateMediaParentEntry", location, {
1453
- method: "GET", schema: "EntryInfoArray", bodies: true
1454
- });
1455
- });
1456
- }
1457
1453
  /**
1458
1454
  * Upload a new media file. The content of the file is passed in the request body
1459
1455
  *
@@ -1502,6 +1498,93 @@ class MoeraNode extends caller_1.Caller {
1502
1498
  });
1503
1499
  });
1504
1500
  }
1501
+ /**
1502
+ * Create a lease for a media file stored on the node.
1503
+ *
1504
+ * @param {API.MediaLeaseAttributes} attributes
1505
+ * @return {Promise<API.MediaLeaseInfo>}
1506
+ */
1507
+ createMediaLease(attributes) {
1508
+ return __awaiter(this, void 0, void 0, function* () {
1509
+ const location = "/media/leases";
1510
+ return yield this.call("createMediaLease", location, {
1511
+ method: "POST", body: attributes, schema: "MediaLeaseInfo"
1512
+ });
1513
+ });
1514
+ }
1515
+ /**
1516
+ * Delete the lease.
1517
+ *
1518
+ * @param {string} id - ID of the lease
1519
+ * @return {Promise<API.Result>}
1520
+ */
1521
+ deleteMediaLease(id) {
1522
+ return __awaiter(this, void 0, void 0, function* () {
1523
+ const location = (0, util_1.ut) `/media/leases/${id}`;
1524
+ return yield this.call("deleteMediaLease", location, {
1525
+ method: "DELETE", schema: "Result"
1526
+ });
1527
+ });
1528
+ }
1529
+ /**
1530
+ * Create a new chunked upload of a private media source file.
1531
+ *
1532
+ * @param {API.MediaUploadAttributes} attributes
1533
+ * @return {Promise<API.MediaUploadInfo>}
1534
+ */
1535
+ createMediaUpload(attributes) {
1536
+ return __awaiter(this, void 0, void 0, function* () {
1537
+ const location = "/media/upload";
1538
+ return yield this.call("createMediaUpload", location, {
1539
+ method: "POST", body: attributes, schema: "MediaUploadInfo"
1540
+ });
1541
+ });
1542
+ }
1543
+ /**
1544
+ * Get chunked upload details.
1545
+ *
1546
+ * @param {string} id - upload ID
1547
+ * @return {Promise<API.MediaUploadInfo>}
1548
+ */
1549
+ getMediaUpload(id) {
1550
+ return __awaiter(this, void 0, void 0, function* () {
1551
+ const location = (0, util_1.ut) `/media/upload/${id}`;
1552
+ return yield this.call("getMediaUpload", location, {
1553
+ method: "GET", schema: "MediaUploadInfo"
1554
+ });
1555
+ });
1556
+ }
1557
+ /**
1558
+ * Upload one chunk of a private media source file.
1559
+ *
1560
+ * @param {string} id - upload ID
1561
+ * @param {number} chunk - zero-based chunk number
1562
+ * @param {Buffer} body
1563
+ * @param {string} contentType - content-type of ``body``
1564
+ * @return {Promise<API.MediaUploadInfo>}
1565
+ */
1566
+ uploadMediaChunk(id, chunk, body, contentType) {
1567
+ return __awaiter(this, void 0, void 0, function* () {
1568
+ const location = (0, util_1.ut) `/media/upload/${id}/${chunk}`;
1569
+ return yield this.call("uploadMediaChunk", location, {
1570
+ method: "PUT", body, contentType, schema: "MediaUploadInfo"
1571
+ });
1572
+ });
1573
+ }
1574
+ /**
1575
+ * Delete a chunked media upload and the corresponding source file.
1576
+ *
1577
+ * @param {string} id - upload ID
1578
+ * @return {Promise<API.Result>}
1579
+ */
1580
+ deleteMediaUpload(id) {
1581
+ return __awaiter(this, void 0, void 0, function* () {
1582
+ const location = (0, util_1.ut) `/media/upload/${id}`;
1583
+ return yield this.call("deleteMediaUpload", location, {
1584
+ method: "DELETE", schema: "Result"
1585
+ });
1586
+ });
1587
+ }
1505
1588
  /**
1506
1589
  * Get the name of the node. Admin user receives the current status of the latest operation with the node name.
1507
1590
  *
@@ -2056,37 +2139,6 @@ class MoeraNode extends caller_1.Caller {
2056
2139
  });
2057
2140
  });
2058
2141
  }
2059
- /**
2060
- * Open the URL passed in the parameters and pass to the client the media file returned by the server.
2061
- *
2062
- * @param {string} url
2063
- * @return {Promise<Blob>}
2064
- */
2065
- proxyMedia(url) {
2066
- return __awaiter(this, void 0, void 0, function* () {
2067
- const location = (0, util_1.ut) `/proxy/media`;
2068
- const params = { url };
2069
- return yield this.call("proxyMedia", location, {
2070
- method: "GET", params, schema: "blob"
2071
- });
2072
- });
2073
- }
2074
- /**
2075
- * Parse the page located at the URL and return the title, the description and the picture that may be used to
2076
- * build a preview of the page.
2077
- *
2078
- * @param {string} url
2079
- * @return {Promise<API.LinkPreviewInfo>}
2080
- */
2081
- proxyLinkPreview(url) {
2082
- return __awaiter(this, void 0, void 0, function* () {
2083
- const location = (0, util_1.ut) `/proxy/link-preview`;
2084
- const params = { url };
2085
- return yield this.call("proxyLinkPreview", location, {
2086
- method: "GET", params, schema: "LinkPreviewInfo"
2087
- });
2088
- });
2089
- }
2090
2142
  /**
2091
2143
  * Register a client at the push relay server to receive messages from this node. The operation is synchronous.
2092
2144
  *
@@ -2377,13 +2429,14 @@ class MoeraNode extends caller_1.Caller {
2377
2429
  *
2378
2430
  * @param {string} remoteNodeName - name of the remote node
2379
2431
  * @param {string} id - id of the media file
2432
+ * @param {API.MediaDownloadAttributes} attributes
2380
2433
  * @return {Promise<API.PrivateMediaFileInfo>}
2381
2434
  */
2382
- downloadRemoteMedia(remoteNodeName, id) {
2435
+ downloadRemoteMedia(remoteNodeName, id, attributes) {
2383
2436
  return __awaiter(this, void 0, void 0, function* () {
2384
2437
  const location = (0, util_1.ut) `/nodes/${remoteNodeName}/media/private/${id}/download`;
2385
2438
  return yield this.call("downloadRemoteMedia", location, {
2386
- method: "POST", schema: "PrivateMediaFileInfo"
2439
+ method: "POST", body: attributes, schema: "PrivateMediaFileInfo"
2387
2440
  });
2388
2441
  });
2389
2442
  }
@@ -3137,6 +3190,70 @@ class MoeraNode extends caller_1.Caller {
3137
3190
  });
3138
3191
  });
3139
3192
  }
3193
+ /**
3194
+ * Search for visited nodes matching the search ``query``. Every space-delimited word in the query must match
3195
+ * case-insensitively a beginning of the node's name or a beginning of any space-delimited word in the node's full
3196
+ * name. The order of words is not significant. \
3197
+ * \
3198
+ * The node may decide to return fewer nodes than the given ``limit``. \
3199
+ * \
3200
+ * The nodes are sorted by *social distance* from the node.
3201
+ *
3202
+ * @param {string | null} query - the search query
3203
+ * @param {number | null} limit - maximum number of nodes returned
3204
+ * @return {Promise<API.SearchNodeInfo[]>}
3205
+ */
3206
+ getVisitedNodes() {
3207
+ return __awaiter(this, arguments, void 0, function* (query = null, limit = null) {
3208
+ const location = (0, util_1.ut) `/people/visited`;
3209
+ const params = { query, limit };
3210
+ return yield this.call("getVisitedNodes", location, {
3211
+ method: "GET", params, schema: "SearchNodeInfoArray"
3212
+ });
3213
+ });
3214
+ }
3215
+ /**
3216
+ * Record a visit to the node.
3217
+ *
3218
+ * @param {API.VisitedNodeAttributes} node
3219
+ * @return {Promise<API.Result>}
3220
+ */
3221
+ recordVisitedNode(node) {
3222
+ return __awaiter(this, void 0, void 0, function* () {
3223
+ const location = "/people/visited";
3224
+ return yield this.call("recordVisitedNode", location, {
3225
+ method: "POST", body: node, schema: "Result"
3226
+ });
3227
+ });
3228
+ }
3229
+ /**
3230
+ * Delete all visits to the node.
3231
+ *
3232
+ * @param {string} remoteNodeName - name of the visited node
3233
+ * @return {Promise<API.Result>}
3234
+ */
3235
+ deleteVisitedNode(remoteNodeName) {
3236
+ return __awaiter(this, void 0, void 0, function* () {
3237
+ const location = (0, util_1.ut) `/people/visited/${remoteNodeName}`;
3238
+ return yield this.call("deleteVisitedNode", location, {
3239
+ method: "DELETE", schema: "Result"
3240
+ });
3241
+ });
3242
+ }
3243
+ /**
3244
+ * Record a visit to a posting, comment or media.
3245
+ *
3246
+ * @param {API.VisitDetails} visit
3247
+ * @return {Promise<API.Result>}
3248
+ */
3249
+ recordVisit(visit) {
3250
+ return __awaiter(this, void 0, void 0, function* () {
3251
+ const location = "/visits";
3252
+ return yield this.call("recordVisit", location, {
3253
+ method: "POST", body: visit, schema: "Result"
3254
+ });
3255
+ });
3256
+ }
3140
3257
  /**
3141
3258
  * Get brief information about the node.
3142
3259
  *
package/lib/node/types.js CHANGED
@@ -6,7 +6,6 @@ exports.SCOPE_VALUES = {
6
6
  "none": 0x00000000,
7
7
  "identify": 0x00000000,
8
8
  "other": 0x00000001,
9
- "view-media": 0x00000002,
10
9
  "view-content": 0x00000004,
11
10
  "add-post": 0x00000008,
12
11
  "update-post": 0x00000010,
@@ -35,6 +34,7 @@ exports.SCOPE_VALUES = {
35
34
  "grant": 0x08000000,
36
35
  "upload-public-media": 0x10000000,
37
36
  "upload-private-media": 0x20000000,
38
- "view-all": 0x00088406,
39
- "all": 0x3fffffff,
37
+ "lease-media": 0x40000000,
38
+ "view-all": 0x00088404,
39
+ "all": 0x7ffffffd,
40
40
  };