mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-10 14:44:40 +02:00
Add fb 'info' support to oputil
This commit is contained in:
parent
058ff3f367
commit
6717cd5179
5 changed files with 180 additions and 7 deletions
|
@ -289,8 +289,37 @@ module.exports = class FileEntry {
|
|||
}
|
||||
}
|
||||
|
||||
// :TODO: Use static get accessor:
|
||||
static getWellKnownMetaValues() { return Object.keys(FILE_WELL_KNOWN_META); }
|
||||
|
||||
static findFileBySha(sha, cb) {
|
||||
// full or partial SHA-256
|
||||
fileDb.all(
|
||||
`SELECT file_id
|
||||
FROM file
|
||||
WHERE file_sha256 LIKE "${sha}%"
|
||||
LIMIT 2;`, // limit 2 such that we can find if there are dupes
|
||||
(err, fileIdRows) => {
|
||||
if(err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
if(!fileIdRows || 0 === fileIdRows.length) {
|
||||
return cb(Errors.DoesNotExist('No matches'));
|
||||
}
|
||||
|
||||
if(fileIdRows.length > 1) {
|
||||
return cb(Errors.Invalid('SHA is ambiguous'));
|
||||
}
|
||||
|
||||
const fileEntry = new FileEntry();
|
||||
return fileEntry.load(fileIdRows[0].file_id, err => {
|
||||
return cb(err, fileEntry);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
static findFiles(filter, cb) {
|
||||
filter = filter || {};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue