This commit is contained in:
seb
2026-08-01 01:36:49 +02:00
parent 243143e7eb
commit 671064bf3f
9 changed files with 181 additions and 5 deletions

View File

@@ -146,7 +146,7 @@ Backend mapping:
| `updateBySku` | `(googleAuthId, sku, { name })` | same shape as `getBySku` |
| `addImage` | `(googleAuthId, sku, imageBuffer)` | image result (see below) |
`addImage` accepts a full-size AVIF `Buffer`. Full image: if already AVIF and ≤1000×1000, stored as-is; otherwise scaled to max 1000×1000 (`pic.binary`). Thumb always scaled to max 200×200 (`pic.thumbbinary`) via `sharp`. Computes `hash` / `thumbhash`, links `articlepic`. Auth like `getBySku`. Errors: `Article not found`, `Not authorized`.
`addImage` accepts a full-size AVIF `Buffer`. Full image: if already AVIF and ≤1000×1000, stored as-is; otherwise scaled to max 1000×1000 (`pic.fullbinary`). Thumb always scaled to max 200×200 (`pic.thumbbinary`) via `sharp`. Computes `hash` / `thumbhash`, links `articlepic`. Auth like `getBySku`. Errors: `Article not found`, `Not authorized`.
`addImage` returns:
@@ -188,6 +188,26 @@ Auth via the article's `categoryarticle` category + `resolveCategoryAccess`. Err
---
## `pic`
Lookup by `pic.hash` (SHA-256 hex from `addImage`), not `thumbhash`.
| Method | Signature | Returns |
| --- | --- | --- |
| `getImageByHash` | `(googleAuthId, hash)` | `{ buffer, w, h, size, contentType }` |
| `getThumbByHash` | `(googleAuthId, hash)` | `{ buffer, w, h, contentType }` |
Auth via `articlepic` → `categoryarticle` → `resolveCategoryAccess`. Errors: `Image not found`, `Not authorized`.
`contentType` is always `image/avif`. In dashback:
```js
const { buffer, contentType } = await store.pic.getImageByHash(req.user.id, hash);
res.set('Content-Type', contentType).send(buffer);
```
---
## Backend route cheatsheet
| Route | Store call |
@@ -204,6 +224,8 @@ Auth via the article's `categoryarticle` category + `resolveCategoryAccess`. Err
| `GET /api/article/:sku` | `article.getBySku(googleAuthId, sku)` |
| `PATCH /api/article/:sku` | `article.updateBySku(googleAuthId, sku, { name })` |
| `POST /api/article/:sku/image` | `article.addImage(googleAuthId, sku, imageBuffer)` |
| `GET /api/image/:hash` | `pic.getImageByHash(googleAuthId, hash)` |
| `GET /api/image/:hash/thumb` | `pic.getThumbByHash(googleAuthId, hash)` |
---