javascript-ampache 1.1.6 → 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.
- package/dist/base.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/package.json +1 -1
- package/src/base.ts +21 -12
package/package.json
CHANGED
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 +
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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 +
|
|
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
|
-
|
|
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(
|