Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add objects basic operations script and update publishContentVersion method #292

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/client/ContentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,8 @@ exports.PublishContentVersion = async function({objectId, versionHash, awaitComm
});

const abi = await this.ContractAbi({id: objectId});
const fromBlock = commit.blockNumber + 1;
const fromBlock = commit.blockNumber - 30; // due to block re-org

const objectHash = await this.ExtractValueFromEvent({
abi,
event: commit,
Expand Down Expand Up @@ -1035,6 +1036,7 @@ exports.PublishContentVersion = async function({objectId, versionHash, awaitComm
contractAddress: this.utils.HashToAddress(objectId),
abi,
fromBlock,
topics: [ Ethers.utils.id("VersionConfirm(address,address,string)") ],
count: 1000
});

Expand Down Expand Up @@ -1077,7 +1079,6 @@ exports.PublishContentVersion = async function({objectId, versionHash, awaitComm
}
}
}

};

/**
Expand Down
93 changes: 93 additions & 0 deletions testScripts/BasicObjectOperations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/* eslint-disable no-console */

const { ElvClient } = require("../src/ElvClient");

const configUrl = "https://test.net955205.contentfabric.io/config";
const libraryId = "ilibE6vhm2YCR6vZCtW9mope6Dbo2Tn"; // to create and edit content

const Tool = async () => {

const client = await ElvClient.FromConfigurationUrl({configUrl});

let wallet = client.GenerateWallet();
let signer = wallet.AddAccount({
privateKey: process.env.PRIVATE_KEY
});

client.SetSigner({signer});
client.ToggleLogging(true);


try {
let start = new Date().getTime();
const {objectId, writeToken} = await client.CreateContentObject({
libraryId: libraryId,
options: {
meta: {commit: "Create Content-" + start.toString()}
}
});
let end = new Date().getTime();
let timeDifference = end - start;
console.log("content object completed after: ", timeDifference, "ms");

start = new Date().getTime();
const {hash} = await client.FinalizeContentObject({
libraryId,
objectId,
writeToken
});
end = new Date();
timeDifference = end - start;
console.log("finalize object completed after: ", timeDifference, "ms");

start = new Date().getTime();
const editResponse = await client.EditContentObject({
libraryId,
objectId,
});
end = new Date().getTime();
timeDifference = end - start;
console.log("edit object completed after: ", timeDifference, "ms");

const metadata = {
description: "edit content",
};

start = new Date().getTime();
await client.ReplaceMetadata({
libraryId,
objectId,
writeToken: editResponse.write_token,
metadata
});
end = new Date().getTime();
timeDifference = end - start;
console.log("replace metadata completed after: ", timeDifference, "ms");


start = new Date().getTime();
await client.FinalizeContentObject({
libraryId,
objectId,
writeToken: editResponse.write_token,
});
end = new Date().getTime();
timeDifference = end - start;
console.log("finalize object completed after: ", timeDifference, "ms");

console.log(`\nSuccessfully created new content version: ${hash}`);
} catch(error) {
console.error("Error creating content object:");
console.error(error);
}
};

const privateKey = process.env.PRIVATE_KEY;
if(!privateKey) {
console.error("PRIVATE_KEY environment variable must be specified");
return;
}

Tool();