This commit is contained in:
seb
2026-10-18 03:57:53 +02:00
parent c687553eea
commit 97c909d10b
5 changed files with 20 additions and 20 deletions

View File

@@ -215,18 +215,18 @@ async function runTests() {
const picResult = await store.article.addImage(googleAuthId, article.sku, sampleImage); const picResult = await store.article.addImage(googleAuthId, article.sku, sampleImage);
const fullHash = picResult.fullHash; const fullHash = picResult.fullHash;
assert.equal(picResult.smallThumb.w, 40); assert.equal(picResult.smallThumb.w, 32);
assert.equal(picResult.smallThumb.h, 27); assert.equal(picResult.smallThumb.h, 21);
const smallThumbRow = provider.db.prepare( const smallThumbRow = provider.db.prepare(
'SELECT smallthumbw, smallthumbh, smallthumbbinary FROM pic WHERE hash = ?', 'SELECT smallthumbw, smallthumbh, smallthumbbinary FROM pic WHERE hash = ?',
).get(fullHash); ).get(fullHash);
assert.equal(smallThumbRow.smallthumbw, 40); assert.equal(smallThumbRow.smallthumbw, 32);
assert.equal(smallThumbRow.smallthumbh, 27); assert.equal(smallThumbRow.smallthumbh, 21);
assert(Buffer.isBuffer(smallThumbRow.smallthumbbinary), 'Small thumb AVIF must be stored in the pic row'); assert(Buffer.isBuffer(smallThumbRow.smallthumbbinary), 'Small thumb AVIF must be stored in the pic row');
const smallThumbMetadata = await sharp(smallThumbRow.smallthumbbinary).metadata(); const smallThumbMetadata = await sharp(smallThumbRow.smallthumbbinary).metadata();
assert.equal(smallThumbMetadata.format, 'heif'); assert.equal(smallThumbMetadata.format, 'heif');
assert.equal(smallThumbMetadata.width, 40); assert.equal(smallThumbMetadata.width, 32);
assert.equal(smallThumbMetadata.height, 27); assert.equal(smallThumbMetadata.height, 21);
const brand = await store.brand.create(googleAuthId, { name: 'Small Thumb Test Brand' }); const brand = await store.brand.create(googleAuthId, { name: 'Small Thumb Test Brand' });
await store.brand.addImage(googleAuthId, brand.id, sampleImage); await store.brand.addImage(googleAuthId, brand.id, sampleImage);
@@ -245,8 +245,8 @@ async function runTests() {
assert(listedBrandWithSmallThumbs, 'Brand list with thumbnails should include the created brand'); assert(listedBrandWithSmallThumbs, 'Brand list with thumbnails should include the created brand');
assert.equal(listedBrandWithSmallThumbs.pics.length, 1); assert.equal(listedBrandWithSmallThumbs.pics.length, 1);
const listedPic = listedBrandWithSmallThumbs.pics[0]; const listedPic = listedBrandWithSmallThumbs.pics[0];
assert.equal(listedPic.smallThumbW, 40); assert.equal(listedPic.smallThumbW, 32);
assert.equal(listedPic.smallThumbH, 27); assert.equal(listedPic.smallThumbH, 21);
assert.equal(typeof listedPic.smallThumbBinary, 'string'); assert.equal(typeof listedPic.smallThumbBinary, 'string');
const listedSmallThumb = Buffer.from(listedPic.smallThumbBinary, 'base64'); const listedSmallThumb = Buffer.from(listedPic.smallThumbBinary, 'base64');
assert.deepEqual(listedSmallThumb, smallThumbRow.smallthumbbinary); assert.deepEqual(listedSmallThumb, smallThumbRow.smallthumbbinary);

View File

@@ -35,14 +35,14 @@ export default function addImage(provider) {
* // => { picId, sort, full: { w, h, size }, thumb: { w, h }, smallThumb: { w, h }, fullHash, thumbHash } * // => { picId, sort, full: { w, h, size }, thumb: { w, h }, smallThumb: { w, h }, fullHash, thumbHash }
*/ */
return async (googleAuthId, sku, image, tx) => { return async (googleAuthId, sku, image, tx) => {
const processed = await processAvifImage(image);
const fullHash = newFullHash(processed.full.buffer);
const runAdd = async (runner) => { const runAdd = async (runner) => {
const { articleId } = await resolve(googleAuthId, sku, runner); const { articleId } = await resolve(googleAuthId, sku, runner);
const processed = await processAvifImage(image);
const sortResult = await runner.query(getSortSql, { articleId }); const sortResult = await runner.query(getSortSql, { articleId });
const sort = sortResult.rows[0].sort; const sort = sortResult.rows[0].sort;
const fullHash = newFullHash(processed.full.buffer);
let picId; let picId;
const existingPic = await runner.query( const existingPic = await runner.query(

View File

@@ -31,16 +31,16 @@ export default function addImage(provider) {
* @returns {Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number, pics: Array<object>}>} * @returns {Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number, pics: Array<object>}>}
*/ */
return async (googleAuthId, attributeValueId, image, tx) => { return async (googleAuthId, attributeValueId, image, tx) => {
const processed = await processAvifImage(image);
const fullHash = newFullHash(processed.full.buffer);
const runAdd = async (runner) => { const runAdd = async (runner) => {
await access(googleAuthId, attributeValueId, runner); await access(googleAuthId, attributeValueId, runner);
const processed = await processAvifImage(image);
// Clean existing attributevaluepic so the attribute value has 1 primary image // Clean existing attributevaluepic so the attribute value has 1 primary image
await runner.query(deleteAvPicSql, { attributeValueId }); await runner.query(deleteAvPicSql, { attributeValueId });
const sort = 0; const sort = 0;
const fullHash = newFullHash(processed.full.buffer);
let picId; let picId;
const existingPic = await runner.query( const existingPic = await runner.query(

View File

@@ -31,16 +31,16 @@ export default function addImage(provider) {
* @returns {Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number, pics: Array<object>}>} * @returns {Promise<{id: number, fullHash: string, thumbW: number, thumbH: number, thumbHash: string, smallThumbW: number, smallThumbH: number, pics: Array<object>}>}
*/ */
return async (googleAuthId, brandId, image, tx) => { return async (googleAuthId, brandId, image, tx) => {
const processed = await processAvifImage(image);
const fullHash = newFullHash(processed.full.buffer);
const runAdd = async (runner) => { const runAdd = async (runner) => {
await access(googleAuthId, brandId, runner); await access(googleAuthId, brandId, runner);
const processed = await processAvifImage(image);
// Clean existing brandpic so the brand has 1 primary logo // Clean existing brandpic so the brand has 1 primary logo
await runner.query(deleteBrandPicSql, { brandId }); await runner.query(deleteBrandPicSql, { brandId });
const sort = 0; const sort = 0;
const fullHash = newFullHash(processed.full.buffer);
let picId; let picId;
const existingPic = await runner.query( const existingPic = await runner.query(

View File

@@ -35,14 +35,14 @@ export default function addImage(provider) {
* // => { id, fullHash, thumbW, thumbH, thumbHash } * // => { id, fullHash, thumbW, thumbH, thumbHash }
*/ */
return async (googleAuthId, categoryId, image, tx) => { return async (googleAuthId, categoryId, image, tx) => {
const processed = await processAvifImage(image);
const fullHash = newFullHash(processed.full.buffer);
const runAdd = async (runner) => { const runAdd = async (runner) => {
await access(googleAuthId, categoryId, runner); await access(googleAuthId, categoryId, runner);
const processed = await processAvifImage(image);
const sortResult = await runner.query(getSortSql, { categoryId }); const sortResult = await runner.query(getSortSql, { categoryId });
const sort = sortResult.rows[0].sort; const sort = sortResult.rows[0].sort;
const fullHash = newFullHash(processed.full.buffer);
let picId; let picId;
const existingPic = await runner.query( const existingPic = await runner.query(