comty.js 0.55.0 → 0.57.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.
@@ -4,7 +4,7 @@ var _session = require('../session'); var _session2 = _interopRequireDefault(_se
4
4
  const emailRegex = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/)
5
5
 
6
6
  class AuthModel {
7
- static __initStatic() {this.login = async (payload) => {
7
+ static __initStatic() {this.login = async (payload, callback) => {
8
8
  const response = await _request2.default.call(void 0, {
9
9
  method: "post",
10
10
  url: "/auth/login",
@@ -16,6 +16,10 @@ const emailRegex = new RegExp(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/)
16
16
 
17
17
  _session2.default.token = response.data.token
18
18
 
19
+ if (typeof callback === "function") {
20
+ await callback()
21
+ }
22
+
19
23
  __comty_shared_state.eventBus.emit("auth:login_success")
20
24
 
21
25
  return response.data
@@ -28,7 +28,7 @@ var _withSettings = require('../../helpers/withSettings'); var _withSettings2 =
28
28
  return data
29
29
  }}
30
30
 
31
- static __initStatic3() {this.getTimelineFeed = async ({ trim, limit } = {}) => {
31
+ static __initStatic3() {this.getTimelineFeed = async ({ trim, limit = 10 } = {}) => {
32
32
  const { data } = await _request2.default.call(void 0, {
33
33
  method: "GET",
34
34
  url: `/feed/timeline`,
@@ -1,18 +1,84 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _request = require('../../handlers/request'); var _request2 = _interopRequireDefault(_request);
2
+ var _pmap = require('p-map'); var _pmap2 = _interopRequireDefault(_pmap);
3
+ var _sync = require('../sync'); var _sync2 = _interopRequireDefault(_sync);
2
4
 
3
5
  class MusicModel {
4
6
  static get api_instance() {
5
7
  return globalThis.__comty_shared_state.instances["music"]
6
8
  }
7
9
 
8
- static __initStatic() {this.getFavorites = async () => {
9
- const { data } = await _request2.default.call(void 0, {
10
- instance: MusicModel.api_instance,
11
- method: "GET",
12
- url: `/tracks/liked`,
10
+ // TODO: Move external services fetching to API
11
+ static __initStatic() {this.getFavorites = async ({
12
+ useTidal = false,
13
+ limit,
14
+ offset,
15
+ }) => {
16
+ let result = []
17
+
18
+ let limitPerRequesters = limit
19
+
20
+ if (useTidal) {
21
+ limitPerRequesters = limitPerRequesters / 2
22
+ }
23
+
24
+ const requesters = [
25
+ async () => {
26
+ let { data } = await _request2.default.call(void 0, {
27
+ instance: MusicModel.api_instance,
28
+ method: "GET",
29
+ url: `/tracks/liked`,
30
+ params: {
31
+ limit: limitPerRequesters,
32
+ offset,
33
+ },
34
+ })
35
+
36
+ return data
37
+ },
38
+ async () => {
39
+ if (!useTidal) {
40
+ return []
41
+ }
42
+
43
+ const tidalResult = await _sync2.default.tidalCore.getMyFavoriteTracks({
44
+ limit: limitPerRequesters,
45
+ offset,
46
+ })
47
+
48
+ return tidalResult
49
+ },
50
+ ]
51
+
52
+ result = await _pmap2.default.call(void 0,
53
+ requesters,
54
+ async (requester) => {
55
+ const data = await requester()
56
+
57
+ return data
58
+ },
59
+ {
60
+ concurrency: 3
61
+ }
62
+ )
63
+
64
+ let total_length = 0
65
+
66
+ result.forEach((result) => {
67
+ total_length += result.total_length
13
68
  })
14
69
 
15
- return data
70
+ let tracks = result.reduce((acc, cur) => {
71
+ return [...acc, ...cur.tracks]
72
+ }, [])
73
+
74
+ tracks = tracks.sort((a, b) => {
75
+ return b.liked_at - a.liked_at
76
+ })
77
+
78
+ return {
79
+ total_length,
80
+ tracks,
81
+ }
16
82
  }}
17
83
 
18
84
  static __initStatic2() {this.search = async (keywords, {
@@ -13,12 +13,16 @@ var _withStorage = require('../../helpers/withStorage'); var _withStorage2 = _in
13
13
  return _withStorage2.default.engine.set(this.storageTokenKey, token)
14
14
  }
15
15
 
16
+ static get roles() {
17
+ return _optionalChain([this, 'access', _ => _.getDecodedToken, 'call', _2 => _2(), 'optionalAccess', _3 => _3.roles])
18
+ }
19
+
16
20
  static get user_id() {
17
- return _optionalChain([this, 'access', _ => _.getDecodedToken, 'call', _2 => _2(), 'optionalAccess', _3 => _3.user_id])
21
+ return _optionalChain([this, 'access', _4 => _4.getDecodedToken, 'call', _5 => _5(), 'optionalAccess', _6 => _6.user_id])
18
22
  }
19
23
 
20
24
  static get session_uuid() {
21
- return _optionalChain([this, 'access', _4 => _4.getDecodedToken, 'call', _5 => _5(), 'optionalAccess', _6 => _6.session_uuid])
25
+ return _optionalChain([this, 'access', _7 => _7.getDecodedToken, 'call', _8 => _8(), 'optionalAccess', _9 => _9.session_uuid])
22
26
  }
23
27
 
24
28
  static __initStatic2() {this.getDecodedToken = () => {
@@ -1,6 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _spotify = require('./services/spotify'); var _spotify2 = _interopRequireDefault(_spotify);
2
2
  var _tidal = require('./services/tidal'); var _tidal2 = _interopRequireDefault(_tidal);
3
3
 
4
+ var _request = require('../../handlers/request'); var _request2 = _interopRequireDefault(_request);
5
+
4
6
  const namespacesServices = {
5
7
  spotify: _spotify2.default,
6
8
  tidal: _tidal2.default
@@ -44,4 +46,14 @@ const namespacesServices = {
44
46
 
45
47
  return await service.isActive()
46
48
  }
49
+
50
+ static async getLinkedServices() {
51
+ const response = await _request2.default.call(void 0, {
52
+ instance: globalThis.__comty_shared_state.instances["sync"],
53
+ method: "GET",
54
+ url: "/active_services",
55
+ })
56
+
57
+ return response.data
58
+ }
47
59
  } exports.default = SyncModel;
@@ -80,4 +80,21 @@
80
80
 
81
81
  return data
82
82
  }
83
+
84
+ static async getMyFavoriteTracks({
85
+ limit = 50,
86
+ offset = 0,
87
+ } = {}) {
88
+ const { data } = await _request2.default.call(void 0, {
89
+ instance: TidalService.api_instance,
90
+ method: "GET",
91
+ url: `/services/tidal/favorites/tracks`,
92
+ params: {
93
+ limit,
94
+ offset,
95
+ },
96
+ })
97
+
98
+ return data
99
+ }
83
100
  } exports.default = TidalService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comty.js",
3
- "version": "0.55.0",
3
+ "version": "0.57.2",
4
4
  "main": "./dist/index.js",
5
5
  "author": "RageStudio <support@ragestudio.net>",
6
6
  "scripts": {
@@ -16,6 +16,7 @@
16
16
  "js-cookie": "^3.0.5",
17
17
  "jsonwebtoken": "^9.0.0",
18
18
  "jwt-decode": "^3.1.2",
19
+ "luxon": "^3.3.0",
19
20
  "socket.io-client": "^4.6.1"
20
21
  },
21
22
  "devDependencies": {