diff --git a/.eslintrc.json b/.eslintrc.json index 93c82f42..8a78c753 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -214,7 +214,7 @@ ], "arrow-parens": [ "error", - "as-needed" + "always" ], "arrow-body-style": [ "error", diff --git a/application/api/auth.2/register.js b/application/api/auth.2/register.js index 320051f2..e1ac8a01 100644 --- a/application/api/auth.2/register.js +++ b/application/api/auth.2/register.js @@ -1,6 +1,6 @@ ({ access: 'public', - async method({ login, password, fullName }) => { + method: async ({ login, password, fullName }) => { const hash = await metarhia.metautil.hashPassword(password); await application.auth.registerUser(login, hash, fullName); const token = await context.client.startSession(); diff --git a/application/api/example.1/wait.js b/application/api/example.1/wait.js index 132277e6..0e7b0835 100644 --- a/application/api/example.1/wait.js +++ b/application/api/example.1/wait.js @@ -1,3 +1,3 @@ -async ({ delay }) => new Promise(resolve => { +async ({ delay }) => new Promise((resolve) => { setTimeout(resolve, delay, 'done'); }); diff --git a/application/domain/remote/start.js b/application/domain/remote/start.js index 74308482..4c03bd69 100644 --- a/application/domain/remote/start.js +++ b/application/domain/remote/start.js @@ -1,6 +1,6 @@ (async () => { // Wait for server start - await new Promise(resolve => setTimeout(resolve, 100)); + await new Promise((resolve) => setTimeout(resolve, 100)); console.debug('Connect to metacom'); const { url } = config.remote; const Metacom = metarhia.metacom; diff --git a/application/static/.eslintrc.json b/application/static/.eslintrc.json new file mode 100644 index 00000000..a3e1c2bb --- /dev/null +++ b/application/static/.eslintrc.json @@ -0,0 +1,15 @@ +{ + "parserOptions": { + "sourceType": "module" + }, + "globals": { + "application": "readonly", + "api": "readonly" + }, + "rules": { + "id-denylist": [ + 2, + "global" + ] + } +} diff --git a/application/static/console.js b/application/static/console.js index 4828782b..2258c895 100644 --- a/application/static/console.js +++ b/application/static/console.js @@ -238,7 +238,7 @@ const upload = () => { }; class Keyboard { - constructor(application) { + constructor() { this.controlKeyboard = document.getElementById('controlKeyboard'); if (!isMobile()) return; for (let i = 0; i < KEYBOARD_LAYOUT.length; i++) { @@ -446,6 +446,7 @@ class Application { } else if (args[0] === 'download') { const packet = await api.example.downloadFile(); console.log({ packet }); + saveFile('fileName', packet); } else if (args[0] === 'counter') { const packet = await api.example.counter(); application.print(`counter: ${packet.result}`); @@ -458,9 +459,14 @@ window.addEventListener('load', async () => { window.application = new Application(); window.api = window.application.metacom.api; await application.metacom.load('auth', 'console', 'example'); - const result = await api.auth.status(); - if (result.status !== 'logged') { - await api.auth.signIn({ login: 'marcus', password: 'marcus' }); + const token = localStorage.getItem('metarhia.session.token'); + if (token) { + await api.auth.restore({ token }); + } else { + const res = await api.auth.signin({ login: 'marcus', password: 'marcus' }); + if (res.token) { + localStorage.setItem('metarhia.session.token', res.token); + } } const { text } = await api.console.content({ name: 'home' }); application.print(text); diff --git a/test/system.js b/test/system.js index 01889f36..3e6b00f0 100644 --- a/test/system.js +++ b/test/system.js @@ -29,7 +29,7 @@ const tasks = [ } ]; -const getRequest = task => { +const getRequest = (task) => { const request = { host: HOST, port: PORT, @@ -54,18 +54,18 @@ const getRequest = task => { }; setTimeout(() => { - tasks.forEach(task => { + tasks.forEach((task) => { const name = task.get || task.post; console.log('HTTP request ' + name); const request = getRequest(task); const req = http.request(request); - req.on('response', res => { + req.on('response', (res) => { const expectedStatus = task.status || 200; setTimeout(() => { assert.equal(res.statusCode, expectedStatus); }, TEST_TIMEOUT); }); - req.on('error', err => { + req.on('error', (err) => { console.log(err.stack); }); if (task.data) req.write(task.data);