summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts
diff options
context:
space:
mode:
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>2024-09-10 18:39:53 +0900
committerGitHub <noreply@github.com>2024-09-10 18:39:53 +0900
commit837a8e15d893a670ab2ce51b3ec87e6b62a51da7 (patch)
tree0b651782db2bf440f1c789606d6367226f2e2253 /packages/frontend/src/scripts
parentDev: cypressをdev containerで実行可に(e2e-dev-container) (#14526) (diff)
downloadsharkey-837a8e15d893a670ab2ce51b3ec87e6b62a51da7.tar.gz
sharkey-837a8e15d893a670ab2ce51b3ec87e6b62a51da7.tar.bz2
sharkey-837a8e15d893a670ab2ce51b3ec87e6b62a51da7.zip
refactor(frontend): frontend-embed/src/to-be-sharedを共通化 (#14536)
* refactor(frontend): shouldCollapsedを共通化 * refactor(frontend): config.js, worker-multi-dispatch.js, intl-const.jsを共通化 * fix(frontend-shared): fix type error * refactor(frontend): is-link.jsと、同一の振る舞いをする記述を共通化 * fix * fix lint * lint fixes
Diffstat (limited to 'packages/frontend/src/scripts')
-rw-r--r--packages/frontend/src/scripts/aiscript/api.ts2
-rw-r--r--packages/frontend/src/scripts/collapsed.ts22
-rw-r--r--packages/frontend/src/scripts/gen-search-query.ts2
-rw-r--r--packages/frontend/src/scripts/get-embed-code.ts2
-rw-r--r--packages/frontend/src/scripts/get-note-menu.ts2
-rw-r--r--packages/frontend/src/scripts/get-user-menu.ts2
-rw-r--r--packages/frontend/src/scripts/initialize-sw.ts2
-rw-r--r--packages/frontend/src/scripts/intl-const.ts2
-rw-r--r--packages/frontend/src/scripts/is-link.ts12
-rw-r--r--packages/frontend/src/scripts/media-proxy.ts2
-rw-r--r--packages/frontend/src/scripts/misskey-api.ts2
-rw-r--r--packages/frontend/src/scripts/player-url-transform.ts2
-rw-r--r--packages/frontend/src/scripts/popout.ts2
-rw-r--r--packages/frontend/src/scripts/upload.ts2
-rw-r--r--packages/frontend/src/scripts/worker-multi-dispatch.ts82
15 files changed, 12 insertions, 128 deletions
diff --git a/packages/frontend/src/scripts/aiscript/api.ts b/packages/frontend/src/scripts/aiscript/api.ts
index 417ba08c3f..46aed49330 100644
--- a/packages/frontend/src/scripts/aiscript/api.ts
+++ b/packages/frontend/src/scripts/aiscript/api.ts
@@ -10,7 +10,7 @@ import { misskeyApi } from '@/scripts/misskey-api.js';
import { $i } from '@/account.js';
import { miLocalStorage } from '@/local-storage.js';
import { customEmojis } from '@/custom-emojis.js';
-import { url, lang } from '@/config.js';
+import { url, lang } from '@@/js/config.js';
export function aiScriptReadline(q: string): Promise<string> {
return new Promise(ok => {
diff --git a/packages/frontend/src/scripts/collapsed.ts b/packages/frontend/src/scripts/collapsed.ts
deleted file mode 100644
index 4ec88a3c65..0000000000
--- a/packages/frontend/src/scripts/collapsed.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * SPDX-FileCopyrightText: syuilo and misskey-project
- * SPDX-License-Identifier: AGPL-3.0-only
- */
-
-import * as Misskey from 'misskey-js';
-
-export function shouldCollapsed(note: Misskey.entities.Note, urls: string[]): boolean {
- const collapsed = note.cw == null && (
- note.text != null && (
- (note.text.includes('$[x2')) ||
- (note.text.includes('$[x3')) ||
- (note.text.includes('$[x4')) ||
- (note.text.includes('$[scale')) ||
- (note.text.split('\n').length > 9) ||
- (note.text.length > 500) ||
- (urls.length >= 4)
- ) || note.files.length >= 5
- );
-
- return collapsed;
-}
diff --git a/packages/frontend/src/scripts/gen-search-query.ts b/packages/frontend/src/scripts/gen-search-query.ts
index 60884d08d3..a85ee01e26 100644
--- a/packages/frontend/src/scripts/gen-search-query.ts
+++ b/packages/frontend/src/scripts/gen-search-query.ts
@@ -4,7 +4,7 @@
*/
import * as Misskey from 'misskey-js';
-import { host as localHost } from '@/config.js';
+import { host as localHost } from '@@/js/config.js';
export async function genSearchQuery(v: any, q: string) {
let host: string;
diff --git a/packages/frontend/src/scripts/get-embed-code.ts b/packages/frontend/src/scripts/get-embed-code.ts
index 007cd6561b..158ab9c7f8 100644
--- a/packages/frontend/src/scripts/get-embed-code.ts
+++ b/packages/frontend/src/scripts/get-embed-code.ts
@@ -5,7 +5,7 @@
import { defineAsyncComponent } from 'vue';
import { v4 as uuid } from 'uuid';
import type { EmbedParams, EmbeddableEntity } from '@@/js/embed-page.js';
-import { url } from '@/config.js';
+import { url } from '@@/js/config.js';
import * as os from '@/os.js';
import { copyToClipboard } from '@/scripts/copy-to-clipboard.js';
import { defaultEmbedParams, embedRouteWithScrollbar } from '@@/js/embed-page.js';
diff --git a/packages/frontend/src/scripts/get-note-menu.ts b/packages/frontend/src/scripts/get-note-menu.ts
index e0ccea813d..49f3199887 100644
--- a/packages/frontend/src/scripts/get-note-menu.ts
+++ b/packages/frontend/src/scripts/get-note-menu.ts
@@ -12,7 +12,7 @@ import { instance } from '@/instance.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { copyToClipboard } from '@/scripts/copy-to-clipboard.js';
-import { url } from '@/config.js';
+import { url } from '@@/js/config.js';
import { defaultStore, noteActions } from '@/store.js';
import { miLocalStorage } from '@/local-storage.js';
import { getUserMenu } from '@/scripts/get-user-menu.js';
diff --git a/packages/frontend/src/scripts/get-user-menu.ts b/packages/frontend/src/scripts/get-user-menu.ts
index 035abc7bd0..33316b4ab6 100644
--- a/packages/frontend/src/scripts/get-user-menu.ts
+++ b/packages/frontend/src/scripts/get-user-menu.ts
@@ -8,7 +8,7 @@ import { defineAsyncComponent, ref, watch } from 'vue';
import * as Misskey from 'misskey-js';
import { i18n } from '@/i18n.js';
import { copyToClipboard } from '@/scripts/copy-to-clipboard.js';
-import { host, url } from '@/config.js';
+import { host, url } from '@@/js/config.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { defaultStore, userActions } from '@/store.js';
diff --git a/packages/frontend/src/scripts/initialize-sw.ts b/packages/frontend/src/scripts/initialize-sw.ts
index 1517e4e1e8..867ebf19ed 100644
--- a/packages/frontend/src/scripts/initialize-sw.ts
+++ b/packages/frontend/src/scripts/initialize-sw.ts
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { lang } from '@/config.js';
+import { lang } from '@@/js/config.js';
export async function initializeSw() {
if (!('serviceWorker' in navigator)) return;
diff --git a/packages/frontend/src/scripts/intl-const.ts b/packages/frontend/src/scripts/intl-const.ts
index aaa4f0a86e..385f59ec39 100644
--- a/packages/frontend/src/scripts/intl-const.ts
+++ b/packages/frontend/src/scripts/intl-const.ts
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { lang } from '@/config.js';
+import { lang } from '@@/js/config.js';
export const versatileLang = (lang ?? 'ja-JP').replace('ja-KS', 'ja-JP');
diff --git a/packages/frontend/src/scripts/is-link.ts b/packages/frontend/src/scripts/is-link.ts
deleted file mode 100644
index 946f86400e..0000000000
--- a/packages/frontend/src/scripts/is-link.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * SPDX-FileCopyrightText: syuilo and misskey-project
- * SPDX-License-Identifier: AGPL-3.0-only
- */
-
-export function isLink(el: HTMLElement) {
- if (el.tagName === 'A') return true;
- if (el.parentElement) {
- return isLink(el.parentElement);
- }
- return false;
-}
diff --git a/packages/frontend/src/scripts/media-proxy.ts b/packages/frontend/src/scripts/media-proxy.ts
index 68a5a1dcf8..78eba35ead 100644
--- a/packages/frontend/src/scripts/media-proxy.ts
+++ b/packages/frontend/src/scripts/media-proxy.ts
@@ -4,7 +4,7 @@
*/
import { MediaProxy } from '@@/js/media-proxy.js';
-import { url } from '@/config.js';
+import { url } from '@@/js/config.js';
import { instance } from '@/instance.js';
let _mediaProxy: MediaProxy | null = null;
diff --git a/packages/frontend/src/scripts/misskey-api.ts b/packages/frontend/src/scripts/misskey-api.ts
index 49fb6f9e59..1b1159fd01 100644
--- a/packages/frontend/src/scripts/misskey-api.ts
+++ b/packages/frontend/src/scripts/misskey-api.ts
@@ -5,7 +5,7 @@
import * as Misskey from 'misskey-js';
import { ref } from 'vue';
-import { apiUrl } from '@/config.js';
+import { apiUrl } from '@@/js/config.js';
import { $i } from '@/account.js';
export const pendingApiRequestsCount = ref(0);
diff --git a/packages/frontend/src/scripts/player-url-transform.ts b/packages/frontend/src/scripts/player-url-transform.ts
index 53b2a9e441..39c6df6500 100644
--- a/packages/frontend/src/scripts/player-url-transform.ts
+++ b/packages/frontend/src/scripts/player-url-transform.ts
@@ -2,7 +2,7 @@
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { hostname } from '@/config.js';
+import { hostname } from '@@/js/config.js';
export function transformPlayerUrl(url: string): string {
const urlObj = new URL(url);
diff --git a/packages/frontend/src/scripts/popout.ts b/packages/frontend/src/scripts/popout.ts
index ed49611b4f..5b141222e8 100644
--- a/packages/frontend/src/scripts/popout.ts
+++ b/packages/frontend/src/scripts/popout.ts
@@ -4,7 +4,7 @@
*/
import { appendQuery } from '@@/js/url.js';
-import * as config from '@/config.js';
+import * as config from '@@/js/config.js';
export function popout(path: string, w?: HTMLElement) {
let url = path.startsWith('http://') || path.startsWith('https://') ? path : config.url + path;
diff --git a/packages/frontend/src/scripts/upload.ts b/packages/frontend/src/scripts/upload.ts
index abb0e1e677..22dce609c6 100644
--- a/packages/frontend/src/scripts/upload.ts
+++ b/packages/frontend/src/scripts/upload.ts
@@ -9,7 +9,7 @@ import { v4 as uuid } from 'uuid';
import { readAndCompressImage } from '@misskey-dev/browser-image-resizer';
import { getCompressionConfig } from './upload/compress-config.js';
import { defaultStore } from '@/store.js';
-import { apiUrl } from '@/config.js';
+import { apiUrl } from '@@/js/config.js';
import { $i } from '@/account.js';
import { alert } from '@/os.js';
import { i18n } from '@/i18n.js';
diff --git a/packages/frontend/src/scripts/worker-multi-dispatch.ts b/packages/frontend/src/scripts/worker-multi-dispatch.ts
deleted file mode 100644
index 6b3fcd9383..0000000000
--- a/packages/frontend/src/scripts/worker-multi-dispatch.ts
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * SPDX-FileCopyrightText: syuilo and misskey-project
- * SPDX-License-Identifier: AGPL-3.0-only
- */
-
-function defaultUseWorkerNumber(prev: number, totalWorkers: number) {
- return prev + 1;
-}
-
-export class WorkerMultiDispatch<POST = any, RETURN = any> {
- private symbol = Symbol('WorkerMultiDispatch');
- private workers: Worker[] = [];
- private terminated = false;
- private prevWorkerNumber = 0;
- private getUseWorkerNumber = defaultUseWorkerNumber;
- private finalizationRegistry: FinalizationRegistry<symbol>;
-
- constructor(workerConstructor: () => Worker, concurrency: number, getUseWorkerNumber = defaultUseWorkerNumber) {
- this.getUseWorkerNumber = getUseWorkerNumber;
- for (let i = 0; i < concurrency; i++) {
- this.workers.push(workerConstructor());
- }
-
- this.finalizationRegistry = new FinalizationRegistry(() => {
- this.terminate();
- });
- this.finalizationRegistry.register(this, this.symbol);
-
- if (_DEV_) console.log('WorkerMultiDispatch: Created', this);
- }
-
- public postMessage(message: POST, options?: Transferable[] | StructuredSerializeOptions, useWorkerNumber: typeof defaultUseWorkerNumber = this.getUseWorkerNumber) {
- let workerNumber = useWorkerNumber(this.prevWorkerNumber, this.workers.length);
- workerNumber = Math.abs(Math.round(workerNumber)) % this.workers.length;
- if (_DEV_) console.log('WorkerMultiDispatch: Posting message to worker', workerNumber, useWorkerNumber);
- this.prevWorkerNumber = workerNumber;
-
- // 不毛だがunionをoverloadに突っ込めない
- // https://stackoverflow.com/questions/66507585/overload-signatures-union-types-and-no-overload-matches-this-call-error
- // https://github.com/microsoft/TypeScript/issues/14107
- if (Array.isArray(options)) {
- this.workers[workerNumber].postMessage(message, options);
- } else {
- this.workers[workerNumber].postMessage(message, options);
- }
- return workerNumber;
- }
-
- public addListener(callback: (this: Worker, ev: MessageEvent<RETURN>) => any, options?: boolean | AddEventListenerOptions) {
- this.workers.forEach(worker => {
- worker.addEventListener('message', callback, options);
- });
- }
-
- public removeListener(callback: (this: Worker, ev: MessageEvent<RETURN>) => any, options?: boolean | AddEventListenerOptions) {
- this.workers.forEach(worker => {
- worker.removeEventListener('message', callback, options);
- });
- }
-
- public terminate() {
- this.terminated = true;
- if (_DEV_) console.log('WorkerMultiDispatch: Terminating', this);
- this.workers.forEach(worker => {
- worker.terminate();
- });
- this.workers = [];
- this.finalizationRegistry.unregister(this);
- }
-
- public isTerminated() {
- return this.terminated;
- }
-
- public getWorkers() {
- return this.workers;
- }
-
- public getSymbol() {
- return this.symbol;
- }
-}