comty.js 0.56.0 → 0.57.5

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
@@ -7,32 +7,50 @@ 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
10
11
  static __initStatic() {this.getFavorites = async ({
11
- useTidal = false
12
+ useTidal = false,
13
+ limit,
14
+ offset,
12
15
  }) => {
13
16
  let result = []
14
17
 
18
+ let limitPerRequesters = limit
19
+
20
+ if (useTidal) {
21
+ limitPerRequesters = limitPerRequesters / 2
22
+ }
23
+
15
24
  const requesters = [
16
25
  async () => {
17
26
  let { data } = await _request2.default.call(void 0, {
18
27
  instance: MusicModel.api_instance,
19
28
  method: "GET",
20
29
  url: `/tracks/liked`,
30
+ params: {
31
+ limit: limitPerRequesters,
32
+ offset,
33
+ },
21
34
  })
22
35
 
23
36
  return data
24
37
  },
25
- ]
38
+ async () => {
39
+ if (!useTidal) {
40
+ return {
41
+ total_length: 0,
42
+ tracks: [],
43
+ }
44
+ }
26
45
 
27
- if (useTidal) {
28
- requesters.push(
29
- async () => {
30
- const tidalResult = await _sync2.default.tidalCore.getMyFavoriteTracks()
46
+ const tidalResult = await _sync2.default.tidalCore.getMyFavoriteTracks({
47
+ limit: limitPerRequesters,
48
+ offset,
49
+ })
31
50
 
32
- return tidalResult
33
- }
34
- )
35
- }
51
+ return tidalResult
52
+ },
53
+ ]
36
54
 
37
55
  result = await _pmap2.default.call(void 0,
38
56
  requesters,
@@ -46,17 +64,24 @@ var _sync = require('../sync'); var _sync2 = _interopRequireDefault(_sync);
46
64
  }
47
65
  )
48
66
 
49
- result = result.reduce((acc, cur) => {
50
- return [...acc, ...cur]
67
+ let total_length = 0
68
+
69
+ result.forEach((result) => {
70
+ total_length += result.total_length
71
+ })
72
+
73
+ let tracks = result.reduce((acc, cur) => {
74
+ return [...acc, ...cur.tracks]
51
75
  }, [])
52
76
 
53
- result = result.sort((a, b) => {
77
+ tracks = tracks.sort((a, b) => {
54
78
  return b.liked_at - a.liked_at
55
79
  })
56
80
 
57
- console.log(result)
58
-
59
- return result
81
+ return {
82
+ total_length,
83
+ tracks,
84
+ }
60
85
  }}
61
86
 
62
87
  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 = () => {
@@ -81,11 +81,18 @@
81
81
  return data
82
82
  }
83
83
 
84
- static async getMyFavoriteTracks() {
84
+ static async getMyFavoriteTracks({
85
+ limit = 50,
86
+ offset = 0,
87
+ } = {}) {
85
88
  const { data } = await _request2.default.call(void 0, {
86
89
  instance: TidalService.api_instance,
87
90
  method: "GET",
88
91
  url: `/services/tidal/favorites/tracks`,
92
+ params: {
93
+ limit,
94
+ offset,
95
+ },
89
96
  })
90
97
 
91
98
  return data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "comty.js",
3
- "version": "0.56.0",
3
+ "version": "0.57.5",
4
4
  "main": "./dist/index.js",
5
5
  "author": "RageStudio <support@ragestudio.net>",
6
6
  "scripts": {