Add local scrape database mode and schema
This commit is contained in:
+13
-8
@@ -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 || ""}`;
|
||||
|
||||
Reference in New Issue
Block a user