Project

General

Profile

Sub-Task #307

Updated by Bricklou 20 days ago

Technical specification of how avatars are stored and served. 

 Storage: 

 * The server has a blob store with three operations on a key: put, get, delete. A missing file reads as nothing and deleting it is not an error. 
 * The backend is chosen by `KUBESTRO_STORAGE_BACKEND`: `fs` (default) or `s3`. 
 * `fs` keeps files under the directory in `KUBESTRO_STORAGE_FS_DIR`, created when missing. `KUBESTRO_STORAGE_FS_DIR`. 
 * `s3` is configured by `KUBESTRO_STORAGE_S3_BUCKET`, `KUBESTRO_STORAGE_S3_ENDPOINT`, `KUBESTRO_STORAGE_S3_REGION`, `KUBESTRO_STORAGE_S3_ACCESS_KEY_ID`, `KUBESTRO_STORAGE_S3_SECRET_ACCESS_KEY` and `KUBESTRO_STORAGE_S3_PATH_STYLE` (for S3-compatible servers such as Garage or MinIO). The bucket must exist. 
 * An in-memory store serves the tests. 
 * The store is built once at boot and handed to the features that need it. A feature owns a key prefix (`avatars/`); the storage settings are never read by a feature. 
 * A Garage S3 service runs in the dev cluster, with a dev bucket and key prepared by the deploy script. 

 Data: 

 * The database keeps only a pointer on the user: the key of the current avatar and the date it was set. 
 * The key is `avatars/{user id}/{random id}.webp`. The previous object is deleted once the new pointer is stored. A new object is deleted again if its pointer could not be stored. 

 Images: 

 * The server decodes the uploaded image with limits on its size (8192 pixels a side), image, crops it to a square, and stores a 256x256 WebP. Metadata of the original is not kept. This is a helper shared by every feature that takes an image. 
 * Accepted input: PNG, JPG, GIF JPG and WebP, up to 2 MB, sent as the raw body of the request. The dashboard crops and reduces the chosen picture (up to 10 MB) before sending it. 

 API: 

 * `PUT /api/v1/me/avatar` sets the avatar. `DELETE /api/v1/me/avatar` removes it. 
 * `GET /api/v1/users/{id}/avatar` returns the image for a signed-in user. The server reads it from the store and answers with an `ETag`, so the bucket stays private. 
 * The user response and carries the user summaries carry the address of the avatar, versioned by its date. 
 * An account that signs in through a login provider cannot change its avatar. Its avatar follows the provider's picture (see the sync sub-task of the read-only user story). 

 Acceptance criteria: 

 * [x] [ ] The `fs` and `s3` backends pass the same tests. 
 * [x] [ ] A file that is not a supported image, or is too large, is refused with a clear error. 
 * [x] [ ] Replacing or removing an avatar leaves no orphan object in the store. 
 * [x] [ ] The storage variables are documented.

Back