@magda/typescript-common 3.0.2-alpha.0 → 3.0.2-alpha.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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Get the access url of a storage api resource from [pseudo storage api resource URL](https://github.com/magda-io/magda/issues/3000)
3
+ * If the input url is not a pseudo storage api resource URL, return the input url directly
4
+ *
5
+ * @export
6
+ * @param {string} resourceUrl pseudo storage api resource URL or ordinary HTTP access url
7
+ * @param {string} storageApiBaseUrl storage api base url
8
+ * @param {string} datasetsBucket datasets storage bucket name
9
+ * @return {*}
10
+ */
11
+ export default function getStorageApiResourceAccessUrl(resourceUrl: string, storageApiBaseUrl: string, datasetsBucket: string): string;
@@ -0,0 +1,37 @@
1
+ import urijs from "urijs";
2
+ /**
3
+ * Get the access url of a storage api resource from [pseudo storage api resource URL](https://github.com/magda-io/magda/issues/3000)
4
+ * If the input url is not a pseudo storage api resource URL, return the input url directly
5
+ *
6
+ * @export
7
+ * @param {string} resourceUrl pseudo storage api resource URL or ordinary HTTP access url
8
+ * @param {string} storageApiBaseUrl storage api base url
9
+ * @param {string} datasetsBucket datasets storage bucket name
10
+ * @return {*}
11
+ */
12
+ export default function getStorageApiResourceAccessUrl(resourceUrl, storageApiBaseUrl, datasetsBucket) {
13
+ if (!resourceUrl) {
14
+ return resourceUrl;
15
+ }
16
+ const uri = urijs(resourceUrl);
17
+ if (uri.protocol() === "magda" && uri.hostname() === "storage-api") {
18
+ // --- convert [pseudo storage api resource URL](https://github.com/magda-io/magda/issues/3000) to http access url
19
+ const [datasetId, distributionId, fileName] = uri.segmentCoded();
20
+ const accessUri = urijs(storageApiBaseUrl);
21
+ const segments = [
22
+ ...accessUri.segmentCoded(),
23
+ datasetsBucket,
24
+ datasetId,
25
+ distributionId,
26
+ fileName
27
+ ];
28
+ return accessUri.segmentCoded(segments).toString();
29
+ }
30
+ else {
31
+ // --- return legacy url directly
32
+ // --- legacy url is a HTTP access url generated when create the resource
33
+ // --- can be used to access storage api directly
34
+ return resourceUrl;
35
+ }
36
+ }
37
+ //# sourceMappingURL=getStorageApiResourceAccessUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getStorageApiResourceAccessUrl.js","sourceRoot":"","sources":["../src/getStorageApiResourceAccessUrl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,8BAA8B,CAClD,WAAmB,EACnB,iBAAyB,EACzB,cAAsB;IAEtB,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,OAAO,WAAW,CAAC;IACvB,CAAC;IACD,MAAM,GAAG,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,IAAI,GAAG,CAAC,QAAQ,EAAE,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,EAAE,KAAK,aAAa,EAAE,CAAC;QACjE,kHAAkH;QAClH,MAAM,CAAC,SAAS,EAAE,cAAc,EAAE,QAAQ,CAAC,GAAG,GAAG,CAAC,YAAY,EAAE,CAAC;QACjE,MAAM,SAAS,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG;YACb,GAAG,SAAS,CAAC,YAAY,EAAE;YAC3B,cAAc;YACd,SAAS;YACT,cAAc;YACd,QAAQ;SACX,CAAC;QACF,OAAO,SAAS,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvD,CAAC;SAAM,CAAC;QACJ,iCAAiC;QACjC,yEAAyE;QACzE,iDAAiD;QACjD,OAAO,WAAW,CAAC;IACvB,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@magda/typescript-common",
3
3
  "description": "Common TypeScript code shared between components.",
4
- "version": "3.0.2-alpha.0",
4
+ "version": "3.0.2-alpha.1",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "exports": {
@@ -23,8 +23,8 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@magda/esm-utils": "^1.0.1",
26
- "@magda/registry-aspects": "^3.0.2-alpha.0",
27
- "@magda/scripts": "^3.0.2-alpha.0",
26
+ "@magda/registry-aspects": "^3.0.2-alpha.1",
27
+ "@magda/scripts": "^3.0.2-alpha.1",
28
28
  "@types/chai": "^4.3.11",
29
29
  "@types/chai-as-promised": "^7.1.0",
30
30
  "@types/cross-spawn": "^6.0.1",