@twin.org/blob-storage-rest-client 0.0.2-next.5 → 0.0.3-next.1

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,25 +1,31 @@
1
- import { BaseRestClient } from '@twin.org/api-core';
2
- import { HttpParameterHelper } from '@twin.org/api-models';
3
- import { Guards, Urn, Coerce, StringHelper, Is } from '@twin.org/core';
4
- import { HeaderTypes, MimeTypes } from '@twin.org/web';
5
-
6
1
  // Copyright 2024 IOTA Stiftung.
7
2
  // SPDX-License-Identifier: Apache-2.0.
3
+ import { BaseRestClient } from "@twin.org/api-core";
4
+ import { HttpParameterHelper } from "@twin.org/api-models";
5
+ import { Coerce, Guards, Is, StringHelper, Urn } from "@twin.org/core";
6
+ import { HeaderTypes, MimeTypes } from "@twin.org/web";
8
7
  /**
9
8
  * Client for performing blob storage through to REST endpoints.
10
9
  */
11
- class BlobStorageRestClient extends BaseRestClient {
10
+ export class BlobStorageRestClient extends BaseRestClient {
12
11
  /**
13
12
  * Runtime name for the class.
14
13
  */
15
14
  static CLASS_NAME = "BlobStorageRestClient";
16
15
  /**
17
- * Create a new instance of BlobStorageClient.
16
+ * Create a new instance of BlobStorageRestClient.
18
17
  * @param config The configuration for the client.
19
18
  */
20
19
  constructor(config) {
21
20
  super(BlobStorageRestClient.CLASS_NAME, config, "blob");
22
21
  }
22
+ /**
23
+ * Returns the class name of the component.
24
+ * @returns The class name of the component.
25
+ */
26
+ className() {
27
+ return BlobStorageRestClient.CLASS_NAME;
28
+ }
23
29
  /**
24
30
  * Create the blob with some metadata.
25
31
  * @param blob The data for the blob in base64 format.
@@ -158,5 +164,4 @@ class BlobStorageRestClient extends BaseRestClient {
158
164
  return link;
159
165
  }
160
166
  }
161
-
162
- export { BlobStorageRestClient };
167
+ //# sourceMappingURL=blobStorageRestClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blobStorageRestClient.js","sourceRoot":"","sources":["../../src/blobStorageRestClient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twin.org/api-core\";\nimport {\n\tHttpParameterHelper,\n\ttype IBaseRestClientConfig,\n\ttype ICreatedResponse,\n\ttype INoContentResponse\n} from \"@twin.org/api-models\";\nimport type {\n\tIBlobStorageComponent,\n\tIBlobStorageCreateRequest,\n\tIBlobStorageEntry,\n\tIBlobStorageEntryList,\n\tIBlobStorageGetRequest,\n\tIBlobStorageGetResponse,\n\tIBlobStorageListRequest,\n\tIBlobStorageListResponse,\n\tIBlobStorageRemoveRequest,\n\tIBlobStorageUpdateRequest\n} from \"@twin.org/blob-storage-models\";\nimport { Coerce, Guards, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { EntityCondition, SortDirection } from \"@twin.org/entity\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes, MimeTypes } from \"@twin.org/web\";\n\n/**\n * Client for performing blob storage through to REST endpoints.\n */\nexport class BlobStorageRestClient extends BaseRestClient implements IBlobStorageComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<BlobStorageRestClient>();\n\n\t/**\n\t * Create a new instance of BlobStorageRestClient.\n\t * @param config The configuration for the client.\n\t */\n\tconstructor(config: IBaseRestClientConfig) {\n\t\tsuper(BlobStorageRestClient.CLASS_NAME, config, \"blob\");\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn BlobStorageRestClient.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create the blob with some metadata.\n\t * @param blob The data for the blob in base64 format.\n\t * @param encodingFormat Mime type for the blob, will be detected if left undefined.\n\t * @param fileExtension Extension for the blob, will be detected if left undefined.\n\t * @param metadata Data for the custom metadata as JSON-LD.\n\t * @param options Optional options for the creation of the blob.\n\t * @param options.disableEncryption Disables encryption if enabled by default.\n\t * @param options.overrideVaultKeyId Use a different vault key id for encryption, if not provided the default vault key id will be used.\n\t * @param options.namespace The namespace to use for storing, defaults to component configured namespace.\n\t * @returns The id of the stored blob in urn format.\n\t */\n\tpublic async create(\n\t\tblob: string,\n\t\tencodingFormat?: string,\n\t\tfileExtension?: string,\n\t\tmetadata?: IJsonLdNodeObject,\n\t\toptions?: {\n\t\t\tdisableEncryption?: boolean;\n\t\t\toverrideVaultKeyId?: string;\n\t\t\tnamespace?: string;\n\t\t}\n\t): Promise<string> {\n\t\tGuards.stringBase64(BlobStorageRestClient.CLASS_NAME, nameof(blob), blob);\n\n\t\tconst response = await this.fetch<IBlobStorageCreateRequest, ICreatedResponse>(\"/\", \"POST\", {\n\t\t\tbody: {\n\t\t\t\tblob,\n\t\t\t\tencodingFormat,\n\t\t\t\tfileExtension,\n\t\t\t\tmetadata,\n\t\t\t\tdisableEncryption: options?.disableEncryption,\n\t\t\t\toverrideVaultKeyId: options?.overrideVaultKeyId,\n\t\t\t\tnamespace: options?.namespace\n\t\t\t}\n\t\t});\n\n\t\treturn response.headers[HeaderTypes.Location];\n\t}\n\n\t/**\n\t * Get the blob and metadata.\n\t * @param id The id of the blob to get in urn format.\n\t * @param options Optional options for the retrieval of the blob.\n\t * @param options.includeContent Include the content, or just get the metadata.\n\t * @param options.overrideVaultKeyId Use a different vault key id for decryption, if not provided the default vault key id will be used.\n\t * @param options.decompress If the content should be decompressed, if it was compressed when stored, defaults to true.\n\t * @returns The metadata and data for the blob if it can be found.\n\t * @throws Not found error if the blob cannot be found.\n\t */\n\tpublic async get(\n\t\tid: string,\n\t\toptions?: {\n\t\t\tincludeContent?: boolean;\n\t\t\tdecompress?: boolean;\n\t\t\toverrideVaultKeyId?: string;\n\t\t}\n\t): Promise<IBlobStorageEntry> {\n\t\tUrn.guard(BlobStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tconst response = await this.fetch<IBlobStorageGetRequest, IBlobStorageGetResponse>(\n\t\t\t\"/:id\",\n\t\t\t\"GET\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tpathParams: {\n\t\t\t\t\tid\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\tincludeContent: Coerce.string(options?.includeContent),\n\t\t\t\t\tdecompress: Coerce.string(options?.decompress),\n\t\t\t\t\toverrideVaultKeyId: options?.overrideVaultKeyId\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Update the blob with metadata.\n\t * @param id The id of the blob metadata to update.\n\t * @param encodingFormat Mime type for the blob, will be detected if left undefined.\n\t * @param fileExtension Extension for the blob, will be detected if left undefined.\n\t * @param metadata Data for the custom metadata as JSON-LD.\n\t * @returns Nothing.\n\t * @throws Not found error if the blob cannot be found.\n\t */\n\tpublic async update(\n\t\tid: string,\n\t\tencodingFormat?: string,\n\t\tfileExtension?: string,\n\t\tmetadata?: IJsonLdNodeObject\n\t): Promise<void> {\n\t\tUrn.guard(BlobStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<IBlobStorageUpdateRequest, INoContentResponse>(\"/:id\", \"PUT\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t},\n\t\t\tbody: {\n\t\t\t\tencodingFormat,\n\t\t\t\tfileExtension,\n\t\t\t\tmetadata\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Remove the blob.\n\t * @param id The id of the blob to remove in urn format.\n\t * @returns Nothing.\n\t */\n\tpublic async remove(id: string): Promise<void> {\n\t\tUrn.guard(BlobStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tawait this.fetch<IBlobStorageRemoveRequest, INoContentResponse>(\"/:id\", \"DELETE\", {\n\t\t\tpathParams: {\n\t\t\t\tid\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Query all the blob storage entries which match the conditions.\n\t * @param conditions The conditions to match for the entries.\n\t * @param orderBy The order for the results, defaults to created.\n\t * @param orderByDirection The direction for the order, defaults to descending.\n\t * @param cursor The cursor to request the next page of entries.\n\t * @param limit The suggested number of entries to return in each chunk, in some scenarios can return a different amount.\n\t * @returns All the entries for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t */\n\tpublic async query(\n\t\tconditions?: EntityCondition<IBlobStorageEntry>,\n\t\torderBy?: keyof Pick<IBlobStorageEntry, \"dateCreated\" | \"dateModified\">,\n\t\torderByDirection?: SortDirection,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<IBlobStorageEntryList> {\n\t\tconst response = await this.fetch<IBlobStorageListRequest, IBlobStorageListResponse>(\n\t\t\t\"/\",\n\t\t\t\"GET\",\n\t\t\t{\n\t\t\t\theaders: {\n\t\t\t\t\t[HeaderTypes.Accept]: MimeTypes.JsonLd\n\t\t\t\t},\n\t\t\t\tquery: {\n\t\t\t\t\tconditions: HttpParameterHelper.objectToString(conditions),\n\t\t\t\t\torderBy,\n\t\t\t\t\torderByDirection,\n\t\t\t\t\tlimit: Coerce.string(limit),\n\t\t\t\t\tcursor\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\n\t\treturn response.body;\n\t}\n\n\t/**\n\t * Create a download link for the blob.\n\t * @param id The id of the blob to get in urn format.\n\t * @param download Should the content disposition be set to download.\n\t * @param filename The filename to use for the download.\n\t * @returns The download link.\n\t */\n\tpublic createDownloadLink(id: string, download?: boolean, filename?: string): string {\n\t\tUrn.guard(BlobStorageRestClient.CLASS_NAME, nameof(id), id);\n\n\t\tlet link = StringHelper.trimTrailingSlashes(this.getEndpointWithPrefix());\n\t\tlink += `/${id}/content`;\n\n\t\tconst downloadQuery: string[] = [];\n\t\tif (download) {\n\t\t\tdownloadQuery.push(\"download=true\");\n\t\t}\n\t\tif (Is.stringValue(filename)) {\n\t\t\tdownloadQuery.push(`filename=${encodeURIComponent(filename)}`);\n\t\t}\n\t\tif (downloadQuery.length > 0) {\n\t\t\tlink += `?${downloadQuery.join(\"&\")}`;\n\t\t}\n\n\t\treturn link;\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export * from "./blobStorageRestClient.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,4BAA4B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./blobStorageRestClient.js\";\n"]}
@@ -12,10 +12,15 @@ export declare class BlobStorageRestClient extends BaseRestClient implements IBl
12
12
  */
13
13
  static readonly CLASS_NAME: string;
14
14
  /**
15
- * Create a new instance of BlobStorageClient.
15
+ * Create a new instance of BlobStorageRestClient.
16
16
  * @param config The configuration for the client.
17
17
  */
18
18
  constructor(config: IBaseRestClientConfig);
19
+ /**
20
+ * Returns the class name of the component.
21
+ * @returns The class name of the component.
22
+ */
23
+ className(): string;
19
24
  /**
20
25
  * Create the blob with some metadata.
21
26
  * @param blob The data for the blob in base64 format.
@@ -1 +1 @@
1
- export * from "./blobStorageRestClient";
1
+ export * from "./blobStorageRestClient.js";
package/docs/changelog.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @twin.org/blob-storage-rest-client - Changelog
2
2
 
3
+ ## [0.0.3-next.1](https://github.com/twinfoundation/blob-storage/compare/blob-storage-rest-client-v0.0.3-next.0...blob-storage-rest-client-v0.0.3-next.1) (2025-11-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * add compression support ([67d239b](https://github.com/twinfoundation/blob-storage/commit/67d239bca8321bd90bf4ff93167c564130309730))
9
+ * add context id features ([#30](https://github.com/twinfoundation/blob-storage/issues/30)) ([fbf1c92](https://github.com/twinfoundation/blob-storage/commit/fbf1c9276424c841ef5ef3f4de8469ab3fba7e9c))
10
+ * add validate-locales ([f20fcec](https://github.com/twinfoundation/blob-storage/commit/f20fceced91e39a0c9edb770b2e43ce944c92f3c))
11
+ * additional encryption options on per item basis ([4b95a65](https://github.com/twinfoundation/blob-storage/commit/4b95a656d19e3b571cea905e36f29b679b13e1e8))
12
+ * eslint migration to flat config ([e4239dd](https://github.com/twinfoundation/blob-storage/commit/e4239dd1c721955cff7f0357255d2bba15319972))
13
+ * update dependencies ([56f0094](https://github.com/twinfoundation/blob-storage/commit/56f0094b68d8bd22864cd899ac1b61d95540f719))
14
+ * update framework core ([ff339fe](https://github.com/twinfoundation/blob-storage/commit/ff339fe7e3f09ddff429907834bdf43617e9c05e))
15
+ * use shared store mechanism ([#12](https://github.com/twinfoundation/blob-storage/issues/12)) ([cae8110](https://github.com/twinfoundation/blob-storage/commit/cae8110681847a1ac4fcac968b8196694e49c320))
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * The following workspace dependencies were updated
21
+ * dependencies
22
+ * @twin.org/blob-storage-models bumped from 0.0.3-next.0 to 0.0.3-next.1
23
+
3
24
  ## [0.0.2-next.5](https://github.com/twinfoundation/blob-storage/compare/blob-storage-rest-client-v0.0.2-next.4...blob-storage-rest-client-v0.0.2-next.5) (2025-10-09)
4
25
 
5
26
 
@@ -16,7 +16,7 @@ Client for performing blob storage through to REST endpoints.
16
16
 
17
17
  > **new BlobStorageRestClient**(`config`): `BlobStorageRestClient`
18
18
 
19
- Create a new instance of BlobStorageClient.
19
+ Create a new instance of BlobStorageRestClient.
20
20
 
21
21
  #### Parameters
22
22
 
@@ -44,6 +44,24 @@ Runtime name for the class.
44
44
 
45
45
  ## Methods
46
46
 
47
+ ### className()
48
+
49
+ > **className**(): `string`
50
+
51
+ Returns the class name of the component.
52
+
53
+ #### Returns
54
+
55
+ `string`
56
+
57
+ The class name of the component.
58
+
59
+ #### Implementation of
60
+
61
+ `IBlobStorageComponent.className`
62
+
63
+ ***
64
+
47
65
  ### create()
48
66
 
49
67
  > **create**(`blob`, `encodingFormat?`, `fileExtension?`, `metadata?`, `options?`): `Promise`\<`string`\>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/blob-storage-rest-client",
3
- "version": "0.0.2-next.5",
3
+ "version": "0.0.3-next.1",
4
4
  "description": "Blob storage implementation which can connect to REST endpoints",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,27 +16,25 @@
16
16
  "dependencies": {
17
17
  "@twin.org/api-core": "next",
18
18
  "@twin.org/api-models": "next",
19
- "@twin.org/blob-storage-models": "0.0.2-next.5",
19
+ "@twin.org/blob-storage-models": "0.0.3-next.1",
20
20
  "@twin.org/core": "next",
21
21
  "@twin.org/data-json-ld": "next",
22
22
  "@twin.org/entity": "next",
23
23
  "@twin.org/nameof": "next",
24
24
  "@twin.org/web": "next"
25
25
  },
26
- "main": "./dist/cjs/index.cjs",
27
- "module": "./dist/esm/index.mjs",
26
+ "main": "./dist/es/index.js",
28
27
  "types": "./dist/types/index.d.ts",
29
28
  "exports": {
30
29
  ".": {
31
30
  "types": "./dist/types/index.d.ts",
32
- "require": "./dist/cjs/index.cjs",
33
- "import": "./dist/esm/index.mjs"
31
+ "import": "./dist/es/index.js",
32
+ "default": "./dist/es/index.js"
34
33
  },
35
34
  "./locales/*.json": "./locales/*.json"
36
35
  },
37
36
  "files": [
38
- "dist/cjs",
39
- "dist/esm",
37
+ "dist/es",
40
38
  "dist/types",
41
39
  "locales",
42
40
  "docs"
@@ -1,164 +0,0 @@
1
- 'use strict';
2
-
3
- var apiCore = require('@twin.org/api-core');
4
- var apiModels = require('@twin.org/api-models');
5
- var core = require('@twin.org/core');
6
- var web = require('@twin.org/web');
7
-
8
- // Copyright 2024 IOTA Stiftung.
9
- // SPDX-License-Identifier: Apache-2.0.
10
- /**
11
- * Client for performing blob storage through to REST endpoints.
12
- */
13
- class BlobStorageRestClient extends apiCore.BaseRestClient {
14
- /**
15
- * Runtime name for the class.
16
- */
17
- static CLASS_NAME = "BlobStorageRestClient";
18
- /**
19
- * Create a new instance of BlobStorageClient.
20
- * @param config The configuration for the client.
21
- */
22
- constructor(config) {
23
- super(BlobStorageRestClient.CLASS_NAME, config, "blob");
24
- }
25
- /**
26
- * Create the blob with some metadata.
27
- * @param blob The data for the blob in base64 format.
28
- * @param encodingFormat Mime type for the blob, will be detected if left undefined.
29
- * @param fileExtension Extension for the blob, will be detected if left undefined.
30
- * @param metadata Data for the custom metadata as JSON-LD.
31
- * @param options Optional options for the creation of the blob.
32
- * @param options.disableEncryption Disables encryption if enabled by default.
33
- * @param options.overrideVaultKeyId Use a different vault key id for encryption, if not provided the default vault key id will be used.
34
- * @param options.namespace The namespace to use for storing, defaults to component configured namespace.
35
- * @returns The id of the stored blob in urn format.
36
- */
37
- async create(blob, encodingFormat, fileExtension, metadata, options) {
38
- core.Guards.stringBase64(BlobStorageRestClient.CLASS_NAME, "blob", blob);
39
- const response = await this.fetch("/", "POST", {
40
- body: {
41
- blob,
42
- encodingFormat,
43
- fileExtension,
44
- metadata,
45
- disableEncryption: options?.disableEncryption,
46
- overrideVaultKeyId: options?.overrideVaultKeyId,
47
- namespace: options?.namespace
48
- }
49
- });
50
- return response.headers[web.HeaderTypes.Location];
51
- }
52
- /**
53
- * Get the blob and metadata.
54
- * @param id The id of the blob to get in urn format.
55
- * @param options Optional options for the retrieval of the blob.
56
- * @param options.includeContent Include the content, or just get the metadata.
57
- * @param options.overrideVaultKeyId Use a different vault key id for decryption, if not provided the default vault key id will be used.
58
- * @param options.decompress If the content should be decompressed, if it was compressed when stored, defaults to true.
59
- * @returns The metadata and data for the blob if it can be found.
60
- * @throws Not found error if the blob cannot be found.
61
- */
62
- async get(id, options) {
63
- core.Urn.guard(BlobStorageRestClient.CLASS_NAME, "id", id);
64
- const response = await this.fetch("/:id", "GET", {
65
- headers: {
66
- [web.HeaderTypes.Accept]: web.MimeTypes.JsonLd
67
- },
68
- pathParams: {
69
- id
70
- },
71
- query: {
72
- includeContent: core.Coerce.string(options?.includeContent),
73
- decompress: core.Coerce.string(options?.decompress),
74
- overrideVaultKeyId: options?.overrideVaultKeyId
75
- }
76
- });
77
- return response.body;
78
- }
79
- /**
80
- * Update the blob with metadata.
81
- * @param id The id of the blob metadata to update.
82
- * @param encodingFormat Mime type for the blob, will be detected if left undefined.
83
- * @param fileExtension Extension for the blob, will be detected if left undefined.
84
- * @param metadata Data for the custom metadata as JSON-LD.
85
- * @returns Nothing.
86
- * @throws Not found error if the blob cannot be found.
87
- */
88
- async update(id, encodingFormat, fileExtension, metadata) {
89
- core.Urn.guard(BlobStorageRestClient.CLASS_NAME, "id", id);
90
- await this.fetch("/:id", "PUT", {
91
- pathParams: {
92
- id
93
- },
94
- body: {
95
- encodingFormat,
96
- fileExtension,
97
- metadata
98
- }
99
- });
100
- }
101
- /**
102
- * Remove the blob.
103
- * @param id The id of the blob to remove in urn format.
104
- * @returns Nothing.
105
- */
106
- async remove(id) {
107
- core.Urn.guard(BlobStorageRestClient.CLASS_NAME, "id", id);
108
- await this.fetch("/:id", "DELETE", {
109
- pathParams: {
110
- id
111
- }
112
- });
113
- }
114
- /**
115
- * Query all the blob storage entries which match the conditions.
116
- * @param conditions The conditions to match for the entries.
117
- * @param orderBy The order for the results, defaults to created.
118
- * @param orderByDirection The direction for the order, defaults to descending.
119
- * @param cursor The cursor to request the next page of entries.
120
- * @param limit The suggested number of entries to return in each chunk, in some scenarios can return a different amount.
121
- * @returns All the entries for the storage matching the conditions,
122
- * and a cursor which can be used to request more entities.
123
- */
124
- async query(conditions, orderBy, orderByDirection, cursor, limit) {
125
- const response = await this.fetch("/", "GET", {
126
- headers: {
127
- [web.HeaderTypes.Accept]: web.MimeTypes.JsonLd
128
- },
129
- query: {
130
- conditions: apiModels.HttpParameterHelper.objectToString(conditions),
131
- orderBy,
132
- orderByDirection,
133
- limit: core.Coerce.string(limit),
134
- cursor
135
- }
136
- });
137
- return response.body;
138
- }
139
- /**
140
- * Create a download link for the blob.
141
- * @param id The id of the blob to get in urn format.
142
- * @param download Should the content disposition be set to download.
143
- * @param filename The filename to use for the download.
144
- * @returns The download link.
145
- */
146
- createDownloadLink(id, download, filename) {
147
- core.Urn.guard(BlobStorageRestClient.CLASS_NAME, "id", id);
148
- let link = core.StringHelper.trimTrailingSlashes(this.getEndpointWithPrefix());
149
- link += `/${id}/content`;
150
- const downloadQuery = [];
151
- if (download) {
152
- downloadQuery.push("download=true");
153
- }
154
- if (core.Is.stringValue(filename)) {
155
- downloadQuery.push(`filename=${encodeURIComponent(filename)}`);
156
- }
157
- if (downloadQuery.length > 0) {
158
- link += `?${downloadQuery.join("&")}`;
159
- }
160
- return link;
161
- }
162
- }
163
-
164
- exports.BlobStorageRestClient = BlobStorageRestClient;