mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-25 12:08:21 +02:00
fb move FILENAME_WC ... DST support: Allow moving entries via their filenames inc. wildcard support
This commit is contained in:
parent
1c92b349cd
commit
3a41a6b2e1
3 changed files with 106 additions and 42 deletions
|
@ -353,6 +353,41 @@ module.exports = class FileEntry {
|
|||
);
|
||||
}
|
||||
|
||||
static findByFileNameWildcard(wc, cb) {
|
||||
// convert any * -> % and ? -> _ for SQLite syntax - see https://www.sqlite.org/lang_expr.html
|
||||
wc = wc.replace(/\*/g, '%').replace(/\?/g, '_');
|
||||
|
||||
fileDb.all(
|
||||
`SELECT file_id
|
||||
FROM file
|
||||
WHERE file_name LIKE "${wc}"
|
||||
`,
|
||||
(err, fileIdRows) => {
|
||||
if(err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
if(!fileIdRows || 0 === fileIdRows.length) {
|
||||
return cb(Errors.DoesNotExist('No matches'));
|
||||
}
|
||||
|
||||
const entries = [];
|
||||
async.each(fileIdRows, (row, nextRow) => {
|
||||
const fileEntry = new FileEntry();
|
||||
fileEntry.load(row.file_id, err => {
|
||||
if(!err) {
|
||||
entries.push(fileEntry);
|
||||
}
|
||||
return nextRow(err);
|
||||
});
|
||||
},
|
||||
err => {
|
||||
return cb(err, entries);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
static findFiles(filter, cb) {
|
||||
filter = filter || {};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue