- number-поля теперь рендерятся как text + inputMode=numeric, чтобы браузер не округлял значения через input type=number - пробелы при вставке в number-поля удаляются - бэкенд нормализует значения number-полей в строку перед сохранением - добавлен хелпер normalizeFieldValueForStorage Closes: искажение расчётного счёта и других длинных числовых полей
37 lines
1004 B
TypeScript
37 lines
1004 B
TypeScript
import { readFileSync, existsSync, writeFileSync } from "fs";
|
|
import { resolve } from "path";
|
|
|
|
export interface FinanceSettings {
|
|
refreshIntervalSeconds: number;
|
|
}
|
|
|
|
const SETTINGS_PATH = resolve(process.cwd(), "data", "finance-settings.json");
|
|
|
|
export function getFinanceSettings(): FinanceSettings {
|
|
if (!existsSync(SETTINGS_PATH)) {
|
|
return { refreshIntervalSeconds: 60 };
|
|
}
|
|
try {
|
|
const raw = readFileSync(SETTINGS_PATH, "utf-8");
|
|
const parsed = JSON.parse(raw) as Partial<FinanceSettings>;
|
|
return {
|
|
refreshIntervalSeconds: Math.max(
|
|
5,
|
|
Math.min(3600, parsed.refreshIntervalSeconds ?? 60)
|
|
),
|
|
};
|
|
} catch {
|
|
return { refreshIntervalSeconds: 60 };
|
|
}
|
|
}
|
|
|
|
export function setFinanceSettings(settings: FinanceSettings): void {
|
|
const validated = {
|
|
refreshIntervalSeconds: Math.max(
|
|
5,
|
|
Math.min(3600, settings.refreshIntervalSeconds ?? 60)
|
|
),
|
|
};
|
|
writeFileSync(SETTINGS_PATH, JSON.stringify(validated, null, 2), "utf-8");
|
|
}
|