From b9ef561058f77d215db7ba6c95b3d95e65844a0c Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 28 Sep 2016 22:26:06 -0600 Subject: [PATCH] Parse file meta values @ load (e.g. to number --- core/file_entry.js | 18 +++++++++++++++++- mods/file_area_list.js | 19 ++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/core/file_entry.js b/core/file_entry.js index fbb97c78..dadafb1d 100644 --- a/core/file_entry.js +++ b/core/file_entry.js @@ -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 diff --git a/mods/file_area_list.js b/mods/file_area_list.js index ea6b1507..010aa4b3 100644 --- a/mods/file_area_list.js +++ b/mods/file_area_list.js @@ -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;