fix: make sure to remove only failed PDF417 scans
This commit is contained in:
parent
393e149b91
commit
1451f78211
1 changed files with 14 additions and 2 deletions
|
|
@ -144,9 +144,21 @@ const readdirRec = rootPath =>
|
||||||
.then(_.flatten)
|
.then(_.flatten)
|
||||||
|
|
||||||
const stat = path => fs.stat(path).then(_.set('path', path))
|
const stat = path => fs.stat(path).then(_.set('path', path))
|
||||||
|
const pathComponents = p => path.normalize(p).split(path.sep)
|
||||||
|
|
||||||
// @see lib/customers.js:updateIdCardData()
|
// @see lib/customers.js:updateIdCardData()
|
||||||
const cleanOldFailedPDF417Scans = () => {
|
const cleanOldFailedPDF417Scans = () => {
|
||||||
|
const matcher = (c, pat) => typeof pat === 'function' ? pat(c) : c === pat
|
||||||
|
const PDF417ScanPathPattern = _.concat(
|
||||||
|
pathComponents(OPERATOR_DATA_DIR),
|
||||||
|
["id-operator", s => /* customerid*/ true, "idcarddata", fname => path.extname(fname) === 'jpg']
|
||||||
|
)
|
||||||
|
const isPDF417Scan = entry => {
|
||||||
|
entry = pathComponents(entry.path)
|
||||||
|
return entry.length === PDF417ScanPathPattern.length
|
||||||
|
&& _.isMatchWith(matcher, PDF417ScanPathPattern, pathComponents(entry.path))
|
||||||
|
}
|
||||||
|
|
||||||
let old = new Date()
|
let old = new Date()
|
||||||
old.setDate(old.getDate() - 2) // 2 days ago
|
old.setDate(old.getDate() - 2) // 2 days ago
|
||||||
old = old.getTime()
|
old = old.getTime()
|
||||||
|
|
@ -157,7 +169,7 @@ const cleanOldFailedPDF417Scans = () => {
|
||||||
readdirRec(path.join(OPERATOR_DATA_DIR, 'id-operator'))
|
readdirRec(path.join(OPERATOR_DATA_DIR, 'id-operator'))
|
||||||
.then(entries => Promise.all(
|
.then(entries => Promise.all(
|
||||||
entries
|
entries
|
||||||
.filter(entry => entry.isFile())
|
.filter(entry => entry.isFile() && isPDF417Scan(entry))
|
||||||
.map(entry => stat(entry.path))
|
.map(entry => stat(entry.path))
|
||||||
))
|
))
|
||||||
.then(filestats => Promise.all(
|
.then(filestats => Promise.all(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue