Read existing Client catalogs through verified workspace context

This commit is contained in:
khondokartowsif171
2026-10-19 01:34:52 +06:00
parent 6db99f96df
commit 165320cc9f
10 changed files with 189 additions and 17 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ function rasterType(body) {
return null;
}
function createImageHandler({ store, fetchPublic, maxConcurrent = 4 }) {
function createImageHandler({ store, fetchPublic, getConnected, maxConcurrent = 4 }) {
if (!Number.isInteger(maxConcurrent) || maxConcurrent < 1) throw new Error('Invalid image concurrency');
let running = 0;
return async function image(request, response, workspace) {
@@ -20,7 +20,7 @@ function createImageHandler({ store, fetchPublic, maxConcurrent = 4 }) {
if (!storeId || storeId.length > 160 || !productId || productId.length > 8192 || params.has('url')) {
throw fail(400, 'INVALID_IMAGE_REFERENCE', 'Catalog-এর product image নির্বাচন করুন।');
}
const records = await store.read(workspace);
const records = storeId.startsWith('connected:') && getConnected ? [await getConnected(workspace)] : await store.read(workspace);
const product = records.find(item => item.id === storeId)?.products?.find(item => String(item.id) === productId);
if (!product || typeof product.image !== 'string' || !product.image) throw fail(404, 'IMAGE_NOT_FOUND', 'Product image পাওয়া যায়নি।');
if (running >= maxConcurrent) throw fail(503, 'IMAGE_BUSY', 'Image অল্প পরে আবার খুলুন।');