Make sure the user is logged in to Pieces - logic to check whether the user is signed in or not - User property when checking for PiecesOS status.
Pieces.Auth0Api.getAuth0UserInfo()
If userContext is empty - user is logged out
Create an asset for the snippet - AssetsApi().assetsCreateNewAsset()
LinkifyApi - Use this to create the link that contains the asset
const link: Share | number = await api.linkifyApi
.linkify({
linkify: {
asset,
distributions,
access: AccessEnum.Public,
},
})
.catch((error) => error.status);
if (typeof link === 'number' || !('link' in link)) {
const errorMessage = `Error occurred with status ${link}. Please check that Pieces OS is installed and running.`;
console.log(`Failed to create link. ${errorMessage}`);
return;
}
console.log('Link creation successful');
// Assuming a function to copy text to the clipboard
const copyToClipboard = async (text: string) => {
// Implementation to copy text to clipboard
console.log(`Copied to clipboard: ${text}`);
};
const message = `Shareable Link: ${link.link}`;
if (true /* Assuming the setting to copy link to clipboard is enabled */) {
await copyToClipboard(link.link);
console.log(`Created a link! It is copied to clipboard. Your ${message}`);
return;
}
Make sure the user is logged in to Pieces - logic to check whether the user is signed in or not - User property when checking for PiecesOS status.
Create an asset for the snippet - AssetsApi().assetsCreateNewAsset()
LinkifyApi - Use this to create the link that contains the asset