javascript-ampache 1.1.4 → 1.1.6
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/dist/albums/index.d.ts +2 -0
- package/dist/albums/types.d.ts +2 -0
- package/dist/artists/types.d.ts +2 -2
- package/dist/auth/types.d.ts +7 -0
- package/dist/genres/types.d.ts +2 -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/dist/playlists/index.d.ts +12 -1
- package/dist/playlists/types.d.ts +8 -0
- package/dist/preferences/types.d.ts +2 -0
- package/dist/shouts/types.d.ts +2 -0
- package/dist/songs/index.d.ts +7 -0
- package/dist/system/index.d.ts +65 -3
- package/dist/system/types.d.ts +8 -0
- package/package.json +1 -1
- package/src/base.ts +134 -134
- package/src/system/index.ts +2 -0
- package/src/system/types.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaylistResponse, PlaylistsResponse } from "./types";
|
|
1
|
+
import { HashResponse, PlaylistResponse, PlaylistsResponse } from "./types";
|
|
2
2
|
import { SongsResponse } from "../songs/types";
|
|
3
3
|
import { Base, BinaryBoolean, ExtendedPagination, Pagination, Success, UID } from "../base";
|
|
4
4
|
export declare class Playlists extends Base {
|
|
@@ -11,6 +11,7 @@ export declare class Playlists extends Base {
|
|
|
11
11
|
* @param [params.update] ISO 8601 Date Format (2020-09-16) Find objects with an 'update' time newer than the specified date
|
|
12
12
|
* @param [params.hide_search] 0, 1 (if true do not include searches/smartlists in the result)
|
|
13
13
|
* @param [params.show_dupes] 0, 1 (if true ignore 'api_hide_dupe_searches' setting)
|
|
14
|
+
* @param [params.include] 0, 1 (if true include the objects in the playlist)
|
|
14
15
|
* @param [params.offset]
|
|
15
16
|
* @param [params.limit]
|
|
16
17
|
* @param [params.cond]
|
|
@@ -24,6 +25,7 @@ export declare class Playlists extends Base {
|
|
|
24
25
|
update?: Date;
|
|
25
26
|
hide_search?: BinaryBoolean;
|
|
26
27
|
show_dupes?: BinaryBoolean;
|
|
28
|
+
include?: BinaryBoolean;
|
|
27
29
|
} & ExtendedPagination): Promise<PlaylistsResponse>;
|
|
28
30
|
/**
|
|
29
31
|
* This returns smartlists based on the specified filter. NOTE: Filtered from Playlists() so pagination is invalid.
|
|
@@ -190,4 +192,13 @@ export declare class Playlists extends Base {
|
|
|
190
192
|
flag?: BinaryBoolean;
|
|
191
193
|
format?: "song" | "index" | "id";
|
|
192
194
|
} & Pagination): Promise<SongsResponse>;
|
|
195
|
+
/**
|
|
196
|
+
* This returns the md5 hash for the songs in a playlist
|
|
197
|
+
* @remarks MINIMUM_API_VERSION=6.6.0
|
|
198
|
+
* @param params.filter string UID of Playlist
|
|
199
|
+
* @see {@link https://ampache.org/api/api-json-methods#playlist_hash}
|
|
200
|
+
*/
|
|
201
|
+
playlistHash(params: {
|
|
202
|
+
filter: UID;
|
|
203
|
+
}): Promise<HashResponse>;
|
|
193
204
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UID } from "../base";
|
|
2
|
+
import { UserSummary } from "../users/types";
|
|
2
3
|
export type PlaylistResponse = {
|
|
3
4
|
id: UID;
|
|
4
5
|
name: string;
|
|
@@ -10,9 +11,16 @@ export type PlaylistResponse = {
|
|
|
10
11
|
flag: boolean;
|
|
11
12
|
rating: number | null;
|
|
12
13
|
averagerating: number | null;
|
|
14
|
+
user: UserSummary;
|
|
15
|
+
has_access: boolean;
|
|
16
|
+
has_collaborate: boolean;
|
|
17
|
+
last_update: number;
|
|
13
18
|
};
|
|
14
19
|
export type PlaylistsResponse = {
|
|
15
20
|
total_count: number;
|
|
16
21
|
md5: string;
|
|
17
22
|
playlist: PlaylistResponse[];
|
|
18
23
|
};
|
|
24
|
+
export type HashResponse = {
|
|
25
|
+
md5: string;
|
|
26
|
+
};
|
package/dist/shouts/types.d.ts
CHANGED
package/dist/songs/index.d.ts
CHANGED
|
@@ -105,6 +105,13 @@ export declare class Songs extends Base {
|
|
|
105
105
|
songDelete(params: {
|
|
106
106
|
filter: UID;
|
|
107
107
|
}): Promise<Success>;
|
|
108
|
+
/**
|
|
109
|
+
* Get the full song file tags using VaInfo
|
|
110
|
+
* This is used to get tags for remote catalogs to allow maximum data to be returned
|
|
111
|
+
* @remarks MINIMUM_API_VERSION=7.5.0
|
|
112
|
+
* @param params.filter UID of song to fetch
|
|
113
|
+
* @see {@link https://ampache.org/api/api-json-methods#song_tags}
|
|
114
|
+
*/
|
|
108
115
|
/**
|
|
109
116
|
* This takes a URL and returns the song object in question
|
|
110
117
|
* @remarks MINIMUM_API_VERSION=380001
|
package/dist/system/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Base, BinaryBoolean, ExtendedPagination, Pagination, Success, UID } from "../base";
|
|
2
|
-
import { IndexEntry } from "./types";
|
|
2
|
+
import { IndexEntry, NowPlayingResponse } from "./types";
|
|
3
3
|
export declare class System extends Base {
|
|
4
4
|
/**
|
|
5
5
|
* Check Ampache for updates and run the update if there is one.
|
|
@@ -24,7 +24,7 @@ export declare class System extends Base {
|
|
|
24
24
|
* @deprecated Being removed in 7.0.0. Use `list` instead.
|
|
25
25
|
*/
|
|
26
26
|
getIndexes(params: {
|
|
27
|
-
type: "song" | "album" | "artist" | "album_artist" | "playlist" | "podcast" | "podcast_episode" | "live_stream";
|
|
27
|
+
type: "song" | "album" | "artist" | "album_artist" | "playlist" | "podcast" | "podcast_episode" | "live_stream" | "catalog" | "song_artist";
|
|
28
28
|
filter?: string;
|
|
29
29
|
add?: Date;
|
|
30
30
|
update?: Date;
|
|
@@ -46,7 +46,7 @@ export declare class System extends Base {
|
|
|
46
46
|
* @see {@link https://ampache.org/api/api-json-methods#list}
|
|
47
47
|
*/
|
|
48
48
|
list(params: {
|
|
49
|
-
type: "song" | "album" | "artist" | "album_artist" | "playlist" | "podcast" | "podcast_episode" | "live_stream";
|
|
49
|
+
type: "song" | "album" | "artist" | "album_artist" | "playlist" | "podcast" | "podcast_episode" | "live_stream" | "catalog" | "song_artist";
|
|
50
50
|
filter?: string;
|
|
51
51
|
add?: Date;
|
|
52
52
|
update?: Date;
|
|
@@ -154,12 +154,14 @@ export declare class System extends Base {
|
|
|
154
154
|
* @param params.type Object type
|
|
155
155
|
* @param params.id UID to find
|
|
156
156
|
* @param params.flag 0, 1
|
|
157
|
+
* @param [params.date] UNIXTIME
|
|
157
158
|
* @see {@link https://ampache.org/api/api-json-methods#flag}
|
|
158
159
|
*/
|
|
159
160
|
flag(params: {
|
|
160
161
|
type: "song" | "album" | "artist" | "playlist" | "podcast" | "podcast_episode" | "video" | "tvshow" | "tvshow_season";
|
|
161
162
|
id: UID;
|
|
162
163
|
flag: BinaryBoolean;
|
|
164
|
+
date?: number;
|
|
163
165
|
}): Promise<Success>;
|
|
164
166
|
/**
|
|
165
167
|
* Take a song_id and update the object_count and user_activity table with a play. This allows other sources to record play history to Ampache.
|
|
@@ -255,6 +257,7 @@ export declare class System extends Base {
|
|
|
255
257
|
* @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
|
|
256
258
|
* @param [params.offset] Time offset
|
|
257
259
|
* @param [params.length] 0, 1 (estimate content length)
|
|
260
|
+
* @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
|
|
258
261
|
* @see {@link https://ampache.org/api/api-json-methods#stream}
|
|
259
262
|
*/
|
|
260
263
|
stream(params: {
|
|
@@ -264,6 +267,7 @@ export declare class System extends Base {
|
|
|
264
267
|
format?: string;
|
|
265
268
|
offset?: number;
|
|
266
269
|
length?: BinaryBoolean;
|
|
270
|
+
stats?: BinaryBoolean;
|
|
267
271
|
}): Promise<Blob>;
|
|
268
272
|
/**
|
|
269
273
|
* Downloads a given media file. set format=raw to download the full file
|
|
@@ -272,23 +276,29 @@ export declare class System extends Base {
|
|
|
272
276
|
* @param params.id UID to find
|
|
273
277
|
* @param params.type Object type
|
|
274
278
|
* @param [params.format] mp3, ogg, raw, etc. (raw returns the original format)
|
|
279
|
+
* @param [params.bitrate] max bitrate for transcoding in bytes (e.g 192000=192Kb)
|
|
280
|
+
* @param [params.stats] 0, 1 (if false disable stat recording when playing the object; default: 1)
|
|
275
281
|
* @see {@link https://ampache.org/api/api-json-methods#download}
|
|
276
282
|
*/
|
|
277
283
|
download(params: {
|
|
278
284
|
id: UID;
|
|
279
285
|
type: "song" | "podcast_episode" | "search" | "playlist";
|
|
280
286
|
format?: string;
|
|
287
|
+
bitrate?: number;
|
|
288
|
+
stats?: BinaryBoolean;
|
|
281
289
|
}): Promise<Blob>;
|
|
282
290
|
/**
|
|
283
291
|
* Get an art image file.
|
|
284
292
|
* @remarks MINIMUM_API_VERSION=400001
|
|
285
293
|
* @param params.id UID to find
|
|
286
294
|
* @param params.type Object type
|
|
295
|
+
* @param [params.size] width x height (e.g. '640x480')
|
|
287
296
|
* @see {@link https://ampache.org/api/api-json-methods#get_art}
|
|
288
297
|
*/
|
|
289
298
|
getArt(params: {
|
|
290
299
|
id: UID;
|
|
291
300
|
type: "song" | "artist" | "album" | "playlist" | "search" | "podcast";
|
|
301
|
+
size?: string;
|
|
292
302
|
}): Promise<Blob>;
|
|
293
303
|
/**
|
|
294
304
|
* This is for controlling localplay
|
|
@@ -324,6 +334,33 @@ export declare class System extends Base {
|
|
|
324
334
|
oid: UID;
|
|
325
335
|
method: "vote" | "devote" | "playlist" | "play";
|
|
326
336
|
}): Promise<unknown>;
|
|
337
|
+
/**
|
|
338
|
+
* Get what is currently being played by all users.
|
|
339
|
+
* @remarks MINIMUM_API_VERSION=6.3.1
|
|
340
|
+
* @see {@link https://ampache.org/api/api-json-methods#now_playing}
|
|
341
|
+
*/
|
|
342
|
+
nowPlaying(): Promise<{
|
|
343
|
+
now_playing: NowPlayingResponse[];
|
|
344
|
+
}>;
|
|
345
|
+
/**
|
|
346
|
+
* Inform the server about the state of your client. (Song you are playing, Play/Pause state, etc.)
|
|
347
|
+
* @remarks MINIMUM_API_VERSION=6.4.0
|
|
348
|
+
* @param params.filter $object_id currently playing/stopping
|
|
349
|
+
* @param [params.type] song, video, podcast_episode (Default: song)
|
|
350
|
+
* @param [params.state] play, stop (Default: play)
|
|
351
|
+
* @param [params.time] current play time in whole seconds (Default: 0)
|
|
352
|
+
* @param [params.client] agent/client name
|
|
353
|
+
* @see {@link https://ampache.org/api/api-json-methods#player}
|
|
354
|
+
*/
|
|
355
|
+
player(params: {
|
|
356
|
+
filter: UID;
|
|
357
|
+
type?: "song" | "video" | "podcast_episode";
|
|
358
|
+
state?: "play" | "stop";
|
|
359
|
+
time?: number;
|
|
360
|
+
client?: string;
|
|
361
|
+
}): Promise<{
|
|
362
|
+
now_playing: NowPlayingResponse[];
|
|
363
|
+
}>;
|
|
327
364
|
/**
|
|
328
365
|
* Perform an advanced search given passed rules.
|
|
329
366
|
* You'll want to consult the docs for this.
|
|
@@ -342,4 +379,29 @@ export declare class System extends Base {
|
|
|
342
379
|
rules: Array<Array<string>>;
|
|
343
380
|
random?: BinaryBoolean;
|
|
344
381
|
} & Pagination): any;
|
|
382
|
+
search: (params: {
|
|
383
|
+
operator: "and" | "or";
|
|
384
|
+
type: "song" | "album" | "album_disk" | "artist" | "album_artist" | "song_artist" | "label" | "playlist" | "podcast" | "podcast_episode" | "genre" | "user" | "video";
|
|
385
|
+
rules: Array<Array<string>>;
|
|
386
|
+
random?: BinaryBoolean;
|
|
387
|
+
} & Pagination) => any;
|
|
388
|
+
/**
|
|
389
|
+
* Perform a search given passed rules and return matching objects in a group.
|
|
390
|
+
* If the rules do not exist for the object type or would return the entire table they will not return objects
|
|
391
|
+
* You'll want to consult the docs for this.
|
|
392
|
+
* @remarks MINIMUM_API_VERSION=6.3.0
|
|
393
|
+
* @param params.operator and, or (whether to match one rule or all)
|
|
394
|
+
* @param params.rules An array of rules
|
|
395
|
+
* @param [params.type] Object type to return (all, music, song_artist, album_artist, podcast, video; all by default)
|
|
396
|
+
* @param [params.random] 0, 1 (random order of results; default to 0)
|
|
397
|
+
* @param [params.offset]
|
|
398
|
+
* @param [params.limit]
|
|
399
|
+
* @see {@link https://ampache.org/api/api-json-methods#search_group}
|
|
400
|
+
*/
|
|
401
|
+
searchGroup(params: {
|
|
402
|
+
operator: "and" | "or";
|
|
403
|
+
rules: Array<Array<string>>;
|
|
404
|
+
type?: "all" | "music" | "song_artist" | "album_artist" | "podcast" | "video";
|
|
405
|
+
random?: BinaryBoolean;
|
|
406
|
+
} & Pagination): any;
|
|
345
407
|
}
|
package/dist/system/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { PodcastResponse, PodcastEpisodeResponse } from "../podcasts/types";
|
|
|
6
6
|
import { LiveStreamResponse } from "../live-streams/types";
|
|
7
7
|
import { VideoResponse } from "../videos/types";
|
|
8
8
|
import { UID } from "../base";
|
|
9
|
+
import { UserSummary } from "../users/types";
|
|
9
10
|
export type IndexType = SongResponse | AlbumResponse | ArtistResponse | PlaylistResponse | PodcastResponse | PodcastEpisodeResponse | LiveStreamResponse;
|
|
10
11
|
export type StatsType = SongResponse | AlbumResponse | ArtistResponse | VideoResponse | PlaylistResponse | PodcastResponse | PodcastEpisodeResponse;
|
|
11
12
|
export type IndexEntry = {
|
|
@@ -14,3 +15,10 @@ export type IndexEntry = {
|
|
|
14
15
|
prefix: string;
|
|
15
16
|
basename: string;
|
|
16
17
|
};
|
|
18
|
+
export type NowPlayingResponse = {
|
|
19
|
+
id: UID;
|
|
20
|
+
type: "song" | "podcast_episode" | "video";
|
|
21
|
+
client: string;
|
|
22
|
+
expire: number;
|
|
23
|
+
user: UserSummary;
|
|
24
|
+
};
|
package/package.json
CHANGED
package/src/base.ts
CHANGED
|
@@ -1,134 +1,134 @@
|
|
|
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.6.8";
|
|
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
|
-
}
|
|
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.6.8";
|
|
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
|
+
}
|
package/src/system/index.ts
CHANGED
|
@@ -525,11 +525,13 @@ export class System extends Base {
|
|
|
525
525
|
* @remarks MINIMUM_API_VERSION=400001
|
|
526
526
|
* @param params.id UID to find
|
|
527
527
|
* @param params.type Object type
|
|
528
|
+
* @param [params.size] width x height (e.g. '640x480')
|
|
528
529
|
* @see {@link https://ampache.org/api/api-json-methods#get_art}
|
|
529
530
|
*/
|
|
530
531
|
getArt(params: {
|
|
531
532
|
id: UID;
|
|
532
533
|
type: "song" | "artist" | "album" | "playlist" | "search" | "podcast";
|
|
534
|
+
size?: string;
|
|
533
535
|
}) {
|
|
534
536
|
let query = "get_art";
|
|
535
537
|
query += qs.stringify(params, "&");
|
package/src/system/types.ts
CHANGED