Keep Studio business branding in verified client storage
This commit is contained in:
+11
-2
@@ -1,4 +1,5 @@
|
||||
const { fail, requireProductWrite } = require('./workspace.cjs');
|
||||
const { normalizeBrand } = require('./brand.cjs');
|
||||
|
||||
function sendJson(response, status, value) {
|
||||
if (response.destroyed || response.writableEnded) return;
|
||||
@@ -78,7 +79,7 @@ function createApiHandler({ resolveWorkspace, store, scrape, imageHandler, getCo
|
||||
try {
|
||||
const pathname = new URL(request.url, origin).pathname;
|
||||
const routes = {
|
||||
'/api/workspace': 'GET', '/api/catalog-image': 'GET',
|
||||
'/api/workspace': 'GET', '/api/brand': 'POST', '/api/catalog-image': 'GET',
|
||||
'/api/get-synced-stores': 'GET', '/api/sync-store': 'POST', '/api/delete-synced-store': 'POST'
|
||||
};
|
||||
if (!routes[pathname]) return sendJson(response, 404, { success: false, code: 'NOT_FOUND', error: 'API পাওয়া যায়নি।' });
|
||||
@@ -86,7 +87,10 @@ function createApiHandler({ resolveWorkspace, store, scrape, imageHandler, getCo
|
||||
if (request.method === 'POST') writeOrigin(request);
|
||||
const workspace = await resolveWorkspace(request);
|
||||
const publicWorkspace = { clientId: workspace.clientId, name: workspace.displayName, tenant: workspace.tenant, canWriteProducts: workspace.canWriteProducts };
|
||||
if (pathname === '/api/workspace') return sendJson(response, 200, { success: true, workspace: publicWorkspace });
|
||||
if (pathname === '/api/workspace') {
|
||||
publicWorkspace.brand = normalizeBrand(await store.readBrand(workspace) || {}, workspace.displayName);
|
||||
return sendJson(response, 200, { success: true, workspace: publicWorkspace });
|
||||
}
|
||||
if (pathname === '/api/catalog-image') {
|
||||
if (!imageHandler) throw fail(503, 'IMAGE_UNAVAILABLE', 'Product image এখন পাওয়া যাচ্ছে না।');
|
||||
return await imageHandler(request, response, workspace);
|
||||
@@ -98,6 +102,11 @@ function createApiHandler({ resolveWorkspace, store, scrape, imageHandler, getCo
|
||||
}
|
||||
requireProductWrite(workspace);
|
||||
const body = await readJson(request, maxBodyBytes);
|
||||
if (pathname === '/api/brand') {
|
||||
const brand = normalizeBrand(body, workspace.displayName);
|
||||
await store.saveBrand(workspace, brand);
|
||||
return sendJson(response, 200, { success: true, brand });
|
||||
}
|
||||
if (pathname === '/api/delete-synced-store') {
|
||||
if (typeof body.storeId === 'string' && body.storeId.startsWith('connected:')) throw fail(403, 'CONNECTED_CATALOG_READ_ONLY', 'Connected catalog মূল Client dashboard থেকে পরিচালনা করুন।');
|
||||
if (typeof body.storeId !== 'string' || !body.storeId || body.storeId.length > 160) throw fail(400, 'INVALID_STORE_ID', 'সঠিক store নির্বাচন করুন।');
|
||||
|
||||
Reference in New Issue
Block a user