Parse file meta values @ load (e.g. to number

This commit is contained in:
Bryan Ashby 2016-09-28 22:26:06 -06:00
parent 5a0b291a02
commit b9ef561058
2 changed files with 25 additions and 12 deletions

View File

@ -13,6 +13,19 @@ const FILE_TABLE_MEMBERS = [
'desc', 'desc_long', 'upload_by_username', 'upload_timestamp'
];
const FILE_WELL_KNOWN_META = {
// name -> *read* converter, if any
upload_by_username : null,
upload_by_user_id : null,
file_md5 : null,
file_sha256 : null,
file_crc32 : null,
est_release_year : parseInt,
dl_count : parseInt,
byte_size : parseInt,
user_rating : parseInt,
};
module.exports = class FileEntry {
constructor(options) {
options = options || {};
@ -74,7 +87,8 @@ module.exports = class FileEntry {
[ this.fileId ],
(err, meta) => {
if(meta) {
this.meta[meta.meta_name] = meta.meta_value;
const conv = FILE_WELL_KNOWN_META[meta.meta_name];
this.meta[meta.meta_name] = conv ? conv(meta.meta_value) : meta.meta_value;
}
},
err => {
@ -104,6 +118,8 @@ module.exports = class FileEntry {
);
}
static getWellKnownMetaValues() { return Object.keys(FILE_WELL_KNOWN_META); }
static findFiles(criteria, cb) {
// :TODO: build search here - return [ fileid1, fileid2, ... ]
// free form

View File

@ -107,8 +107,7 @@ exports.getModule = class FileAreaList extends MenuModule {
}
theme.displayThemedAsset(
//config.art.browse,
'FBRWSE',
config.art.browse,
self.client,
{ font : self.menuConfig.font, trailingLF : false },
(err, artData) => {
@ -174,18 +173,16 @@ exports.getModule = class FileAreaList extends MenuModule {
hashTags : Array.from(currEntry.hashTags).join(hashTagsSep),
};
const META_NUMBERS = [ 'byte_size', 'dl_count' ];
_.forEach(self.currentFileEntry.meta, (value, name) => {
if(META_NUMBERS.indexOf(name) > -1) {
value = parseInt(value);
}
//
// We need the entry object to contain meta keys even if they are empty as
// consumers may very likely attempt to use them
//
const metaValues = FileEntry.getWellKnownMetaValues();
metaValues.forEach(name => {
const value = currEntry.meta[name] || '';
entryInfo[_.camelCase(name)] = value;
});
// entryInfo.fileSize = 1241234; // :TODO: REMOVE ME!
// 10+ are custom textviews
let textView;
let customMciId = 10;