UI overhaul: fire-gradient theme and visual polish; logic: added answer shuffling and improved Baserow error handling
This commit is contained in:
+18
-10
@@ -3,17 +3,24 @@ const { getEnvConfig } = require('./config');
|
||||
async function baserowFetch(endpoint, options = {}) {
|
||||
const { baserowUrl, baserowToken } = getEnvConfig();
|
||||
const url = `${baserowUrl}/api${endpoint}`;
|
||||
const res = await fetch(url, {
|
||||
...options,
|
||||
headers: {
|
||||
Authorization: `Token ${baserowToken}`,
|
||||
'Content-Type': 'application/json',
|
||||
...(options.headers || {}),
|
||||
},
|
||||
});
|
||||
console.log(`[baserow] ${options.method || 'GET'} ${url}`);
|
||||
|
||||
const headers = {
|
||||
Authorization: `Token ${baserowToken}`,
|
||||
...(options.headers || {}),
|
||||
};
|
||||
// Only set Content-Type for requests with body
|
||||
if (options.body) {
|
||||
headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
|
||||
const res = await fetch(url, { ...options, headers });
|
||||
|
||||
if (!res.ok) {
|
||||
const body = await res.text().catch(() => '');
|
||||
throw new Error(`Baserow ${res.status}: ${body.substring(0, 200)}`);
|
||||
const msg = `Baserow ${res.status} ${res.statusText}: ${body.substring(0, 300)}`;
|
||||
console.error(`[baserow] ERROR: ${msg}`);
|
||||
throw new Error(msg);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
@@ -27,6 +34,7 @@ async function listRows(tableId, filters = {}) {
|
||||
url += `&filter__${encodeURIComponent(field)}__equal=${encodeURIComponent(value)}`;
|
||||
}
|
||||
const data = await baserowFetch(url);
|
||||
console.log(`[baserow] Table ${tableId} page ${page}: ${(data.results || []).length} rows`);
|
||||
all = all.concat(data.results || []);
|
||||
if (!data.next) break;
|
||||
page++;
|
||||
@@ -36,7 +44,7 @@ async function listRows(tableId, filters = {}) {
|
||||
|
||||
async function batchCreateRows(tableId, rows) {
|
||||
if (!rows.length) return;
|
||||
// Baserow limit: 200 per batch
|
||||
console.log(`[baserow] Batch create ${rows.length} rows in table ${tableId}`);
|
||||
for (let i = 0; i < rows.length; i += 200) {
|
||||
const chunk = rows.slice(i, i + 200);
|
||||
await baserowFetch(`/database/rows/table/${tableId}/batch/?user_field_names=true`, {
|
||||
|
||||
Reference in New Issue
Block a user