Commit Graph
35 Commits
Author SHA1 Message Date
zk ae5e72aa89 fix: resize profile images on upload and cache redirect responses (#1564)
* fix: resize profile images on upload and add cache headers

Profile pictures were stored at original upload size (up to 1 MB) but
only ever displayed at 32–128 px, so every page load downloaded the full
original image. Additionally, no Cache-Control headers were set anywhere
in the pipeline, forcing a fresh round-trip through the API redirect and
CDN on every page view.

- Resize JPEG/PNG pfps to max 256×256 and banners to max 1920×1080 via
  sharp before storing; re-encode to WebP at 85% quality (GIFs skipped
  to preserve the animated-GIF easter egg)
- Hash the resized buffer so the CDN path reflects what's on disk
- Set ContentType and CacheControl: immutable on S3 PutObject so CDN
  edges and browsers cache the objects indefinitely (safe because paths
  are content-addressed via SHA-256)
- Add Cache-Control: public, max-age=3600, stale-while-revalidate=86400
  to the GET /pfp and GET /banner redirect responses so browsers cache
  the userId→CDN-URL mapping and skip the API hop on repeat visits

Fixes #1553

* chore: apply biome formatting

* chore: generate ImportTimestop kanel type

* feat: add backfill-media script to migrate existing profile images

One-off script that reads every user's existing pfp and banner from S3,
runs them through the same sharp resize/WebP pipeline as new uploads,
stores the result under the new content-addressed key with immutable
cache headers, and updates custom_pfp_location/custom_banner_location
in the DB.

Features:
- --dry-run flag to preview changes without writing anything
- Skips objects already at optimal size (idempotent)
- Gracefully handles missing S3 objects (logs + skips)
- Summary stats at the end
- Reads S3 config from CLI args or TACHI_CDN_SAVE_LOCATION_* env vars

* chore: apply biome formatting to backfill-media

* fix: resize animated GIFs to animated WebP via sharp animated:true

* test: rewrite change-pfp/banner tests as real S3 + sharp integration

Remove the CDN mock entirely. Tests now pass real image buffers through
sharp and verify the stored S3 object via CDNRetrieve:

- PNG/JPEG input → assert stored object is WebP, dimensions ≤256×256,
  smaller than the original
- GIF input → assert stored object is WebP
- Hash returned from the action == SHA256 of the stored WebP bytes
  (not the original upload)
- Delete tests upload a real pfp then delete it and verify CDNRetrieve
  throws afterwards

Also move change-pfp.test.ts from the isolated vitest project back to
the default pool now that it no longer uses vi.mock.

* chore: apply biome formatting to test file

* fix: use POSTGRES_TEST_HOST env var in bot vitest setup

Both vitest.globalSetup.ts and vitest.setup.ts hardcoded 'tachi-postgres'
(the dev server), but just bot-db-test-template-reset creates the template
on 'tachi-postgres-test' (the tmpfs test server). Workers then failed to
clone the template because they were looking on the wrong host.

Mirrors the pattern already used in the server package:
  process.env.POSTGRES_TEST_HOST ?? 'tachi-postgres-test'

* fix: update pfp router tests for WebP resize pipeline

The PUT tests were comparing the stored S3 bytes directly to the original
upload buffer. Since we now resize and re-encode to WebP, this always
fails. Also, following the mockApi redirect to fetch the bytes added a
slow supertest round-trip.

Replace with: read custom_pfp_location from the DB after PUT, fetch the
stored object directly via CDNRetrieve, and assert it is smaller than the
original (non-deterministic WebP compression makes exact byte comparison
inappropriate).

* fix: update banner router tests for WebP resize pipeline

* fix: tests

* fix: ci
2026-05-23 13:48:49 +01:00
zk aa402be116 feat: check.yml (#1541) 2026-05-21 17:53:40 +01:00
zk 6d77ed3c48 feat: significantly better ci images (#1516) 2026-05-20 01:20:32 +01:00
zk 4ffc001580 ci: run bot and github-bot checks on pull requests (#1509)
Add PR workflows for tachi-bot (lint, typecheck, vitest with Postgres) and
tachi-github-bot (lint, typecheck). Gate image build and deploy on passing
tests. Fix github-bot path filters and add eslint scripts to the package.
2026-05-20 00:33:28 +01:00
zk 6b85f158be fix: i push my fingers into my eeeeeyyyeees 2026-05-17 21:04:44 +01:00
zk 0338769d2b fix: why does github@'git checkout' depend on Node.JS 20, and why should I care that it's deprecated. Why? 2026-05-17 20:49:13 +01:00
zk 0dcd5325b6 refactor: change how hashes work 2026-05-16 13:42:22 +00:00
zk 9f2ca87665 fix: harden ci, don't log any kamal stuff here, it's a liability 2026-05-16 13:15:32 +00:00
zk c732034a6d fix: update github workflows to use kamal 2026-05-16 12:39:39 +00:00
zk da1fdafa51 fix: improve Dockerfiles 2 2026-05-15 20:34:56 +00:00
zk ea98706c75 fix: i'd be dangerous if i could read 2026-05-08 18:48:44 +01:00
zk 38e652de92 ?? 2026-05-08 17:44:07 +00:00
zk e02e42e69a wire all or die 2026-05-03 18:00:58 +00:00
zk 1a37735ad5 antimony (2, redux) 2026-05-03 16:59:53 +00:00
zk a7905c80ec remove zgoat and use non :latest patching 2026-05-03 16:39:50 +00:00
zk 4fd3b17185 latest tag simulator 2026-05-03 15:42:57 +00:00
zk 622ce1ef21 hard leather hard house 2026-05-03 15:13:23 +01:00
zk c04afbc755 more ci fixes 2026-05-03 15:11:21 +01:00
zk 374f1af8e0 something to do with... (#59)
* something to do with...

* kill and die

* ririri midori
2026-04-28 22:56:24 +01:00
Albert Shinandzkldi a09291265c feat: add myt chunithm support (#1082)
* feat: add myt chunithm support

* fix: check linting when merging

* fix: run linter

* fix: my ide is very broken and likes to delete code at random

* fix: linting isn't being called correctly *anywhere*...

* fix: eslint ignore .d.ts

* fix: lint common

* fix: well whatever i guess literally nothing ever fucking works in js tools

---------

Co-authored-by: zkldi <20380519+zkldi@users.noreply.github.com>
2024-05-17 21:43:29 +01:00
zkldi 2fa4eb7745 ci: copypaste without looking 2024-04-06 20:38:34 +01:00
zkldi 4bf4a15628 fix: deploy depends on push 2024-04-06 20:33:07 +01:00
zkldi 123a7089a1 ci: enable deploys 2024-04-06 20:26:29 +01:00
zkldi bba153e656 ci: first attempt at general bits and bobs...
Obviously given the state of github yaml-engineering there's
no way I'm going to get this right on the first try
but hey ho. things *should* work.
2024-04-04 15:52:54 +01:00
zkldi 1200f00f92 temp: do away with all CI 2024-04-01 22:01:21 +01:00
ereti 39aa2c4445 fix: github actions 2022-12-01 21:15:29 +00:00
ereti 1af9942147 feat: the monorepo man 2022-12-01 21:10:23 +00:00
zkldi b7ffa82f53 fix: whoops 2022-10-22 16:01:25 +01:00
zkldi 9239365c16 fix(ci): completely refactor how bot ci works 2022-10-22 15:54:55 +01:00
zkldi 1f1d6184b8 fix(ci): probably unbreak docker buildx 2022-10-21 03:02:48 +01:00
zkldi c7005dd678 fix(ci): point to correct dockerfiles 2022-09-29 19:30:29 +01:00
zkldi ad492da4d5 chore: rename workflows 2022-07-15 19:18:48 +01:00
ereti 3c3f533414 Update bot.yml 2022-07-14 00:25:11 +01:00
ereti 9cd4ec5a62 Update bot.yml 2022-07-14 00:05:55 +01:00
ereti 51f1571b0d Create bot.yml 2022-07-13 23:45:34 +01:00