This commit is contained in:
seb
2026-08-01 01:59:05 +02:00
parent a05a4791d6
commit 59c874144b
6 changed files with 36 additions and 25 deletions

View File

@@ -156,7 +156,7 @@ Backend mapping:
sort,
full: { w, h, size }, // AVIF, max 1000×1000 (stored as-is when already AVIF and within bounds)
thumb: { w, h }, // scaled AVIF, max 200×200 (fit inside)
hash, // SHA-256 hex of full image bytes
fullHash, // SHA-256 hex — use for GET /api/image/:fullHash and GET /api/thumb/:fullHash
thumbHash, // base64 thumbhash of thumb preview
}
```
@@ -190,20 +190,25 @@ Auth via the article's `categoryarticle` category + `resolveCategoryAccess`. Err
## `pic`
Lookup by `pic.hash` (SHA-256 hex from `addImage`), not `thumbhash`.
Lookup by `pic.hash` (`fullHash` — SHA-256 hex from `addImage.fullHash`), not `thumbhash`.
| Method | Signature | Returns |
| --- | --- | --- |
| `getImageByHash` | `(googleAuthId, hash)` | `{ buffer, w, h, size, contentType }` |
| `getThumbByHash` | `(googleAuthId, hash)` | `{ buffer, w, h, contentType }` |
| `getImageByHash` | `(googleAuthId, fullHash)` | `{ buffer, w, h, size, contentType }` |
| `getThumbByHash` | `(googleAuthId, fullHash)` | `{ buffer, w, h, contentType }` |
Auth via `articlepic` → `categoryarticle` → `resolveCategoryAccess`. Errors: `Image not found`, `Not authorized`.
`contentType` is always `image/avif`. In dashback:
`contentType` is always `image/avif`.
```js
const { buffer, contentType } = await store.pic.getImageByHash(req.user.id, hash);
// GET /api/image/:fullHash
const { buffer, contentType } = await store.pic.getImageByHash(req.user.id, fullHash);
res.set('Content-Type', contentType).send(buffer);
// GET /api/thumb/:fullHash
const thumb = await store.pic.getThumbByHash(req.user.id, fullHash);
res.set('Content-Type', thumb.contentType).send(thumb.buffer);
```
---
@@ -224,8 +229,8 @@ res.set('Content-Type', contentType).send(buffer);
| `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)` |
| `GET /api/image/:fullHash` | `pic.getImageByHash(googleAuthId, fullHash)` |
| `GET /api/thumb/:fullHash` | `pic.getThumbByHash(googleAuthId, fullHash)` |
---