Add local scrape database mode and schema

This commit is contained in:
2026-08-05 16:18:50 +02:00
parent 1076c3c040
commit 38dfb9fd54
12 changed files with 193 additions and 25 deletions
+13 -8
View File
@@ -59,7 +59,10 @@ window.fetch = (input, init = {}) => {
if (!url.startsWith("/api/"))
return nativeFetch(input, init);
const headers = new Headers(init.headers || (typeof input !== "string" ? input.headers : undefined));
headers.set("X-Database-Mode", localStorage.getItem("catalog-maker:database-mode") || "local");
const selectedMode = localStorage.getItem("catalog-maker:database-mode") || "local";
// Scrape storage is separate; existing catalog endpoints continue reading Local 9bplus.
headers.set("X-Database-Mode", selectedMode === "live" ? "live" : "local");
headers.set("X-Scrape-Database", selectedMode === "scrape" ? "1" : "0");
return nativeFetch(input, { ...init, headers });
};
let currentPosition = 1;
@@ -940,7 +943,7 @@ function loadDatabaseMode() {
refreshDatabaseStatusLabel();
}
function saveDatabaseMode(event) {
const mode = event.target.value === "live" ? "live" : "local";
const mode = ["local", "live", "scrape"].includes(event.target.value) ? event.target.value : "local";
localStorage.setItem("catalog-maker:database-mode", mode);
syncDatabasePermissions(mode);
syncLocalDbFields(mode);
@@ -987,10 +990,10 @@ function syncLocalDbFields(mode) {
localDbFields.hidden = mode !== "local";
}
function syncDatabasePermissions(mode) {
const isLive = mode === "live";
const isReadOnly = mode === "live" || mode === "scrape";
for (const input of permissionInputs) {
input.disabled = isLive;
if (isLive)
input.disabled = isReadOnly;
if (isReadOnly)
input.checked = false;
}
}
@@ -1008,7 +1011,7 @@ function refreshDatabaseStatusLabel() {
const transactionMode = localStorage.getItem("catalog-maker:transaction-mode") || "transaction";
const permissions = JSON.parse(localStorage.getItem("catalog-maker:db-permissions") || "{}");
const writesEnabled = mode === "local" && (permissions.allowInsertToggle || permissions.allowUpdateToggle || permissions.allowDeleteToggle);
const dbLabel = mode === "live" ? "Live DB" : "Local DB";
const dbLabel = mode === "live" ? "Live 9bplus DB" : mode === "scrape" ? "Local scrape DB" : "Local 9bplus DB";
const configuredDriver = databaseStatus.dataset.driver;
const connectionError = (mode === "local" && configuredDriver !== "mariadb")
|| (mode === "live" && configuredDriver !== "endpoint");
@@ -1022,8 +1025,10 @@ function refreshDatabaseStatusLabel() {
}
function renderDatabaseModeNote(mode) {
databaseModeNote.textContent = mode === "live"
? "Live DB selected for preparation. The current project still stays read-only."
: "Local test database selected.";
? "Live 9bplus DB selected for read-only data."
: mode === "scrape"
? "Local scrape DB selected for scraper settings and scraped data. Catalog reads stay on Local 9bplus DB."
: "Local 9bplus DB selected.";
}
function renderProduct(product) {
const productKey = `${manufacturerSelect.value}:${product.idProductCatalog || product.supplierReference || product.name || ""}`;
+13 -8
View File
@@ -60,7 +60,10 @@ window.fetch = (input, init = {}) => {
if (!url.startsWith("/api/")) return nativeFetch(input, init);
const headers = new Headers(init.headers || (typeof input !== "string" ? input.headers : undefined));
headers.set("X-Database-Mode", localStorage.getItem("catalog-maker:database-mode") || "local");
const selectedMode = localStorage.getItem("catalog-maker:database-mode") || "local";
// Scrape storage is separate; existing catalog endpoints continue reading Local 9bplus.
headers.set("X-Database-Mode", selectedMode === "live" ? "live" : "local");
headers.set("X-Scrape-Database", selectedMode === "scrape" ? "1" : "0");
return nativeFetch(input, { ...init, headers });
};
@@ -1034,7 +1037,7 @@ function loadDatabaseMode() {
}
function saveDatabaseMode(event) {
const mode = event.target.value === "live" ? "live" : "local";
const mode = ["local", "live", "scrape"].includes(event.target.value) ? event.target.value : "local";
localStorage.setItem("catalog-maker:database-mode", mode);
syncDatabasePermissions(mode);
syncLocalDbFields(mode);
@@ -1082,10 +1085,10 @@ function syncLocalDbFields(mode) {
}
function syncDatabasePermissions(mode) {
const isLive = mode === "live";
const isReadOnly = mode === "live" || mode === "scrape";
for (const input of permissionInputs) {
input.disabled = isLive;
if (isLive) input.checked = false;
input.disabled = isReadOnly;
if (isReadOnly) input.checked = false;
}
}
@@ -1105,7 +1108,7 @@ function refreshDatabaseStatusLabel() {
const writesEnabled = mode === "local" && (
permissions.allowInsertToggle || permissions.allowUpdateToggle || permissions.allowDeleteToggle
);
const dbLabel = mode === "live" ? "Live DB" : "Local DB";
const dbLabel = mode === "live" ? "Live 9bplus DB" : mode === "scrape" ? "Local scrape DB" : "Local 9bplus DB";
const configuredDriver = databaseStatus.dataset.driver;
const connectionError = (mode === "local" && configuredDriver !== "mariadb")
|| (mode === "live" && configuredDriver !== "endpoint");
@@ -1120,8 +1123,10 @@ function refreshDatabaseStatusLabel() {
function renderDatabaseModeNote(mode) {
databaseModeNote.textContent = mode === "live"
? "Live DB selected for preparation. The current project still stays read-only."
: "Local test database selected.";
? "Live 9bplus DB selected for read-only data."
: mode === "scrape"
? "Local scrape DB selected for scraper settings and scraped data. Catalog reads stay on Local 9bplus DB."
: "Local 9bplus DB selected.";
}
function renderProduct(product) {
+7 -3
View File
@@ -151,11 +151,15 @@
<legend>Database</legend>
<label class="settings-option">
<input type="radio" name="databaseMode" value="local" checked />
<span>Local DB</span>
<span>Local 9bplus DB</span>
</label>
<label class="settings-option">
<input type="radio" name="databaseMode" value="live" />
<span>Live DB</span>
<span>Live 9bplus DB</span>
</label>
<label class="settings-option">
<input type="radio" name="databaseMode" value="scrape" />
<span>Local scrape DB</span>
</label>
<div class="local-db-fields" id="localDbFields">
<label class="settings-field">
@@ -181,7 +185,7 @@
<button class="settings-test-button" id="testLocalDbButton" type="button">Test connection</button>
<p class="settings-note" id="localDbTestResult">Connection not tested.</p>
</div>
<p class="settings-note" id="databaseModeNote">Local test database selected.</p>
<p class="settings-note" id="databaseModeNote">Local 9bplus database selected.</p>
</fieldset>
<fieldset class="settings-group">