From 45672a70f9f8fd932896468f9bfdc6c511013682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:27:33 +0900 Subject: [PATCH 1/8] =?UTF-8?q?fix(frontend):=20router=E9=81=B7=E7=A7=BB?= =?UTF-8?q?=E6=99=82=E3=81=ABmatchAll=E3=81=AB=E5=85=A5=E3=81=A3=E3=81=9F?= =?UTF-8?q?=E5=A0=B4=E5=90=88=E4=B8=80=E5=BA=A6`location.href`=E3=82=92?= =?UTF-8?q?=E7=B5=8C=E7=94=B1=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=20(#13509)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(frontend): router遷移時にmatchAllに入った場合一度`location.href`を経由するように * Update Changelog * Update CHANGELOG.md * remove unnecessary args --- CHANGELOG.md | 2 +- packages/frontend/src/nirax.ts | 20 ++++++++++++-------- packages/frontend/vite.config.local-dev.ts | 3 +++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 349e99d13..0cebaabff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - ### Client -- +- Fix: 一部のページ内リンクが正しく動作しない問題を修正 ### Server - diff --git a/packages/frontend/src/nirax.ts b/packages/frontend/src/nirax.ts index 616fb104e..6a8ea09ed 100644 --- a/packages/frontend/src/nirax.ts +++ b/packages/frontend/src/nirax.ts @@ -373,7 +373,7 @@ export class Router extends EventEmitter implements IRouter { this.currentRoute.value = res.route; this.currentKey = res.route.globalCacheKey ?? key ?? path; - if (emitChange) { + if (emitChange && res.route.path !== '/:(*)') { this.emit('change', { beforePath, path, @@ -408,13 +408,17 @@ export class Router extends EventEmitter implements IRouter { if (cancel) return; } const res = this.navigate(path, null); - this.emit('push', { - beforePath, - path: res._parsedRoute.fullPath, - route: res.route, - props: res.props, - key: this.currentKey, - }); + if (res.route.path === '/:(*)') { + location.href = path; + } else { + this.emit('push', { + beforePath, + path: res._parsedRoute.fullPath, + route: res.route, + props: res.props, + key: this.currentKey, + }); + } } public replace(path: string, key?: string | null) { diff --git a/packages/frontend/vite.config.local-dev.ts b/packages/frontend/vite.config.local-dev.ts index 6d9488797..460787fd0 100644 --- a/packages/frontend/vite.config.local-dev.ts +++ b/packages/frontend/vite.config.local-dev.ts @@ -48,6 +48,9 @@ const devConfig = { }, '/url': httpUrl, '/proxy': httpUrl, + '/_info_card_': httpUrl, + '/bios': httpUrl, + '/cli': httpUrl, }, }, build: { From 08d618bb8b98199a4670313019d6a85ad4cf155b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:06:57 +0900 Subject: [PATCH 2/8] =?UTF-8?q?enhance(frontend):=20=E8=87=AA=E5=88=86?= =?UTF-8?q?=E3=81=AE=E3=83=8E=E3=83=BC=E3=83=88=E3=81=AE=E6=B7=BB=E4=BB=98?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=8B=E3=82=89=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=AE=E8=A9=B3?= =?UTF-8?q?=E7=B4=B0=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=AB=E9=A3=9B=E3=81=B9?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B=20(#1352?= =?UTF-8?q?0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enhance(frontend): 自分のノートの添付ファイルから直接ファイルの詳細ページに飛べるようにする * 他のファイルタイプにも対応 * Update Changelog --------- Co-authored-by: syuilo <4439005+syuilo@users.noreply.github.com> --- CHANGELOG.md | 1 + .../src/core/entities/DriveFileEntityService.ts | 2 +- packages/frontend/src/components/MkMediaAudio.vue | 15 ++++++++++++--- packages/frontend/src/components/MkMediaImage.vue | 9 ++++++++- packages/frontend/src/components/MkMediaVideo.vue | 15 ++++++++++++--- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cebaabff..1b9009427 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - ### Client +- Enhance: 自分のノートの添付ファイルから直接ファイルの詳細ページに飛べるように - Fix: 一部のページ内リンクが正しく動作しない問題を修正 ### Server diff --git a/packages/backend/src/core/entities/DriveFileEntityService.ts b/packages/backend/src/core/entities/DriveFileEntityService.ts index 8affe2b3b..26bf386cb 100644 --- a/packages/backend/src/core/entities/DriveFileEntityService.ts +++ b/packages/backend/src/core/entities/DriveFileEntityService.ts @@ -248,7 +248,7 @@ export class DriveFileEntityService { folder: opts.detail && file.folderId ? this.driveFolderEntityService.pack(file.folderId, { detail: true, }) : null, - userId: opts.withUser ? file.userId : null, + userId: file.userId, user: (opts.withUser && file.userId) ? this.userEntityService.pack(file.userId) : null, }); } diff --git a/packages/frontend/src/components/MkMediaAudio.vue b/packages/frontend/src/components/MkMediaAudio.vue index d42146f94..96c9b9fd6 100644 --- a/packages/frontend/src/components/MkMediaAudio.vue +++ b/packages/frontend/src/components/MkMediaAudio.vue @@ -66,7 +66,7 @@ import * as os from '@/os.js'; import bytes from '@/filters/bytes.js'; import { hms } from '@/filters/hms.js'; import MkMediaRange from '@/components/MkMediaRange.vue'; -import { iAmModerator } from '@/account.js'; +import { $i, iAmModerator } from '@/account.js'; const props = defineProps<{ audio: Misskey.entities.DriveFile; @@ -96,8 +96,6 @@ function showMenu(ev: MouseEvent) { if (iAmModerator) { menu.push({ - type: 'divider', - }, { text: props.audio.isSensitive ? i18n.ts.unmarkAsSensitive : i18n.ts.markAsSensitive, icon: props.audio.isSensitive ? 'ti ti-eye' : 'ti ti-eye-exclamation', danger: true, @@ -105,6 +103,17 @@ function showMenu(ev: MouseEvent) { }); } + if ($i?.id === props.audio.userId) { + menu.push({ + type: 'divider', + }, { + type: 'link' as const, + text: i18n.ts._fileViewer.title, + icon: 'ti ti-info-circle', + to: `/my/drive/file/${props.audio.id}`, + }); + } + menuShowing.value = true; os.popupMenu(menu, ev.currentTarget ?? ev.target, { align: 'right', diff --git a/packages/frontend/src/components/MkMediaImage.vue b/packages/frontend/src/components/MkMediaImage.vue index 4ba2c7613..82f36fe5c 100644 --- a/packages/frontend/src/components/MkMediaImage.vue +++ b/packages/frontend/src/components/MkMediaImage.vue @@ -59,7 +59,7 @@ import ImgWithBlurhash from '@/components/MkImgWithBlurhash.vue'; import { defaultStore } from '@/store.js'; import { i18n } from '@/i18n.js'; import * as os from '@/os.js'; -import { iAmModerator } from '@/account.js'; +import { $i, iAmModerator } from '@/account.js'; const props = withDefaults(defineProps<{ image: Misskey.entities.DriveFile; @@ -114,6 +114,13 @@ function showMenu(ev: MouseEvent) { action: () => { os.apiWithDialog('drive/files/update', { fileId: props.image.id, isSensitive: true }); }, + }] : []), ...($i?.id === props.image.userId ? [{ + type: 'divider' as const, + }, { + type: 'link' as const, + text: i18n.ts._fileViewer.title, + icon: 'ti ti-info-circle', + to: `/my/drive/file/${props.image.id}`, }] : [])], ev.currentTarget ?? ev.target); } diff --git a/packages/frontend/src/components/MkMediaVideo.vue b/packages/frontend/src/components/MkMediaVideo.vue index eab4fdfd6..73c1b6ff9 100644 --- a/packages/frontend/src/components/MkMediaVideo.vue +++ b/packages/frontend/src/components/MkMediaVideo.vue @@ -94,7 +94,7 @@ import * as os from '@/os.js'; import { isFullscreenNotSupported } from '@/scripts/device-kind.js'; import hasAudio from '@/scripts/media-has-audio.js'; import MkMediaRange from '@/components/MkMediaRange.vue'; -import { iAmModerator } from '@/account.js'; +import { $i, iAmModerator } from '@/account.js'; const props = defineProps<{ video: Misskey.entities.DriveFile; @@ -122,8 +122,6 @@ function showMenu(ev: MouseEvent) { if (iAmModerator) { menu.push({ - type: 'divider', - }, { text: props.video.isSensitive ? i18n.ts.unmarkAsSensitive : i18n.ts.markAsSensitive, icon: props.video.isSensitive ? 'ti ti-eye' : 'ti ti-eye-exclamation', danger: true, @@ -131,6 +129,17 @@ function showMenu(ev: MouseEvent) { }); } + if ($i?.id === props.video.userId) { + menu.push({ + type: 'divider', + }, { + type: 'link' as const, + text: i18n.ts._fileViewer.title, + icon: 'ti ti-info-circle', + to: `/my/drive/file/${props.video.id}`, + }); + } + menuShowing.value = true; os.popupMenu(menu, ev.currentTarget ?? ev.target, { align: 'right', From 4457b02db2ca7591afa8683141e4b223170ea367 Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 6 Mar 2024 08:08:32 +0000 Subject: [PATCH 3/8] =?UTF-8?q?fix(frontend)=3F:=20importAppScript?= =?UTF-8?q?=E3=81=AFimport=E3=82=92await=E3=81=99=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/web/boot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/web/boot.js b/packages/backend/src/server/web/boot.js index 59441826b..396536948 100644 --- a/packages/backend/src/server/web/boot.js +++ b/packages/backend/src/server/web/boot.js @@ -86,8 +86,8 @@ //#endregion //#region Script - function importAppScript() { - import(`/vite/${CLIENT_ENTRY}`) + async function importAppScript() { + await import(`/vite/${CLIENT_ENTRY}`) .catch(async e => { console.error(e); renderError('APP_IMPORT', e); From 00c1e4eb550c68f43ae44ba9f0c8da9887fc2180 Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 6 Mar 2024 09:40:47 +0000 Subject: [PATCH 4/8] =?UTF-8?q?perf:=20boot.js=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/web/boot.js | 525 ++++++++++++++---------- 1 file changed, 300 insertions(+), 225 deletions(-) diff --git a/packages/backend/src/server/web/boot.js b/packages/backend/src/server/web/boot.js index 396536948..bc7b800d2 100644 --- a/packages/backend/src/server/web/boot.js +++ b/packages/backend/src/server/web/boot.js @@ -7,17 +7,257 @@ * BOOT LOADER * サーバーからレスポンスされるHTMLに埋め込まれるスクリプトで、以下の役割を持ちます。 * - 翻訳ファイルをフェッチする。 - * - バージョンに基づいて適切なメインスクリプトを読み込む。 + * - 事前に挿入されたCLIENT_ENTRYを読んで適切なメインスクリプトを読み込む。 * - キャッシュされたコンパイル済みテーマを適用する。 * - クライアントの設定値に基づいて対応するHTMLクラス等を設定する。 + * - もしメインスクリプトの読み込みなどでエラーが発生した場合は、renderErrorでエラーを描画する。 * テーマをこの段階で設定するのは、メインスクリプトが読み込まれる間もテーマを適用したいためです。 - * 注: webpackは介さないため、このファイルではrequireやimportは使えません。 */ 'use strict'; +var misskey_loader = new Set(); + // ブロックの中に入れないと、定義した変数がブラウザのグローバルスコープに登録されてしまい邪魔なので -(async () => { +function boot() { + const defaultSolutions = [ + 'Clear the browser cache / ブラウザのキャッシュをクリアする', + 'Update your os and browser / ブラウザおよびOSを最新バージョンに更新する', + 'Disable an adblocker / アドブロッカーを無効にする', + '(Tor Browser) Set dom.webaudio.enabled to true / dom.webaudio.enabledをtrueに設定する' + ]; + + const onErrorStyle = ` + * { + font-family: BIZ UDGothic, Roboto, HelveticaNeue, Arial, sans-serif; + } + + #misskey_app, + #splash { + display: none !important; + } + + body, + html { + background-color: #222; + color: #dfddcc; + justify-content: center; + margin: auto; + padding: 10px; + text-align: center; + } + + button { + border-radius: 999px; + padding: 0px 12px 0px 12px; + border: none; + cursor: pointer; + margin-bottom: 12px; + } + + .button-big { + background: linear-gradient(90deg, rgb(134, 179, 0), rgb(74, 179, 0)); + line-height: 50px; + } + + .button-big:hover { + background: rgb(153, 204, 0); + } + + .button-small { + background: #444; + line-height: 40px; + } + + .button-small:hover { + background: #555; + } + + .button-label-big { + color: #222; + font-weight: bold; + font-size: 1.2em; + padding: 12px; + } + + .button-label-small { + color: rgb(153, 204, 0); + font-size: 16px; + padding: 12px; + } + + a { + color: rgb(134, 179, 0); + text-decoration: none; + } + + p, + li { + font-size: 16px; + } + + .icon-warning { + color: #dec340; + height: 4rem; + padding-top: 2rem; + } + + h1 { + font-size: 1.5em; + margin: 1em; + } + + summary { + cursor: pointer; + } + + code { + font-family: Fira, FiraCode, monospace; + } + + #errors { + display: flex; + flex-direction: column; + align-items: center; + } + + .errorInfo { + background: #333; + width: 40rem; + max-width: 100%; + border-radius: 10px; + justify-content: center; + padding: 1rem; + margin-bottom: 1rem; + box-sizing: border-box; + } + + .errorInfo > pre { + text-wrap: auto; + text-wrap: balance; + } + `; + + + const addStyle = (styleText) => { + try { + let css = document.createElement('style'); + css.appendChild(document.createTextNode(styleText)); + document.head.appendChild(css); + } catch (e) { + console.error(e); + } + } + + const renderError = (code, details, solutions = defaultSolutions) => { + if (document.readyState === 'loading') { + window.addEventListener('DOMContentLoaded', () => { + renderError(code, details, solutions); + }); + try { + addStyle(onErrorStyle); + } catch (e) { } + return; + } + + let errorsElement = document.getElementById('errors'); + + if (!errorsElement) { + // エラー描画用のビューになっていない場合は、エラー描画用のビューに切り替える + document.body.innerHTML = ` + + + + + +

Failed to load
読み込みに失敗しました

+ +

The following actions may solve the problem. / 以下を行うと解決する可能性があります。

+ ${solutions.map(x => `

${x}

`).join('')} +
+ Other options / その他のオプション + + + +
+ + + +
+ + + +
+
+
+ `; + errorsElement = document.getElementById('errors'); + } + + if (typeof details === 'string') { + const errorEl = document.createElement('div'); + errorEl.classList.add('errorInfo'); + + const titleCodeElement = document.createElement('code'); + titleCodeElement.textContent = `ERROR CODE: ${code}`; + errorEl.appendChild(titleCodeElement); + + errorEl.appendChild(document.createElement('br')); + + const detailsCodeElement = document.createElement('code'); + detailsCodeElement.textContent = details; + errorEl.appendChild(detailsCodeElement); + + errorsElement.appendChild(errorEl); + } else if (details instanceof Error) { + const errorEl = document.createElement('details'); + errorEl.classList.add('errorInfo'); + + const summaryElement = document.createElement('summary'); + const titleCodeElement = document.createElement('code'); + titleCodeElement.textContent = `ERROR CODE: ${code}`; + summaryElement.appendChild(titleCodeElement); + errorEl.appendChild(summaryElement); + + const detailsPreElement = document.createElement('pre'); + const detailsMessageElement = document.createElement('code'); + detailsMessageElement.textContent = details.message; + detailsPreElement.appendChild(detailsMessageElement); + detailsPreElement.appendChild(document.createElement('br')); + const detailsCodeElement = document.createElement('code'); + detailsCodeElement.textContent = details.stack; + detailsPreElement.appendChild(detailsCodeElement); + errorEl.appendChild(detailsPreElement); + + errorsElement.appendChild(errorEl); + } else { + const errorEl = document.createElement('details'); + errorEl.classList.add('errorInfo'); + + const summaryElement = document.createElement('summary'); + const titleCodeElement = document.createElement('code'); + titleCodeElement.textContent = `ERROR CODE: ${code}`; + summaryElement.appendChild(titleCodeElement); + errorEl.appendChild(summaryElement); + + const detailsCodeElement = document.createElement('code'); + detailsCodeElement.textContent = JSON.stringify(details); + errorEl.appendChild(detailsCodeElement); + + errorsElement.appendChild(errorEl); + } + + addStyle(onErrorStyle); + } + window.onerror = (e) => { console.error(e); renderError('SOMETHING_HAPPENED', e); @@ -30,63 +270,65 @@ let forceError = localStorage.getItem('forceError'); if (forceError != null) { renderError('FORCED_ERROR', 'This error is forced by having forceError in local storage.') + renderError('FORCED_ERROR', Error('This error is forced by having forceError in local storage.')); + return; } - //#region Detect language & fetch translations - if (!localStorage.hasOwnProperty('locale')) { - const supportedLangs = LANGS; - let lang = localStorage.getItem('lang'); - if (lang == null || !supportedLangs.includes(lang)) { - if (supportedLangs.includes(navigator.language)) { - lang = navigator.language; - } else { - lang = supportedLangs.find(x => x.split('-')[0] === navigator.language); + //#region After DOM loaded + async function oncontentload() { + const providedMetaEl = document.getElementById('misskey_meta'); + const meta = providedMetaEl && providedMetaEl.textContent ? JSON.parse(providedMetaEl.textContent) : null; + const providedAt = providedMetaEl && providedMetaEl.dataset.generatedAt ? parseInt(providedMetaEl.dataset.generatedAt) : 0; + console.log('providedAt', providedAt, 'now', Date.now()); + if (providedAt < Date.now() - 1000 * 60 * 60 * 24) { + // 古いデータがなぜか提供された場合は、エラーを描画する + renderError( + 'META_PROVIDED_AT_TOO_OLD', + 'This view is too old. Please reload.', + [ + 'Reload / リロードする', + 'Clear the browser cache then reload / ブラウザのキャッシュをクリアしてリロードする', + 'Disable an adblocker / アドブロッカーを無効にする', + ] + ); + return; + } - // Fallback - if (lang == null) lang = 'en-US'; + //#region Detect language & fetch translations on first load + if (!localStorage.hasOwnProperty('locale')) { + const supportedLangs = LANGS; + let lang = localStorage.getItem('lang'); + if (lang == null || !supportedLangs.includes(lang)) { + if (supportedLangs.includes(navigator.language)) { + lang = navigator.language; + } else { + lang = supportedLangs.find(x => x.split('-')[0] === navigator.language); + + // Fallback + if (lang == null) lang = 'en-US'; + } + } + + const v = meta?.version; + + // for https://github.com/misskey-dev/misskey/issues/10202 + if (lang == null || lang.toString == null || lang.toString() === 'null') { + console.warn('invalid lang value detected!!!', typeof lang, lang); + lang = 'en-US'; + } + + const localRes = await window.fetch(`/assets/locales/${lang}.${v}.json`); + if (localRes.status === 200) { + localStorage.setItem('lang', lang); + localStorage.setItem('locale', await localRes.text()); + localStorage.setItem('localeVersion', v); + } else { + renderError('LOCALE_FETCH'); + return; } } + //#endregion - const metaRes = await window.fetch('/api/meta', { - method: 'POST', - body: JSON.stringify({}), - credentials: 'omit', - cache: 'no-cache', - headers: { - 'Content-Type': 'application/json', - }, - }); - if (metaRes.status !== 200) { - renderError('META_FETCH'); - return; - } - const meta = await metaRes.json(); - const v = meta.version; - if (v == null) { - renderError('META_FETCH_V'); - return; - } - - // for https://github.com/misskey-dev/misskey/issues/10202 - if (lang == null || lang.toString == null || lang.toString() === 'null') { - console.error('invalid lang value detected!!!', typeof lang, lang); - lang = 'en-US'; - } - - const localRes = await window.fetch(`/assets/locales/${lang}.${v}.json`); - if (localRes.status === 200) { - localStorage.setItem('lang', lang); - localStorage.setItem('locale', await localRes.text()); - localStorage.setItem('localeVersion', v); - } else { - renderError('LOCALE_FETCH'); - return; - } - } - //#endregion - - //#region Script - async function importAppScript() { await import(`/vite/${CLIENT_ENTRY}`) .catch(async e => { console.error(e); @@ -94,12 +336,11 @@ }); } - // タイミングによっては、この時点でDOMの構築が済んでいる場合とそうでない場合とがある if (document.readyState !== 'loading') { - importAppScript(); + misskey_loader.add(oncontentload()); } else { window.addEventListener('DOMContentLoaded', () => { - importAppScript(); + misskey_loader.add(oncontentload()); }); } //#endregion @@ -148,172 +389,6 @@ style.innerHTML = customCss; document.head.appendChild(style); } +} - async function addStyle(styleText) { - let css = document.createElement('style'); - css.appendChild(document.createTextNode(styleText)); - document.head.appendChild(css); - } - - function renderError(code, details) { - let errorsElement = document.getElementById('errors'); - - if (!errorsElement) { - document.body.innerHTML = ` - - - - - -

Failed to load
読み込みに失敗しました

- -

The following actions may solve the problem. / 以下を行うと解決する可能性があります。

-

Clear the browser cache / ブラウザのキャッシュをクリアする

-

Update your os and browser / ブラウザおよびOSを最新バージョンに更新する

-

Disable an adblocker / アドブロッカーを無効にする

-

(Tor Browser) Set dom.webaudio.enabled to true / dom.webaudio.enabledをtrueに設定する

-
- Other options / その他のオプション - - - -
- - - -
- - - -
-
-
- `; - errorsElement = document.getElementById('errors'); - } - const detailsElement = document.createElement('details'); - detailsElement.id = 'errorInfo'; - detailsElement.innerHTML = ` -
- - ERROR CODE: ${code} - - ${JSON.stringify(details)}`; - errorsElement.appendChild(detailsElement); - addStyle(` - * { - font-family: BIZ UDGothic, Roboto, HelveticaNeue, Arial, sans-serif; - } - - #misskey_app, - #splash { - display: none !important; - } - - body, - html { - background-color: #222; - color: #dfddcc; - justify-content: center; - margin: auto; - padding: 10px; - text-align: center; - } - - button { - border-radius: 999px; - padding: 0px 12px 0px 12px; - border: none; - cursor: pointer; - margin-bottom: 12px; - } - - .button-big { - background: linear-gradient(90deg, rgb(134, 179, 0), rgb(74, 179, 0)); - line-height: 50px; - } - - .button-big:hover { - background: rgb(153, 204, 0); - } - - .button-small { - background: #444; - line-height: 40px; - } - - .button-small:hover { - background: #555; - } - - .button-label-big { - color: #222; - font-weight: bold; - font-size: 1.2em; - padding: 12px; - } - - .button-label-small { - color: rgb(153, 204, 0); - font-size: 16px; - padding: 12px; - } - - a { - color: rgb(134, 179, 0); - text-decoration: none; - } - - p, - li { - font-size: 16px; - } - - .icon-warning { - color: #dec340; - height: 4rem; - padding-top: 2rem; - } - - h1 { - font-size: 1.5em; - margin: 1em; - } - - code { - font-family: Fira, FiraCode, monospace; - } - - #errorInfo { - background: #333; - margin-bottom: 2rem; - padding: 0.5rem 1rem; - width: 40rem; - border-radius: 10px; - justify-content: center; - margin: auto; - } - - #errorInfo summary { - cursor: pointer; - } - - #errorInfo summary > * { - display: inline; - } - - @media screen and (max-width: 500px) { - #errorInfo { - width: 50%; - } - `) - } -})(); +boot(); From 62922352b3cddaee9f72261448d862002e55a67c Mon Sep 17 00:00:00 2001 From: tamaina Date: Wed, 6 Mar 2024 09:49:01 +0000 Subject: [PATCH 5/8] =?UTF-8?q?Revert=20"perf:=20boot.js=E3=81=AE=E8=AA=BF?= =?UTF-8?q?=E6=95=B4"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 00c1e4eb550c68f43ae44ba9f0c8da9887fc2180. --- packages/backend/src/server/web/boot.js | 523 ++++++++++-------------- 1 file changed, 224 insertions(+), 299 deletions(-) diff --git a/packages/backend/src/server/web/boot.js b/packages/backend/src/server/web/boot.js index bc7b800d2..396536948 100644 --- a/packages/backend/src/server/web/boot.js +++ b/packages/backend/src/server/web/boot.js @@ -7,257 +7,17 @@ * BOOT LOADER * サーバーからレスポンスされるHTMLに埋め込まれるスクリプトで、以下の役割を持ちます。 * - 翻訳ファイルをフェッチする。 - * - 事前に挿入されたCLIENT_ENTRYを読んで適切なメインスクリプトを読み込む。 + * - バージョンに基づいて適切なメインスクリプトを読み込む。 * - キャッシュされたコンパイル済みテーマを適用する。 * - クライアントの設定値に基づいて対応するHTMLクラス等を設定する。 - * - もしメインスクリプトの読み込みなどでエラーが発生した場合は、renderErrorでエラーを描画する。 * テーマをこの段階で設定するのは、メインスクリプトが読み込まれる間もテーマを適用したいためです。 + * 注: webpackは介さないため、このファイルではrequireやimportは使えません。 */ 'use strict'; -var misskey_loader = new Set(); - // ブロックの中に入れないと、定義した変数がブラウザのグローバルスコープに登録されてしまい邪魔なので -function boot() { - const defaultSolutions = [ - 'Clear the browser cache / ブラウザのキャッシュをクリアする', - 'Update your os and browser / ブラウザおよびOSを最新バージョンに更新する', - 'Disable an adblocker / アドブロッカーを無効にする', - '(Tor Browser) Set dom.webaudio.enabled to true / dom.webaudio.enabledをtrueに設定する' - ]; - - const onErrorStyle = ` - * { - font-family: BIZ UDGothic, Roboto, HelveticaNeue, Arial, sans-serif; - } - - #misskey_app, - #splash { - display: none !important; - } - - body, - html { - background-color: #222; - color: #dfddcc; - justify-content: center; - margin: auto; - padding: 10px; - text-align: center; - } - - button { - border-radius: 999px; - padding: 0px 12px 0px 12px; - border: none; - cursor: pointer; - margin-bottom: 12px; - } - - .button-big { - background: linear-gradient(90deg, rgb(134, 179, 0), rgb(74, 179, 0)); - line-height: 50px; - } - - .button-big:hover { - background: rgb(153, 204, 0); - } - - .button-small { - background: #444; - line-height: 40px; - } - - .button-small:hover { - background: #555; - } - - .button-label-big { - color: #222; - font-weight: bold; - font-size: 1.2em; - padding: 12px; - } - - .button-label-small { - color: rgb(153, 204, 0); - font-size: 16px; - padding: 12px; - } - - a { - color: rgb(134, 179, 0); - text-decoration: none; - } - - p, - li { - font-size: 16px; - } - - .icon-warning { - color: #dec340; - height: 4rem; - padding-top: 2rem; - } - - h1 { - font-size: 1.5em; - margin: 1em; - } - - summary { - cursor: pointer; - } - - code { - font-family: Fira, FiraCode, monospace; - } - - #errors { - display: flex; - flex-direction: column; - align-items: center; - } - - .errorInfo { - background: #333; - width: 40rem; - max-width: 100%; - border-radius: 10px; - justify-content: center; - padding: 1rem; - margin-bottom: 1rem; - box-sizing: border-box; - } - - .errorInfo > pre { - text-wrap: auto; - text-wrap: balance; - } - `; - - - const addStyle = (styleText) => { - try { - let css = document.createElement('style'); - css.appendChild(document.createTextNode(styleText)); - document.head.appendChild(css); - } catch (e) { - console.error(e); - } - } - - const renderError = (code, details, solutions = defaultSolutions) => { - if (document.readyState === 'loading') { - window.addEventListener('DOMContentLoaded', () => { - renderError(code, details, solutions); - }); - try { - addStyle(onErrorStyle); - } catch (e) { } - return; - } - - let errorsElement = document.getElementById('errors'); - - if (!errorsElement) { - // エラー描画用のビューになっていない場合は、エラー描画用のビューに切り替える - document.body.innerHTML = ` - - - - - -

Failed to load
読み込みに失敗しました

- -

The following actions may solve the problem. / 以下を行うと解決する可能性があります。

- ${solutions.map(x => `

${x}

`).join('')} -
- Other options / その他のオプション - - - -
- - - -
- - - -
-
-
- `; - errorsElement = document.getElementById('errors'); - } - - if (typeof details === 'string') { - const errorEl = document.createElement('div'); - errorEl.classList.add('errorInfo'); - - const titleCodeElement = document.createElement('code'); - titleCodeElement.textContent = `ERROR CODE: ${code}`; - errorEl.appendChild(titleCodeElement); - - errorEl.appendChild(document.createElement('br')); - - const detailsCodeElement = document.createElement('code'); - detailsCodeElement.textContent = details; - errorEl.appendChild(detailsCodeElement); - - errorsElement.appendChild(errorEl); - } else if (details instanceof Error) { - const errorEl = document.createElement('details'); - errorEl.classList.add('errorInfo'); - - const summaryElement = document.createElement('summary'); - const titleCodeElement = document.createElement('code'); - titleCodeElement.textContent = `ERROR CODE: ${code}`; - summaryElement.appendChild(titleCodeElement); - errorEl.appendChild(summaryElement); - - const detailsPreElement = document.createElement('pre'); - const detailsMessageElement = document.createElement('code'); - detailsMessageElement.textContent = details.message; - detailsPreElement.appendChild(detailsMessageElement); - detailsPreElement.appendChild(document.createElement('br')); - const detailsCodeElement = document.createElement('code'); - detailsCodeElement.textContent = details.stack; - detailsPreElement.appendChild(detailsCodeElement); - errorEl.appendChild(detailsPreElement); - - errorsElement.appendChild(errorEl); - } else { - const errorEl = document.createElement('details'); - errorEl.classList.add('errorInfo'); - - const summaryElement = document.createElement('summary'); - const titleCodeElement = document.createElement('code'); - titleCodeElement.textContent = `ERROR CODE: ${code}`; - summaryElement.appendChild(titleCodeElement); - errorEl.appendChild(summaryElement); - - const detailsCodeElement = document.createElement('code'); - detailsCodeElement.textContent = JSON.stringify(details); - errorEl.appendChild(detailsCodeElement); - - errorsElement.appendChild(errorEl); - } - - addStyle(onErrorStyle); - } - +(async () => { window.onerror = (e) => { console.error(e); renderError('SOMETHING_HAPPENED', e); @@ -270,65 +30,63 @@ function boot() { let forceError = localStorage.getItem('forceError'); if (forceError != null) { renderError('FORCED_ERROR', 'This error is forced by having forceError in local storage.') - renderError('FORCED_ERROR', Error('This error is forced by having forceError in local storage.')); - return; } - //#region After DOM loaded - async function oncontentload() { - const providedMetaEl = document.getElementById('misskey_meta'); - const meta = providedMetaEl && providedMetaEl.textContent ? JSON.parse(providedMetaEl.textContent) : null; - const providedAt = providedMetaEl && providedMetaEl.dataset.generatedAt ? parseInt(providedMetaEl.dataset.generatedAt) : 0; - console.log('providedAt', providedAt, 'now', Date.now()); - if (providedAt < Date.now() - 1000 * 60 * 60 * 24) { - // 古いデータがなぜか提供された場合は、エラーを描画する - renderError( - 'META_PROVIDED_AT_TOO_OLD', - 'This view is too old. Please reload.', - [ - 'Reload / リロードする', - 'Clear the browser cache then reload / ブラウザのキャッシュをクリアしてリロードする', - 'Disable an adblocker / アドブロッカーを無効にする', - ] - ); + //#region Detect language & fetch translations + if (!localStorage.hasOwnProperty('locale')) { + const supportedLangs = LANGS; + let lang = localStorage.getItem('lang'); + if (lang == null || !supportedLangs.includes(lang)) { + if (supportedLangs.includes(navigator.language)) { + lang = navigator.language; + } else { + lang = supportedLangs.find(x => x.split('-')[0] === navigator.language); + + // Fallback + if (lang == null) lang = 'en-US'; + } + } + + const metaRes = await window.fetch('/api/meta', { + method: 'POST', + body: JSON.stringify({}), + credentials: 'omit', + cache: 'no-cache', + headers: { + 'Content-Type': 'application/json', + }, + }); + if (metaRes.status !== 200) { + renderError('META_FETCH'); + return; + } + const meta = await metaRes.json(); + const v = meta.version; + if (v == null) { + renderError('META_FETCH_V'); return; } - //#region Detect language & fetch translations on first load - if (!localStorage.hasOwnProperty('locale')) { - const supportedLangs = LANGS; - let lang = localStorage.getItem('lang'); - if (lang == null || !supportedLangs.includes(lang)) { - if (supportedLangs.includes(navigator.language)) { - lang = navigator.language; - } else { - lang = supportedLangs.find(x => x.split('-')[0] === navigator.language); - - // Fallback - if (lang == null) lang = 'en-US'; - } - } - - const v = meta?.version; - - // for https://github.com/misskey-dev/misskey/issues/10202 - if (lang == null || lang.toString == null || lang.toString() === 'null') { - console.warn('invalid lang value detected!!!', typeof lang, lang); - lang = 'en-US'; - } - - const localRes = await window.fetch(`/assets/locales/${lang}.${v}.json`); - if (localRes.status === 200) { - localStorage.setItem('lang', lang); - localStorage.setItem('locale', await localRes.text()); - localStorage.setItem('localeVersion', v); - } else { - renderError('LOCALE_FETCH'); - return; - } + // for https://github.com/misskey-dev/misskey/issues/10202 + if (lang == null || lang.toString == null || lang.toString() === 'null') { + console.error('invalid lang value detected!!!', typeof lang, lang); + lang = 'en-US'; } - //#endregion + const localRes = await window.fetch(`/assets/locales/${lang}.${v}.json`); + if (localRes.status === 200) { + localStorage.setItem('lang', lang); + localStorage.setItem('locale', await localRes.text()); + localStorage.setItem('localeVersion', v); + } else { + renderError('LOCALE_FETCH'); + return; + } + } + //#endregion + + //#region Script + async function importAppScript() { await import(`/vite/${CLIENT_ENTRY}`) .catch(async e => { console.error(e); @@ -336,11 +94,12 @@ function boot() { }); } + // タイミングによっては、この時点でDOMの構築が済んでいる場合とそうでない場合とがある if (document.readyState !== 'loading') { - misskey_loader.add(oncontentload()); + importAppScript(); } else { window.addEventListener('DOMContentLoaded', () => { - misskey_loader.add(oncontentload()); + importAppScript(); }); } //#endregion @@ -389,6 +148,172 @@ function boot() { style.innerHTML = customCss; document.head.appendChild(style); } -} -boot(); + async function addStyle(styleText) { + let css = document.createElement('style'); + css.appendChild(document.createTextNode(styleText)); + document.head.appendChild(css); + } + + function renderError(code, details) { + let errorsElement = document.getElementById('errors'); + + if (!errorsElement) { + document.body.innerHTML = ` + + + + + +

Failed to load
読み込みに失敗しました

+ +

The following actions may solve the problem. / 以下を行うと解決する可能性があります。

+

Clear the browser cache / ブラウザのキャッシュをクリアする

+

Update your os and browser / ブラウザおよびOSを最新バージョンに更新する

+

Disable an adblocker / アドブロッカーを無効にする

+

(Tor Browser) Set dom.webaudio.enabled to true / dom.webaudio.enabledをtrueに設定する

+
+ Other options / その他のオプション + + + +
+ + + +
+ + + +
+
+
+ `; + errorsElement = document.getElementById('errors'); + } + const detailsElement = document.createElement('details'); + detailsElement.id = 'errorInfo'; + detailsElement.innerHTML = ` +
+ + ERROR CODE: ${code} + + ${JSON.stringify(details)}`; + errorsElement.appendChild(detailsElement); + addStyle(` + * { + font-family: BIZ UDGothic, Roboto, HelveticaNeue, Arial, sans-serif; + } + + #misskey_app, + #splash { + display: none !important; + } + + body, + html { + background-color: #222; + color: #dfddcc; + justify-content: center; + margin: auto; + padding: 10px; + text-align: center; + } + + button { + border-radius: 999px; + padding: 0px 12px 0px 12px; + border: none; + cursor: pointer; + margin-bottom: 12px; + } + + .button-big { + background: linear-gradient(90deg, rgb(134, 179, 0), rgb(74, 179, 0)); + line-height: 50px; + } + + .button-big:hover { + background: rgb(153, 204, 0); + } + + .button-small { + background: #444; + line-height: 40px; + } + + .button-small:hover { + background: #555; + } + + .button-label-big { + color: #222; + font-weight: bold; + font-size: 1.2em; + padding: 12px; + } + + .button-label-small { + color: rgb(153, 204, 0); + font-size: 16px; + padding: 12px; + } + + a { + color: rgb(134, 179, 0); + text-decoration: none; + } + + p, + li { + font-size: 16px; + } + + .icon-warning { + color: #dec340; + height: 4rem; + padding-top: 2rem; + } + + h1 { + font-size: 1.5em; + margin: 1em; + } + + code { + font-family: Fira, FiraCode, monospace; + } + + #errorInfo { + background: #333; + margin-bottom: 2rem; + padding: 0.5rem 1rem; + width: 40rem; + border-radius: 10px; + justify-content: center; + margin: auto; + } + + #errorInfo summary { + cursor: pointer; + } + + #errorInfo summary > * { + display: inline; + } + + @media screen and (max-width: 500px) { + #errorInfo { + width: 50%; + } + `) + } +})(); From 7ead98cbe592e6911e4a54550cb7bb507e782d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Wed, 6 Mar 2024 21:08:42 +0900 Subject: [PATCH 6/8] =?UTF-8?q?enhance(frontend):=20=E3=83=AA=E3=82=A2?= =?UTF-8?q?=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=AE=E7=B7=8F=E6=95=B0?= =?UTF-8?q?=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=20(#13532)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enhance(frontend): リアクションの総数を表示するように * Update Changelog * リアクション選択済の色をaccentに --- CHANGELOG.md | 2 ++ locales/index.d.ts | 4 +++ locales/ja-JP.yml | 1 + .../src/core/entities/NoteEntityService.ts | 1 + .../backend/src/models/json-schema/note.ts | 4 +++ packages/frontend/src/components/MkNote.vue | 25 ++++++++++----- .../src/components/MkNoteDetailed.vue | 31 ++++++++++++------- .../src/components/MkNotification.vue | 27 ++++++++++------ .../src/components/MkTutorialDialog.Note.vue | 1 + .../components/MkTutorialDialog.PostNote.vue | 1 + .../components/MkTutorialDialog.Sensitive.vue | 1 + .../frontend/src/scripts/use-note-capture.ts | 2 ++ packages/frontend/src/style.scss | 7 +++++ packages/misskey-js/src/autogen/types.ts | 1 + 14 files changed, 79 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b9009427..7bdfa53e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ ### Client - Enhance: 自分のノートの添付ファイルから直接ファイルの詳細ページに飛べるように +- Enhance: リアクション・いいねの総数を表示するように +- Enhance: リアクション受け入れが「いいねのみ」の場合はリアクション絵文字一覧を表示しないように - Fix: 一部のページ内リンクが正しく動作しない問題を修正 ### Server diff --git a/locales/index.d.ts b/locales/index.d.ts index c1aa163f9..3ac4ff9e7 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -8909,6 +8909,10 @@ export interface Locale extends ILocale { * {n}人がリアクションしました */ "reactedBySomeUsers": ParameterizedString<"n">; + /** + * {n}人がいいねしました + */ + "likedBySomeUsers": ParameterizedString<"n">; /** * {n}人がリノートしました */ diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 51380e49c..177d6a06c 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -2355,6 +2355,7 @@ _notification: sendTestNotification: "テスト通知を送信する" notificationWillBeDisplayedLikeThis: "通知はこのように表示されます" reactedBySomeUsers: "{n}人がリアクションしました" + likedBySomeUsers: "{n}人がいいねしました" renotedBySomeUsers: "{n}人がリノートしました" followedBySomeUsers: "{n}人にフォローされました" flushNotification: "通知の履歴をリセットする" diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts index 5b6affc6a..22d01462e 100644 --- a/packages/backend/src/core/entities/NoteEntityService.ts +++ b/packages/backend/src/core/entities/NoteEntityService.ts @@ -333,6 +333,7 @@ export class NoteEntityService implements OnModuleInit { visibleUserIds: note.visibility === 'specified' ? note.visibleUserIds : undefined, renoteCount: note.renoteCount, repliesCount: note.repliesCount, + reactionCount: Object.values(note.reactions).reduce((a, b) => a + b, 0), reactions: this.reactionService.convertLegacyReactions(note.reactions), reactionEmojis: this.customEmojiService.populateEmojis(reactionEmojiNames, host), reactionAndUserPairCache: opts.withReactionAndUserPairCache ? note.reactionAndUserPairCache : undefined, diff --git a/packages/backend/src/models/json-schema/note.ts b/packages/backend/src/models/json-schema/note.ts index bb4ccc7ee..2641161c8 100644 --- a/packages/backend/src/models/json-schema/note.ts +++ b/packages/backend/src/models/json-schema/note.ts @@ -223,6 +223,10 @@ export const packedNoteSchema = { }], }, }, + reactionCount: { + type: 'number', + optional: false, nullable: false, + }, renoteCount: { type: 'number', optional: false, nullable: false, diff --git a/packages/frontend/src/components/MkNote.vue b/packages/frontend/src/components/MkNote.vue index 03a283cab..656ccc795 100644 --- a/packages/frontend/src/components/MkNote.vue +++ b/packages/frontend/src/components/MkNote.vue @@ -93,7 +93,7 @@ SPDX-License-Identifier: AGPL-3.0-only {{ appearNote.channel.name }} - + @@ -101,7 +101,7 @@ SPDX-License-Identifier: AGPL-3.0-only