Skip to content

Generate shareable code snippet links from code snippets saved on the user’s DB: #92

Description

@shivaypiece
  1. 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
  2. Create an asset for the snippet - AssetsApi().assetsCreateNewAsset()

  3. 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;
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomers in the OSP Community.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions