comty.js 0.57.5 → 0.58.2

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.
@@ -53,17 +53,4 @@ var _withSettings = require('../../helpers/withSettings'); var _withSettings2 =
53
53
 
54
54
  return data
55
55
  }}
56
-
57
- static __initStatic5() {this.getPlaylistsFeed = async ({ trim, limit } = {}) => {
58
- const { data } = await _request2.default.call(void 0, {
59
- method: "GET",
60
- url: `/feed/playlists`,
61
- params: {
62
- trim: _nullishCoalesce(trim, () => ( 0)),
63
- limit: _nullishCoalesce(limit, () => ( _withSettings2.default.get("feed_max_fetch"))),
64
- }
65
- })
66
-
67
- return data
68
- }}
69
- } FeedModel.__initStatic(); FeedModel.__initStatic2(); FeedModel.__initStatic3(); FeedModel.__initStatic4(); FeedModel.__initStatic5(); exports.default = FeedModel;
56
+ } FeedModel.__initStatic(); FeedModel.__initStatic2(); FeedModel.__initStatic3(); FeedModel.__initStatic4(); exports.default = FeedModel;
@@ -2,7 +2,6 @@
2
2
  var _feed = require('./feed'); var _feed2 = _interopRequireDefault(_feed);
3
3
  var _follows = require('./follows'); var _follows2 = _interopRequireDefault(_follows);
4
4
  var _livestream = require('./livestream'); var _livestream2 = _interopRequireDefault(_livestream);
5
- var _playlists = require('./playlists'); var _playlists2 = _interopRequireDefault(_playlists);
6
5
  var _post = require('./post'); var _post2 = _interopRequireDefault(_post);
7
6
  var _session = require('./session'); var _session2 = _interopRequireDefault(_session);
8
7
  var _sync = require('./sync'); var _sync2 = _interopRequireDefault(_sync);
@@ -22,7 +21,6 @@ function createHandlers() {
22
21
  feed: getEndpointsFromModel(_feed2.default),
23
22
  follows: getEndpointsFromModel(_follows2.default),
24
23
  livestream: getEndpointsFromModel(_livestream2.default),
25
- playlists: getEndpointsFromModel(_playlists2.default),
26
24
  post: getEndpointsFromModel(_post2.default),
27
25
  session: getEndpointsFromModel(_session2.default),
28
26
  sync: getEndpointsFromModel(_sync2.default),
@@ -40,5 +38,4 @@ function createHandlers() {
40
38
 
41
39
 
42
40
 
43
-
44
- exports.AuthModel = _auth2.default; exports.FeedModel = _feed2.default; exports.FollowsModel = _follows2.default; exports.LivestreamModel = _livestream2.default; exports.PlaylistsModel = _playlists2.default; exports.PostModel = _post2.default; exports.SessionModel = _session2.default; exports.SyncModel = _sync2.default; exports.UserModel = _user2.default; exports.createHandlers = createHandlers;
41
+ exports.AuthModel = _auth2.default; exports.FeedModel = _feed2.default; exports.FollowsModel = _follows2.default; exports.LivestreamModel = _livestream2.default; exports.PostModel = _post2.default; exports.SessionModel = _session2.default; exports.SyncModel = _sync2.default; exports.UserModel = _user2.default; exports.createHandlers = createHandlers;
@@ -7,12 +7,51 @@ var _sync = require('../sync'); var _sync2 = _interopRequireDefault(_sync);
7
7
  return globalThis.__comty_shared_state.instances["music"]
8
8
  }
9
9
 
10
- // TODO: Move external services fetching to API
11
- static __initStatic() {this.getFavorites = async ({
12
- useTidal = false,
13
- limit,
14
- offset,
15
- }) => {
10
+ /**
11
+ * Retrieves track data for a given ID.
12
+ *
13
+ * @param {string} id - The ID of the track.
14
+ * @return {Promise<Object>} The track data.
15
+ */
16
+ static async getTrackData(id) {
17
+ const response = await _request2.default.call(void 0, {
18
+ instance: MusicModel.api_instance,
19
+ method: "GET",
20
+ url: `/tracks/${id}/data`,
21
+ })
22
+
23
+ return response.data
24
+ }
25
+
26
+ /**
27
+ * Retrieves tracks data for the given track IDs.
28
+ *
29
+ * @param {Array} ids - An array of track IDs.
30
+ * @return {Promise<Object>} A promise that resolves to the tracks data.
31
+ */
32
+ static async getTracksData(ids) {
33
+ const response = await _request2.default.call(void 0, {
34
+ instance: MusicModel.api_instance,
35
+ method: "GET",
36
+ url: `/tracks/many`,
37
+ params: {
38
+ ids,
39
+ }
40
+ })
41
+
42
+ return response.data
43
+ }
44
+
45
+ /**
46
+ * Retrieves favorite tracks based on specified parameters.
47
+ *
48
+ * @param {Object} options - The options for retrieving favorite tracks.
49
+ * @param {boolean} options.useTidal - Whether to use Tidal for retrieving tracks. Defaults to false.
50
+ * @param {number} options.limit - The maximum number of tracks to retrieve.
51
+ * @param {number} options.offset - The offset from which to start retrieving tracks.
52
+ * @return {Promise<Object>} - An object containing the total length of the tracks and the retrieved tracks.
53
+ */
54
+ static async getFavoriteTracks({ useTidal = false, limit, offset }) {
16
55
  let result = []
17
56
 
18
57
  let limitPerRequesters = limit
@@ -54,19 +93,19 @@ var _sync = require('../sync'); var _sync2 = _interopRequireDefault(_sync);
54
93
 
55
94
  result = await _pmap2.default.call(void 0,
56
95
  requesters,
57
- async (requester) => {
96
+ async requester => {
58
97
  const data = await requester()
59
98
 
60
99
  return data
61
100
  },
62
101
  {
63
- concurrency: 3
64
- }
102
+ concurrency: 3,
103
+ },
65
104
  )
66
105
 
67
106
  let total_length = 0
68
107
 
69
- result.forEach((result) => {
108
+ result.forEach(result => {
70
109
  total_length += result.total_length
71
110
  })
72
111
 
@@ -82,13 +121,184 @@ var _sync = require('../sync'); var _sync2 = _interopRequireDefault(_sync);
82
121
  total_length,
83
122
  tracks,
84
123
  }
85
- }}
124
+ }
125
+
126
+ /**
127
+ * Retrieves favorite playlists based on the specified parameters.
128
+ *
129
+ * @param {Object} options - The options for retrieving favorite playlists.
130
+ * @param {number} options.limit - The maximum number of playlists to retrieve. Default is 50.
131
+ * @param {number} options.offset - The offset of playlists to retrieve. Default is 0.
132
+ * @param {Object} options.services - The services to include for retrieving playlists. Default is an empty object.
133
+ * @param {string} options.keywords - The keywords to filter playlists by.
134
+ * @return {Promise<Object>} - An object containing the total length of the playlists and the playlist items.
135
+ */
136
+ static async getFavoritePlaylists({ limit = 50, offset = 0, services = {}, keywords } = {}) {
137
+ let result = []
138
+
139
+ let limitPerRequesters = limit
140
+
141
+ const requesters = [
142
+ async () => {
143
+ const { data } = await _request2.default.call(void 0, {
144
+ instance: MusicModel.api_instance,
145
+ method: "GET",
146
+ url: `/playlists/self`,
147
+ params: {
148
+ keywords,
149
+ },
150
+ })
151
+
152
+ return data
153
+ },
154
+ ]
155
+
156
+ if (services["tidal"] === true) {
157
+ limitPerRequesters = limitPerRequesters / (requesters.length + 1)
158
+
159
+ requesters.push(async () => {
160
+ const _result = await _sync2.default.tidalCore.getMyFavoritePlaylists({
161
+ limit: limitPerRequesters,
162
+ offset,
163
+ })
164
+
165
+ return _result
166
+ })
167
+ }
168
+
169
+ result = await _pmap2.default.call(void 0,
170
+ requesters,
171
+ async requester => {
172
+ const data = await requester()
173
+
174
+ return data
175
+ },
176
+ {
177
+ concurrency: 3,
178
+ },
179
+ )
180
+
181
+ // calculate total length
182
+ let total_length = 0
183
+
184
+ result.forEach(result => {
185
+ total_length += result.total_length
186
+ })
187
+
188
+ // reduce items
189
+ let items = result.reduce((acc, cur) => {
190
+ return [...acc, ...cur.items]
191
+ }, [])
192
+
193
+
194
+ // sort by created_at
195
+ items = items.sort((a, b) => {
196
+ return new Date(b.created_at) - new Date(a.created_at)
197
+ })
198
+
199
+ return {
200
+ total_length: total_length,
201
+ items,
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Retrieves playlist items based on the provided parameters.
207
+ *
208
+ * @param {Object} options - The options object.
209
+ * @param {string} options.playlist_id - The ID of the playlist.
210
+ * @param {string} options.service - The service from which to retrieve the playlist items.
211
+ * @param {number} options.limit - The maximum number of items to retrieve.
212
+ * @param {number} options.offset - The number of items to skip before retrieving.
213
+ * @return {Promise<Object>} Playlist items data.
214
+ */
215
+ static async getPlaylistItems({
216
+ playlist_id,
217
+ service,
218
+
219
+ limit,
220
+ offset,
221
+ }) {
222
+ if (service === "tidal") {
223
+ const result = await _sync2.default.tidalCore.getPlaylistItems({
224
+ playlist_id,
225
+
226
+ limit,
227
+ offset,
228
+
229
+ resolve_items: true,
230
+ })
231
+
232
+ return result
233
+ }
234
+
235
+ const { data } = await _request2.default.call(void 0, {
236
+ instance: MusicModel.api_instance,
237
+ method: "GET",
238
+ url: `/playlists/${playlist_id}/items`,
239
+ params: {
240
+ limit,
241
+ offset,
242
+ }
243
+ })
244
+
245
+ return data
246
+ }
247
+
248
+ /**
249
+ * Retrieves playlist data based on the provided parameters.
250
+ *
251
+ * @param {Object} options - The options object.
252
+ * @param {string} options.playlist_id - The ID of the playlist.
253
+ * @param {string} options.service - The service to use.
254
+ * @param {number} options.limit - The maximum number of items to retrieve.
255
+ * @param {number} options.offset - The offset for pagination.
256
+ * @return {Promise<Object>} Playlist data.
257
+ */
258
+ static async getPlaylistData({
259
+ playlist_id,
260
+ service,
261
+
262
+ limit,
263
+ offset,
264
+ }) {
265
+ if (service === "tidal") {
266
+ const result = await _sync2.default.tidalCore.getPlaylistData({
267
+ playlist_id,
268
+
269
+ limit,
270
+ offset,
271
+
272
+ resolve_items: true,
273
+ })
274
+
275
+ return result
276
+ }
86
277
 
87
- static __initStatic2() {this.search = async (keywords, {
88
- limit = 5,
89
- offset = 0,
90
- useTidal = false,
91
- }) => {
278
+ const { data } = await _request2.default.call(void 0, {
279
+ instance: MusicModel.api_instance,
280
+ method: "GET",
281
+ url: `/playlists/${playlist_id}/data`,
282
+ params: {
283
+ limit,
284
+ offset,
285
+ }
286
+ })
287
+
288
+ return data
289
+ }
290
+
291
+ /**
292
+ * Performs a search based on the provided keywords, with optional parameters for limiting the number of results and pagination.
293
+ *
294
+ * @param {string} keywords - The keywords to search for.
295
+ * @param {object} options - An optional object containing additional parameters.
296
+ * @param {number} options.limit - The maximum number of results to return. Defaults to 5.
297
+ * @param {number} options.offset - The offset to start returning results from. Defaults to 0.
298
+ * @param {boolean} options.useTidal - Whether to use Tidal for the search. Defaults to false.
299
+ * @return {Promise<Object>} The search results.
300
+ */
301
+ static async search(keywords, { limit = 5, offset = 0, useTidal = false }) {
92
302
  const { data } = await _request2.default.call(void 0, {
93
303
  instance: MusicModel.api_instance,
94
304
  method: "GET",
@@ -98,9 +308,239 @@ var _sync = require('../sync'); var _sync2 = _interopRequireDefault(_sync);
98
308
  limit,
99
309
  offset,
100
310
  useTidal,
101
- }
311
+ },
312
+ })
313
+
314
+ return data
315
+ }
316
+
317
+ /**
318
+ * Creates a new playlist.
319
+ *
320
+ * @param {object} payload - The payload containing the data for the new playlist.
321
+ * @return {Promise<Object>} The new playlist data.
322
+ */
323
+ static async newPlaylist(payload) {
324
+ const { data } = await _request2.default.call(void 0, {
325
+ instance: MusicModel.api_instance,
326
+ method: "POST",
327
+ url: `/playlists/new`,
328
+ data: payload,
102
329
  })
103
330
 
104
331
  return data
105
- }}
106
- } MusicModel.__initStatic(); MusicModel.__initStatic2(); exports.default = MusicModel;
332
+ }
333
+
334
+ /**
335
+ * Updates a playlist item in the specified playlist.
336
+ *
337
+ * @param {string} playlist_id - The ID of the playlist to update.
338
+ * @param {object} item - The updated playlist item to be added.
339
+ * @return {Promise<Object>} - The updated playlist item.
340
+ */
341
+ static async putPlaylistItem(playlist_id, item) {
342
+ const response = await _request2.default.call(void 0, {
343
+ instance: MusicModel.api_instance,
344
+ method: "PUT",
345
+ url: `/playlists/${playlist_id}/items`,
346
+ data: item,
347
+ })
348
+
349
+ return response.data
350
+ }
351
+
352
+ /**
353
+ * Delete a playlist item.
354
+ *
355
+ * @param {string} playlist_id - The ID of the playlist.
356
+ * @param {string} item_id - The ID of the item to delete.
357
+ * @return {Promise<Object>} The data returned by the server after the item is deleted.
358
+ */
359
+ static async deletePlaylistItem(playlist_id, item_id) {
360
+ const response = await _request2.default.call(void 0, {
361
+ instance: MusicModel.api_instance,
362
+ method: "DELETE",
363
+ url: `/playlists/${playlist_id}/items/${item_id}`,
364
+ })
365
+
366
+ return response.data
367
+ }
368
+
369
+ /**
370
+ * Deletes a playlist.
371
+ *
372
+ * @param {number} playlist_id - The ID of the playlist to be deleted.
373
+ * @return {Promise<Object>} The response data from the server.
374
+ */
375
+ static async deletePlaylist(playlist_id) {
376
+ const response = await _request2.default.call(void 0, {
377
+ instance: MusicModel.api_instance,
378
+ method: "DELETE",
379
+ url: `/playlists/${playlist_id}`,
380
+ })
381
+
382
+ return response.data
383
+ }
384
+
385
+ /**
386
+ * Execute a PUT request to update or create a release.
387
+ *
388
+ * @param {object} payload - The payload data.
389
+ * @return {Promise<Object>} The response data from the server.
390
+ */
391
+ static async putRelease(payload) {
392
+ const response = await _request2.default.call(void 0, {
393
+ instance: MusicModel.api_instance,
394
+ method: "PUT",
395
+ url: `/releases/release`,
396
+ data: payload
397
+ })
398
+
399
+ return response.data
400
+ }
401
+
402
+
403
+ /**
404
+ * Retrieves the releases associated with the authenticated user.
405
+ *
406
+ * @param {string} keywords - The keywords to filter the releases by.
407
+ * @return {Promise<Object>} A promise that resolves to the data of the releases.
408
+ */
409
+ static async getMyReleases(keywords) {
410
+ const response = await _request2.default.call(void 0, {
411
+ instance: MusicModel.api_instance,
412
+ method: "GET",
413
+ url: `/releases/self`,
414
+ params: {
415
+ keywords,
416
+ }
417
+ })
418
+
419
+ return response.data
420
+ }
421
+
422
+
423
+ /**
424
+ * Retrieves releases based on the provided parameters.
425
+ *
426
+ * @param {object} options - The options for retrieving releases.
427
+ * @param {string} options.user_id - The ID of the user.
428
+ * @param {string[]} options.keywords - The keywords to filter releases by.
429
+ * @param {number} options.limit - The maximum number of releases to retrieve.
430
+ * @param {number} options.offset - The offset for paginated results.
431
+ * @return {Promise<Object>} - A promise that resolves to the retrieved releases.
432
+ */
433
+ static async getReleases({
434
+ user_id,
435
+ keywords,
436
+ limit = 50,
437
+ offset = 0,
438
+ }) {
439
+ const response = await _request2.default.call(void 0, {
440
+ instance: MusicModel.api_instance,
441
+ method: "GET",
442
+ url: `/releases/user/${user_id}`,
443
+ params: {
444
+ keywords,
445
+ limit,
446
+ offset,
447
+ }
448
+ })
449
+
450
+ return response.data
451
+ }
452
+
453
+ /**
454
+ * Retrieves release data by ID.
455
+ *
456
+ * @param {number} id - The ID of the release.
457
+ * @return {Promise<Object>} The release data.
458
+ */
459
+ static async getReleaseData(id) {
460
+ const response = await _request2.default.call(void 0, {
461
+ instance: MusicModel.api_instance,
462
+ method: "GET",
463
+ url: `/releases/${id}/data`
464
+ })
465
+
466
+ return response.data
467
+ }
468
+
469
+ /**
470
+ * Deletes a release by its ID.
471
+ *
472
+ * @param {string} id - The ID of the release to delete.
473
+ * @return {Promise<Object>} - A Promise that resolves to the data returned by the API.
474
+ */
475
+ static async deleteRelease(id) {
476
+ const response = await _request2.default.call(void 0, {
477
+ instance: MusicModel.api_instance,
478
+ method: "DELETE",
479
+ url: `/releases/${id}`
480
+ })
481
+
482
+ return response.data
483
+ }
484
+
485
+ /**
486
+ * Refreshes the track cache for a given track ID.
487
+ *
488
+ * @param {string} track_id - The ID of the track to refresh the cache for.
489
+ * @throws {Error} If track_id is not provided.
490
+ * @return {Promise<Object>} The response data from the API call.
491
+ */
492
+ static async refreshTrackCache(track_id) {
493
+ if (!track_id) {
494
+ throw new Error("Track ID is required")
495
+ }
496
+
497
+ const response = await _request2.default.call(void 0, {
498
+ instance: MusicModel.api_instance,
499
+ method: "POST",
500
+ url: `/tracks/${track_id}/refresh-cache`,
501
+ })
502
+
503
+ return response.data
504
+ }
505
+
506
+ /**
507
+ * Toggles the like status of a track.
508
+ *
509
+ * @param {Object} manifest - The manifest object containing track information.
510
+ * @param {boolean} to - The like status to toggle (true for like, false for unlike).
511
+ * @throws {Error} Throws an error if the manifest is missing.
512
+ * @return {Object} The response data from the API.
513
+ */
514
+ static async toggleTrackLike(manifest, to) {
515
+ if (!manifest) {
516
+ throw new Error("Manifest is required")
517
+ }
518
+
519
+ console.log(`Toggling track ${manifest._id} like status to ${to}`)
520
+
521
+ const track_id = manifest._id
522
+
523
+ switch (manifest.service) {
524
+ case "tidal": {
525
+ const response = await _sync2.default.tidalCore.toggleTrackLike({
526
+ track_id,
527
+ to,
528
+ })
529
+
530
+ return response
531
+ }
532
+ default: {
533
+ const response = await _request2.default.call(void 0, {
534
+ instance: MusicModel.api_instance,
535
+ method: to ? "POST" : "DELETE",
536
+ url: `/tracks/${track_id}/like`,
537
+ params: {
538
+ service: manifest.service
539
+ }
540
+ })
541
+
542
+ return response.data
543
+ }
544
+ }
545
+ }
546
+ } exports.default = MusicModel;
@@ -97,4 +97,76 @@
97
97
 
98
98
  return data
99
99
  }
100
+
101
+ static async getMyFavoritePlaylists({
102
+ limit = 50,
103
+ offset = 0,
104
+ } = {}) {
105
+ const { data } = await _request2.default.call(void 0, {
106
+ instance: TidalService.api_instance,
107
+ method: "GET",
108
+ url: `/services/tidal/favorites/playlists`,
109
+ params: {
110
+ limit,
111
+ offset,
112
+ },
113
+ })
114
+
115
+ return data
116
+ }
117
+
118
+ static async getPlaylistData({
119
+ playlist_id,
120
+
121
+ resolve_items = false,
122
+ limit = 50,
123
+ offset = 0,
124
+ }) {
125
+ const { data } = await _request2.default.call(void 0, {
126
+ instance: TidalService.api_instance,
127
+ method: "GET",
128
+ url: `/services/tidal/playlist/${playlist_id}/data`,
129
+ params: {
130
+ limit,
131
+ offset,
132
+ resolve_items,
133
+ },
134
+ })
135
+
136
+ return data
137
+ }
138
+
139
+ static async getPlaylistItems({
140
+ playlist_id,
141
+
142
+ resolve_items = false,
143
+ limit = 50,
144
+ offset = 0,
145
+ }) {
146
+ const { data } = await _request2.default.call(void 0, {
147
+ instance: TidalService.api_instance,
148
+ method: "GET",
149
+ url: `/services/tidal/playlist/${playlist_id}/items`,
150
+ params: {
151
+ limit,
152
+ offset,
153
+ resolve_items,
154
+ },
155
+ })
156
+
157
+ return data
158
+ }
159
+
160
+ static async toggleTrackLike({
161
+ track_id,
162
+ to,
163
+ }) {
164
+ const { data } = await _request2.default.call(void 0, {
165
+ instance: TidalService.api_instance,
166
+ method: to ? "POST" : "DELETE",
167
+ url: `/services/tidal/track/${track_id}/like`,
168
+ })
169
+
170
+ return data
171
+ }
100
172
  } exports.default = TidalService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comty.js",
3
- "version": "0.57.5",
3
+ "version": "0.58.2",
4
4
  "main": "./dist/index.js",
5
5
  "author": "RageStudio <support@ragestudio.net>",
6
6
  "scripts": {