windmill-components 1.700.1 → 1.700.2
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.
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* When OpenAPI
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* When OpenAPI is configured to authenticate via headers (TOKEN, basic auth,
|
|
3
|
+
* or arbitrary HEADERS) we cannot rely on a plain `<a href>` browser
|
|
4
|
+
* navigation because the browser does not attach those headers. In that case
|
|
5
|
+
* fetch the file via the OpenAPI client (which carries the configured auth)
|
|
6
|
+
* and trigger a download from a blob URL. Cookie-only auth still works with
|
|
7
|
+
* a plain link.
|
|
6
8
|
*
|
|
7
9
|
* `apiPath` should be the path relative to OpenAPI.BASE, starting with `/`
|
|
8
10
|
* (e.g. `/w/foo/job_helpers/download_s3_file?file_key=...`).
|
|
@@ -1,31 +1,25 @@
|
|
|
1
1
|
import { OpenAPI } from '../gen';
|
|
2
|
+
import { getHeaders } from '../gen/core/request';
|
|
2
3
|
import { sendUserToast } from '../toast';
|
|
3
|
-
async function resolveToken() {
|
|
4
|
-
const t = OpenAPI.TOKEN;
|
|
5
|
-
if (!t)
|
|
6
|
-
return undefined;
|
|
7
|
-
return typeof t === 'string' ? t : await t({});
|
|
8
|
-
}
|
|
9
4
|
/**
|
|
10
|
-
* When OpenAPI
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
5
|
+
* When OpenAPI is configured to authenticate via headers (TOKEN, basic auth,
|
|
6
|
+
* or arbitrary HEADERS) we cannot rely on a plain `<a href>` browser
|
|
7
|
+
* navigation because the browser does not attach those headers. In that case
|
|
8
|
+
* fetch the file via the OpenAPI client (which carries the configured auth)
|
|
9
|
+
* and trigger a download from a blob URL. Cookie-only auth still works with
|
|
10
|
+
* a plain link.
|
|
14
11
|
*
|
|
15
12
|
* `apiPath` should be the path relative to OpenAPI.BASE, starting with `/`
|
|
16
13
|
* (e.g. `/w/foo/job_helpers/download_s3_file?file_key=...`).
|
|
17
14
|
*/
|
|
18
15
|
export function shouldDownloadViaClient() {
|
|
19
|
-
return Boolean(OpenAPI.TOKEN);
|
|
16
|
+
return Boolean(OpenAPI.TOKEN || OpenAPI.HEADERS || OpenAPI.USERNAME);
|
|
20
17
|
}
|
|
21
18
|
export async function downloadViaClient(apiPath, filename) {
|
|
22
|
-
const token = await resolveToken();
|
|
23
19
|
const url = `${OpenAPI.BASE}${apiPath}`;
|
|
24
|
-
const headers = {};
|
|
25
|
-
if (token)
|
|
26
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
27
20
|
let response;
|
|
28
21
|
try {
|
|
22
|
+
const headers = await getHeaders(OpenAPI, { method: 'GET', url: apiPath });
|
|
29
23
|
response = await fetch(url, { headers, credentials: OpenAPI.CREDENTIALS });
|
|
30
24
|
}
|
|
31
25
|
catch (e) {
|