2024-06-16 00:17:38 +00:00
|
|
|
# Share Endpoints
|
|
|
|
|
|
|
|
Share endpoints allow sharing files with other users.
|
|
|
|
|
2024-06-17 22:32:45 +00:00
|
|
|
## POST `/share` (auth required)
|
2024-06-16 00:17:38 +00:00
|
|
|
|
2024-06-17 22:32:45 +00:00
|
|
|
### Description
|
|
|
|
|
|
|
|
The `/share` endpoint shares 1 or more filesystem items
|
|
|
|
with one or more recipients. The recipients will receive
|
|
|
|
some notification about the shared item, making this
|
|
|
|
different from calling `/grant-user-user` with a permission.
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
|
|
|
- **recipients** _- required_
|
|
|
|
- **accepts:** `string | Array<string>`
|
|
|
|
- **description:**
|
|
|
|
recipients for the filesystem entries being shared.
|
|
|
|
- **notes:**
|
|
|
|
- validation on `string`: email or username
|
|
|
|
- requirement of at least one value
|
2024-06-20 05:16:59 +00:00
|
|
|
- **things:** _- required_
|
|
|
|
- **accepts:** `object | Array<object>`
|
|
|
|
- **structure:**
|
|
|
|
- > `path`, `uid`, `name` are mutually exclusive
|
|
|
|
- **type:** _- required_
|
|
|
|
- **accepts:** one of: `fsitem`, `app`
|
|
|
|
- **uid:**
|
|
|
|
- **accepts:**
|
|
|
|
- file or directory (path or UUID)
|
|
|
|
- app UUID,
|
|
|
|
- **path:** _alias for uid_
|
|
|
|
- **name:** name of app
|
|
|
|
- **access:**
|
|
|
|
- `"read"` or `"write"` for files (default: `"read"`)
|
|
|
|
- unspecified for apps
|
2024-06-17 22:32:45 +00:00
|
|
|
- **notes:**
|
2024-06-20 05:16:59 +00:00
|
|
|
- requirement that file/directory or app exists
|
|
|
|
- requirement of at least one entry
|
2024-06-18 00:35:49 +00:00
|
|
|
- **examples:**
|
|
|
|
- ```json
|
2024-06-20 05:16:59 +00:00
|
|
|
{
|
|
|
|
"type": "fsitem",
|
|
|
|
"path": "/some/path",
|
|
|
|
"access": "write"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
- ```json
|
|
|
|
[
|
|
|
|
{ "type": "fsitem", "path": "/some/path" },
|
|
|
|
{ "type": "fsitem", "path": "/another/path" }
|
|
|
|
]
|
2024-06-18 00:35:49 +00:00
|
|
|
```
|
|
|
|
- ```json
|
2024-06-20 05:16:59 +00:00
|
|
|
{
|
|
|
|
"type": "app",
|
|
|
|
"uid": "app-7978dd66-e5a8-43a0-80c8-1c7eca8cb00a"
|
|
|
|
}
|
2024-06-18 00:35:49 +00:00
|
|
|
```
|
2024-06-17 22:32:45 +00:00
|
|
|
- **dry_run:** _- optional_
|
|
|
|
- **accepts:** `bool`
|
|
|
|
- **description:**
|
|
|
|
when true, only validation will occur
|
|
|
|
|
|
|
|
### Response
|
|
|
|
|
|
|
|
- **$:** `api:share`
|
|
|
|
- **$version:** `v0.0.0`
|
|
|
|
- **status:** one of: `"success"`, `"mixed"`, `"aborted"`
|
|
|
|
- **recipients:** array of: `api:status-report` or
|
|
|
|
`heyputer:api/APIError`
|
|
|
|
- **paths:** array of: `api:status-report` or
|
|
|
|
`heyputer:api/APIError`
|
|
|
|
- **dry_run:** `true` if present
|
|
|
|
|
2024-06-17 22:44:21 +00:00
|
|
|
### Request Example
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
await fetch("http://puter.localhost:4100/share", {
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Authorization": `Bearer ${puter.authToken}`,
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
// dry_run: true,
|
|
|
|
recipients: [
|
|
|
|
'user_that_gets_shared_to',
|
|
|
|
],
|
|
|
|
paths: [
|
|
|
|
'/user_that_shares/file_that_gets_shared.txt',
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
method: "POST",
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2024-06-17 22:32:45 +00:00
|
|
|
### Success Response
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"$": "api:share",
|
|
|
|
"$version": "v0.0.0",
|
|
|
|
"status": "success",
|
|
|
|
"recipients": [
|
|
|
|
{
|
|
|
|
"$": "api:status-report",
|
|
|
|
"status": "success"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"paths": [
|
|
|
|
{
|
|
|
|
"$": "api:status-report",
|
|
|
|
"status": "success"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"dry_run": true
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Error response (missing file)
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"$": "api:share",
|
|
|
|
"$version": "v0.0.0",
|
|
|
|
"status": "mixed",
|
|
|
|
"recipients": [
|
|
|
|
{
|
|
|
|
"$": "api:status-report",
|
|
|
|
"status": "success"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"paths": [
|
|
|
|
{
|
|
|
|
"$": "heyputer:api/APIError",
|
|
|
|
"code": "subject_does_not_exist",
|
|
|
|
"message": "File or directory not found.",
|
|
|
|
"status": 404
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"dry_run": true
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Error response (missing user)
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"$": "api:share",
|
|
|
|
"$version": "v0.0.0",
|
|
|
|
"status": "mixed",
|
|
|
|
"recipients": [
|
|
|
|
{
|
|
|
|
"$": "heyputer:api/APIError",
|
|
|
|
"code": "user_does_not_exist",
|
|
|
|
"message": "The user `non_existing_user` does not exist.",
|
|
|
|
"username": "non_existing_user",
|
|
|
|
"status": 422
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"paths": [
|
|
|
|
{
|
|
|
|
"$": "api:status-report",
|
|
|
|
"status": "success"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"dry_run": true
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## **deprecated** POST `/share/item-by-username` (auth required)
|
2024-06-16 00:17:38 +00:00
|
|
|
|
|
|
|
### Description
|
|
|
|
|
|
|
|
The `/share/item-by-username` endpoint grants access permission
|
|
|
|
for an item to the specified user. This user will also receive an
|
|
|
|
email about the shared item.
|
|
|
|
|
|
|
|
### Parameters
|
|
|
|
|
|
|
|
| Name | Description | Default Value |
|
|
|
|
| ---- | ----------- | -------- |
|
|
|
|
| path | Location of the item | **required** |
|
|
|
|
| username | Username of the user to share to | **required** |
|
|
|
|
| access_level | Either `'read'` or `'write'` | `'write'` |
|
|
|
|
|
|
|
|
### Response
|
|
|
|
|
|
|
|
This endpoint responds with an empty object (`{}`).
|
|
|
|
|
|
|
|
### Request Example
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
await fetch("https://api.puter.local/share/item-by-username", {
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Authorization": `Bearer ${puter.authToken}`,
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
path: "/my-username/Desktop/some-file.txt",
|
|
|
|
username: "other-username",
|
|
|
|
}),
|
|
|
|
method: "POST",
|
|
|
|
});
|
|
|
|
```
|