javascript-ampache 1.0.8 → 1.1.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.
- package/README.md +50 -47
- package/dist/base.d.ts +6 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.m.js +1 -1
- package/dist/index.m.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +38 -38
- package/src/albums/index.ts +86 -86
- package/src/albums/types.ts +38 -32
- package/src/artists/index.ts +88 -88
- package/src/artists/types.ts +38 -32
- package/src/auth/index.ts +103 -103
- package/src/auth/types.ts +25 -25
- package/src/base.ts +134 -97
- package/src/bookmarks/index.ts +115 -122
- package/src/bookmarks/types.ts +15 -9
- package/src/catalogs/index.ts +130 -119
- package/src/catalogs/types.ts +27 -15
- package/src/genres/index.ts +39 -40
- package/src/genres/types.ts +23 -17
- package/src/index.ts +63 -26
- package/src/labels/index.ts +43 -44
- package/src/labels/types.ts +20 -14
- package/src/licenses/index.ts +43 -44
- package/src/licenses/types.ts +14 -8
- package/src/live-streams/index.ts +104 -107
- package/src/live-streams/types.ts +16 -10
- package/src/playlists/index.ts +264 -269
- package/src/playlists/types.ts +20 -14
- package/src/podcasts/index.ts +174 -177
- package/src/podcasts/types.ts +85 -67
- package/src/preferences/index.ts +114 -116
- package/src/preferences/types.ts +18 -12
- package/src/shares/index.ts +100 -96
- package/src/shares/types.ts +25 -19
- package/src/shouts/index.ts +18 -22
- package/src/shouts/types.ts +9 -9
- package/src/songs/index.ts +208 -203
- package/src/songs/types.ts +77 -65
- package/src/system/index.ts +689 -572
- package/src/system/types.ts +33 -19
- package/src/users/index.ts +227 -245
- package/src/users/types.ts +38 -32
- package/src/utils.ts +25 -25
- package/src/videos/index.ts +49 -53
- package/src/videos/types.ts +42 -30
package/src/auth/index.ts
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import JsSHA from "jssha/dist/sha256";
|
|
2
|
-
import qs from
|
|
3
|
-
import fetch from "isomorphic-unfetch";
|
|
4
|
-
import { Base, Success } from "../base";
|
|
5
|
-
import { AuthResponse } from
|
|
6
|
-
|
|
7
|
-
export class Auth extends Base {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
1
|
+
import JsSHA from "jssha/dist/sha256";
|
|
2
|
+
import qs from "querystringify";
|
|
3
|
+
import fetch from "isomorphic-unfetch";
|
|
4
|
+
import { Base, Success } from "../base";
|
|
5
|
+
import { AuthResponse } from "./types";
|
|
6
|
+
|
|
7
|
+
export class Auth extends Base {
|
|
8
|
+
/**
|
|
9
|
+
* Handles verifying a new handshake
|
|
10
|
+
* @remarks MINIMUM_API_VERSION=380001
|
|
11
|
+
* @param params.auth encrypted apikey OR password if using password auth
|
|
12
|
+
* @param [params.user] username
|
|
13
|
+
* @param [params.timestamp] UNIXTIME()
|
|
14
|
+
* @param [params.version] version of Ampache API to establish connection with
|
|
15
|
+
* @see {@link https://ampache.org/api/api-json-methods#handshake}
|
|
16
|
+
*/
|
|
17
|
+
handshake(params: {
|
|
18
|
+
auth: string;
|
|
19
|
+
user?: string;
|
|
20
|
+
timestamp?: number;
|
|
21
|
+
version?: string;
|
|
22
|
+
}) {
|
|
23
|
+
// generate a timestamp if one wasn't provided
|
|
24
|
+
if (!params.timestamp) {
|
|
25
|
+
params.timestamp = Math.floor(new Date().getTime() / 1000);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// override the fallback API version with specified
|
|
29
|
+
if (params.version) {
|
|
30
|
+
this.version = params.version;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// drop timestamp if no user provided (i.e. logging in with API key)
|
|
34
|
+
if (!params.user) {
|
|
35
|
+
delete params.timestamp;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let query = this.url + "/server/json.server.php?action=handshake";
|
|
39
|
+
query += qs.stringify(params, "&");
|
|
40
|
+
|
|
41
|
+
return fetch(query)
|
|
42
|
+
.then((response) => response.json())
|
|
43
|
+
.then((data) => {
|
|
44
|
+
if (data.auth) {
|
|
45
|
+
this.sessionKey = data.auth;
|
|
46
|
+
}
|
|
47
|
+
return <AuthResponse>data;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* This can be called without being authenticated, it is useful for determining if what the status
|
|
53
|
+
* of the server is, and what version it is running/compatible with
|
|
54
|
+
* @remarks MINIMUM_API_VERSION=380001
|
|
55
|
+
* @param [params.auth] (Session ID) returns version information and extends the session if passed
|
|
56
|
+
* @param [params.version] API Version that the application understands
|
|
57
|
+
* @see {@link https://ampache.org/api/api-json-methods#ping}
|
|
58
|
+
*/
|
|
59
|
+
ping(params?: { auth?: string; version?: string }) {
|
|
60
|
+
let query = "ping";
|
|
61
|
+
query += qs.stringify(params, "&");
|
|
62
|
+
return this.request<AuthResponse>(query);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Destroy a session using the session auth parameter
|
|
67
|
+
* @remarks MINIMUM_API_VERSION=400001
|
|
68
|
+
* @param params.auth Session ID to destroy
|
|
69
|
+
* @see {@link https://ampache.org/api/api-json-methods#goodbye}
|
|
70
|
+
*/
|
|
71
|
+
goodbye(params: { auth: string }) {
|
|
72
|
+
let query = "goodbye";
|
|
73
|
+
query += qs.stringify(params, "&");
|
|
74
|
+
return this.request<Success>(query);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Email a new password to the user (if allowed) using a reset token.
|
|
79
|
+
* @remarks MINIMUM_API_VERSION=6.1.0
|
|
80
|
+
* @param params.auth Password reset token
|
|
81
|
+
* @see {@link https://ampache.org/api/api-json-methods#lost_password}
|
|
82
|
+
*/
|
|
83
|
+
lostPassword(params: { auth: string }) {
|
|
84
|
+
let query = "lost_password";
|
|
85
|
+
query += qs.stringify(params, "&");
|
|
86
|
+
return this.request<Success>(query);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Encrypt your password into the accepted format.
|
|
91
|
+
*/
|
|
92
|
+
encryptPassword(params: { password: string; time: number }) {
|
|
93
|
+
let key = getSHA256(params.password);
|
|
94
|
+
return getSHA256(params.time + key);
|
|
95
|
+
|
|
96
|
+
function getSHA256(text) {
|
|
97
|
+
let shaObj = new JsSHA("SHA-256", "TEXT", { encoding: "UTF8" });
|
|
98
|
+
shaObj.update(text);
|
|
99
|
+
|
|
100
|
+
return shaObj.getHash("HEX");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
package/src/auth/types.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export type AuthResponse = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
1
|
+
export type AuthResponse = {
|
|
2
|
+
add: string;
|
|
3
|
+
albums: number;
|
|
4
|
+
api: string;
|
|
5
|
+
artists: number;
|
|
6
|
+
auth: string;
|
|
7
|
+
catalogs: number;
|
|
8
|
+
compatible: string;
|
|
9
|
+
clean: string;
|
|
10
|
+
genres: number;
|
|
11
|
+
labels: number;
|
|
12
|
+
licenses: number;
|
|
13
|
+
live_streams: number;
|
|
14
|
+
playlists: number;
|
|
15
|
+
podcasts: number;
|
|
16
|
+
podcast_episodes: number;
|
|
17
|
+
server: string;
|
|
18
|
+
session_expire: string;
|
|
19
|
+
shares: number;
|
|
20
|
+
songs: number;
|
|
21
|
+
update: string;
|
|
22
|
+
user: number;
|
|
23
|
+
version: string;
|
|
24
|
+
videos: number;
|
|
25
|
+
};
|
package/src/base.ts
CHANGED
|
@@ -1,97 +1,134 @@
|
|
|
1
|
-
import fetch from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* @param [
|
|
25
|
-
* @param [
|
|
26
|
-
* @param [
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
1
|
+
import fetch from "isomorphic-unfetch";
|
|
2
|
+
import qs from "querystringify";
|
|
3
|
+
|
|
4
|
+
type Config = {
|
|
5
|
+
url: string;
|
|
6
|
+
sessionKey?: string;
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type Success = {
|
|
11
|
+
success: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param [offset] Return results starting from this index position
|
|
16
|
+
* @param [limit] Maximum number of results to return
|
|
17
|
+
*/
|
|
18
|
+
export type Pagination = {
|
|
19
|
+
offset?: number;
|
|
20
|
+
limit?: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param [offset] Return results starting from this index position
|
|
25
|
+
* @param [limit] Maximum number of results to return
|
|
26
|
+
* @param [cond] Apply additional filters to the browse using ; separated comma string pairs (e.g. 'filter1,value1;filter2,value2')
|
|
27
|
+
* @param [sort] Sort name or comma-separated key pair. (e.g. 'name,order') Default order 'ASC' (e.g. 'name,ASC' == 'name')
|
|
28
|
+
*/
|
|
29
|
+
export type ExtendedPagination = Pagination & {
|
|
30
|
+
cond?: string;
|
|
31
|
+
sort?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type BinaryBoolean = 0 | 1;
|
|
35
|
+
|
|
36
|
+
export type UID = string | number;
|
|
37
|
+
|
|
38
|
+
export abstract class Base {
|
|
39
|
+
sessionKey: string;
|
|
40
|
+
url: string;
|
|
41
|
+
version: string = "6.3.0"; // default to latest version
|
|
42
|
+
debug: boolean;
|
|
43
|
+
|
|
44
|
+
constructor(config: Config) {
|
|
45
|
+
this.sessionKey = config.sessionKey || null;
|
|
46
|
+
this.url = config.url;
|
|
47
|
+
this.debug = config.debug || false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected request<T>(endpoint: string): Promise<T> {
|
|
51
|
+
let url =
|
|
52
|
+
this.url +
|
|
53
|
+
"/server/json.server.php?action=" +
|
|
54
|
+
endpoint +
|
|
55
|
+
"&version=" +
|
|
56
|
+
this.version;
|
|
57
|
+
|
|
58
|
+
if (this.debug) {
|
|
59
|
+
console.debug(
|
|
60
|
+
"javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
|
|
61
|
+
"color: black; font-style: italic; background-color: orange;padding: 2px",
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return fetch(url, {
|
|
66
|
+
method: "GET",
|
|
67
|
+
headers: {
|
|
68
|
+
Authorization: "Bearer " + this.sessionKey,
|
|
69
|
+
},
|
|
70
|
+
}).then((r) => {
|
|
71
|
+
if (r.ok) {
|
|
72
|
+
return r.json();
|
|
73
|
+
}
|
|
74
|
+
throw new Error(r.statusText);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
protected binary<T>(endpoint: string): Promise<Blob> {
|
|
79
|
+
let url =
|
|
80
|
+
this.url +
|
|
81
|
+
"/server/json.server.php?action=" +
|
|
82
|
+
endpoint +
|
|
83
|
+
"&version=" +
|
|
84
|
+
this.version;
|
|
85
|
+
|
|
86
|
+
if (this.debug) {
|
|
87
|
+
console.debug(
|
|
88
|
+
"javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
|
|
89
|
+
"color: black; font-style: italic; background-color: orange;padding: 2px",
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return fetch(url, {
|
|
94
|
+
method: "GET",
|
|
95
|
+
headers: {
|
|
96
|
+
Authorization: "Bearer " + this.sessionKey,
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
.then((response) => response.blob())
|
|
100
|
+
.then((r) => {
|
|
101
|
+
return r;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public setSessionKey(sessionKey: string) {
|
|
106
|
+
this.sessionKey = sessionKey;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Construct and return a URL
|
|
111
|
+
* @param endpoint
|
|
112
|
+
* @param [params]
|
|
113
|
+
*/
|
|
114
|
+
public rawURL(endpoint: string, params?: {}) {
|
|
115
|
+
let query = endpoint;
|
|
116
|
+
query += qs.stringify(params, "&");
|
|
117
|
+
|
|
118
|
+
let url =
|
|
119
|
+
this.url +
|
|
120
|
+
"/server/json.server.php?action=" +
|
|
121
|
+
query +
|
|
122
|
+
"&version=" +
|
|
123
|
+
this.version;
|
|
124
|
+
|
|
125
|
+
if (this.debug) {
|
|
126
|
+
console.debug(
|
|
127
|
+
"javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
|
|
128
|
+
"color: black; font-style: italic; background-color: orange;padding: 2px",
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return url;
|
|
133
|
+
}
|
|
134
|
+
}
|