upd
This commit is contained in:
		
							
								
								
									
										30
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								README.md
									
									
									
									
									
								
							@@ -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.
 | 
					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
 | 
					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
 | 
					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
 | 
					# Environment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| Variable          | Default               |
 | 
					| Variable          | Default               |
 | 
				
			||||||
@@ -33,7 +55,7 @@ Query parameters:
 | 
				
			|||||||
* `depth`. Archive depth. Default: 0 (current page)
 | 
					* `depth`. Archive depth. Default: 0 (current page)
 | 
				
			||||||
* `tag`. List of comma separated tags e.g. `my_tag`, `my_tag,another_one`.
 | 
					* `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'
 | 
					curl -i 'http://localhost:9998/add?url=https://example.com&depth=0&tag=api,example'
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										14
									
								
								cursed-archivebox-api.service
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								cursed-archivebox-api.service
									
									
									
									
									
										Normal 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
 | 
				
			||||||
@@ -45,6 +45,7 @@ def run_bg_task(cmd):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@get('/add')
 | 
					@get('/add')
 | 
				
			||||||
def add_to_archive() -> str:
 | 
					def add_to_archive() -> str:
 | 
				
			||||||
 | 
					    response.set_header('Content-Type', 'application/json')
 | 
				
			||||||
    url = request.query.url or None
 | 
					    url = request.query.url or None
 | 
				
			||||||
    depth = request.query.depth or None
 | 
					    depth = request.query.depth or None
 | 
				
			||||||
    tag = request.query.tag or None
 | 
					    tag = request.query.tag or None
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user