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