Skip to content

Commit

Permalink
Merge pull request #179 from contentstack/next
Browse files Browse the repository at this point in the history
updateAssetURL method added
  • Loading branch information
nadeem-cs authored May 17, 2024
2 parents 2f11c24 + ff1151c commit 78fd181
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ fileignoreconfig:
checksum: c88b336f9a271397ffedcf8c5085941ceb0bd1cd7e25ed9ada3acd8ce4f8970c
- filename: test/typescript/stack.test.ts
checksum: bbb3c425f8e1a63d4793f69ee9eaba9559294ff53f163a28f70ae54b1792276a
- filename: src/core/contentstack.js
checksum: 90a3b07300155a34f67dc3df87363107eec202123a21bc0cefda324e477a676d
version: ""
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Change log

### Version: 3.19.3
#### Date: May-17-2024
##### Enhanncement:
- Update Asset URL method added

### Version: 3.19.2
#### Date: April-17-2024
##### Dependency:
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export function Stack(config: Config): Stack;
*/
export function Stack(api_key: string, access_token: string, environment_name: string, region?: string, fetchOptions?: FetchOptions): Stack;

export function updateAssetURL(entry: object): object;
export class ContentType {
constructor();
content_type_uid: string
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contentstack",
"version": "3.19.2",
"version": "3.19.3",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand All @@ -11,7 +11,7 @@
"browser": "dist/web/contentstack.js",
"react-native": "dist/react-native/contentstack.js",
"types": "./index.d.ts",
"_id": "contentstack@3.16.1",
"_id": "contentstack@3.19.3",
"scripts": {
"test": "npm run test:e2e && npm run test:typescript",
"test:e2e": "tape test/index.js | tap-html --out ./tap-html.html",
Expand Down
32 changes: 29 additions & 3 deletions src/core/contentstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,39 @@ class Contentstack {

this.Utils = require('@contentstack/utils');
}
/**

* @memberOf Contentstack
*/
/**
* @memberOf Contentstack
*/
Stack(...stack_arguments){
return new Stack(...stack_arguments);
}

updateAssetURL(entry) {
// check if entry consist of _embedded_items object
if (entry._embedded_items == undefined) {
throw new Error("_embedded_items not present in entry. Call includeEmbeddedItems() before fetching entry.");
}

// Iterate through each object in _embedded_items and update the asset link
for (let key in entry._embedded_items) {
let embedded_item = entry._embedded_items[key];
if (Array.isArray(embedded_item)) {

embedded_item.forEach((item) => {

if (item._content_type_uid == 'sys_assets' && item.filename) {

const correspondingAsset = entry[key].children.find(child => child.attrs['asset-uid'] === item.uid);
if (correspondingAsset) {
correspondingAsset.attrs['asset-link'] = item.url;
}
}
});
}
}
}
}

module.exports = new Contentstack();

0 comments on commit 78fd181

Please sign in to comment.