puter.fs.unshare()

Websites Puter Apps Node.js Workers

This method withdraws a user's access to a file or directory.

What an app can share. An app never gets more reach than it was given. It can share its own AppData, and files the user specifically granted it, at up to the level of access it holds itself — so an app with read access can grant read, and nothing more. Files its user owns but never handed to the app stay out of reach, and listShared() shows an app only the shares it can reach. Shares an app creates are attributed to the user and carry issuedByApp, so the owner can tell them apart in getShares() — and those are the only ones an app can list or withdraw on an item. Opening an item to anyone with the link is the owner's own call, never an app's.

Syntax

puter.fs.unshare(path, recipient)
puter.fs.unshare(options)

Parameters

path (String) (required)

The path to the file or directory. If path is not absolute, it will be resolved relative to the app's root directory.

recipient (String | Object) (required)

Whose access to withdraw. A string containing @ is treated as an email address, and any other string as a username.

Pass yourself to leave a share someone else gave you. Pass { team: uid } to withdraw a team's access, or { anyone: true } to stop sharing with anyone with the link — the latter is the owner's call, in person, as opening it was.

options (Object) (optional)

An object with the following properties:

  • path (String) - The item. Required when passing options as the only argument.
  • uid (String) - The item, by UID. Can be used instead of path.
  • recipient (String | Object) - Whose access to withdraw.

Return value

A Promise that resolves to { revoked }, where revoked is how many grants were actually removed. It is 0 when there was nothing to withdraw, which is not an error.

Who can withdraw what

  • The item's owner can withdraw any share of it, whoever granted it.
  • Anyone else can withdraw the shares they granted.
  • An app acting for you withdraws only the shares that app issued, whatever authority you have over the rest: your own shares, another app's and a delegate's all report revoked: 0 to it. Leaving a share yourself still works through an app, since that is your own access to drop.
  • Anyone can withdraw their own access, whoever granted it.

An item's owner cannot be removed from their own item.

Withdrawing someone's access also withdraws whatever they re-shared of that item — unless their authority to grant does not rest on what you took back. Someone who still holds manage here from another person, from a team, or from a folder above keeps what they granted; it was never yours to withdraw.

Passing an email address that was invited but has not yet joined cancels the invitation. Nothing was granted, so nothing is revoked from anyone — the pending share simply stops waiting.

Examples

Stop sharing a file

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        (async () => {
            await puter.fs.write('report.txt', 'Quarterly numbers');
            await puter.fs.share('report.txt', 'friend@example.com');

            const result = await puter.fs.unshare('report.txt', 'friend@example.com');
            puter.print(`Removed ${result.revoked} share(s)<br>`);
        })()
    </script>
</body>
</html>

Leave a share someone gave you

const me = await puter.auth.getUser();
await puter.fs.unshare('/alice/report.txt', me.username);