diff --git a/scripts/test-sqlite-storage.js b/scripts/test-sqlite-storage.js index 76a5ee7..408f581 100644 --- a/scripts/test-sqlite-storage.js +++ b/scripts/test-sqlite-storage.js @@ -215,18 +215,18 @@ async function runTests() { const picResult = await store.article.addImage(googleAuthId, article.sku, sampleImage); const fullHash = picResult.fullHash; - assert.equal(picResult.smallThumb.w, 40); - assert.equal(picResult.smallThumb.h, 27); + assert.equal(picResult.smallThumb.w, 32); + assert.equal(picResult.smallThumb.h, 21); const smallThumbRow = provider.db.prepare( 'SELECT smallthumbw, smallthumbh, smallthumbbinary FROM pic WHERE hash = ?', ).get(fullHash); - assert.equal(smallThumbRow.smallthumbw, 40); - assert.equal(smallThumbRow.smallthumbh, 27); + assert.equal(smallThumbRow.smallthumbw, 32); + assert.equal(smallThumbRow.smallthumbh, 21); assert(Buffer.isBuffer(smallThumbRow.smallthumbbinary), 'Small thumb AVIF must be stored in the pic row'); const smallThumbMetadata = await sharp(smallThumbRow.smallthumbbinary).metadata(); assert.equal(smallThumbMetadata.format, 'heif'); - assert.equal(smallThumbMetadata.width, 40); - assert.equal(smallThumbMetadata.height, 27); + assert.equal(smallThumbMetadata.width, 32); + assert.equal(smallThumbMetadata.height, 21); const brand = await store.brand.create(googleAuthId, { name: 'Small Thumb Test Brand' }); 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.equal(listedBrandWithSmallThumbs.pics.length, 1); const listedPic = listedBrandWithSmallThumbs.pics[0]; - assert.equal(listedPic.smallThumbW, 40); - assert.equal(listedPic.smallThumbH, 27); + assert.equal(listedPic.smallThumbW, 32); + assert.equal(listedPic.smallThumbH, 21); assert.equal(typeof listedPic.smallThumbBinary, 'string'); const listedSmallThumb = Buffer.from(listedPic.smallThumbBinary, 'base64'); assert.deepEqual(listedSmallThumb, smallThumbRow.smallthumbbinary); diff --git a/src/store/article/addImage.js b/src/store/article/addImage.js index 3d298c5..067f068 100644 --- a/src/store/article/addImage.js +++ b/src/store/article/addImage.js @@ -35,14 +35,14 @@ export default function addImage(provider) { * // => { picId, sort, full: { w, h, size }, thumb: { w, h }, smallThumb: { w, h }, fullHash, thumbHash } */ return async (googleAuthId, sku, image, tx) => { + const processed = await processAvifImage(image); + const fullHash = newFullHash(processed.full.buffer); + const runAdd = async (runner) => { const { articleId } = await resolve(googleAuthId, sku, runner); - const processed = await processAvifImage(image); - const sortResult = await runner.query(getSortSql, { articleId }); const sort = sortResult.rows[0].sort; - const fullHash = newFullHash(processed.full.buffer); let picId; const existingPic = await runner.query( diff --git a/src/store/attributevalue/addImage.js b/src/store/attributevalue/addImage.js index 21edf80..3e01ecc 100644 --- a/src/store/attributevalue/addImage.js +++ b/src/store/attributevalue/addImage.js @@ -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}>} */ return async (googleAuthId, attributeValueId, image, tx) => { + const processed = await processAvifImage(image); + const fullHash = newFullHash(processed.full.buffer); + const runAdd = async (runner) => { await access(googleAuthId, attributeValueId, runner); - const processed = await processAvifImage(image); - // Clean existing attributevaluepic so the attribute value has 1 primary image await runner.query(deleteAvPicSql, { attributeValueId }); const sort = 0; - const fullHash = newFullHash(processed.full.buffer); let picId; const existingPic = await runner.query( diff --git a/src/store/brand/addImage.js b/src/store/brand/addImage.js index ae580fc..bea472f 100644 --- a/src/store/brand/addImage.js +++ b/src/store/brand/addImage.js @@ -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}>} */ return async (googleAuthId, brandId, image, tx) => { + const processed = await processAvifImage(image); + const fullHash = newFullHash(processed.full.buffer); + const runAdd = async (runner) => { await access(googleAuthId, brandId, runner); - const processed = await processAvifImage(image); - // Clean existing brandpic so the brand has 1 primary logo await runner.query(deleteBrandPicSql, { brandId }); const sort = 0; - const fullHash = newFullHash(processed.full.buffer); let picId; const existingPic = await runner.query( diff --git a/src/store/category/addImage.js b/src/store/category/addImage.js index 89e6d29..a937b02 100644 --- a/src/store/category/addImage.js +++ b/src/store/category/addImage.js @@ -35,14 +35,14 @@ export default function addImage(provider) { * // => { id, fullHash, thumbW, thumbH, thumbHash } */ return async (googleAuthId, categoryId, image, tx) => { + const processed = await processAvifImage(image); + const fullHash = newFullHash(processed.full.buffer); + const runAdd = async (runner) => { await access(googleAuthId, categoryId, runner); - const processed = await processAvifImage(image); - const sortResult = await runner.query(getSortSql, { categoryId }); const sort = sortResult.rows[0].sort; - const fullHash = newFullHash(processed.full.buffer); let picId; const existingPic = await runner.query(