u
This commit is contained in:
@@ -15,6 +15,9 @@ export function photoFromUploadedImage(image) {
|
||||
return {
|
||||
sort: image.sort,
|
||||
fullHash: image.fullHash,
|
||||
fullW: image.full.w,
|
||||
fullH: image.full.h,
|
||||
fullSize: image.full.size,
|
||||
thumbW: image.thumb.w,
|
||||
thumbH: image.thumb.h,
|
||||
thumbHash: image.thumbHash,
|
||||
@@ -23,12 +26,36 @@ export function photoFromUploadedImage(image) {
|
||||
|
||||
export function articleWithUploadedPhoto(article, image) {
|
||||
const photo = photoFromUploadedImage(image);
|
||||
const photos = sortedPhotos(article).filter((row) => row.sort !== photo.sort);
|
||||
const photos = sortedPhotos(article).filter((row) => row.fullHash !== photo.fullHash);
|
||||
photos.push(photo);
|
||||
photos.sort((a, b) => a.sort - b.sort);
|
||||
return { ...article, photos };
|
||||
}
|
||||
|
||||
/** After DELETE /api/article/:sku/image/:fullHash */
|
||||
export function articleWithoutPhoto(article, fullHash) {
|
||||
const photos = sortedPhotos(article)
|
||||
.filter((row) => row.fullHash !== fullHash)
|
||||
.map((row, index) => ({ ...row, sort: index }));
|
||||
return { ...article, photos };
|
||||
}
|
||||
|
||||
/**
|
||||
* After PUT /api/article/:sku/images/order → { fullHashes }.
|
||||
* Reorders local photos[] to match; sort = index.
|
||||
*/
|
||||
export function articleWithPhotoOrder(article, fullHashes) {
|
||||
const byHash = new Map(sortedPhotos(article).map((row) => [row.fullHash, row]));
|
||||
const photos = fullHashes.map((fullHash, index) => {
|
||||
const row = byHash.get(fullHash);
|
||||
if (!row) {
|
||||
throw new Error(`photos order: unbekanntes fullHash ${fullHash}`);
|
||||
}
|
||||
return { ...row, sort: index };
|
||||
});
|
||||
return { ...article, photos };
|
||||
}
|
||||
|
||||
export function primaryPrice(article) {
|
||||
if (!Array.isArray(article?.prices) || article.prices.length === 0) return null;
|
||||
return article.prices.find((row) => row.minmultiplier === 1) ?? article.prices[0];
|
||||
@@ -47,3 +74,11 @@ export function articleEans(article) {
|
||||
if (!Array.isArray(article?.eans)) return [];
|
||||
return article.eans.filter(Boolean);
|
||||
}
|
||||
|
||||
export function formatPhotoSizeKb(fullSize) {
|
||||
return `${Math.round(fullSize / 1024)} KB`;
|
||||
}
|
||||
|
||||
export function formatPhotoDimensions(fullW, fullH) {
|
||||
return `${fullW}×${fullH}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user