moeralib 0.18.3 → 0.18.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.
@@ -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,31 +1360,15 @@ 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
+ * Upload a new private media file. The content of the file is passed in the request body.
1364
1364
  *
1365
1365
  * @param {Buffer} body
1366
1366
  * @param {string} contentType - content-type of ``body``
1367
1367
  * @return {Promise<API.PrivateMediaFileInfo>}
1368
1368
  */
1369
- uploadAdminMedia(body, contentType) {
1369
+ uploadPrivateMedia(body, contentType) {
1370
1370
  return __awaiter(this, void 0, void 0, function* () {
1371
1371
  const location = "/media/private";
1372
- return yield this.call("uploadAdminMedia", location, {
1373
- method: "POST", body, contentType, schema: "PrivateMediaFileInfo"
1374
- });
1375
- });
1376
- }
1377
- /**
1378
- * Upload a new media file owned by the given node. The content of the file is passed in the request body.
1379
- *
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
- * @return {Promise<API.PrivateMediaFileInfo>}
1384
- */
1385
- uploadPrivateMedia(clientName, body, contentType) {
1386
- return __awaiter(this, void 0, void 0, function* () {
1387
- const location = (0, util_1.ut) `/media/private/${clientName}`;
1388
1372
  return yield this.call("uploadPrivateMedia", location, {
1389
1373
  method: "POST", body, contentType, schema: "PrivateMediaFileInfo"
1390
1374
  });
@@ -1398,14 +1382,15 @@ class MoeraNode extends caller_1.Caller {
1398
1382
  * the smallest in size, but the best in quality variant of the media, according to the width provided
1399
1383
  * @param {boolean | null} download - if ``true``, the node will add ``Content-Disposition: attachment`` header to
1400
1384
  * the output
1385
+ * @param {string | null} grant - media grant allowing access to the media file
1401
1386
  * @param {boolean | null} ignoremalware - if ``true``, the node will ignore malware detection and return the media
1402
1387
  * file; only admin may use this option
1403
1388
  * @return {Promise<Blob>}
1404
1389
  */
1405
1390
  getPrivateMedia(id_1) {
1406
- return __awaiter(this, arguments, void 0, function* (id, width = null, download = null, ignoremalware = null) {
1391
+ return __awaiter(this, arguments, void 0, function* (id, width = null, download = null, grant = null, ignoremalware = null) {
1407
1392
  const location = (0, util_1.ut) `/media/private/${id}/data`;
1408
- const params = { width, download, ignoremalware };
1393
+ const params = { width, download, grant, ignoremalware };
1409
1394
  return yield this.call("getPrivateMedia", location, {
1410
1395
  method: "GET", params, schema: "blob"
1411
1396
  });
@@ -1415,13 +1400,15 @@ class MoeraNode extends caller_1.Caller {
1415
1400
  * Get media file details.
1416
1401
  *
1417
1402
  * @param {string} id - media file ID
1403
+ * @param {string | null} grant - media grant allowing access to the media file
1418
1404
  * @return {Promise<API.PrivateMediaFileInfo>}
1419
1405
  */
1420
- getPrivateMediaInfo(id) {
1421
- return __awaiter(this, void 0, void 0, function* () {
1406
+ getPrivateMediaInfo(id_1) {
1407
+ return __awaiter(this, arguments, void 0, function* (id, grant = null) {
1422
1408
  const location = (0, util_1.ut) `/media/private/${id}/info`;
1409
+ const params = { grant };
1423
1410
  return yield this.call("getPrivateMediaInfo", location, {
1424
- method: "GET", schema: "PrivateMediaFileInfo"
1411
+ method: "GET", params, schema: "PrivateMediaFileInfo"
1425
1412
  });
1426
1413
  });
1427
1414
  }
@@ -1440,20 +1427,6 @@ class MoeraNode extends caller_1.Caller {
1440
1427
  });
1441
1428
  });
1442
1429
  }
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
1430
  /**
1458
1431
  * Upload a new media file. The content of the file is passed in the request body
1459
1432
  *
@@ -1502,6 +1475,34 @@ class MoeraNode extends caller_1.Caller {
1502
1475
  });
1503
1476
  });
1504
1477
  }
1478
+ /**
1479
+ * Create a lease for a media file stored on the node.
1480
+ *
1481
+ * @param {API.MediaLeaseAttributes} attributes
1482
+ * @return {Promise<API.MediaLeaseInfo>}
1483
+ */
1484
+ createMediaLease(attributes) {
1485
+ return __awaiter(this, void 0, void 0, function* () {
1486
+ const location = "/media/leases";
1487
+ return yield this.call("createMediaLease", location, {
1488
+ method: "POST", body: attributes, schema: "MediaLeaseInfo"
1489
+ });
1490
+ });
1491
+ }
1492
+ /**
1493
+ * Delete the lease.
1494
+ *
1495
+ * @param {string} id - ID of the lease
1496
+ * @return {Promise<API.Result>}
1497
+ */
1498
+ deleteMediaLease(id) {
1499
+ return __awaiter(this, void 0, void 0, function* () {
1500
+ const location = (0, util_1.ut) `/media/leases/${id}`;
1501
+ return yield this.call("deleteMediaLease", location, {
1502
+ method: "DELETE", schema: "Result"
1503
+ });
1504
+ });
1505
+ }
1505
1506
  /**
1506
1507
  * Get the name of the node. Admin user receives the current status of the latest operation with the node name.
1507
1508
  *
@@ -2377,13 +2378,14 @@ class MoeraNode extends caller_1.Caller {
2377
2378
  *
2378
2379
  * @param {string} remoteNodeName - name of the remote node
2379
2380
  * @param {string} id - id of the media file
2381
+ * @param {API.MediaDownloadAttributes} attributes
2380
2382
  * @return {Promise<API.PrivateMediaFileInfo>}
2381
2383
  */
2382
- downloadRemoteMedia(remoteNodeName, id) {
2384
+ downloadRemoteMedia(remoteNodeName, id, attributes) {
2383
2385
  return __awaiter(this, void 0, void 0, function* () {
2384
2386
  const location = (0, util_1.ut) `/nodes/${remoteNodeName}/media/private/${id}/download`;
2385
2387
  return yield this.call("downloadRemoteMedia", location, {
2386
- method: "POST", schema: "PrivateMediaFileInfo"
2388
+ method: "POST", body: attributes, schema: "PrivateMediaFileInfo"
2387
2389
  });
2388
2390
  });
2389
2391
  }
@@ -3137,6 +3139,20 @@ class MoeraNode extends caller_1.Caller {
3137
3139
  });
3138
3140
  });
3139
3141
  }
3142
+ /**
3143
+ * Record a visit to a posting, comment or media.
3144
+ *
3145
+ * @param {API.VisitDetails} visit
3146
+ * @return {Promise<API.Result>}
3147
+ */
3148
+ recordVisit(visit) {
3149
+ return __awaiter(this, void 0, void 0, function* () {
3150
+ const location = "/visits";
3151
+ return yield this.call("recordVisit", location, {
3152
+ method: "POST", body: visit, schema: "Result"
3153
+ });
3154
+ });
3155
+ }
3140
3156
  /**
3141
3157
  * Get brief information about the node.
3142
3158
  *
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
  };