Parse file meta values @ load (e.g. to number
This commit is contained in:
parent
5a0b291a02
commit
b9ef561058
|
@ -13,6 +13,19 @@ const FILE_TABLE_MEMBERS = [
|
||||||
'desc', 'desc_long', 'upload_by_username', 'upload_timestamp'
|
'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 {
|
module.exports = class FileEntry {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
@ -74,7 +87,8 @@ module.exports = class FileEntry {
|
||||||
[ this.fileId ],
|
[ this.fileId ],
|
||||||
(err, meta) => {
|
(err, meta) => {
|
||||||
if(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 => {
|
err => {
|
||||||
|
@ -104,6 +118,8 @@ module.exports = class FileEntry {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getWellKnownMetaValues() { return Object.keys(FILE_WELL_KNOWN_META); }
|
||||||
|
|
||||||
static findFiles(criteria, cb) {
|
static findFiles(criteria, cb) {
|
||||||
// :TODO: build search here - return [ fileid1, fileid2, ... ]
|
// :TODO: build search here - return [ fileid1, fileid2, ... ]
|
||||||
// free form
|
// free form
|
||||||
|
|
|
@ -107,8 +107,7 @@ exports.getModule = class FileAreaList extends MenuModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
theme.displayThemedAsset(
|
theme.displayThemedAsset(
|
||||||
//config.art.browse,
|
config.art.browse,
|
||||||
'FBRWSE',
|
|
||||||
self.client,
|
self.client,
|
||||||
{ font : self.menuConfig.font, trailingLF : false },
|
{ font : self.menuConfig.font, trailingLF : false },
|
||||||
(err, artData) => {
|
(err, artData) => {
|
||||||
|
@ -174,18 +173,16 @@ exports.getModule = class FileAreaList extends MenuModule {
|
||||||
hashTags : Array.from(currEntry.hashTags).join(hashTagsSep),
|
hashTags : Array.from(currEntry.hashTags).join(hashTagsSep),
|
||||||
};
|
};
|
||||||
|
|
||||||
const META_NUMBERS = [ 'byte_size', 'dl_count' ];
|
//
|
||||||
_.forEach(self.currentFileEntry.meta, (value, name) => {
|
// We need the entry object to contain meta keys even if they are empty as
|
||||||
if(META_NUMBERS.indexOf(name) > -1) {
|
// consumers may very likely attempt to use them
|
||||||
value = parseInt(value);
|
//
|
||||||
}
|
const metaValues = FileEntry.getWellKnownMetaValues();
|
||||||
|
metaValues.forEach(name => {
|
||||||
|
const value = currEntry.meta[name] || '';
|
||||||
entryInfo[_.camelCase(name)] = value;
|
entryInfo[_.camelCase(name)] = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// entryInfo.fileSize = 1241234; // :TODO: REMOVE ME!
|
|
||||||
|
|
||||||
// 10+ are custom textviews
|
// 10+ are custom textviews
|
||||||
let textView;
|
let textView;
|
||||||
let customMciId = 10;
|
let customMciId = 10;
|
||||||
|
|
Loading…
Reference in New Issue