diff options
| author | syuilo <4439005+syuilo@users.noreply.github.com> | 2024-11-21 07:58:34 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-21 07:58:34 +0900 |
| commit | f0c3a4cc0b47b392dd155ebabea0d5587df2753d (patch) | |
| tree | 116098b3f4f5013d3656f5c33573d1fb030db3a0 /packages/frontend/src/server-context.ts | |
| parent | feat: 絵文字のポップアップメニューに編集を追加 (#15004) (diff) | |
| download | sharkey-f0c3a4cc0b47b392dd155ebabea0d5587df2753d.tar.gz sharkey-f0c3a4cc0b47b392dd155ebabea0d5587df2753d.tar.bz2 sharkey-f0c3a4cc0b47b392dd155ebabea0d5587df2753d.zip | |
perf(frontend): reduce api requests for non-logged-in enviroment (#15001)
* wip
* Update CHANGELOG.md
* wip
Diffstat (limited to 'packages/frontend/src/server-context.ts')
| -rw-r--r-- | packages/frontend/src/server-context.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/frontend/src/server-context.ts b/packages/frontend/src/server-context.ts new file mode 100644 index 0000000000..aa44a10290 --- /dev/null +++ b/packages/frontend/src/server-context.ts @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ +import * as Misskey from 'misskey-js'; +import { $i } from '@/account.js'; + +const providedContextEl = document.getElementById('misskey_clientCtx'); + +export type ServerContext = { + clip?: Misskey.entities.Clip; + note?: Misskey.entities.Note; + user?: Misskey.entities.UserLite; +} | null; + +export const serverContext: ServerContext = (providedContextEl && providedContextEl.textContent) ? JSON.parse(providedContextEl.textContent) : null; + +export function getServerContext<K extends keyof NonNullable<ServerContext>>(entity: K): Required<Pick<NonNullable<ServerContext>, K>> | null { + // contextは非ログイン状態の情報しかないためログイン時は利用できない + if ($i) return null; + + return serverContext ? (serverContext[entity] ?? null) : null; +} |