Name local database write permission explicitly
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
"database": {
|
||||
"driver": "endpoint",
|
||||
"mode": "local",
|
||||
"allowWrites": false,
|
||||
"allowLocalWrites": false,
|
||||
"host": "127.0.0.1",
|
||||
"port": 3306,
|
||||
"name": "9bplus",
|
||||
|
||||
+4
-1
@@ -30,7 +30,10 @@ export function loadConfig({ configPath = "config/local.json", dryRun } = {}) {
|
||||
database: {
|
||||
driver: String(env.DB_DRIVER || config.database?.driver || "endpoint").toLowerCase(),
|
||||
mode: String(env.DB_MODE || config.database?.mode || "local").toLowerCase(),
|
||||
allowWrites: parseBoolean(env.DB_ALLOW_WRITES, config.database?.allowWrites),
|
||||
allowLocalWrites: parseBoolean(
|
||||
env.DB_LOCAL_ALLOW_WRITES,
|
||||
config.database?.allowLocalWrites ?? config.database?.allowWrites,
|
||||
),
|
||||
host: env.DB_HOST || config.database?.host || "127.0.0.1",
|
||||
port: Number(env.DB_PORT || config.database?.port || 3306),
|
||||
name: env.DB_NAME || config.database?.name || "catalog_maker_test",
|
||||
|
||||
@@ -40,8 +40,8 @@ export async function executeMariaDbWrite(config, sql) {
|
||||
if (config.database.mode !== "local") {
|
||||
throw new Error("MariaDB writes are blocked outside Local DB mode.");
|
||||
}
|
||||
if (!config.database.allowWrites) {
|
||||
throw new Error("MariaDB writes are disabled. Enable local database writes in settings first.");
|
||||
if (!config.database.allowLocalWrites) {
|
||||
throw new Error("Local MariaDB writes are disabled. Enable local database writes in Settings first.");
|
||||
}
|
||||
|
||||
const connection = await getPool(config).getConnection();
|
||||
|
||||
+5
-3
@@ -197,7 +197,9 @@ function getStatus() {
|
||||
driver: config.database.driver,
|
||||
mode: config.database.mode,
|
||||
scrapeName: config.database.scrapeName,
|
||||
allowWrites: config.database.driver === "mariadb" && config.database.mode === "local" && config.database.allowWrites,
|
||||
allowLocalWrites: config.database.driver === "mariadb"
|
||||
&& config.database.mode === "local"
|
||||
&& config.database.allowLocalWrites,
|
||||
},
|
||||
workbook: path.basename(config.sourceWorkbook),
|
||||
workbookExists: true,
|
||||
@@ -230,8 +232,8 @@ function getRequestConfig(request) {
|
||||
database: {
|
||||
...config.database,
|
||||
mode: selectedMode,
|
||||
allowWrites: selectedMode === "local"
|
||||
&& config.database.allowWrites
|
||||
allowLocalWrites: selectedMode === "local"
|
||||
&& config.database.allowLocalWrites
|
||||
&& request.headers["x-local-write-access"] === "1",
|
||||
},
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
|
||||
export async function loadManufacturerCatalogState(config, { manufacturerId, position = 1 }) {
|
||||
const refreshResults = [];
|
||||
if (config.database?.mode === "local" && config.database.allowWrites) {
|
||||
if (config.database?.mode === "local" && config.database.allowLocalWrites) {
|
||||
for (const sql of prepareManufacturerCatalogSqls({ manufacturerId })) {
|
||||
refreshResults.push(
|
||||
await executeEndpointWrite(config, sql, {
|
||||
|
||||
Reference in New Issue
Block a user