BREAKING CHANGE: Move accounts into subfolder of SessionStore

- provided migrate_accounts.js for ease of transistion
This commit is contained in:
zefie
2022-10-17 10:25:51 -04:00
parent 23566742e4
commit 4d36e305ba
6 changed files with 40 additions and 11 deletions

View File

@@ -99,7 +99,7 @@ class WTVAdmin {
}
getAccountInfo(username, directory = null) {
var search_dir = this.minisrv_config.config.SessionStore;
var search_dir = this.minisrv_config.config.SessionStore + this.path.sep + "accounts";
var account_data = null;
var self = this;
if (directory) search_dir = directory;
@@ -114,7 +114,7 @@ class WTVAdmin {
var temp_session_data = JSON.parse(temp_session_data_file);
if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) {
account_data = [temp_session_data, (search_dir + self.path.sep + file).replace(this.minisrv_config.config.SessionStore + this.path.sep, "").split(this.path.sep)[0]];
account_data = [temp_session_data, (search_dir + self.path.sep + file).replace(this.minisrv_config.config.SessionStore + this.path.sep + "accounts", "").split(this.path.sep)[1]];
}
} catch (e) {
console.error(" # Error parsing Session Data JSON", search_dir + self.path.sep + file, e);

View File

@@ -188,6 +188,10 @@ class WTVClientSessionData {
);
}
getAccountStoreDirectory() {
return this.minisrv_config.config.SessionStore + this.path.sep + "accounts";
}
/**
* Returns the absolute path to the user's file store, or false if unregistered
* @param subscriber {boolean} Returns the parent subscriber directory instead of the user's directory
@@ -195,7 +199,7 @@ class WTVClientSessionData {
*/
getUserStoreDirectory(subscriber = false, user_id = null) {
if (user_id == null) user_id = this.user_id;
var userstore = this.minisrv_config.config.SessionStore + this.path.sep + this.ssid + this.path.sep;
var userstore = this.getAccountStoreDirectory() + this.path.sep + this.ssid + this.path.sep;
if (!subscriber) userstore += "user" + user_id + this.path.sep;
return userstore;
}
@@ -539,7 +543,7 @@ class WTVClientSessionData {
}
unregisterBox() {
var user_store_base = this.wtvshared.makeSafePath(this.wtvshared.getAbsolutePath(this.minisrv_config.config.SessionStore), this.path.sep + this.ssid);
var user_store_base = this.wtvshared.makeSafePath(this.wtvshared.getAbsolutePath(this.getAccountStoreDirectory()), this.path.sep + this.ssid);
try {
if (this.fs.existsSync(user_store_base + ".json")) {
this.fs.unlinkSync(user_store_base + ".json");

View File

@@ -9,7 +9,7 @@ class WTVRegister {
constructor(minisrv_config, session_store_dir = null) {
this.minisrv_config = minisrv_config;
this.service_owner = minisrv_config.config.service_owner || "a minisrv user";
if (session_store_dir) this.session_store_dir = session_store_dir
this.session_store_dir = session_store_dir || this.minisrv_config.config.SessionStore;
}
getServiceOperator(first_letter_lower = false) {
@@ -30,13 +30,12 @@ class WTVRegister {
checkUsernameAvailable(username, directory = null) {
// returns the user's ssid, and user_id and userid in an array if true, false if not
var search_dir = this.minisrv_config.config.SessionStore;
var search_dir = this.session_store_dir + this.path.sep + "accounts";
var return_val = false;
var self = this;
if (directory) search_dir = directory;
this.fs.readdirSync(search_dir).forEach(file => {
if (self.fs.lstatSync(search_dir + self.path.sep + file).isDirectory() && !return_val) {
if (search_dir.match(/minisrv\_internal\_nntp/)) return;
return_val = !self.checkUsernameAvailable(username, search_dir + self.path.sep + file);
}
if (!file.match(/user.*\.json/ig)) return;

View File

@@ -38,9 +38,6 @@
"enable_port_isolation": true,
"allow_guests": true,
"domain_name": "wtv.zefie.com",
"ssid_block_list": [
"minisrv_internal_nntp"
],
"user_accounts": {
"max_users_per_account": 6,
"min_username_length": 5,