Merge pull request #1699 from omnivore-app/fix/matter-importer-archive-dir
Use glob to find _matter_history file in archives
This commit is contained in:
@ -41,6 +41,7 @@
|
||||
"csv-parser": "^3.0.0",
|
||||
"dompurify": "^2.4.3",
|
||||
"fs-extra": "^11.1.0",
|
||||
"glob": "^8.1.0",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"linkedom": "^0.14.21",
|
||||
"nodemon": "^2.0.15",
|
||||
@ -48,4 +49,4 @@
|
||||
"urlsafe-base64": "^1.0.0",
|
||||
"uuid": "^9.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import unzip from 'unzip-stream'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import * as fsExtra from 'fs-extra'
|
||||
import glob from 'glob'
|
||||
|
||||
import { parseHTML } from 'linkedom'
|
||||
import { Readability } from '@omnivore/readability'
|
||||
@ -20,6 +21,8 @@ import { ImportContext } from '.'
|
||||
|
||||
export type UrlHandler = (url: URL) => Promise<void>
|
||||
|
||||
const HISTORY_FILE = '_matter_history.csv'
|
||||
|
||||
export const importMatterHistoryCsv = async (
|
||||
ctx: ImportContext,
|
||||
stream: Stream
|
||||
@ -132,7 +135,28 @@ const unarchive = async (stream: Stream): Promise<string> => {
|
||||
stream
|
||||
.pipe(unzip.Extract({ path: archiveDir }))
|
||||
.on('close', () => {
|
||||
resolve(archiveDir)
|
||||
glob(`${archiveDir}/**/_matter_history.csv`, function (err, files) {
|
||||
console.log('files: ', files)
|
||||
|
||||
if (err) {
|
||||
reject(err)
|
||||
return
|
||||
}
|
||||
|
||||
const first = files.find((f) => true)
|
||||
console.log('first: ', first)
|
||||
if (!first) {
|
||||
reject('No files found')
|
||||
return
|
||||
}
|
||||
|
||||
if (first.length < HISTORY_FILE.length) {
|
||||
reject('Invalid file: ' + first)
|
||||
return
|
||||
}
|
||||
|
||||
resolve(first.substring(0, first.length - HISTORY_FILE.length))
|
||||
})
|
||||
})
|
||||
.on('error', reject)
|
||||
})
|
||||
|
||||
11
yarn.lock
11
yarn.lock
@ -15347,6 +15347,17 @@ glob@^8.0.0:
|
||||
minimatch "^5.0.1"
|
||||
once "^1.3.0"
|
||||
|
||||
glob@^8.1.0:
|
||||
version "8.1.0"
|
||||
resolved "https://registry.yarnpkg.com/glob/-/glob-8.1.0.tgz#d388f656593ef708ee3e34640fdfb99a9fd1c33e"
|
||||
integrity sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==
|
||||
dependencies:
|
||||
fs.realpath "^1.0.0"
|
||||
inflight "^1.0.4"
|
||||
inherits "2"
|
||||
minimatch "^5.0.1"
|
||||
once "^1.3.0"
|
||||
|
||||
global-dirs@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-3.0.0.tgz#70a76fe84ea315ab37b1f5576cbde7d48ef72686"
|
||||
|
||||
Reference in New Issue
Block a user