mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-08-05 17:28:06 +02:00
* Lots of improvements (WIP) to file browsing
This commit is contained in:
parent
67e2ff987f
commit
806e6539f4
7 changed files with 412 additions and 98 deletions
|
@ -266,7 +266,7 @@ module.exports = class ArchiveUtil {
|
|||
while((m = entryMatchRe.exec(output))) {
|
||||
// :TODO: allow alternate ordering!!!
|
||||
entries.push({
|
||||
size : m[1],
|
||||
byteSize : parseInt(m[1]),
|
||||
fileName : m[2],
|
||||
});
|
||||
}
|
||||
|
|
|
@ -239,24 +239,28 @@ function getDefaultConfig() {
|
|||
offset : 0,
|
||||
exts : [ 'zip' ],
|
||||
handler : '7Zip',
|
||||
desc : 'ZIP Archive',
|
||||
},
|
||||
'7z' : {
|
||||
sig : '377abcaf271c',
|
||||
offset : 0,
|
||||
exts : [ '7z' ],
|
||||
handler : '7Zip',
|
||||
desc : '7-Zip Archive',
|
||||
},
|
||||
arj : {
|
||||
sig : '60ea',
|
||||
offset : 0,
|
||||
exts : [ 'arj' ],
|
||||
handler : '7Zip',
|
||||
desc : 'ARJ Archive',
|
||||
},
|
||||
rar : {
|
||||
sig : '526172211a0700',
|
||||
offset : 0,
|
||||
exts : [ 'rar' ],
|
||||
handler : '7Zip',
|
||||
desc : 'RAR Archive',
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -339,7 +343,11 @@ function getDefaultConfig() {
|
|||
areaStoragePrefix : paths.join(__dirname, './../file_base/'),
|
||||
|
||||
fileNamePatterns: {
|
||||
shortDesc : [ '^FILE_ID\.DIZ$', '^DESC\.SDI$' ],
|
||||
// These are NOT case sensitive
|
||||
shortDesc : [
|
||||
'^FILE_ID\.DIZ$', '^DESC\.SDI$', '^DESCRIPT\.ION$', '^FILE\.DES$', '$FILE\.SDI$', '^DISK\.ID$'
|
||||
],
|
||||
|
||||
longDesc : [ '^.*\.NFO$', '^README\.1ST$', '^README\.TXT$' ],
|
||||
},
|
||||
|
||||
|
@ -349,7 +357,7 @@ function getDefaultConfig() {
|
|||
// The year may be YY or YYYY
|
||||
//
|
||||
'[0-3]?[0-9][\\-\\/\\.][0-3]?[0-9][\\-\\/\\.]((?:[0-9]{2})?[0-9]{2})', // m/d/yyyy, mm-dd-yyyy, etc.
|
||||
"\\B('[1789][0-9])\\b",
|
||||
"\\B('[1789][0-9])\\b", // eslint-disable-line quotes
|
||||
// :TODO: DD/MMM/YY, DD/MMMM/YY, DD/MMM/YYYY, etc.
|
||||
],
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ const iconv = require('iconv-lite');
|
|||
|
||||
exports.getAvailableFileAreas = getAvailableFileAreas;
|
||||
exports.getSortedAvailableFileAreas = getSortedAvailableFileAreas;
|
||||
exports.getDefaultFileArea = getDefaultFileArea;
|
||||
exports.getDefaultFileAreaTag = getDefaultFileAreaTag;
|
||||
exports.getFileAreaByTag = getFileAreaByTag;
|
||||
exports.changeFileAreaWithOptions = changeFileAreaWithOptions;
|
||||
//exports.addOrUpdateFileEntry = addOrUpdateFileEntry;
|
||||
|
@ -45,18 +45,20 @@ function getAvailableFileAreas(client, options) {
|
|||
}
|
||||
|
||||
function getSortedAvailableFileAreas(client, options) {
|
||||
const areas = _.map(getAvailableFileAreas(client, options), (v, k) => {
|
||||
return {
|
||||
const areas = _.map(getAvailableFileAreas(client, options), (v, k) => {
|
||||
const areaInfo = {
|
||||
areaTag : k,
|
||||
area : v
|
||||
};
|
||||
|
||||
return areaInfo;
|
||||
});
|
||||
|
||||
sortAreasOrConfs(areas, 'area');
|
||||
return areas;
|
||||
}
|
||||
|
||||
function getDefaultFileArea(client, disableAcsCheck) {
|
||||
function getDefaultFileAreaTag(client, disableAcsCheck) {
|
||||
let defaultArea = _.findKey(Config.fileAreas, o => o.default);
|
||||
if(defaultArea) {
|
||||
const area = Config.fileAreas.areas[defaultArea];
|
||||
|
@ -76,7 +78,8 @@ function getDefaultFileArea(client, disableAcsCheck) {
|
|||
function getFileAreaByTag(areaTag) {
|
||||
const areaInfo = Config.fileAreas.areas[areaTag];
|
||||
if(areaInfo) {
|
||||
areaInfo.areaTag = areaTag; // convienence!
|
||||
areaInfo.areaTag = areaTag; // convienence!
|
||||
areaInfo.storageDirectory = getAreaStorageDirectory(areaInfo);
|
||||
return areaInfo;
|
||||
}
|
||||
}
|
||||
|
@ -177,7 +180,20 @@ function attemptSetEstimatedReleaseDate(fileEntry) {
|
|||
//
|
||||
const match = getMatch(fileEntry.desc) || getMatch(fileEntry.descLong);
|
||||
if(match && match[1]) {
|
||||
const year = (2 === match[1].length) ? parseInt('19' + match[1]) : parseInt(match[1]);
|
||||
let year;
|
||||
if(2 === match[1].length) {
|
||||
year = parseInt(match[1]);
|
||||
if(year) {
|
||||
if(year > 70) {
|
||||
year += 1900;
|
||||
} else {
|
||||
year += 2000;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
year = parseInt(match[1]);
|
||||
}
|
||||
|
||||
if(year) {
|
||||
fileEntry.meta.est_release_year = year;
|
||||
}
|
||||
|
@ -290,14 +306,18 @@ function addNewFileEntry(fileEntry, filePath, cb) {
|
|||
function populateInfo(callback) {
|
||||
archiveUtil.detectType(filePath, (err, archiveType) => {
|
||||
if(archiveType) {
|
||||
// save this off
|
||||
fileEntry.meta.archive_type = archiveType;
|
||||
|
||||
populateFileEntryWithArchive(fileEntry, filePath, archiveType, err => {
|
||||
if(err) {
|
||||
populateFileEntry(fileEntry, filePath, err => {
|
||||
// :TODO: log err
|
||||
return callback(null); // ignore err
|
||||
});
|
||||
} else {
|
||||
return callback(null);
|
||||
}
|
||||
return callback(null);
|
||||
});
|
||||
} else {
|
||||
populateFileEntry(fileEntry, filePath, err => {
|
||||
|
@ -310,7 +330,10 @@ function addNewFileEntry(fileEntry, filePath, cb) {
|
|||
function addNewDbRecord(callback) {
|
||||
return fileEntry.persist(callback);
|
||||
}
|
||||
]
|
||||
],
|
||||
err => {
|
||||
return cb(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -371,7 +394,7 @@ function addOrUpdateFileEntry(areaInfo, fileName, options, cb) {
|
|||
return callback(err, existingEntries);
|
||||
});
|
||||
},
|
||||
function addOrUpdate(callback, existingEntries) {
|
||||
function addOrUpdate(existingEntries, callback) {
|
||||
if(existingEntries.length > 0) {
|
||||
|
||||
} else {
|
||||
|
@ -396,7 +419,7 @@ function scanFileAreaForChanges(areaInfo, cb) {
|
|||
return callback(err);
|
||||
}
|
||||
|
||||
async.each(files, (fileName, next) => {
|
||||
async.eachSeries(files, (fileName, next) => {
|
||||
const fullPath = paths.join(areaPhysDir, fileName);
|
||||
|
||||
fs.stat(fullPath, (err, stats) => {
|
||||
|
@ -409,8 +432,8 @@ function scanFileAreaForChanges(areaInfo, cb) {
|
|||
return next(null);
|
||||
}
|
||||
|
||||
addOrUpdateFileEntry(areaInfo, fileName, err => {
|
||||
|
||||
addOrUpdateFileEntry(areaInfo, fileName, { areaTag : areaInfo.areaTag }, err => {
|
||||
return next(err);
|
||||
});
|
||||
});
|
||||
}, err => {
|
||||
|
|
|
@ -25,6 +25,7 @@ const FILE_WELL_KNOWN_META = {
|
|||
dl_count : (d) => parseInt(d) || 0,
|
||||
byte_size : (b) => parseInt(b) || 0,
|
||||
user_rating : (r) => Math.min(parseInt(r) || 0, 5),
|
||||
archive_type : null,
|
||||
};
|
||||
|
||||
module.exports = class FileEntry {
|
||||
|
@ -33,8 +34,13 @@ module.exports = class FileEntry {
|
|||
|
||||
this.fileId = options.fileId || 0;
|
||||
this.areaTag = options.areaTag || '';
|
||||
this.meta = {};
|
||||
this.hashTags = new Set();
|
||||
this.meta = options.meta || {
|
||||
// values we always want
|
||||
user_rating : 0,
|
||||
dl_count : 0,
|
||||
};
|
||||
|
||||
this.hashTags = options.hashTags || new Set();
|
||||
this.fileName = options.fileName;
|
||||
}
|
||||
|
||||
|
|
|
@ -113,30 +113,39 @@ HorizontalMenuView.prototype.setItems = function(items) {
|
|||
this.positionCacheExpired = true;
|
||||
};
|
||||
|
||||
HorizontalMenuView.prototype.focusNext = function() {
|
||||
if(this.items.length - 1 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = 0;
|
||||
} else {
|
||||
this.focusedItemIndex++;
|
||||
}
|
||||
|
||||
// :TODO: Optimize this in cases where we only need to redraw two items. Always the case now, somtimes
|
||||
this.redraw();
|
||||
|
||||
HorizontalMenuView.super_.prototype.focusNext.call(this);
|
||||
};
|
||||
|
||||
HorizontalMenuView.prototype.focusPrevious = function() {
|
||||
|
||||
if(0 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = this.items.length - 1;
|
||||
} else {
|
||||
this.focusedItemIndex--;
|
||||
}
|
||||
|
||||
// :TODO: Optimize this in cases where we only need to redraw two items. Always the case now, somtimes
|
||||
this.redraw();
|
||||
|
||||
HorizontalMenuView.super_.prototype.focusPrevious.call(this);
|
||||
};
|
||||
|
||||
HorizontalMenuView.prototype.onKeyPress = function(ch, key) {
|
||||
if(key) {
|
||||
var prevFocusedItemIndex = this.focusedItemIndex;
|
||||
|
||||
if(this.isKeyMapped('left', key.name)) {
|
||||
if(0 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = this.items.length - 1;
|
||||
} else {
|
||||
this.focusedItemIndex--;
|
||||
}
|
||||
|
||||
this.focusPrevious();
|
||||
} else if(this.isKeyMapped('right', key.name)) {
|
||||
if(this.items.length - 1 === this.focusedItemIndex) {
|
||||
this.focusedItemIndex = 0;
|
||||
} else {
|
||||
this.focusedItemIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
if(prevFocusedItemIndex !== this.focusedItemIndex) {
|
||||
// :TODO: Optimize this in cases where we only need to redraw two items. Always the case now, somtimes
|
||||
// if this is changed to allow scrolling
|
||||
this.redraw();
|
||||
return;
|
||||
this.focusNext();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,8 +143,10 @@ function ViewController(options) {
|
|||
var mci = mciMap[name];
|
||||
var view = self.mciViewFactory.createFromMCI(mci);
|
||||
|
||||
if(view && false === self.noInput) {
|
||||
view.on('action', self.viewActionListener);
|
||||
if(view) {
|
||||
if(false === self.noInput) {
|
||||
view.on('action', self.viewActionListener);
|
||||
}
|
||||
|
||||
self.addView(view);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue