@kmlckj/licos-platform-sdk 0.3.0 → 0.5.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 CHANGED
@@ -5,8 +5,11 @@ LICOS 平台对象存储 SDK,兼容前端和后端调用。
5
5
  ## 后端模式
6
6
 
7
7
  - `baseUrl` / `token` / `userId` / `projectId` 不传时,会回退读取 `LICOS_*` 环境变量
8
+ - 后端默认读取 `LICOS_ORCHESTRATOR_API_BASE_URL`
9
+ - 这些存储接口实际挂在调度器 `/api/v1/storage/*` 和 `/api/v1/public/storage/*`
8
10
  - `uploadUser` / `uploadProject` 支持直接传本地文件路径
9
11
  - `download(url, outputPath)` 会把文件写到本地路径
12
+ - 上传、预览、下载都要求鉴权;`download(...)` 会自动带上 `token` 或 `LICOS_USER_TOKEN`
10
13
 
11
14
  ```js
12
15
  import { uploadProject, download } from '@kmlckj/licos-platform-sdk';
@@ -21,6 +24,7 @@ await download(uploaded.download_url, '/tmp/report-downloaded.pdf');
21
24
  - 上传支持 `File` / `Blob` / `ArrayBuffer` / TypedArray / `{ data, fileName, contentType }`
22
25
  - `download(url)` 返回 `Blob`
23
26
  - TypeScript 前端可显式导入浏览器入口 `@kmlckj/licos-platform-sdk/browser`,拿到浏览器专用类型
27
+ - 预览 / 下载接口同样要求传 `token`
24
28
 
25
29
  ```js
26
30
  import { uploadUser, download } from '@kmlckj/licos-platform-sdk';
@@ -29,7 +33,7 @@ const uploaded = await uploadUser(fileInput.files[0], {
29
33
  token: userJwt,
30
34
  });
31
35
 
32
- const blob = await download(uploaded.download_url);
36
+ const blob = await download(uploaded.download_url, { token: userJwt });
33
37
  ```
34
38
 
35
39
  ```ts
@@ -39,5 +43,5 @@ const uploaded = await uploadUser(fileInput.files![0], {
39
43
  token: userJwt,
40
44
  });
41
45
 
42
- const blob = await download(uploaded.download_url);
46
+ const blob = await download(uploaded.download_url, { token: userJwt });
43
47
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kmlckj/licos-platform-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "LICOS platform SDK for storage upload, download, and preview in browser and Node runtimes",
5
5
  "author": "kmlckj",
6
6
  "type": "module",
package/src/browser.js CHANGED
@@ -63,6 +63,7 @@ export class StorageClient {
63
63
  );
64
64
  }
65
65
  return downloadBlob(this.fetchImpl, url, {
66
+ token: this.token,
66
67
  headers: this.headers,
67
68
  credentials: this.credentials,
68
69
  });
package/src/index.js CHANGED
@@ -53,6 +53,7 @@ export class StorageClient {
53
53
 
54
54
  async download(url, outputPath) {
55
55
  const blob = await downloadBlob(this.fetchImpl, url, {
56
+ token: this.token,
56
57
  headers: this.headers,
57
58
  credentials: this.credentials,
58
59
  });
package/src/shared.js CHANGED
@@ -36,7 +36,7 @@ export function normalizeBaseUrl(baseUrl) {
36
36
  return baseUrl.replace(/\/+$/, '');
37
37
  }
38
38
 
39
- const envBaseUrl = readEnv('LICOS_API_BASE_URL');
39
+ const envBaseUrl = readEnv('LICOS_ORCHESTRATOR_API_BASE_URL');
40
40
  if (envBaseUrl) {
41
41
  return envBaseUrl.replace(/\/+$/, '');
42
42
  }
@@ -45,7 +45,9 @@ export function normalizeBaseUrl(baseUrl) {
45
45
  return '';
46
46
  }
47
47
 
48
- throw new ConfigurationError('Missing required environment variable: LICOS_API_BASE_URL');
48
+ throw new ConfigurationError(
49
+ 'Missing required environment variable: LICOS_ORCHESTRATOR_API_BASE_URL',
50
+ );
49
51
  }
50
52
 
51
53
  export function resolveUserId(userId) {
@@ -223,7 +225,7 @@ export async function downloadBlob(fetchImpl, url, options = {}) {
223
225
  url,
224
226
  buildRequestInit(options, {
225
227
  method: 'GET',
226
- headers: buildRequestHeaders(options),
228
+ headers: buildRequestHeaders(options, { authenticated: true }),
227
229
  }),
228
230
  );
229
231
  if (!response.ok) {