From b8845e9b775d1347848869b70fd75af6aee8177b Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Mon, 27 Jan 2025 23:30:09 +1100 Subject: [PATCH] Autodetect OFX version during import --- src/importers/ofx.ts | 31 +++++++++++++++++++++++++++++++ src/importers/ofx1.ts | 4 ++-- src/importers/ofx2.ts | 4 ++-- src/pages/ImportStatementView.vue | 16 ++++++---------- 4 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 src/importers/ofx.ts diff --git a/src/importers/ofx.ts b/src/importers/ofx.ts new file mode 100644 index 0000000..25bd778 --- /dev/null +++ b/src/importers/ofx.ts @@ -0,0 +1,31 @@ +/* + DrCr: Web-based double-entry bookkeeping framework + Copyright (C) 2022–2025 Lee Yingtong Li (RunasSudo) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +import importOfx1 from './ofx1.ts'; +import importOfx2 from './ofx2.ts'; +import { StatementLine } from '../db.ts'; + +export default function importOfxAutodetectVersion(sourceAccount: string, content: string): StatementLine[] { + if (content.startsWith('File type
@@ -86,12 +85,11 @@ import ComboBoxAccounts from '../components/ComboBoxAccounts.vue'; import { ppWithCommodity } from '../display.ts'; - import import_ofx1 from '../importers/ofx1.ts'; - import import_ofx2 from '../importers/ofx2.ts'; + import importOfxAutodetectVersion from '../importers/ofx.ts'; const fileInput = useTemplateRef('file'); - const format = ref('ofx2'); + const format = ref('ofx'); const selectedFilename = ref(''); const sourceAccount = ref(''); @@ -115,10 +113,8 @@ const content = await file.text(); - if (format.value === 'ofx2') { - statementLines.value = import_ofx2(sourceAccount.value, content); - } else if (format.value === 'ofx1') { - statementLines.value = import_ofx1(sourceAccount.value, content); + if (format.value === 'ofx') { + statementLines.value = importOfxAutodetectVersion(sourceAccount.value, content); } else { throw new Error('Unexpected import format'); }