From c5a0c01e4e9c20d1945153fb1eecd84f30d1f492 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Mon, 5 Jun 2023 21:15:49 -0700 Subject: [PATCH] Revert "chore: formatting" This reverts commit 36283b9a358886bfcf6f40c04b5bed1fe6088ff5. --- cypress.config.ts | 20 +-- cypress/e2e/basic.cy.js | 126 +++++++++--------- cypress/e2e/widgets.cy.js | 78 +++++------ cypress/plugins/index.js | 6 +- cypress/support/commands.js | 34 +++-- cypress/support/e2e.js | 18 ++- locales/index.js | 113 ++++++---------- .../1658656633972-note-replies-function.js | 2 +- ...ddFkAbuseUserReportTargetUserIdToUserId.js | 2 +- .../migration/1680375641101-clean-charts.js | 16 +-- packages/backend/src/boot/master.ts | 2 +- .../remote/activitypub/misc/ld-signature.ts | 8 +- .../src/remote/activitypub/models/image.ts | 4 +- .../backend/src/server/api/endpoints/meta.ts | 4 +- .../src/server/api/endpoints/notes/edit.ts | 4 +- .../server/api/mastodon/endpoints/timeline.ts | 2 +- packages/backend/src/server/web/boot.js | 4 +- packages/backend/src/services/note/create.ts | 6 +- packages/backend/test/api-visibility.ts | 16 +-- packages/backend/test/get-file-info.ts | 72 +++++----- packages/backend/test/streaming.ts | 8 +- packages/backend/test/utils.ts | 10 +- packages/client/src/components/mfm.ts | 2 +- scripts/clean-all.js | 44 ++---- scripts/clean.js | 19 +-- scripts/dev.js | 28 ++-- 26 files changed, 292 insertions(+), 356 deletions(-) diff --git a/cypress.config.ts b/cypress.config.ts index 25ff2aa075..e390c41a54 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,12 +1,12 @@ -import { defineConfig } from "cypress"; +import { defineConfig } from 'cypress' export default defineConfig({ - e2e: { - // We've imported your old cypress plugins here. - // You may want to clean this up later by importing these. - setupNodeEvents(on, config) { - return require("./cypress/plugins/index.js")(on, config); - }, - baseUrl: "http://localhost:61812", - }, -}); + e2e: { + // We've imported your old cypress plugins here. + // You may want to clean this up later by importing these. + setupNodeEvents(on, config) { + return require('./cypress/plugins/index.js')(on, config) + }, + baseUrl: 'http://localhost:61812', + }, +}) diff --git a/cypress/e2e/basic.cy.js b/cypress/e2e/basic.cy.js index f73a25efbc..eb5195c4b2 100644 --- a/cypress/e2e/basic.cy.js +++ b/cypress/e2e/basic.cy.js @@ -1,4 +1,4 @@ -describe("Before setup instance", () => { +describe('Before setup instance', () => { beforeEach(() => { cy.resetState(); }); @@ -9,31 +9,31 @@ describe("Before setup instance", () => { cy.wait(1000); }); - it("successfully loads", () => { - cy.visit("/"); - }); + it('successfully loads', () => { + cy.visit('/'); + }); - it("setup instance", () => { - cy.visit("/"); + it('setup instance', () => { + cy.visit('/'); - cy.intercept("POST", "/api/admin/accounts/create").as("signup"); - - cy.get("[data-cy-admin-username] input").type("admin"); - cy.get("[data-cy-admin-password] input").type("admin1234"); - cy.get("[data-cy-admin-ok]").click(); + cy.intercept('POST', '/api/admin/accounts/create').as('signup'); + + cy.get('[data-cy-admin-username] input').type('admin'); + cy.get('[data-cy-admin-password] input').type('admin1234'); + cy.get('[data-cy-admin-ok]').click(); // なぜか動かない //cy.wait('@signup').should('have.property', 'response.statusCode'); - cy.wait("@signup"); - }); + cy.wait('@signup'); + }); }); -describe("After setup instance", () => { +describe('After setup instance', () => { beforeEach(() => { cy.resetState(); // インスタンス初期セットアップ - cy.registerUser("admin", "pass", true); + cy.registerUser('admin', 'pass', true); }); afterEach(() => { @@ -42,34 +42,34 @@ describe("After setup instance", () => { cy.wait(1000); }); - it("successfully loads", () => { - cy.visit("/"); - }); + it('successfully loads', () => { + cy.visit('/'); + }); - it("signup", () => { - cy.visit("/"); + it('signup', () => { + cy.visit('/'); - cy.intercept("POST", "/api/signup").as("signup"); + cy.intercept('POST', '/api/signup').as('signup'); - cy.get("[data-cy-signup]").click(); - cy.get("[data-cy-signup-username] input").type("alice"); - cy.get("[data-cy-signup-password] input").type("alice1234"); - cy.get("[data-cy-signup-password-retype] input").type("alice1234"); - cy.get("[data-cy-signup-submit]").click(); + cy.get('[data-cy-signup]').click(); + cy.get('[data-cy-signup-username] input').type('alice'); + cy.get('[data-cy-signup-password] input').type('alice1234'); + cy.get('[data-cy-signup-password-retype] input').type('alice1234'); + cy.get('[data-cy-signup-submit]').click(); - cy.wait("@signup"); - }); + cy.wait('@signup'); + }); }); -describe("After user signup", () => { +describe('After user signup', () => { beforeEach(() => { cy.resetState(); // インスタンス初期セットアップ - cy.registerUser("admin", "pass", true); + cy.registerUser('admin', 'pass', true); // ユーザー作成 - cy.registerUser("alice", "alice1234"); + cy.registerUser('alice', 'alice1234'); }); afterEach(() => { @@ -78,53 +78,51 @@ describe("After user signup", () => { cy.wait(1000); }); - it("successfully loads", () => { - cy.visit("/"); - }); + it('successfully loads', () => { + cy.visit('/'); + }); - it("signin", () => { - cy.visit("/"); + it('signin', () => { + cy.visit('/'); - cy.intercept("POST", "/api/signin").as("signin"); + cy.intercept('POST', '/api/signin').as('signin'); - cy.get("[data-cy-signin]").click(); - cy.get("[data-cy-signin-username] input").type("alice"); + cy.get('[data-cy-signin]').click(); + cy.get('[data-cy-signin-username] input').type('alice'); // Enterキーでサインインできるかの確認も兼ねる - cy.get("[data-cy-signin-password] input").type("alice1234{enter}"); + cy.get('[data-cy-signin-password] input').type('alice1234{enter}'); - cy.wait("@signin"); - }); + cy.wait('@signin'); + }); - it("suspend", function () { - cy.request("POST", "/api/admin/suspend-user", { + it('suspend', function() { + cy.request('POST', '/api/admin/suspend-user', { i: this.admin.token, userId: this.alice.id, }); - cy.visit("/"); + cy.visit('/'); - cy.get("[data-cy-signin]").click(); - cy.get("[data-cy-signin-username] input").type("alice"); - cy.get("[data-cy-signin-password] input").type("alice1234{enter}"); + cy.get('[data-cy-signin]').click(); + cy.get('[data-cy-signin-username] input').type('alice'); + cy.get('[data-cy-signin-password] input').type('alice1234{enter}'); // TODO: cypressにブラウザの言語指定できる機能が実装され次第英語のみテストするようにする - cy.contains( - /アカウントが凍結されています|This account has been suspended due to/gi, - ); + cy.contains(/アカウントが凍結されています|This account has been suspended due to/gi); }); }); -describe("After user singed in", () => { +describe('After user singed in', () => { beforeEach(() => { cy.resetState(); // インスタンス初期セットアップ - cy.registerUser("admin", "pass", true); + cy.registerUser('admin', 'pass', true); // ユーザー作成 - cy.registerUser("alice", "alice1234"); + cy.registerUser('alice', 'alice1234'); - cy.login("alice", "alice1234"); + cy.login('alice', 'alice1234'); }); afterEach(() => { @@ -133,17 +131,17 @@ describe("After user singed in", () => { cy.wait(1000); }); - it("successfully loads", () => { - cy.get("[data-cy-open-post-form]").should("be.visible"); - }); + it('successfully loads', () => { + cy.get('[data-cy-open-post-form]').should('be.visible'); + }); - it("note", () => { - cy.get("[data-cy-open-post-form]").click(); - cy.get("[data-cy-post-form-text]").type("Hello, Misskey!"); - cy.get("[data-cy-open-post-form-submit]").click(); + it('note', () => { + cy.get('[data-cy-open-post-form]').click(); + cy.get('[data-cy-post-form-text]').type('Hello, Misskey!'); + cy.get('[data-cy-open-post-form-submit]').click(); - cy.contains("Hello, Misskey!"); - }); + cy.contains('Hello, Misskey!'); + }); }); // TODO: 投稿フォームの公開範囲指定のテスト diff --git a/cypress/e2e/widgets.cy.js b/cypress/e2e/widgets.cy.js index e3c9326db8..9eea010bde 100644 --- a/cypress/e2e/widgets.cy.js +++ b/cypress/e2e/widgets.cy.js @@ -1,14 +1,14 @@ -describe("After user signed in", () => { +describe('After user signed in', () => { beforeEach(() => { cy.resetState(); - cy.viewport("macbook-16"); + cy.viewport('macbook-16'); // インスタンス初期セットアップ - cy.registerUser("admin", "pass", true); + cy.registerUser('admin', 'pass', true); // ユーザー作成 - cy.registerUser("alice", "alice1234"); + cy.registerUser('alice', 'alice1234'); - cy.login("alice", "alice1234"); + cy.login('alice', 'alice1234'); }); afterEach(() => { @@ -17,47 +17,47 @@ describe("After user signed in", () => { cy.wait(1000); }); - it("widget edit toggle is visible", () => { - cy.get(".mk-widget-edit").should("be.visible"); - }); + it('widget edit toggle is visible', () => { + cy.get('.mk-widget-edit').should('be.visible'); + }); - it("widget select should be visible in edit mode", () => { - cy.get(".mk-widget-edit").click(); - cy.get(".mk-widget-select").should("be.visible"); - }); + it('widget select should be visible in edit mode', () => { + cy.get('.mk-widget-edit').click(); + cy.get('.mk-widget-select').should('be.visible'); + }); - it("first widget should be removed", () => { - cy.get(".mk-widget-edit").click(); - cy.get(".customize-container:first-child .remove._button").click(); - cy.get(".customize-container").should("have.length", 2); + it('first widget should be removed', () => { + cy.get('.mk-widget-edit').click(); + cy.get('.customize-container:first-child .remove._button').click(); + cy.get('.customize-container').should('have.length', 2); }); function buildWidgetTest(widgetName) { it(`${widgetName} widget should get added`, () => { - cy.get(".mk-widget-edit").click(); - cy.get(".mk-widget-select select").select(widgetName, { force: true }); - cy.get(".bg._modalBg.transparent").click({ multiple: true, force: true }); - cy.get(".mk-widget-add").click({ force: true }); - cy.get(`.mkw-${widgetName}`).should("exist"); + cy.get('.mk-widget-edit').click(); + cy.get('.mk-widget-select select').select(widgetName, { force: true }); + cy.get('.bg._modalBg.transparent').click({ multiple: true, force: true }); + cy.get('.mk-widget-add').click({ force: true }); + cy.get(`.mkw-${widgetName}`).should('exist'); }); } - buildWidgetTest("memo"); - buildWidgetTest("notifications"); - buildWidgetTest("timeline"); - buildWidgetTest("calendar"); - buildWidgetTest("rss"); - buildWidgetTest("trends"); - buildWidgetTest("clock"); - buildWidgetTest("activity"); - buildWidgetTest("photos"); - buildWidgetTest("digitalClock"); - buildWidgetTest("federation"); - buildWidgetTest("postForm"); - buildWidgetTest("slideshow"); - buildWidgetTest("serverMetric"); - buildWidgetTest("onlineUsers"); - buildWidgetTest("jobQueue"); - buildWidgetTest("button"); - buildWidgetTest("aiscript"); + buildWidgetTest('memo'); + buildWidgetTest('notifications'); + buildWidgetTest('timeline'); + buildWidgetTest('calendar'); + buildWidgetTest('rss'); + buildWidgetTest('trends'); + buildWidgetTest('clock'); + buildWidgetTest('activity'); + buildWidgetTest('photos'); + buildWidgetTest('digitalClock'); + buildWidgetTest('federation'); + buildWidgetTest('postForm'); + buildWidgetTest('slideshow'); + buildWidgetTest('serverMetric'); + buildWidgetTest('onlineUsers'); + buildWidgetTest('jobQueue'); + buildWidgetTest('button'); + buildWidgetTest('aiscript'); }); diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index 3a4b6deb18..aa9918d215 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -16,6 +16,6 @@ * @type {Cypress.PluginConfig} */ module.exports = (on, config) => { - // `on` is used to hook into various events Cypress emits - // `config` is the resolved Cypress config -}; + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config +} diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 3fe95b93d0..95bfcf6855 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -24,34 +24,32 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) -Cypress.Commands.add("resetState", () => { - cy.window((win) => { - win.indexedDB.deleteDatabase("keyval-store"); +Cypress.Commands.add('resetState', () => { + cy.window(win => { + win.indexedDB.deleteDatabase('keyval-store'); }); - cy.request("POST", "/api/reset-db").as("reset"); - cy.get("@reset").its("status").should("equal", 204); + cy.request('POST', '/api/reset-db').as('reset'); + cy.get('@reset').its('status').should('equal', 204); cy.reload(true); }); -Cypress.Commands.add("registerUser", (username, password, isAdmin = false) => { - const route = isAdmin ? "/api/admin/accounts/create" : "/api/signup"; +Cypress.Commands.add('registerUser', (username, password, isAdmin = false) => { + const route = isAdmin ? '/api/admin/accounts/create' : '/api/signup'; - cy.request("POST", route, { + cy.request('POST', route, { username: username, password: password, - }) - .its("body") - .as(username); + }).its('body').as(username); }); -Cypress.Commands.add("login", (username, password) => { - cy.visit("/"); +Cypress.Commands.add('login', (username, password) => { + cy.visit('/'); - cy.intercept("POST", "/api/signin").as("signin"); + cy.intercept('POST', '/api/signin').as('signin'); - cy.get("[data-cy-signin]").click(); - cy.get("[data-cy-signin-username] input").type(username); - cy.get("[data-cy-signin-password] input").type(`${password}{enter}`); + cy.get('[data-cy-signin]').click(); + cy.get('[data-cy-signin-username] input').type(username); + cy.get('[data-cy-signin-password] input').type(`${password}{enter}`); - cy.wait("@signin").as("signedIn"); + cy.wait('@signin').as('signedIn'); }); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index 961c6ac888..9185be344c 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -14,21 +14,19 @@ // *********************************************************** // Import commands.js using ES2015 syntax: -import "./commands"; +import './commands' // Alternatively you can use CommonJS syntax: // require('./commands') -Cypress.on("uncaught:exception", (err, runnable) => { - if ( - [ - // Chrome - "ResizeObserver loop limit exceeded", +Cypress.on('uncaught:exception', (err, runnable) => { + if ([ + // Chrome + 'ResizeObserver loop limit exceeded', - // Firefox - "ResizeObserver loop completed with undelivered notifications", - ].some((msg) => err.message.includes(msg)) - ) { + // Firefox + 'ResizeObserver loop completed with undelivered notifications', + ].some(msg => err.message.includes(msg))) { return false; } }); diff --git a/locales/index.js b/locales/index.js index 20e9593dad..7399bb5a18 100644 --- a/locales/index.js +++ b/locales/index.js @@ -2,90 +2,59 @@ * Languages Loader */ -const fs = require("fs"); -const yaml = require("js-yaml"); -let languages = []; -let languages_custom = []; +const fs = require('fs'); +const yaml = require('js-yaml'); +let languages = [] +let languages_custom = [] + +const merge = (...args) => args.reduce((a, c) => ({ + ...a, + ...c, + ...Object.entries(a) + .filter(([k]) => c && typeof c[k] === 'object') + .reduce((a, [k, v]) => (a[k] = merge(v, c[k]), a), {}) +}), {}); -const merge = (...args) => - args.reduce( - (a, c) => ({ - ...a, - ...c, - ...Object.entries(a) - .filter(([k]) => c && typeof c[k] === "object") - .reduce((a, [k, v]) => ((a[k] = merge(v, c[k])), a), {}), - }), - {}, - ); fs.readdirSync(__dirname).forEach((file) => { - if (file.includes(".yml")) { - file = file.slice(0, file.indexOf(".")); + if (file.includes('.yml')){ + file = file.slice(0, file.indexOf('.')) languages.push(file); } -}); +}) -fs.readdirSync(__dirname + "/../custom/locales").forEach((file) => { - if (file.includes(".yml")) { - file = file.slice(0, file.indexOf(".")); +fs.readdirSync(__dirname + '/../custom/locales').forEach((file) => { + if (file.includes('.yml')){ + file = file.slice(0, file.indexOf('.')) languages_custom.push(file); } -}); +}) const primaries = { - en: "US", - ja: "JP", - zh: "CN", + 'en': 'US', + 'ja': 'JP', + 'zh': 'CN', }; // 何故か文字列にバックスペース文字が混入することがあり、YAMLが壊れるので取り除く -const clean = (text) => - text.replace(new RegExp(String.fromCodePoint(0x08), "g"), ""); +const clean = (text) => text.replace(new RegExp(String.fromCodePoint(0x08), 'g'), ''); -const locales = languages.reduce( - (a, c) => ( - (a[c] = - yaml.load(clean(fs.readFileSync(`${__dirname}/${c}.yml`, "utf-8"))) || - {}), - a - ), - {}, -); -const locales_custom = languages_custom.reduce( - (a, c) => ( - (a[c] = - yaml.load( - clean( - fs.readFileSync(`${__dirname}/../custom/locales/${c}.yml`, "utf-8"), - ), - ) || {}), - a - ), - {}, -); -Object.assign(locales, locales_custom); +const locales = languages.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/${c}.yml`, 'utf-8'))) || {}, a), {}); +const locales_custom = languages_custom.reduce((a, c) => (a[c] = yaml.load(clean(fs.readFileSync(`${__dirname}/../custom/locales/${c}.yml`, 'utf-8'))) || {}, a), {}); +Object.assign(locales, locales_custom) -module.exports = Object.entries(locales).reduce( - (a, [k, v]) => ( - (a[k] = (() => { - const [lang] = k.split("-"); - switch (k) { - case "ja-JP": - return v; - case "ja-KS": - case "en-US": - return merge(locales["ja-JP"], v); - default: - return merge( - locales["ja-JP"], - locales["en-US"], - locales[`${lang}-${primaries[lang]}`] || {}, - v, - ); - } - })()), - a - ), - {}, -); +module.exports = Object.entries(locales) + .reduce((a, [k ,v]) => (a[k] = (() => { + const [lang] = k.split('-'); + switch (k) { + case 'ja-JP': return v; + case 'ja-KS': + case 'en-US': return merge(locales['ja-JP'], v); + default: return merge( + locales['ja-JP'], + locales['en-US'], + locales[`${lang}-${primaries[lang]}`] || {}, + v + ); + } + })(), a), {}); diff --git a/packages/backend/migration/1658656633972-note-replies-function.js b/packages/backend/migration/1658656633972-note-replies-function.js index 705d1c9350..810e238439 100644 --- a/packages/backend/migration/1658656633972-note-replies-function.js +++ b/packages/backend/migration/1658656633972-note-replies-function.js @@ -47,6 +47,6 @@ export class noteRepliesFunction1658656633972 { } async down(queryRunner) { - await queryRunner.query("DROP FUNCTION note_replies"); + await queryRunner.query(`DROP FUNCTION note_replies`); } } diff --git a/packages/backend/migration/1671199573000-AddFkAbuseUserReportTargetUserIdToUserId.js b/packages/backend/migration/1671199573000-AddFkAbuseUserReportTargetUserIdToUserId.js index 8fb5d08af8..96ed8e1d6b 100644 --- a/packages/backend/migration/1671199573000-AddFkAbuseUserReportTargetUserIdToUserId.js +++ b/packages/backend/migration/1671199573000-AddFkAbuseUserReportTargetUserIdToUserId.js @@ -12,7 +12,7 @@ export class addFkAbuseUserReportTargetUserIdToUserId1671199573000 { async down(queryRunner) { await queryRunner.query( - "ALTER TABLE abuse_user_report DROP CONSTRAINT fk_7f4e851a35d81b64dda28eee0", + `ALTER TABLE abuse_user_report DROP CONSTRAINT fk_7f4e851a35d81b64dda28eee0`, ); } } diff --git a/packages/backend/migration/1680375641101-clean-charts.js b/packages/backend/migration/1680375641101-clean-charts.js index 827dcd2ce2..bfb8aa9d92 100644 --- a/packages/backend/migration/1680375641101-clean-charts.js +++ b/packages/backend/migration/1680375641101-clean-charts.js @@ -4,22 +4,22 @@ export class CleanCharts1680375641101 { } async up(queryRunner) { await queryRunner.query( - "delete from __chart__hashtag where ___local_users = 0 and ___remote_users = 0;", + `delete from __chart__hashtag where ___local_users = 0 and ___remote_users = 0;`, ); await queryRunner.query( - "delete from __chart_day__hashtag where ___local_users = 0 and ___remote_users = 0;", + `delete from __chart_day__hashtag where ___local_users = 0 and ___remote_users = 0;`, ); - await queryRunner.query("COMMIT;"); - await queryRunner.query("vacuum __chart__hashtag;"); - await queryRunner.query("vacuum __chart_day__hashtag;"); - await queryRunner.query("COMMIT;"); + await queryRunner.query(`COMMIT;`); + await queryRunner.query(`vacuum __chart__hashtag;`); + await queryRunner.query(`vacuum __chart_day__hashtag;`); + await queryRunner.query(`COMMIT;`); } async down(queryRunner) { await queryRunner.query( - "delete from __chart__hashtag where ___local_users = 0 and ___remote_users = 0;", + `delete from __chart__hashtag where ___local_users = 0 and ___remote_users = 0;`, ); await queryRunner.query( - "delete from __chart_day__hashtag where ___local_users = 0 and ___remote_users = 0;", + `delete from __chart_day__hashtag where ___local_users = 0 and ___remote_users = 0;`, ); } } diff --git a/packages/backend/src/boot/master.ts b/packages/backend/src/boot/master.ts index 17b84c74a5..bee8c8b0cd 100644 --- a/packages/backend/src/boot/master.ts +++ b/packages/backend/src/boot/master.ts @@ -93,7 +93,7 @@ export async function masterMain() { true, ); - if (!(envOption.noDaemons || config.onlyQueueProcessor)) { + if (!envOption.noDaemons && !config.onlyQueueProcessor) { import("../daemons/server-stats.js").then((x) => x.default()); import("../daemons/queue-stats.js").then((x) => x.default()); import("../daemons/janitor.js").then((x) => x.default()); diff --git a/packages/backend/src/remote/activitypub/misc/ld-signature.ts b/packages/backend/src/remote/activitypub/misc/ld-signature.ts index 1fb452c079..62707624be 100644 --- a/packages/backend/src/remote/activitypub/misc/ld-signature.ts +++ b/packages/backend/src/remote/activitypub/misc/ld-signature.ts @@ -68,13 +68,13 @@ export class LdSignature { ...options, "@context": "https://w3id.org/identity/v1", }; - transformedOptions["type"] = undefined; - transformedOptions["id"] = undefined; - transformedOptions["signatureValue"] = undefined; + delete transformedOptions["type"]; + delete transformedOptions["id"]; + delete transformedOptions["signatureValue"]; const canonizedOptions = await this.normalize(transformedOptions); const optionsHash = this.sha256(canonizedOptions); const transformedData = { ...data }; - transformedData["signature"] = undefined; + delete transformedData["signature"]; const cannonidedData = await this.normalize(transformedData); if (this.debug) console.debug(`cannonidedData: ${cannonidedData}`); const documentHash = this.sha256(cannonidedData); diff --git a/packages/backend/src/remote/activitypub/models/image.ts b/packages/backend/src/remote/activitypub/models/image.ts index b47b16c86f..211aa3931e 100644 --- a/packages/backend/src/remote/activitypub/models/image.ts +++ b/packages/backend/src/remote/activitypub/models/image.ts @@ -29,8 +29,8 @@ export async function createImage( throw new Error("invalid image: url not privided"); } - if (!(image.url.startsWith("https://") || image.url.startsWith("http://"))) { - throw new Error(`invalid image: unexpected shcema of url: ${image.url}`); + if (!image.url.startsWith("https://") && !image.url.startsWith("http://")) { + throw new Error("invalid image: unexpected shcema of url: " + image.url); } logger.info(`Creating the Image: ${image.url}`); diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index 4c222d7c33..c603cb9acf 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -529,8 +529,8 @@ export default define(meta, paramDef, async (ps, me) => { github: instance.enableGithubIntegration, discord: instance.enableDiscordIntegration, serviceWorker: instance.enableServiceWorker, - postEditing: instance.experimentalFeatures?.postEditing, - postImports: instance.experimentalFeatures?.postImports, + postEditing: instance.experimentalFeatures?.postEditing || false, + postImports: instance.experimentalFeatures?.postImports || false, miauth: true, }; } diff --git a/packages/backend/src/server/api/endpoints/notes/edit.ts b/packages/backend/src/server/api/endpoints/notes/edit.ts index 37d0f31701..66db6f644f 100644 --- a/packages/backend/src/server/api/endpoints/notes/edit.ts +++ b/packages/backend/src/server/api/endpoints/notes/edit.ts @@ -614,13 +614,13 @@ export default define(meta, paramDef, async (ps, user) => { } // Post is a reply and remote user is the contributor of the original post - if (note.reply?.userHost !== null) { + if (note.reply && note.reply.userHost !== null) { const u = await Users.findOneBy({ id: note.reply.userId }); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); } // Post is a renote and remote user is the contributor of the original post - if (note.renote?.userHost !== null) { + if (note.renote && note.renote.userHost !== null) { const u = await Users.findOneBy({ id: note.renote.userId }); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); } diff --git a/packages/backend/src/server/api/mastodon/endpoints/timeline.ts b/packages/backend/src/server/api/mastodon/endpoints/timeline.ts index 91841a19af..b8ef0929ee 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/timeline.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/timeline.ts @@ -49,7 +49,7 @@ export function toTextWithReaction(status: Entity.Status[], host: string) { if (t.reblog) t.reblog = toTextWithReaction([t.reblog], host)[0]; const reactions = t.emoji_reactions.map((r) => { const emojiNotation = r.url ? `:${r.name.replace("@.", "")}:` : r.name; - return `${emojiNotation} (${r.count}${r.me ? "* " : ""})`; + return `${emojiNotation} (${r.count}${r.me ? `* ` : ""})`; }); const reaction = t.emoji_reactions as Entity.Reaction[]; const emoji = t.emojis || []; diff --git a/packages/backend/src/server/web/boot.js b/packages/backend/src/server/web/boot.js index d80d3ca134..e7e859d20c 100644 --- a/packages/backend/src/server/web/boot.js +++ b/packages/backend/src/server/web/boot.js @@ -97,7 +97,7 @@ const fontSize = localStorage.getItem("fontSize"); if (fontSize) { - document.documentElement.classList.add(`f-${fontSize}`); + document.documentElement.classList.add("f-" + fontSize); } const useSystemFont = localStorage.getItem("useSystemFont"); @@ -292,7 +292,7 @@ const meta = await res.json(); - if (meta.version !== v) { + if (meta.version != v) { localStorage.setItem("v", meta.version); refresh(); } diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index 723a6be3df..abb8d94e88 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -564,13 +564,13 @@ export default async ( } // 投稿がリプライかつ投稿者がローカルユーザーかつリプライ先の投稿の投稿者がリモートユーザーなら配送 - if (data.reply?.userHost !== null) { + if (data.reply && data.reply.userHost !== null) { const u = await Users.findOneBy({ id: data.reply.userId }); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); } // 投稿がRenoteかつ投稿者がローカルユーザーかつRenote元の投稿の投稿者がリモートユーザーなら配送 - if (data.renote?.userHost !== null) { + if (data.renote && data.renote.userHost !== null) { const u = await Users.findOneBy({ id: data.renote.userId }); if (u && Users.isRemoteUser(u)) dm.addDirectRecipe(u); } @@ -671,7 +671,7 @@ async function insertNote( tags: tags.map((tag) => normalizeForSearch(tag)), emojis, userId: user.id, - localOnly: data.localOnly, + localOnly: data.localOnly || false, visibility: data.visibility as any, visibleUserIds: data.visibility === "specified" diff --git a/packages/backend/test/api-visibility.ts b/packages/backend/test/api-visibility.ts index 20a530fce4..0ee4a4d337 100644 --- a/packages/backend/test/api-visibility.ts +++ b/packages/backend/test/api-visibility.ts @@ -462,21 +462,21 @@ describe("API visibility", () => { it("[HTL] public-post が 自分が見れる", async(async () => { const res = await request("/notes/timeline", { limit: 100 }, alice); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id === pub.id); + const notes = res.body.filter((n: any) => n.id == pub.id); assert.strictEqual(notes[0].text, "x"); })); it("[HTL] public-post が 非フォロワーから見れない", async(async () => { const res = await request("/notes/timeline", { limit: 100 }, other); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id === pub.id); + const notes = res.body.filter((n: any) => n.id == pub.id); assert.strictEqual(notes.length, 0); })); it("[HTL] followers-post が フォロワーから見れる", async(async () => { const res = await request("/notes/timeline", { limit: 100 }, follower); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id === fol.id); + const notes = res.body.filter((n: any) => n.id == fol.id); assert.strictEqual(notes[0].text, "x"); })); //#endregion @@ -489,7 +489,7 @@ describe("API visibility", () => { follower, ); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id === folR.id); + const notes = res.body.filter((n: any) => n.id == folR.id); assert.strictEqual(notes[0].text, "x"); })); @@ -500,7 +500,7 @@ describe("API visibility", () => { other, ); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id === folR.id); + const notes = res.body.filter((n: any) => n.id == folR.id); assert.strictEqual(notes.length, 0); })); @@ -511,7 +511,7 @@ describe("API visibility", () => { target, ); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id === folR.id); + const notes = res.body.filter((n: any) => n.id == folR.id); assert.strictEqual(notes[0].text, "x"); })); //#endregion @@ -520,14 +520,14 @@ describe("API visibility", () => { it("[mentions] followers-reply が 非フォロワー (リプライ先である) から見れる", async(async () => { const res = await request("/notes/mentions", { limit: 100 }, target); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id === folR.id); + const notes = res.body.filter((n: any) => n.id == folR.id); assert.strictEqual(notes[0].text, "x"); })); it("[mentions] followers-mention が 非フォロワー (メンション先である) から見れる", async(async () => { const res = await request("/notes/mentions", { limit: 100 }, target); assert.strictEqual(res.status, 200); - const notes = res.body.filter((n: any) => n.id === folM.id); + const notes = res.body.filter((n: any) => n.id == folM.id); assert.strictEqual(notes[0].text, "@target x"); })); //#endregion diff --git a/packages/backend/test/get-file-info.ts b/packages/backend/test/get-file-info.ts index d399005144..22dc28c8e0 100644 --- a/packages/backend/test/get-file-info.ts +++ b/packages/backend/test/get-file-info.ts @@ -13,10 +13,10 @@ describe("Get file info", () => { const info = (await getFileInfo(path, { skipSensitiveDetection: true, })) as any; - info.warnings = undefined; - info.blurhash = undefined; - info.sensitive = undefined; - info.porn = undefined; + delete info.warnings; + delete info.blurhash; + delete info.sensitive; + delete info.porn; assert.deepStrictEqual(info, { size: 0, md5: "d41d8cd98f00b204e9800998ecf8427e", @@ -35,10 +35,10 @@ describe("Get file info", () => { const info = (await getFileInfo(path, { skipSensitiveDetection: true, })) as any; - info.warnings = undefined; - info.blurhash = undefined; - info.sensitive = undefined; - info.porn = undefined; + delete info.warnings; + delete info.blurhash; + delete info.sensitive; + delete info.porn; assert.deepStrictEqual(info, { size: 25360, md5: "091b3f259662aa31e2ffef4519951168", @@ -57,10 +57,10 @@ describe("Get file info", () => { const info = (await getFileInfo(path, { skipSensitiveDetection: true, })) as any; - info.warnings = undefined; - info.blurhash = undefined; - info.sensitive = undefined; - info.porn = undefined; + delete info.warnings; + delete info.blurhash; + delete info.sensitive; + delete info.porn; assert.deepStrictEqual(info, { size: 1868, md5: "08189c607bea3b952704676bb3c979e0", @@ -79,10 +79,10 @@ describe("Get file info", () => { const info = (await getFileInfo(path, { skipSensitiveDetection: true, })) as any; - info.warnings = undefined; - info.blurhash = undefined; - info.sensitive = undefined; - info.porn = undefined; + delete info.warnings; + delete info.blurhash; + delete info.sensitive; + delete info.porn; assert.deepStrictEqual(info, { size: 2248, md5: "32c47a11555675d9267aee1a86571e7e", @@ -101,10 +101,10 @@ describe("Get file info", () => { const info = (await getFileInfo(path, { skipSensitiveDetection: true, })) as any; - info.warnings = undefined; - info.blurhash = undefined; - info.sensitive = undefined; - info.porn = undefined; + delete info.warnings; + delete info.blurhash; + delete info.sensitive; + delete info.porn; assert.deepStrictEqual(info, { size: 3772, md5: "f73535c3e1e27508885b69b10cf6e991", @@ -123,10 +123,10 @@ describe("Get file info", () => { const info = (await getFileInfo(path, { skipSensitiveDetection: true, })) as any; - info.warnings = undefined; - info.blurhash = undefined; - info.sensitive = undefined; - info.porn = undefined; + delete info.warnings; + delete info.blurhash; + delete info.sensitive; + delete info.porn; assert.deepStrictEqual(info, { size: 505, md5: "b6f52b4b021e7b92cdd04509c7267965", @@ -146,10 +146,10 @@ describe("Get file info", () => { const info = (await getFileInfo(path, { skipSensitiveDetection: true, })) as any; - info.warnings = undefined; - info.blurhash = undefined; - info.sensitive = undefined; - info.porn = undefined; + delete info.warnings; + delete info.blurhash; + delete info.sensitive; + delete info.porn; assert.deepStrictEqual(info, { size: 544, md5: "4b7a346cde9ccbeb267e812567e33397", @@ -168,10 +168,10 @@ describe("Get file info", () => { const info = (await getFileInfo(path, { skipSensitiveDetection: true, })) as any; - info.warnings = undefined; - info.blurhash = undefined; - info.sensitive = undefined; - info.porn = undefined; + delete info.warnings; + delete info.blurhash; + delete info.sensitive; + delete info.porn; assert.deepStrictEqual(info, { size: 75933, md5: "268c5dde99e17cf8fe09f1ab3f97df56", @@ -190,10 +190,10 @@ describe("Get file info", () => { const info = (await getFileInfo(path, { skipSensitiveDetection: true, })) as any; - info.warnings = undefined; - info.blurhash = undefined; - info.sensitive = undefined; - info.porn = undefined; + delete info.warnings; + delete info.blurhash; + delete info.sensitive; + delete info.porn; assert.deepStrictEqual(info, { size: 12624, md5: "68d5b2d8d1d1acbbce99203e3ec3857e", diff --git a/packages/backend/test/streaming.ts b/packages/backend/test/streaming.ts index 05c972992d..3292c66e17 100644 --- a/packages/backend/test/streaming.ts +++ b/packages/backend/test/streaming.ts @@ -599,7 +599,7 @@ describe("Streaming", () => { chitose, "hashtag", ({ type, body }) => { - if (type === "note") { + if (type == "note") { assert.deepStrictEqual(body.text, "#foo"); ws.close(); done(); @@ -625,7 +625,7 @@ describe("Streaming", () => { chitose, "hashtag", ({ type, body }) => { - if (type === "note") { + if (type == "note") { if (body.text === "#foo") fooCount++; if (body.text === "#bar") barCount++; if (body.text === "#foo #bar") fooBarCount++; @@ -668,7 +668,7 @@ describe("Streaming", () => { chitose, "hashtag", ({ type, body }) => { - if (type === "note") { + if (type == "note") { if (body.text === "#foo") fooCount++; if (body.text === "#bar") barCount++; if (body.text === "#foo #bar") fooBarCount++; @@ -718,7 +718,7 @@ describe("Streaming", () => { chitose, "hashtag", ({ type, body }) => { - if (type === "note") { + if (type == "note") { if (body.text === "#foo") fooCount++; if (body.text === "#bar") barCount++; if (body.text === "#foo #bar") fooBarCount++; diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts index 28c1a7925f..f3f68b2609 100644 --- a/packages/backend/test/utils.ts +++ b/packages/backend/test/utils.ts @@ -53,7 +53,7 @@ export const api = async (endpoint: string, params: any, me?: any) => { beforeError: [ (error) => { const { response } = error; - if (response?.body) console.warn(response.body); + if (response && response.body) console.warn(response.body); return error; }, ], @@ -316,7 +316,7 @@ export function launchServer( moreProcess: () => Promise = async () => {}, ) { return (done: (err?: Error) => any) => { - const p = childProcess.spawn("node", [`${_dirname}/../index.js`], { + const p = childProcess.spawn("node", [_dirname + "/../index.js"], { stdio: ["inherit", "inherit", "inherit", "ipc"], env: { NODE_ENV: "test", PATH: process.env.PATH }, }); @@ -340,8 +340,8 @@ export async function initTestDb(justBorrow = false, initEntities?: any[]) { username: config.db.user, password: config.db.pass, database: config.db.db, - synchronize: !justBorrow, - dropSchema: !justBorrow, + synchronize: true && !justBorrow, + dropSchema: true && !justBorrow, entities: initEntities || entities, }); @@ -359,7 +359,7 @@ export function startServer( rej("timeout to start"); }, timeout); - const p = childProcess.spawn("node", [`${_dirname}/../built/index.js`], { + const p = childProcess.spawn("node", [_dirname + "/../built/index.js"], { stdio: ["inherit", "inherit", "inherit", "ipc"], env: { NODE_ENV: "test", PATH: process.env.PATH }, }); diff --git a/packages/client/src/components/mfm.ts b/packages/client/src/components/mfm.ts index 1521438082..50a566d331 100644 --- a/packages/client/src/components/mfm.ts +++ b/packages/client/src/components/mfm.ts @@ -59,7 +59,7 @@ export default defineComponent({ }; // const validEase = (e: string | null | undefined) => { // if (e == null) return null; - // return e.match(/(steps)?\(-?[0-9.]+,-?[0-9.]+,-?[0-9.]+,-?[0-9.]+\)/) + // return e.match(/(steps)?\(-?[0-9.]+,-?[0-9.]+,-?[0-9.]+,-?[0-9.]+\)/) // ? (e.startsWith("steps") ? e : "cubic-bezier" + e) // : null // } diff --git a/scripts/clean-all.js b/scripts/clean-all.js index 5b7469040c..e347ee6a9f 100644 --- a/scripts/clean-all.js +++ b/scripts/clean-all.js @@ -1,39 +1,21 @@ -const fs = require("fs"); -const execa = require("execa"); +const fs = require('fs'); +const execa = require('execa'); (async () => { - fs.rmSync(`${__dirname}/../packages/backend/built`, { - recursive: true, - force: true, - }); - fs.rmSync(`${__dirname}/../packages/backend/node_modules`, { - recursive: true, - force: true, - }); + fs.rmSync(__dirname + '/../packages/backend/built', { recursive: true, force: true }); + fs.rmSync(__dirname + '/../packages/backend/node_modules', { recursive: true, force: true }); - fs.rmSync(`${__dirname}/../packages/client/built`, { - recursive: true, - force: true, - }); - fs.rmSync(`${__dirname}/../packages/client/node_modules`, { - recursive: true, - force: true, - }); + fs.rmSync(__dirname + '/../packages/client/built', { recursive: true, force: true }); + fs.rmSync(__dirname + '/../packages/client/node_modules', { recursive: true, force: true }); - fs.rmSync(`${__dirname}/../packages/sw/built`, { - recursive: true, - force: true, - }); - fs.rmSync(`${__dirname}/../packages/sw/node_modules`, { - recursive: true, - force: true, - }); + fs.rmSync(__dirname + '/../packages/sw/built', { recursive: true, force: true }); + fs.rmSync(__dirname + '/../packages/sw/node_modules', { recursive: true, force: true }); - fs.rmSync(`${__dirname}/../built`, { recursive: true, force: true }); - fs.rmSync(`${__dirname}/../node_modules`, { recursive: true, force: true }); + fs.rmSync(__dirname + '/../built', { recursive: true, force: true }); + fs.rmSync(__dirname + '/../node_modules', { recursive: true, force: true }); - execa("pnpm", ["store", "prune"], { - cwd: `${__dirname}/../`, - stdio: "inherit", + execa('pnpm', ['store', 'prune'], { + cwd: __dirname + '/../', + stdio: 'inherit' }); })(); diff --git a/scripts/clean.js b/scripts/clean.js index e052e3defa..70b9d882b5 100644 --- a/scripts/clean.js +++ b/scripts/clean.js @@ -1,17 +1,8 @@ -const fs = require("fs"); +const fs = require('fs'); (async () => { - fs.rmSync(`${__dirname}/../packages/backend/built`, { - recursive: true, - force: true, - }); - fs.rmSync(`${__dirname}/../packages/client/built`, { - recursive: true, - force: true, - }); - fs.rmSync(`${__dirname}/../packages/sw/built`, { - recursive: true, - force: true, - }); - fs.rmSync(`${__dirname}/../built`, { recursive: true, force: true }); + fs.rmSync(__dirname + '/../packages/backend/built', { recursive: true, force: true }); + fs.rmSync(__dirname + '/../packages/client/built', { recursive: true, force: true }); + fs.rmSync(__dirname + '/../packages/sw/built', { recursive: true, force: true }); + fs.rmSync(__dirname + '/../built', { recursive: true, force: true }); })(); diff --git a/scripts/dev.js b/scripts/dev.js index 2a79e9b377..7a61070f5c 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -1,45 +1,45 @@ -const execa = require("execa"); +const execa = require('execa'); (async () => { - await execa("pnpm", ["clean"], { - cwd: `${__dirname}/../`, + await execa('pnpm', ['clean'], { + cwd: __dirname + '/../', stdout: process.stdout, stderr: process.stderr, }); - execa("pnpm", ["dlx", "gulp", "watch"], { - cwd: `${__dirname}/../`, + execa('pnpm', ['dlx', 'gulp', 'watch'], { + cwd: __dirname + '/../', stdout: process.stdout, stderr: process.stderr, }); - execa("pnpm", ["--filter", "backend", "watch"], { - cwd: `${__dirname}/../`, + execa('pnpm', ['--filter', 'backend', 'watch'], { + cwd: __dirname + '/../', stdout: process.stdout, stderr: process.stderr, }); - execa("pnpm", ["--filter", "client", "watch"], { - cwd: `${__dirname}/../`, + execa('pnpm', ['--filter', 'client', 'watch'], { + cwd: __dirname + '/../', stdout: process.stdout, stderr: process.stderr, }); - execa("pnpm", ["--filter", "sw", "watch"], { - cwd: `${__dirname}/../`, + execa('pnpm', ['--filter', 'sw', 'watch'], { + cwd: __dirname + '/../', stdout: process.stdout, stderr: process.stderr, }); const start = async () => { try { - await execa("pnpm", ["start"], { - cwd: `${__dirname}/../`, + await execa('pnpm', ['start'], { + cwd: __dirname + '/../', stdout: process.stdout, stderr: process.stderr, }); } catch (e) { - await new Promise((resolve) => setTimeout(resolve, 3000)); + await new Promise(resolve => setTimeout(resolve, 3000)); start(); } };