https://github.com/gmemstr/daily-servo
https://github.com/gmemstr/daily-servo
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/gmemstr/daily-servo
- Owner: gmemstr
- License: agpl-3.0
- Created: 2024-08-01T14:26:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-04T14:58:21.000Z (over 1 year ago)
- Last Synced: 2025-03-19T08:19:14.590Z (10 months ago)
- Language: JavaScript
- Size: 62.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Daily Servo
===
Despite the name, this doesn't (technically) render Servo images daily (at least, not automatically)
Still very much a work in progress but is generally at a point where you can fork and use it.
About
---
Various tools for rendering and sharing snapshots of websites using Servo, primarily to track [my own site](https://servo.arch.dog)
over time.
`snapshot.sh` is a wrapper around Docker for rendering a screenshot then producing a hash of the image. This can help
indicate when Servo's rendering has changed. If you get inconsistant results with the same version and site, see
[this GitHub issue](https://github.com/servo/servo/issues/32771).
`worker/` is a small Cloudflare Worker for collecting and serving the images. Currently requires manual uploading.
snapshot.sh
---
Generating snapshots is easy but requires a few commands to be run in sequence. `snapshot.sh` wraps:
* Pulling the latest container image
* Running the container image with a volume mount to produce a snapshot
* Hashing the image
* Uploading the image to a Worker endpoint (see below)
Uploading the image is optional, provided `--dry-run` is passed.
Worker
---
The main purpose of the worker is to serve as a repository for snapshots over time. It stores images in Cloudflare R2 and
pointers to the image in KV, with a dedicated `LATEST` key pointing to the latest snapshot. The hash of the image is used as
the filename (it could technically be anything, but it *should* be the hash).
### Setup
You'll need a KV namespace and R2 bucket, which you can swap out in `worker/wrangler.toml`. You'll
also want to set an API token with `npx wrangler secret put API_TOKEN`.
You can then POST to it!
```
curl -X POST -H "Authorization: API_TOKEN" \
https://daily-servo.your-name.workers.dev/new \
-F date=(date -I) -F hash=098f6bcd4621d373cade4e832627b4f6 \
-F file=@file.png
```
The hash is md5 since that's "good enough" for detecting duplicate files at the moment, but it could easily be swapped out.
### Endpoints
A few endpoints are exposed
| endpoint | about |
|----------|-------|
|`/`|Basic HTML page|
|`/latest`|Will `302` redirect to the latest snapshot's image|
|`/latest.json`|Latest snapshot info with the hash, file URL and date|
|`/list.json`|List of all snapshots (dates and hashes), along with a `latest` pointer|
|`/new`|`POST` endpoint for uploading a new snapshot. Authorized endpoint|
|`/`|Specific snapshot in JSON format|
#### `/latest.json` | `/`
```json
{
"hash": string,
"file": string,
"date": ISO-8601 string
}
```
#### `/list.json`
```json
{
"latest": string,
"list": [
{
"date": ISO-8601 string,
"hash": string
}
]
}
```