Add bookmark assets API (#1003)

* Add list, details and download endpoints

* Avoid using multiple DefaultRoute instances

* Add upload endpoint

* Add docs

* Allow configuring max request content length

* Add option for disabling uploads

* Remove gzip field

* Add delete endpoint
This commit is contained in:
Sascha Ißbrücker
2025-03-06 09:09:53 +01:00
committed by GitHub
parent b21812c30a
commit 8a3572ba4b
18 changed files with 726 additions and 72 deletions

View File

@@ -7,7 +7,8 @@ The application provides a REST API that can be used by 3rd party applications t
## Authentication
All requests against the API must be authorized using an authorization token. The application automatically generates an API token for each user, which can be accessed through the *Settings* page.
All requests against the API must be authorized using an authorization token. The application automatically generates an
API token for each user, which can be accessed through the *Settings* page.
The token needs to be passed as `Authorization` header in the HTTP request:
@@ -91,9 +92,11 @@ Retrieves a single bookmark by ID.
GET /api/bookmarks/check/?url=https%3A%2F%2Fexample.com
```
Allows to check if a URL is already bookmarked. If the URL is already bookmarked, the `bookmark` property in the response holds the bookmark data, otherwise it is `null`.
Allows to check if a URL is already bookmarked. If the URL is already bookmarked, the `bookmark` property in the
response holds the bookmark data, otherwise it is `null`.
Also returns a `metadata` property that contains metadata scraped from the website. Finally, the `auto_tags` property contains the tag names that would be automatically added when creating a bookmark for that URL.
Also returns a `metadata` property that contains metadata scraped from the website. Finally, the `auto_tags` property
contains the tag names that would be automatically added when creating a bookmark for that URL.
Example response:
@@ -127,9 +130,13 @@ POST /api/bookmarks/
Creates a new bookmark. Tags are simply assigned using their names. Including
`is_archived: true` saves a bookmark directly to the archive.
If the provided URL is already bookmarked, this silently updates the existing bookmark instead of creating a new one. If you are implementing a user interface, consider notifying users about this behavior. You can use the `/check` endpoint to check if a URL is already bookmarked and at the same time get the existing bookmark data. This behavior may change in the future to return an error instead.
If the provided URL is already bookmarked, this silently updates the existing bookmark instead of creating a new one. If
you are implementing a user interface, consider notifying users about this behavior. You can use the `/check` endpoint
to check if a URL is already bookmarked and at the same time get the existing bookmark data. This behavior may change in
the future to return an error instead.
If the title and description are not provided or empty, the application automatically tries to scrape them from the bookmarked website. This behavior can be disabled by adding the `disable_scraping` query parameter to the API request.
If the title and description are not provided or empty, the application automatically tries to scrape them from the
bookmarked website. This behavior can be disabled by adding the `disable_scraping` query parameter to the API request.
Example payload:
@@ -202,6 +209,96 @@ DELETE /api/bookmarks/<id>/
Deletes a bookmark by ID.
### Bookmark Assets
**List**
```
GET /api/bookmarks/<bookmark_id>/assets/
```
List assets for a specific bookmark.
Example response:
```json
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"id": 1,
"bookmark": 1,
"asset_type": "snapshot",
"date_created": "2023-10-01T12:00:00Z",
"content_type": "text/html",
"display_name": "HTML snapshot from 10/01/2023",
"status": "complete",
"gzip": true
},
{
"id": 2,
"bookmark": 1,
"asset_type": "upload",
"date_created": "2023-10-01T12:05:00Z",
"content_type": "image/png",
"display_name": "example.png",
"status": "complete",
"gzip": false
}
]
}
```
**Retrieve**
```
GET /api/bookmarks/<bookmark_id>/assets/<id>/
```
Retrieves a single asset by ID for a specific bookmark.
**Download**
```
GET /api/bookmarks/<bookmark_id>/assets/<id>/download/
```
Downloads the asset file.
**Upload**
```
POST /api/bookmarks/<bookmark_id>/assets/upload/
```
Uploads a new asset for a specific bookmark. The request must be a `multipart/form-data` request with a single part
named `file` containing the file to upload.
Example response:
```json
{
"id": 3,
"bookmark": 1,
"asset_type": "upload",
"date_created": "2023-10-01T12:10:00Z",
"content_type": "application/pdf",
"display_name": "example.pdf",
"status": "complete",
"gzip": false
}
```
**Delete**
```
DELETE /api/bookmarks/<bookmark_id>/assets/<id>/
```
Deletes an asset by ID for a specific bookmark.
### Tags
**List**

View File

@@ -55,6 +55,12 @@ Values: `True`, `False` | Default = `False`
Completely disables URL validation for bookmarks.
This can be useful if you intend to store non fully qualified domain name URLs, such as network paths, or you want to store URLs that use another protocol than `http` or `https`.
### `LD_REQUEST_MAX_CONTENT_LENGTH`
Values: `Integer` as bytes | Default = `None`
Configures the maximum content length for POST requests in the uwsgi application server. This can be used to prevent uploading large files that might cause the server to run out of memory. By default, the server does not limit the content length.
### `LD_REQUEST_TIMEOUT`
Values: `Integer` as seconds | Default = `60`