Поправки багов

This commit is contained in:
Book Pauk
2022-11-27 21:03:12 +07:00
parent a7f71562b4
commit 49583d3407
4 changed files with 15 additions and 21 deletions

View File

@@ -109,10 +109,6 @@ class Api {
} }
} }
get config() {
return this.$store.state.config;
}
get settings() { get settings() {
return this.$store.state.settings; return this.$store.state.settings;
} }

View File

@@ -435,6 +435,8 @@ class Search {
mounted() { mounted() {
(async() => { (async() => {
await this.api.updateConfig();
//для встраивания в liberama //для встраивания в liberama
window.addEventListener('message', (event) => { window.addEventListener('message', (event) => {
if (!_.isObject(event.data) || event.data.from != 'ExternalLibs') if (!_.isObject(event.data) || event.data.from != 'ExternalLibs')

View File

@@ -68,7 +68,7 @@ class WebSocketController {
this.send({_rok: 1}, req, ws); this.send({_rok: 1}, req, ws);
//access //access
if (!this.webAccess.hasAccess(req.accessToken)) { if (!await this.webAccess.hasAccess(req.accessToken)) {
await utils.sleep(500); await utils.sleep(500);
const salt = this.webAccess.newToken(); const salt = this.webAccess.newToken();
this.send({error: 'need_access_token', salt}, req, ws); this.send({error: 'need_access_token', salt}, req, ws);

View File

@@ -47,28 +47,22 @@ class WebAccess {
} }
} }
//проверим, можно ли загружать токены из таблицы access await db.create({table: 'access', quietIfExists: true});
//проверим, нужно ли обнулить таблицу access
const pass = utils.getBufHash(this.config.accessPassword, 'sha256', 'hex'); const pass = utils.getBufHash(this.config.accessPassword, 'sha256', 'hex');
await db.create({table: 'config', quietIfExists: true}); await db.create({table: 'config', quietIfExists: true});
let rows = await db.select({table: 'config', where: `@@id('pass')`}); let rows = await db.select({table: 'config', where: `@@id('pass')`});
let loadMap = false; if (!rows.length || rows[0].value !== pass) {
if (rows.length && rows[0].value === pass) { //пароль сменился в конфиге, обнуляем токены
//пароль не сменился в конфиге, можно загружать токены await db.truncate({table: 'access'});
loadMap = true;
} else {
await db.insert({table: 'config', replace: true, rows: [{id: 'pass', value: pass}]}); await db.insert({table: 'config', replace: true, rows: [{id: 'pass', value: pass}]});
} }
await db.create({table: 'access', quietIfExists: true}); //загрузим токены сессий
rows = await db.select({table: 'access'});
if (loadMap) { for (const row of rows)
//загрузим токены сессий this.accessMap.set(row.id, row.value);
rows = await db.select({table: 'access'});
for (const row of rows)
this.accessMap.set(row.id, row.value);
}
this.db = db; this.db = db;
} }
@@ -99,7 +93,7 @@ class WebAccess {
} }
} }
hasAccess(accessToken) { async hasAccess(accessToken) {
if (this.freeAccess) if (this.freeAccess)
return true; return true;
@@ -111,6 +105,8 @@ class WebAccess {
accessRec.used++; accessRec.used++;
accessRec.time = now; accessRec.time = now;
accessRec.saved = false; accessRec.saved = false;
if (accessRec.used === 1)
await this.saveAccess(accessToken);
return true; return true;
} }
} }