From 6778aa434363e37ecc69df40a6a12e28b83ae3ff Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 8 May 2024 09:44:31 +0100 Subject: [PATCH 1/4] Resolve eslint issues in Russian translation /puter/src/i18n/translations/ru.js 180:34 error Irregular whitespace not allowed no-irregular-whitespace 257:9 error Duplicate key 'storage_puter_used' no-dupe-keys --- src/i18n/translations/ru.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/i18n/translations/ru.js b/src/i18n/translations/ru.js index bd15f365..53e7effc 100644 --- a/src/i18n/translations/ru.js +++ b/src/i18n/translations/ru.js @@ -177,7 +177,7 @@ const ru = { properties: "Свойства", publish: "Опубликовать", publish_as_website: 'Опубликовать как сайт', - puter_description: `Puter — это персональное облако, обеспечивающее конфиденциальность, позволяющее хранить все ваши файлы, приложения и игры в одном безопасном месте, доступном из любого места в любое время.`, + puter_description: `Puter — это персональное облако, обеспечивающее конфиденциальность, позволяющее хранить все ваши файлы, приложения и игры в одном безопасном месте, доступном из любого места в любое время.`, recent: "Недавний", recover_password: "Восстановить Пароль", refer_friends_c2a: "Получите 1 ГБ за каждого друга, который создаст и подтвердит учетную запись на Puter. Ваш друг тоже получит 1 ГБ!", @@ -254,7 +254,6 @@ const ru = { yes_release_it: 'Да, освободить.', you_have_been_referred_to_puter_by_a_friend: "Вы были приглашены в Puter другом!", zip: "Заархивировать", - storage_puter_used: "использовано Puter", } }; From 2604dae83c181f64aa3f2e603cd1d076d9640756 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 8 May 2024 09:49:58 +0100 Subject: [PATCH 2/4] Resolve eslint issues in new 2FA code /puter/src/UI/Settings/UITabSecurity.js 13:13 error 'user' is not defined no-undef 31:13 error 'user' is not defined no-undef 32:70 error 'user' is not defined no-undef 36:30 error 'user' is not defined no-undef 40:82 error 'user' is not defined no-undef 41:83 error 'user' is not defined no-undef 87:41 error 'api_origin' is not defined no-undef /puter/src/UI/UIWindow2FASetup.js 39:33 error 'api_origin' is not defined no-undef 51:37 error 'api_origin' is not defined no-undef 69:37 error 'api_origin' is not defined no-undef /puter/src/UI/UIWindowLogin.js 202:73 error 'api_origin' is not defined no-undef 271:73 error 'api_origin' is not defined no-undef --- src/UI/Settings/UITabSecurity.js | 3 ++- src/UI/UIWindow2FASetup.js | 6 +++--- src/UI/UIWindowLogin.js | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/UI/Settings/UITabSecurity.js b/src/UI/Settings/UITabSecurity.js index 65ccf5b4..7514b9ce 100644 --- a/src/UI/Settings/UITabSecurity.js +++ b/src/UI/Settings/UITabSecurity.js @@ -8,6 +8,7 @@ export default { icon: 'shield.svg', html: () => { let h = `

${i18n('security')}

`; + let user = window.user; // change password button if(!user.is_temp){ @@ -84,7 +85,7 @@ export default { ] }) if ( ! alert_resp ) return; - const resp = await fetch(`${api_origin}/auth/configure-2fa/disable`, { + const resp = await fetch(`${window.api_origin}/auth/configure-2fa/disable`, { method: 'POST', headers: { Authorization: `Bearer ${puter.authToken}`, diff --git a/src/UI/UIWindow2FASetup.js b/src/UI/UIWindow2FASetup.js index b76fafd9..d574f8d3 100644 --- a/src/UI/UIWindow2FASetup.js +++ b/src/UI/UIWindow2FASetup.js @@ -36,7 +36,7 @@ import UIComponentWindow from "./UIComponentWindow.js"; const UIWindow2FASetup = async function UIWindow2FASetup () { // FIRST REQUEST :: Generate the QR code and recovery codes - const resp = await fetch(`${api_origin}/auth/configure-2fa/setup`, { + const resp = await fetch(`${window.api_origin}/auth/configure-2fa/setup`, { method: 'POST', headers: { Authorization: `Bearer ${puter.authToken}`, @@ -48,7 +48,7 @@ const UIWindow2FASetup = async function UIWindow2FASetup () { // SECOND REQUEST :: Verify the code [first wizard screen] const check_code_ = async function check_code_ (value) { - const resp = await fetch(`${api_origin}/auth/configure-2fa/test`, { + const resp = await fetch(`${window.api_origin}/auth/configure-2fa/test`, { method: 'POST', headers: { Authorization: `Bearer ${puter.authToken}`, @@ -66,7 +66,7 @@ const UIWindow2FASetup = async function UIWindow2FASetup () { // FINAL REQUEST :: Enable 2FA [second wizard screen] const enable_2fa_ = async function check_code_ (value) { - const resp = await fetch(`${api_origin}/auth/configure-2fa/enable`, { + const resp = await fetch(`${window.api_origin}/auth/configure-2fa/enable`, { method: 'POST', headers: { Authorization: `Bearer ${puter.authToken}`, diff --git a/src/UI/UIWindowLogin.js b/src/UI/UIWindowLogin.js index 6c1ca26c..0885577a 100644 --- a/src/UI/UIWindowLogin.js +++ b/src/UI/UIWindowLogin.js @@ -199,7 +199,7 @@ async function UIWindowLogin(options){ let error_i18n_key = 'something_went_wrong'; if ( ! value ) return; try { - const resp = await fetch(`${api_origin}/login/otp`, { + const resp = await fetch(`${window.api_origin}/login/otp`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -268,7 +268,7 @@ async function UIWindowLogin(options){ let error_i18n_key = 'something_went_wrong'; if ( ! value ) return; try { - const resp = await fetch(`${api_origin}/login/recovery-code`, { + const resp = await fetch(`${window.api_origin}/login/recovery-code`, { method: 'POST', headers: { 'Content-Type': 'application/json', From 8c70efa058fa058c605c9925661649a315826691 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 8 May 2024 18:53:36 +0100 Subject: [PATCH 3/4] Suppress remaining eslint errors These two seem like bugs but are unclear to me how to fix, so I've added FIXMEs. /puter/packages/backend/src/routers/kvstore/clearItems.js 41:32 error 'DB_MODE_WRITE' is not defined no-undef /puter/packages/backend/src/routers/whoami.js 104:35 error 'db' is not defined no-undef --- packages/backend/src/routers/kvstore/clearItems.js | 2 ++ packages/backend/src/routers/whoami.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/backend/src/routers/kvstore/clearItems.js b/packages/backend/src/routers/kvstore/clearItems.js index 6390148a..6a895867 100644 --- a/packages/backend/src/routers/kvstore/clearItems.js +++ b/packages/backend/src/routers/kvstore/clearItems.js @@ -38,6 +38,8 @@ module.exports = eggspress('/clearItems', { } const svc_mysql = req.services.get('mysql'); + // TODO: Check if used anywhere, maybe remove + // eslint-disable-next-line no-undef const dbrw = svc_mysql.get(DB_MODE_WRITE, 'kvstore-clearItems'); await dbrw.execute( `DELETE FROM kv WHERE user_id=? AND app=?`, diff --git a/packages/backend/src/routers/whoami.js b/packages/backend/src/routers/whoami.js index 2c267a2a..fe6bf912 100644 --- a/packages/backend/src/routers/whoami.js +++ b/packages/backend/src/routers/whoami.js @@ -101,6 +101,8 @@ WHOAMI_POST.post('/whoami', auth, fs, express.json(), async (req, response, next if(req.query.return_desktop_items === 1 || req.query.return_desktop_items === '1' || req.query.return_desktop_items === 'true'){ // by cached desktop id if(req.user.desktop_id){ + // TODO: Check if used anywhere, maybe remove + // eslint-disable-next-line no-undef desktop_items = await db.read( `SELECT * FROM fsentries WHERE user_id = ? AND parent_uid = ?`, From fbda8c8286f41f062ae776febb903e8f9b2a4af5 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 8 May 2024 10:17:48 +0100 Subject: [PATCH 4/4] Run ESLint on CI Run the ESLint static analysis tool on any code that is submitted, to find possible bugs such as undefined functions and variables. We may want to adjust the ESLint settings over time, but this seems like a good start. This is merged into the previous check-translations.yml action, because that's also a form of linting. Possibly that could be reimplemented as an ESLint plugin. --- .../{check-translations.yml => lint.yml} | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) rename .github/workflows/{check-translations.yml => lint.yml} (65%) diff --git a/.github/workflows/check-translations.yml b/.github/workflows/lint.yml similarity index 65% rename from .github/workflows/check-translations.yml rename to .github/workflows/lint.yml index 364328e9..c0976139 100644 --- a/.github/workflows/check-translations.yml +++ b/.github/workflows/lint.yml @@ -1,6 +1,6 @@ -# This workflow runs the tools/check-translations.js script to make sure that the translation data is valid. +# Lint PRs and pushes to the main branch -name: Check Translations +name: Lint env: NODE_VERSION: 21.x @@ -13,7 +13,7 @@ on: branches: [ "main" ] jobs: - test: + build: runs-on: ubuntu-latest steps: @@ -24,5 +24,10 @@ jobs: node-version: ${{ env.NODE_VERSION }} cache: 'npm' cache-dependency-path: ./package-lock.json - - run: npm ci - - run: npm run check-translations \ No newline at end of file + - name: Install dependencies + run: npm ci + - name: Run ESLint + run: npx eslint + - name: Check translations + if: '!cancelled()' + run: npm run check-translations