This commit is contained in:
seb
2026-09-29 13:44:14 +02:00
parent 6966c5f092
commit b92e2deb41
6 changed files with 43 additions and 12 deletions

View File

@@ -51,6 +51,7 @@ function parseFullHash(value) {
function articleErrorStatus(error) {
if (error.message === 'No company selected') return 400;
if (error.message === 'Unsupported image format' || error.message?.includes('unsupported image format')) return 400;
if (error.message === 'Not authorized') return 403;
if (error.message === 'Parent not found') return 404;
if (error.message === 'Article not found') return 404;
@@ -738,7 +739,8 @@ export function register(app, basePath = '') {
* tags: [Article]
* summary: Add article image
* description: |
* Accepts a full-size AVIF body (`Content-Type: image/avif`).
* Accepts a full-size AVIF body (`Content-Type: image/avif`) or WebP body (`Content-Type: image/webp`).
* WebP images are automatically converted to AVIF on the server.
* Full: stored as-is when already AVIF and ≤1000×1000; otherwise scaled to max 1000×1000.
* Thumb always scaled to max 200×200. Stores hash/thumbhash, links `articlepic`.
* Auth like GET by SKU.
@@ -760,6 +762,10 @@ export function register(app, basePath = '') {
* schema:
* type: string
* format: binary
* image/webp:
* schema:
* type: string
* format: binary
* responses:
* 201:
* description: Image stored and linked
@@ -797,7 +803,7 @@ export function register(app, basePath = '') {
*/
app.post(
`${basePath}/article/:sku/image`,
express.raw({ type: ['image/avif', 'application/octet-stream'], limit: AVIF_BODY_LIMIT }),
express.raw({ type: ['image/avif', 'image/webp', 'application/octet-stream'], limit: AVIF_BODY_LIMIT }),
async (req, res) => {
const sku = typeof req.params.sku === 'string' ? req.params.sku.trim() : '';
if (!sku) {
@@ -806,7 +812,7 @@ export function register(app, basePath = '') {
const imageBuffer = Buffer.isBuffer(req.body) ? req.body : null;
if (!imageBuffer?.length) {
return res.status(400).json({ error: 'AVIF image body is required' });
return res.status(400).json({ error: 'AVIF or WebP image body is required' });
}
try {

View File

@@ -13,6 +13,7 @@ function requireSelectedCompany(req) {
function brandErrorStatus(error) {
if (error.message === 'No company selected') return 400;
if (error.message === 'Unsupported image format' || error.message?.includes('unsupported image format')) return 400;
if (error.message === 'Not authorized') return 403;
if (error.message === 'Company not found') return 404;
if (error.message === 'Brand not found') return 404;
@@ -244,7 +245,7 @@ export function register(app, basePath = '') {
app.post(
`${basePath}/brand/:id/image`,
express.raw({ type: ['image/avif', 'application/octet-stream'], limit: AVIF_BODY_LIMIT }),
express.raw({ type: ['image/avif', 'image/webp', 'application/octet-stream'], limit: AVIF_BODY_LIMIT }),
async (req, res) => {
const selected = requireSelectedCompany(req);
if (selected.error) {
@@ -258,7 +259,7 @@ export function register(app, basePath = '') {
const imageBuffer = Buffer.isBuffer(req.body) ? req.body : null;
if (!imageBuffer?.length) {
return res.status(400).json({ error: 'AVIF image body is required' });
return res.status(400).json({ error: 'AVIF or WebP image body is required' });
}
try {

View File

@@ -24,6 +24,7 @@ function parsePositiveInt(value, field) {
function categoryErrorStatus(error) {
if (error.message === 'No company selected') return 400;
if (error.message === 'Unsupported image format' || error.message?.includes('unsupported image format')) return 400;
if (error.message === 'Not authorized') return 403;
if (error.message === 'Company not found') return 404;
if (error.message === 'Parent not found') return 404;
@@ -647,7 +648,8 @@ export function register(app, basePath = '') {
* tags: [Category]
* summary: Add category image
* description: |
* Accepts a full-size AVIF body (`Content-Type: image/avif`).
* Accepts a full-size AVIF body (`Content-Type: image/avif`) or WebP body (`Content-Type: image/webp`).
* WebP images are automatically converted to AVIF on the server.
* Full: stored as-is when already AVIF and ≤1000×1000; otherwise scaled to max 1000×1000.
* Thumb always scaled to max 200×200. Stores hash/thumbhash, links `categorypic`.
* Auth like GET /category/tree — user must be authorized for the category's company.
@@ -669,6 +671,10 @@ export function register(app, basePath = '') {
* schema:
* type: string
* format: binary
* image/webp:
* schema:
* type: string
* format: binary
* responses:
* 201:
* description: Image stored and linked
@@ -772,7 +778,7 @@ export function register(app, basePath = '') {
*/
app.post(
`${basePath}/category/:id/image`,
express.raw({ type: ['image/avif', 'application/octet-stream'], limit: AVIF_BODY_LIMIT }),
express.raw({ type: ['image/avif', 'image/webp', 'application/octet-stream'], limit: AVIF_BODY_LIMIT }),
async (req, res) => {
const parsed = parsePositiveInt(req.params.id, 'id');
if (parsed.error) {
@@ -781,7 +787,7 @@ export function register(app, basePath = '') {
const imageBuffer = Buffer.isBuffer(req.body) ? req.body : null;
if (!imageBuffer?.length) {
return res.status(400).json({ error: 'AVIF image body is required' });
return res.status(400).json({ error: 'AVIF or WebP image body is required' });
}
try {