The original script (J621-Django/extras/fish_greeting system) downloaded image bytes from /random/?rating=X and read the X-File-* headers. The new API answers with JSON and a signed link, so the greeting now: - asks /api/random/?fastfetch=1&rating=<mode> for JSON; - parses url/j_id/filename/md5 with jq, python3, or a grep/sed fallback; - downloads the signed link and keeps the original display path (fastfetch kitty/kitty-icat logos, gifsicle preprocessing for GIFs, recursion guard, logging with rotation, greeting_mode 0/1/2 = NSFW/SFW/Questionable); - is configured through ~/.config/j621Greeting/config.fish or universal variables (J621_BASE, J621_WEB, J621_TOKEN, J621_FASTFETCH_CONFIG) instead of a hardcoded host, and prints the /detail/<J-ID> link on J621_WEB; - reports the API's own 404 message when a rating has no images, and keeps curl quiet so failures do not spill into the greeting. extras/fish_greeting/ contains the function, an install.fish (copies it into the fish functions dir, creates the config once, checks dependencies) and a README with the old-vs-new table and troubleshooting. The existing gm-switch helper and .desktop launchers keep working (same mode file). Tested with fish 4.9.3: syntax check on every file, guest and token runs against the dev API (unsigned vs signed URLs), the empty-rating and unreachable-API paths, and the grep/sed fallback with jq and python3 unavailable.
75 lines
2.9 KiB
Markdown
75 lines
2.9 KiB
Markdown
# fish_greeting (updated for the J621 rewrite)
|
|
|
|
Shows a random library image as your shell greeting, using fastfetch. This is
|
|
the updated version of the script from
|
|
`J621-Django/extras/fish_greeting system/fish_greeting.fish`, adapted to the
|
|
new REST API.
|
|
|
|
## What changed from the old script
|
|
|
|
| | Old J621-Django | This version |
|
|
| --- | --- | --- |
|
|
| Endpoint | `GET /random/?rating=X` returned **image bytes** | `GET /api/random/?fastfetch=1&rating=X` returns **JSON** |
|
|
| Image access | same response, `X-File-MD5`/`X-File-Name` headers | signed `url` from the JSON, downloaded separately |
|
|
| Unsupported types | rolled again (recursion) | server only returns png/jpg/gif in fastfetch mode |
|
|
| Config | hardcoded `https://j621.jake.i` | `J621_BASE` / `J621_TOKEN` / `J621_WEB` |
|
|
| Printed link | `/view/<md5>` on the old host | `/detail/<J-ID>` on `J621_WEB` |
|
|
| Modes, logging, gifsicle, fastfetch flags | same | same (`~/.config/fish/greeting_mode`, `~/.config/j621Logos/logs.log`) |
|
|
|
|
The `gm-switch` helper and the `.desktop` launchers from the old repo keep
|
|
working unchanged: they write the same `~/.config/fish/greeting_mode` file
|
|
(0 = NSFW, 1 = SFW, 2 = Questionable).
|
|
|
|
## Install
|
|
|
|
```fish
|
|
cd extras/fish_greeting
|
|
fish install.fish
|
|
```
|
|
|
|
Then edit `~/.config/j621Greeting/config.fish` (at least `J621_BASE`) and test:
|
|
|
|
```fish
|
|
fish_greeting
|
|
```
|
|
|
|
Requirements: `curl` (or `wget`), `fastfetch`, `file`. Optional: `gifsicle`
|
|
(GIF downscaling), `jq` or `python3` (JSON parsing — without either it falls
|
|
back to grep/sed).
|
|
|
|
## Configuration
|
|
|
|
Any of these work; the config file is read by the function on every run:
|
|
|
|
```fish
|
|
# ~/.config/j621Greeting/config.fish, or universal variables
|
|
set -g J621_BASE https://j621.rainbow-herring.ts.net # API origin
|
|
set -g J621_WEB https://j621.example.ts.net # link origin (split deploys)
|
|
set -g J621_TOKEN <api token> # signed URLs + hidden items
|
|
set -g J621_FASTFETCH_CONFIG jake # fastfetch config name
|
|
```
|
|
|
|
`J621_TOKEN` is the same token the SPA uses (`Authorization: Token …`). With
|
|
it the API signs the image URL for your account, so you also get items that
|
|
are hidden from guests. Without it the greeting runs as a guest and sees the
|
|
public library only.
|
|
|
|
## Rating filters
|
|
|
|
| `greeting_mode` | Rating requested | Label |
|
|
| --- | --- | --- |
|
|
| `0` | `e` | NSFW |
|
|
| `1` | `s` | SFW |
|
|
| `2` (default) | `q` | Questionable |
|
|
|
|
## Troubleshooting
|
|
|
|
- `No logo (No image matches those filters.)` — the library has no images for
|
|
that rating; try another mode or add files.
|
|
- `No logo (API error)` — check `J621_BASE`, and that the deployment is up
|
|
(`https://<host>/health`).
|
|
- `No logo (download failed)` — the signed URL expired (they last 24 h) or the
|
|
item was deleted between the two requests; just run it again.
|
|
- The greeting is slow — the API and image fetch have `--max-time` guards; a
|
|
slow tailnet link is usually the cause.
|