* Don't allow 'system' filters to be deleted

* Code cleanup
* Static UUID for "default/system" filters
This commit is contained in:
Bryan Ashby 2017-07-09 20:00:36 -06:00
parent fb9ecbfb93
commit d230a2f58b
11 changed files with 91 additions and 24 deletions

View File

@ -473,4 +473,3 @@ function setEmulatedBaudRate(rate) {
}[rate] || 0;
return 0 === speed ? exports.emulationSpeed() : exports.emulationSpeed(1, speed);
}

View File

@ -368,7 +368,7 @@ function getDefaultConfig() {
desc : 'Gzip Archive',
sig : '1f8b',
offset : 0,
archiveHandler : '7Zip',
archiveHandler : 'TarGz',
},
// :TODO: application/x-bzip
'application/x-bzip2' : {
@ -479,6 +479,22 @@ function getDefaultConfig() {
cmd : 'unrar',
args : [ 'e', '{archivePath}', '{extractPath}', '{fileList}' ],
}
},
TarGz : {
decompress : {
cmd : 'tar',
args : [ '-xf', '{archivePath}', '-C', '{extractPath}', '--strip-components=1' ],
},
list : {
cmd : 'tar',
args : [ '-tvf', '{archivePath}' ],
entryMatch : '^[drwx\\-]{10}\\s[A-Za-z0-9\\/]+\\s+([0-9]+)\\s[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}\\s[0-9]{2}\\:[0-9]{2}\\s([^\\r\\n]+)$',
},
extract : {
cmd : 'tar',
args : [ '-xvf', '{archivePath}', '-C', '{extractPath}', '{fileList}' ],
}
}
},
},

View File

@ -71,9 +71,13 @@ function initializeDatabases(cb) {
});
}
function enableForeignKeys(db) {
db.run('PRAGMA foreign_keys = ON;');
}
const DB_INIT_TABLE = {
system : (cb) => {
dbs.system.run('PRAGMA foreign_keys = ON;');
enableForeignKeys(dbs.system);
// Various stat/event logging - see stat_log.js
dbs.system.run(
@ -110,7 +114,7 @@ const DB_INIT_TABLE = {
},
user : (cb) => {
dbs.user.run('PRAGMA foreign_keys = ON;');
enableForeignKeys(dbs.user);
dbs.user.run(
`CREATE TABLE IF NOT EXISTS user (
@ -152,7 +156,7 @@ const DB_INIT_TABLE = {
},
message : (cb) => {
dbs.message.run('PRAGMA foreign_keys = ON;');
enableForeignKeys(dbs.message);
dbs.message.run(
`CREATE TABLE IF NOT EXISTS message (
@ -260,7 +264,7 @@ const DB_INIT_TABLE = {
},
file : (cb) => {
dbs.file.run('PRAGMA foreign_keys = ON;');
enableForeignKeys(dbs.file);
dbs.file.run(
// :TODO: should any of this be unique -- file_sha256 unless dupes are allowed on the system
@ -363,6 +367,13 @@ const DB_INIT_TABLE = {
expire_timestamp DATETIME NOT NULL
);`
);
/*
dbs.file.run(
`CREATE TABLE IF NOT EXISTS user_file_last_upload_timestamp (
user_id INTEGER PRIMARY KEY NOT NULL,
upload_timestamp DATETIME NOT NULL
);`
);*/
return cb(null);
}

View File

@ -284,7 +284,7 @@ class FileAreaWebAccess {
resp.on('finish', () => {
// transfer completed fully
this.updateDownloadStatsForUserId(servedItem.userId, stats.size);
this.updateDownloadStatsForUserIdAndSystemAndSystem(servedItem.userId, stats.size);
});
const headers = {
@ -301,7 +301,7 @@ class FileAreaWebAccess {
});
}
updateDownloadStatsForUserId(userId, dlBytes, cb) {
updateDownloadStatsForUserIdAndSystem(userId, dlBytes, cb) {
async.waterfall(
[
function fetchActiveUser(callback) {

View File

@ -65,14 +65,14 @@ module.exports = class FileBaseFilters {
let filtersProperty = this.client.user.properties.file_base_filters;
let defaulted;
if(!filtersProperty) {
filtersProperty = JSON.stringify(FileBaseFilters.getDefaultFilters());
filtersProperty = JSON.stringify(FileBaseFilters.getBuiltInSystemFilters());
defaulted = true;
}
try {
this.filters = JSON.parse(filtersProperty);
} catch(e) {
this.filters = FileBaseFilters.getDefaultFilters(); // something bad happened; reset everything back to defaults :(
this.filters = FileBaseFilters.getBuiltInSystemFilters(); // something bad happened; reset everything back to defaults :(
defaulted = true;
this.client.log.error( { error : e.message, property : filtersProperty }, 'Failed parsing file base filters property' );
}
@ -107,20 +107,33 @@ module.exports = class FileBaseFilters {
return false;
}
static getDefaultFilters() {
const filters = {};
const uuid = uuidV4();
filters[uuid] = {
name : 'Default',
static getBuiltInSystemFilters() {
const U_LATEST = '7458b09d-40ab-4f9b-a0d7-0cf866646329';
const filters = {
[ U_LATEST ] : {
name : 'Latest Additions',
areaTag : '', // all
terms : '', // *
tags : '', // *
order : 'descending',
sort : 'upload_timestamp',
uuid : U_LATEST,
system : true,
}
};
/*
filters[U_LATEST] = {
name : 'Latest Additions',
areaTag : '', // all
terms : '', // *
tags : '', // *
order : 'descending',
sort : 'upload_timestamp',
uuid : uuid,
uuid : U_LATEST,
system : true,
};
*/
return filters;
}

View File

@ -15,7 +15,8 @@ function startup(cb) {
//
const ADDITIONAL_EXT_MIMETYPES = {
arj : 'application/x-arj',
ans : 'text/x-ansi',
ans : 'text/x-ansi',
gz : 'application/gzip', // not in mime-types 2.1.15 :(
};
_.forEach(ADDITIONAL_EXT_MIMETYPES, (mimeType, ext) => {
@ -23,6 +24,10 @@ function startup(cb) {
if(!_.isString(mimeTypes.types[ext])) {
mimeTypes[ext] = mimeType;
}
if(!mimeTypes.extensions[mimeType]) {
mimeTypes.extensions[mimeType] = [ ext ];
}
});
return cb(null);

View File

@ -92,6 +92,10 @@ class StatLog {
getSystemStat(statName) { return this.systemStats[statName]; }
getSystemStatNum(statName) {
return parseInt(this.getSystemStat(statName)) || 0;
}
incrementSystemStat(statName, incrementBy, cb) {
incrementBy = incrementBy || 1;

View File

@ -507,8 +507,8 @@ function createCleanAnsi(input, options, cb) {
parser.parse(input);
}
/*
const fs = require('graceful-fs');
let data = fs.readFileSync('/home/nuskooler/Downloads/art3.ans');
data = iconv.decode(data, 'cp437');

View File

@ -17,6 +17,7 @@ const crypto = require('crypto');
//
// Class to read and hold information from a TIC file
//
// * FTS-5006.001 @ http://www.filegate.net/ftsc/FTS-5006.001
// * FSP-1039.001 @ http://ftsc.org/docs/old/fsp-1039.001
// * FSC-0087.001 @ http://ftsc.org/docs/fsc-0087.001
//

View File

@ -61,7 +61,6 @@ exports.getModule = class FileAreaFilterEdit extends MenuModule {
this.menuMethods = {
saveFilter : (formData, extraArgs, cb) => {
return this.saveCurrentFilter(formData, cb);
},
prevFilter : (formData, extraArgs, cb) => {
this.currentFilterIndex -= 1;
@ -93,7 +92,15 @@ exports.getModule = class FileAreaFilterEdit extends MenuModule {
return cb(null);
},
deleteFilter : (formData, extraArgs, cb) => {
const filterUuid = this.filtersArray[this.currentFilterIndex].uuid;
const selectedFilter = this.filtersArray[this.currentFilterIndex];
const filterUuid = selectedFilter.uuid;
// cannot delete built-in/system filters
if(true === selectedFilter.system) {
this.showError('Cannot delete built in filters!');
return cb(null);
}
this.filtersArray.splice(this.currentFilterIndex, 1); // remove selected entry
// remove from stored properties
@ -143,6 +150,17 @@ exports.getModule = class FileAreaFilterEdit extends MenuModule {
},
};
}
showError(errMsg) {
const errorView = this.viewControllers.editor.getView(MciViewIds.editor.error);
if(errorView) {
if(errMsg) {
errorView.setText(errMsg);
} else {
errorView.clearText();
}
}
}
mciReady(mciData, cb) {
super.mciReady(mciData, err => {

View File

@ -212,8 +212,8 @@ exports.getModule = class FileAreaList extends MenuModule {
const entryInfo = currEntry.entryInfo = {
fileId : currEntry.fileId,
areaTag : currEntry.areaTag,
areaName : area.name || 'N/A',
areaDesc : area.desc || 'N/A',
areaName : _.get(area, 'name') || 'N/A',
areaDesc : _.get(area, 'desc') || 'N/A',
fileSha256 : currEntry.fileSha256,
fileName : currEntry.fileName,
desc : currEntry.desc || '',