comty.js 0.54.0 → 0.56.0
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.
|
@@ -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,17 +1,81 @@
|
|
|
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 (
|
|
10
|
+
static __initStatic() {this.getFavorites = async ({
|
|
11
|
+
useTidal = false
|
|
12
|
+
}) => {
|
|
13
|
+
let result = []
|
|
14
|
+
|
|
15
|
+
const requesters = [
|
|
16
|
+
async () => {
|
|
17
|
+
let { data } = await _request2.default.call(void 0, {
|
|
18
|
+
instance: MusicModel.api_instance,
|
|
19
|
+
method: "GET",
|
|
20
|
+
url: `/tracks/liked`,
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
return data
|
|
24
|
+
},
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
if (useTidal) {
|
|
28
|
+
requesters.push(
|
|
29
|
+
async () => {
|
|
30
|
+
const tidalResult = await _sync2.default.tidalCore.getMyFavoriteTracks()
|
|
31
|
+
|
|
32
|
+
return tidalResult
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
result = await _pmap2.default.call(void 0,
|
|
38
|
+
requesters,
|
|
39
|
+
async (requester) => {
|
|
40
|
+
const data = await requester()
|
|
41
|
+
|
|
42
|
+
return data
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
concurrency: 3
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
result = result.reduce((acc, cur) => {
|
|
50
|
+
return [...acc, ...cur]
|
|
51
|
+
}, [])
|
|
52
|
+
|
|
53
|
+
result = result.sort((a, b) => {
|
|
54
|
+
return b.liked_at - a.liked_at
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
console.log(result)
|
|
58
|
+
|
|
59
|
+
return result
|
|
60
|
+
}}
|
|
61
|
+
|
|
62
|
+
static __initStatic2() {this.search = async (keywords, {
|
|
63
|
+
limit = 5,
|
|
64
|
+
offset = 0,
|
|
65
|
+
useTidal = false,
|
|
66
|
+
}) => {
|
|
9
67
|
const { data } = await _request2.default.call(void 0, {
|
|
10
68
|
instance: MusicModel.api_instance,
|
|
11
69
|
method: "GET",
|
|
12
|
-
url: `/
|
|
70
|
+
url: `/search`,
|
|
71
|
+
params: {
|
|
72
|
+
keywords,
|
|
73
|
+
limit,
|
|
74
|
+
offset,
|
|
75
|
+
useTidal,
|
|
76
|
+
}
|
|
13
77
|
})
|
|
14
78
|
|
|
15
79
|
return data
|
|
16
80
|
}}
|
|
17
|
-
} MusicModel.__initStatic(); exports.default = MusicModel;
|
|
81
|
+
} MusicModel.__initStatic(); MusicModel.__initStatic2(); exports.default = MusicModel;
|
|
@@ -1,11 +1,59 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
+
var _tidal = require('./services/tidal'); var _tidal2 = _interopRequireDefault(_tidal);
|
|
3
|
+
|
|
4
|
+
var _request = require('../../handlers/request'); var _request2 = _interopRequireDefault(_request);
|
|
5
|
+
|
|
6
|
+
const namespacesServices = {
|
|
7
|
+
spotify: _spotify2.default,
|
|
8
|
+
tidal: _tidal2.default
|
|
9
|
+
}
|
|
2
10
|
|
|
3
11
|
class SyncModel {
|
|
4
|
-
static get
|
|
5
|
-
return
|
|
12
|
+
static get spotifyCore() {
|
|
13
|
+
return namespacesServices.spotify
|
|
6
14
|
}
|
|
7
15
|
|
|
8
|
-
static get
|
|
9
|
-
return
|
|
16
|
+
static get tidalCore() {
|
|
17
|
+
return namespacesServices.tidal
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static async linkService(namespace) {
|
|
21
|
+
const service = namespacesServices[namespace]
|
|
22
|
+
|
|
23
|
+
if (!service || typeof service.linkAccount !== "function") {
|
|
24
|
+
throw new Error(`Service ${namespace} not found or not accepting linking.`)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return await service.linkAccount()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static async unlinkService(namespace) {
|
|
31
|
+
const service = namespacesServices[namespace]
|
|
32
|
+
|
|
33
|
+
if (!service || typeof service.unlinkAccount !== "function") {
|
|
34
|
+
throw new Error(`Service ${namespace} not found or not accepting unlinking.`)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return await service.unlinkAccount()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static async hasServiceLinked(namespace) {
|
|
41
|
+
const service = namespacesServices[namespace]
|
|
42
|
+
|
|
43
|
+
if (!service || typeof service.isActive !== "function") {
|
|
44
|
+
throw new Error(`Service ${namespace} not found or not accepting linking.`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return await service.isActive()
|
|
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
|
|
10
58
|
}
|
|
11
59
|
} exports.default = SyncModel;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); class SpotifySyncModel {
|
|
2
|
+
static get spotify_redirect_uri() {
|
|
3
|
+
return window.location.origin + "/callbacks/sync/spotify"
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
static get spotify_authorize_endpoint() {
|
|
7
|
+
return "https://accounts.spotify.com/authorize?response_type=code&client_id={{client_id}}&scope={{scope}}&redirect_uri={{redirect_uri}}&response_type=code"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static async authorizeAccount() {
|
|
11
|
+
const scopes = [
|
|
12
|
+
"user-read-private",
|
|
13
|
+
"user-modify-playback-state",
|
|
14
|
+
"user-read-currently-playing",
|
|
15
|
+
"user-read-playback-state",
|
|
16
|
+
"streaming",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
const { client_id } = await SpotifySyncModel.get_client_id()
|
|
20
|
+
|
|
21
|
+
const parsedUrl = SpotifySyncModel.spotify_authorize_endpoint
|
|
22
|
+
.replace("{{client_id}}", client_id)
|
|
23
|
+
.replace("{{scope}}", scopes.join(" "))
|
|
24
|
+
.replace("{{redirect_uri}}", SpotifySyncModel.spotify_redirect_uri)
|
|
25
|
+
|
|
26
|
+
// open on a new tab
|
|
27
|
+
window.open(parsedUrl, "_blank")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static async get_client_id() {
|
|
31
|
+
const { data } = await app.cores.api.customRequest({
|
|
32
|
+
method: "GET",
|
|
33
|
+
url: `/sync/spotify/client_id`,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
return data
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static async syncAuthCode(code) {
|
|
40
|
+
const { data } = await app.cores.api.customRequest({
|
|
41
|
+
method: "POST",
|
|
42
|
+
url: `/sync/spotify/auth`,
|
|
43
|
+
data: {
|
|
44
|
+
redirect_uri: SpotifySyncModel.spotify_redirect_uri,
|
|
45
|
+
code,
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return data
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static async unlinkAccount() {
|
|
53
|
+
const { data } = await app.cores.api.customRequest({
|
|
54
|
+
method: "POST",
|
|
55
|
+
url: `/sync/spotify/unlink`,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return data
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static async isAuthorized() {
|
|
62
|
+
const { data } = await app.cores.api.customRequest({
|
|
63
|
+
method: "GET",
|
|
64
|
+
url: `/sync/spotify/is_authorized`,
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
return data
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async getData() {
|
|
71
|
+
const { data } = await app.cores.api.customRequest({
|
|
72
|
+
method: "GET",
|
|
73
|
+
url: `/sync/spotify/data`,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
return data
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static async getCurrentPlaying() {
|
|
80
|
+
const { data } = await app.cores.api.customRequest({
|
|
81
|
+
method: "GET",
|
|
82
|
+
url: `/sync/spotify/currently_playing`,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
return data
|
|
86
|
+
}
|
|
87
|
+
} exports.default = SpotifySyncModel;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
|
|
3
|
+
class TidalService {
|
|
4
|
+
static get api_instance() {
|
|
5
|
+
return globalThis.__comty_shared_state.instances["sync"]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static async linkAccount() {
|
|
9
|
+
if (!window) {
|
|
10
|
+
throw new Error("This method is only available in the browser.")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { data } = await _request2.default.call(void 0, {
|
|
14
|
+
instance: TidalService.api_instance,
|
|
15
|
+
method: "GET",
|
|
16
|
+
url: `/services/tidal/create_link`,
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
if (data.auth_url) {
|
|
20
|
+
window.open(data.auth_url, "_blank")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return data
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static async unlinkAccount() {
|
|
27
|
+
if (!window) {
|
|
28
|
+
throw new Error("This method is only available in the browser.")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { data } = await _request2.default.call(void 0, {
|
|
32
|
+
instance: TidalService.api_instance,
|
|
33
|
+
method: "POST",
|
|
34
|
+
url: `/services/tidal/delete_link`,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return data
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static async isActive() {
|
|
41
|
+
if (!window) {
|
|
42
|
+
throw new Error("This method is only available in the browser.")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const { data } = await _request2.default.call(void 0, {
|
|
46
|
+
instance: TidalService.api_instance,
|
|
47
|
+
method: "GET",
|
|
48
|
+
url: `/services/tidal/is_active`,
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
return data
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static async getCurrentUser() {
|
|
55
|
+
const { data } = await _request2.default.call(void 0, {
|
|
56
|
+
instance: TidalService.api_instance,
|
|
57
|
+
method: "GET",
|
|
58
|
+
url: `/services/tidal/current`,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
return data
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static async getPlaybackUrl(track_id) {
|
|
65
|
+
const { data } = await _request2.default.call(void 0, {
|
|
66
|
+
instance: TidalService.api_instance,
|
|
67
|
+
method: "GET",
|
|
68
|
+
url: `/services/tidal/playback/${track_id}`,
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
return data
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static async getTrackManifest(track_id) {
|
|
75
|
+
const { data } = await _request2.default.call(void 0, {
|
|
76
|
+
instance: TidalService.api_instance,
|
|
77
|
+
method: "GET",
|
|
78
|
+
url: `/services/tidal/manifest/${track_id}`,
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
return data
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static async getMyFavoriteTracks() {
|
|
85
|
+
const { data } = await _request2.default.call(void 0, {
|
|
86
|
+
instance: TidalService.api_instance,
|
|
87
|
+
method: "GET",
|
|
88
|
+
url: `/services/tidal/favorites/tracks`,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
return data
|
|
92
|
+
}
|
|
93
|
+
} exports.default = TidalService;
|
package/dist/remotes.js
CHANGED
|
@@ -24,6 +24,7 @@ const envOrigins = {
|
|
|
24
24
|
marketplace: `http://${getCurrentHostname()}:3040`,
|
|
25
25
|
music: `http://${getCurrentHostname()}:3050`,
|
|
26
26
|
files: `http://${getCurrentHostname()}:3060`,
|
|
27
|
+
sync: `http://${getCurrentHostname()}:3070`,
|
|
27
28
|
},
|
|
28
29
|
"indev": {
|
|
29
30
|
default: `https://indev_api.comty.app/main`,
|
|
@@ -32,6 +33,7 @@ const envOrigins = {
|
|
|
32
33
|
marketplace: `https://indev_api.comty.app/marketplace`,
|
|
33
34
|
music: `https://indev_api.comty.app/music`,
|
|
34
35
|
files: `https://indev_api.comty.app/files`,
|
|
36
|
+
sync: `https://indev_api.comty.app/sync`,
|
|
35
37
|
},
|
|
36
38
|
"production": {
|
|
37
39
|
default: "https://api.comty.app",
|
|
@@ -40,6 +42,7 @@ const envOrigins = {
|
|
|
40
42
|
marketplace: `https://marketplace_api.comty.app`,
|
|
41
43
|
music: `https://music_api.comty.app`,
|
|
42
44
|
files: `https://files_api.comty.app`,
|
|
45
|
+
sync: `https://sync_api.comty.app`,
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
|
|
@@ -67,5 +70,9 @@ exports. default = {
|
|
|
67
70
|
files: {
|
|
68
71
|
origin: composeRemote("files"),
|
|
69
72
|
hasWebsocket: false,
|
|
73
|
+
},
|
|
74
|
+
sync: {
|
|
75
|
+
origin: composeRemote("sync"),
|
|
76
|
+
hasWebsocket: false,
|
|
70
77
|
}
|
|
71
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "comty.js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.56.0",
|
|
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": {
|