Spectura is a microservice for taking screenshots of websites in an Open Graph compatible format usable for link previews on sites such as Facebook and LinkedIn.
Spectura takes a url
and an optional signature s
as query parameters. The
signature ensures that we only visit pre-approved URLs.
In local testing, USE_SIGNATURES
is set to false, so you dont need the s
parameter.
Spectura also takes expire
. This is so that we don’t spend time generating screenshots of expired jobs.
Expire is a unix timestamp in seconds. We return the fallback image if expire is exceeded.
If there is no present expire
property, we always return the fallback image. This is for backwards compatability reasons.
You either need to run a Decap instance manually, or run everything inside Docker as described below.
To run Spectura in Docker, you need Docker version 20.10 or higher.
Assuming that Decap is listening on localhost:4531
:
go build
USE_SIGNATURES=false ./spectura
Then make a GET request on the same host:
curl 'http://localhost:19165/api/spectura/v0/screenshot?url=https%3A%2F%2Fwww.jobindex.dk%2F%3Fspectura%3D1&expire=2000000000' --output screenshot.png
To run Spectura
Note
|
Always run with --build
|
docker compose up --build
To test Spectura with curl
Remeber you need to set
&expire=2000000000
or some other time after today. If you don’t have expire or expire is earlier than today, you will get the fallback image.
curl 'http://localhost:19165/api/spectura/v0/screenshot?url=https://pyjam.as&expire=2000000000'
If you use kitty terminal you can print the image directly in your terminal
curl 'http://localhost:19165/api/spectura/v0/screenshot?url=https://pyjam.as&expire=2000000000' | kitty +kitten icat
To get webhook updates you can set the WEBHOOK_URL
and the WEBHOOK_AUTHORIZATION_HEADER
.
The WEBHOOK_URL
will receive a POST
request with the Authorization
header set to the value in WEBHOOK_AUTHORIZATION_HEADER
and a JSON body looking like this:
{ "EventType": "image_created", "URL": "https://pyjam.as", "ImageCreated": 1675773692, "Expire": 2000000000 }
Timestamps are represented as a UNIX seconds in UTC.
Event types contain the same data and are:
-
image_created
, sent whenever and entry is created -
image_updated
, sent whenever the image itself of a cache entry is updated.
Name |
Required |
Default |
|
no |
|
|
no |
|
|
no |
|
|
no |
|
|
no |
|
|
no |
|
|
no |
|
|
no |
|
|
if |
no default |
|
if |
no default |
|
no |
|
|
no |
|
|
no |
no default |
|
no |
no default |
Unless otherwise noted, code in this repository is covered by a BSD 3-Clause License (see the LICENSE file for details).
Files in the xlib package may contain code written by different authors and covered by other Open Source licenses. Consult the copyright headers in the specific files for details.