Add fb 'info' support to oputil

This commit is contained in:
Bryan Ashby 2017-02-18 19:00:09 -07:00
parent 058ff3f367
commit 6717cd5179
5 changed files with 180 additions and 7 deletions

View file

@ -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 || {};