Commit Graph
64 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 00d76747e2 feat: kill tis (#1528) 2026-05-20 19:54:10 +01:00
zk c569243194 feat: remove mongo and all of its deps (#1525)
* feat: remove mongo and all of its deps

* feat: remove all mongodb logic+thin out some unused deps
2026-05-20 19:48:39 +01:00
zk ff06287e87 fix: this fucking regexp bug that has annoyed me for 4 years 2026-05-17 23:19:38 +00:00
zk 612b69a960 fix: formatting fixes 2026-05-17 14:44:43 +00:00
zk d5c28aa61a unfuck sqlite 2026-05-03 15:04:24 +00:00
zk b8a98b581c if it hurts to breathe (open a window) (#58)
* if it hurts to breathe (open a window)

* clocked it.

* must sleep tonight, sorry

* feat: leaderboard now shows #1 if you're #1 even in ties
2026-04-22 22:26:43 +01:00
zk 2bc4c3a628 more (#53)
* checkpoint

* server compiles again

* fmt

* checkpoint

* last one out, get the lights

* euston station

* like, mostly good. I'm under the ocean right now.

* fix: some nonsense AI stuff

* fix: new eslint rules, and cleanup imports across the board

* feat: folder slug rewrite, email logic change, too

* fix: register must use txn not db

* checkpoint
2026-04-20 23:11:16 +01:00
zk edda03e916 sunday 5th apr (rip mark hollis) (#52)
* lots of work

* feat: move rg-stats in, ensure consistency in db queries

* the clocks dont work

* almost

* ok jesus been and gone now back to usual
2026-04-06 01:25:30 +01:00
zk 7f5aa96779 way more actionizing 2026-03-20 02:07:30 +00:00
zk c80e2ea2ef feat: start actionising on the west coast 2026-03-19 20:20:11 +00:00
zk 6c041e1f9a antimony 2026-03-18 20:20:03 +00:00
zk 4d489cbdea checkpoint 2026-03-13 17:35:10 +00:00
zk d7bb9541f6 refactor: migrate bot/ to a sensible logging solution 2026-03-12 20:19:27 +00:00
zk 5ea514cfa8 feat: first v3 refactor 2026-03-11 00:06:28 +00:00
zkldi 3f524af1ed feat: rename back to zkldi 2025-11-15 12:16:00 +00:00
zkldi ca5ada19b2 feat: vendor TAP 2024-08-17 14:58:52 +00:00
zk 593adb2717 feat: Dev Container (#1149)
* temporary dvctr

* start of work

* fix: timeouts in windows

* fish?

* feat: better, working stuff

* refactor: rename database-seeds to seeds/

* better

* fdsaf

* feat: don't let our container get owned by root

* fix: better user handling

* feat: falling asleep at my desk i yield to you what i have done

* feat: autoadminify

* docs: denote trickshot

* feat: open in browser on launch

* better seeds workings...

* fix: dont kill shell

* docs: mention dev/debs

* fix: whoops

* fix: make seeds load within the century

* feat: rest of the containerisation

* feat: new alias

* style: fix linter errors

* fix: bad call

* fix: better justfile
2024-08-17 15:01:40 +01:00
zkldi 315b83ee51 docs: rename zk to something more memorable 2024-07-14 19:55:41 +01:00
zkldi 2ebe9f9544 feat: things (#1098)
* feat: clean up this disgusting filter directive thing

* fix: THIS FIX WAS THIS EASY FOR THIS LONG???

* fix: version is obsolete

* feat: much prettier...

* feat: big import warnings

* feat: sour times
2024-06-05 01:49:51 +01:00
zkldi 89e4c6ff2f feat: patch winston loki so it works for us 2024-04-14 02:50:08 +01:00
zkldi 1486ccf2f5 feat: prometheus metrics (#1033) 2024-04-10 02:31:47 +01:00
zkldi 0bb76fb338 merge cirratism 2024-04-09 23:27:10 +01:00
zkldi 73dfd64cd3 fix: remove some extremely annoying deprecation warnings (#1028)
* fix: enforce 3.6.3 to avoid deprecation warning

* fix: nonsense old debug message

* fix: just re-patch browserslist, whatever.
2024-04-09 23:24:29 +01:00
zkldi ee9d2bb3c0 bump version 2024-04-06 14:21:27 +01:00
zkldi 287b5fac27 feat: move urls 2024-04-05 20:48:55 +01:00
zkldi b42eacf1ad feat: 7 2023-10-16 13:07:41 +01:00
zkldi 37516ffc56 feat: unscrew pnpm forcefully 2023-10-16 12:55:11 +01:00
zkldi 0d25b70555 release: 2.4.3 2023-06-29 18:04:02 +01:00
zkldi 2a1231841f feat: global session calendar 2023-02-20 01:56:01 +00:00
zkldi 9667a5765a release: 2.4.2 2023-02-16 01:28:04 +00:00
zkldi dc0ee4b24f fix: better scripts 2023-02-09 00:23:44 +00:00
zkldi ba6e3f9009 fix: more bootstrap alterations 2023-02-08 21:50:47 +00:00
zkldi 3e8fabc814 feat: seeds dockerisation 2023-02-08 04:18:59 +00:00
zkldi 76f1b10be5 feat: dockerise everything 2023-02-08 03:36:09 +00:00
zkldi a39a52c75a feat: we node18 now 2023-01-26 16:29:08 +00:00
zkldi f7975d3201 fix: i'm just going to call this 2.4 2023-01-24 22:48:09 +00:00
zkldi 0c48b6cef0 fix: that's all probably 2023-01-19 16:39:53 +00:00
zkldi c9964d9662 fix: temp migrations 2023-01-19 16:39:52 +00:00
zkldi 2ff1dc1c29 feat: validators 2023-01-19 16:39:42 +00:00
zkldi 45231a3914 checkpoint: 1 2023-01-19 16:39:15 +00:00
zkldi 95eee4343a feat: migration to typescript 4.9 2022-12-28 15:44:27 +00:00
zkldi 23458f5ceb temp: remove patchedDependencies until pnpm actually works 2022-12-23 07:02:27 +00:00
zkldi c2bccd64ae feat: just a bunch of cleanup
- no deduping, ui improvements, general fixups
2022-12-22 17:23:37 +00:00
zkldi b2335d71ba feat: pnpm make-user-admin 2022-12-14 07:14:50 +00:00
ereti b59b6707c0 fix: ci 2022-12-14 05:08:01 +00:00
zkldi 1d14b78dce fix: patch out obnoxious browserslist err 2022-12-14 03:32:51 +00:00
ereti 1af9942147 feat: the monorepo man 2022-12-01 21:10:23 +00:00
ereti 98a74e12cf feat: make monorepo sane 2022-11-28 00:58:38 +00:00
zkldi c8a614f114 release: 2.2.0 2022-11-26 22:49:55 +00:00