javascript-ampache 1.1.5 → 1.1.7

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.
@@ -292,11 +292,13 @@ export declare class System extends Base {
292
292
  * @remarks MINIMUM_API_VERSION=400001
293
293
  * @param params.id UID to find
294
294
  * @param params.type Object type
295
+ * @param [params.size] width x height (e.g. '640x480')
295
296
  * @see {@link https://ampache.org/api/api-json-methods#get_art}
296
297
  */
297
298
  getArt(params: {
298
299
  id: UID;
299
300
  type: "song" | "artist" | "album" | "playlist" | "search" | "podcast";
301
+ size?: string;
300
302
  }): Promise<Blob>;
301
303
  /**
302
304
  * This is for controlling localplay
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-ampache",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "A JS library for the Ampache API",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.m.js",
package/src/base.ts CHANGED
@@ -4,6 +4,7 @@ import qs from "querystringify";
4
4
  type Config = {
5
5
  url: string;
6
6
  sessionKey?: string;
7
+ useBearerToken: false;
7
8
  debug?: boolean;
8
9
  };
9
10
 
@@ -39,15 +40,18 @@ export abstract class Base {
39
40
  sessionKey: string;
40
41
  url: string;
41
42
  version: string = "6.6.8";
43
+ useBearerToken: boolean;
42
44
  debug: boolean;
43
45
 
44
46
  constructor(config: Config) {
45
47
  this.sessionKey = config.sessionKey || null;
46
48
  this.url = config.url;
49
+ this.useBearerToken = config.useBearerToken || false;
47
50
  this.debug = config.debug || false;
48
51
  }
49
52
 
50
53
  protected request<T>(endpoint: string): Promise<T> {
54
+ let authString = "&auth=" + this.sessionKey;
51
55
  let url =
52
56
  this.url +
53
57
  "/server/json.server.php?action=" +
@@ -55,9 +59,13 @@ export abstract class Base {
55
59
  "&version=" +
56
60
  this.version;
57
61
 
62
+ if (!this.useBearerToken) {
63
+ url += authString;
64
+ }
65
+
58
66
  if (this.debug) {
59
67
  console.debug(
60
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
68
+ "javascript-ampache query URL %c" + url + authString,
61
69
  "color: black; font-style: italic; background-color: orange;padding: 2px",
62
70
  );
63
71
  }
@@ -65,7 +73,7 @@ export abstract class Base {
65
73
  return fetch(url, {
66
74
  method: "GET",
67
75
  headers: {
68
- Authorization: "Bearer " + this.sessionKey,
76
+ Authorization: this.useBearerToken ? "Bearer " + this.sessionKey : undefined,
69
77
  },
70
78
  }).then((r) => {
71
79
  if (r.ok) {
@@ -76,16 +84,19 @@ export abstract class Base {
76
84
  }
77
85
 
78
86
  protected binary<T>(endpoint: string): Promise<Blob> {
87
+ let authString = "&auth=" + this.sessionKey;
79
88
  let url =
80
89
  this.url +
81
- "/server/json.server.php?action=" +
82
- endpoint +
83
- "&version=" +
84
- this.version;
90
+ "/server/json.server.php?action=" + endpoint +
91
+ "&version=" + this.version;
92
+
93
+ if (!this.useBearerToken) {
94
+ url += authString;
95
+ }
85
96
 
86
97
  if (this.debug) {
87
98
  console.debug(
88
- "javascript-ampache query URL %c" + url + "&auth=" + this.sessionKey,
99
+ "javascript-ampache query URL %c" + url + authString,
89
100
  "color: black; font-style: italic; background-color: orange;padding: 2px",
90
101
  );
91
102
  }
@@ -93,7 +104,7 @@ export abstract class Base {
93
104
  return fetch(url, {
94
105
  method: "GET",
95
106
  headers: {
96
- Authorization: "Bearer " + this.sessionKey,
107
+ Authorization: this.useBearerToken ? "Bearer " + this.sessionKey : undefined,
97
108
  },
98
109
  })
99
110
  .then((response) => response.blob())
@@ -117,10 +128,8 @@ export abstract class Base {
117
128
 
118
129
  let url =
119
130
  this.url +
120
- "/server/json.server.php?action=" +
121
- query +
122
- "&version=" +
123
- this.version;
131
+ "/server/json.server.php?action=" + query +
132
+ "&version=" + this.version;
124
133
 
125
134
  if (this.debug) {
126
135
  console.debug(
@@ -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, "&");