This commit is contained in:
ge 2023-04-26 16:46:36 +03:00
parent 21e3ae3b1c
commit c0d4ad668b
3 changed files with 41 additions and 4 deletions

View File

@ -2,20 +2,42 @@
ArchiveBox [doesn't have a web API](https://github.com/ArchiveBox/ArchiveBox/issues/496) yet. This is shitty single-endpoint API to automate page archiving. It uses subprocess to run archivebox CLI. archivebox CLI runs in new thread to avoid blocking main thread.
# Install and run
# Deployment
Install dependencies:
You must deploy API to server which ArchieveBox runs.
Make working directory, create virtualenv and install dependencies:
```
apt install -y git python3-venv
mkdir -p /opt/cursed_archievebox_api && cd /opt/cursed_archievebox_api
python -m venv env
source env/bin/activate
pip install bottle gunicorn
git clone https://git.nxhs.cloud/ge/cursed-archivebox-api.git .
```
Start API on server where ArchiveBox container is running. Set actual path to docker-compose.yml.
Start API. Set actual path to docker-compose.yml:
```
ARCHIVEBOX_BIN="docker compose -f /opt/archievebox/docker-compose.yml run archivebox" python cursed_archivebox_api.py
```
See also [cursed-archivebox-api.service](cursed-archivebox-api.service).
Install service:
```
cp cursed-archivebox-api.service /etc/systemd/system
systemctl enable --now cursed-archivebox-api.service
```
See logs:
```
journalctl -u cursed-archivebox-api.service -f
```
# Environment
| Variable | Default |
@ -33,7 +55,7 @@ Query parameters:
* `depth`. Archive depth. Default: 0 (current page)
* `tag`. List of comma separated tags e.g. `my_tag`, `my_tag,another_one`.
Example:
Example request:
```
curl -i 'http://localhost:9998/add?url=https://example.com&depth=0&tag=api,example'

View File

@ -0,0 +1,14 @@
[Unit]
Description=Cursed API for ArchiveBox
After=syslog.target
After=network.target
[Service]
Type=simple
Environment=ARCHIVEBOX_BIN="docker compose -f /opt/archivebox/docker-compose.yml run archivebox"
WorkingDirectory=/opt/cursed_archivebox_api
ExecStart=/opt/cursed_archivebox_api/env/bin/python cursed_archivebox_api.py
Restart=on-failure
[Install]
WantedBy=multi-user.target

View File

@ -45,6 +45,7 @@ def run_bg_task(cmd):
@get('/add')
def add_to_archive() -> str:
response.set_header('Content-Type', 'application/json')
url = request.query.url or None
depth = request.query.depth or None
tag = request.query.tag or None