mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-23 00:29:22 +09:00
fix(frontend): serverContextの型エラーを修正 (#15131)
Some checks failed
Lint / lint (misskey-js) (push) Has been cancelled
API report (misskey.js) / report (push) Has been cancelled
Check SPDX-License-Identifier / check-spdx-license-id (push) Has been cancelled
Check copyright year / check_copyright_year (push) Has been cancelled
Publish Docker image (develop) / Build (linux/amd64) (push) Has been cancelled
Publish Docker image (develop) / Build (linux/arm64) (push) Has been cancelled
Publish Docker image (develop) / merge (push) Has been cancelled
Lint / lint (misskey-reversi) (push) Has been cancelled
Dockle / dockle (push) Has been cancelled
Lint / pnpm_install (push) Has been cancelled
Lint / lint (backend) (push) Has been cancelled
Lint / lint (frontend) (push) Has been cancelled
Lint / lint (frontend-embed) (push) Has been cancelled
Lint / lint (frontend-shared) (push) Has been cancelled
Lint / lint (misskey-bubble-game) (push) Has been cancelled
Lint / lint (sw) (push) Has been cancelled
Lint / typecheck (backend) (push) Has been cancelled
Lint / typecheck (misskey-js) (push) Has been cancelled
Lint / typecheck (sw) (push) Has been cancelled
Release Manager: sync changelog with PR / edit (push) Has been cancelled
Storybook / build (push) Has been cancelled
Test (backend) / unit (22.11.0) (push) Has been cancelled
Test (backend) / e2e (22.11.0) (push) Has been cancelled
Test (federation) / test (22.11.0) (push) Has been cancelled
Test (frontend) / vitest (22.11.0) (push) Has been cancelled
Test (frontend) / e2e (chrome, 22.11.0) (push) Has been cancelled
Test (misskey.js) / test (22.11.0) (push) Has been cancelled
Test (production install and build) / production (22.11.0) (push) Has been cancelled
Some checks failed
Lint / lint (misskey-js) (push) Has been cancelled
API report (misskey.js) / report (push) Has been cancelled
Check SPDX-License-Identifier / check-spdx-license-id (push) Has been cancelled
Check copyright year / check_copyright_year (push) Has been cancelled
Publish Docker image (develop) / Build (linux/amd64) (push) Has been cancelled
Publish Docker image (develop) / Build (linux/arm64) (push) Has been cancelled
Publish Docker image (develop) / merge (push) Has been cancelled
Lint / lint (misskey-reversi) (push) Has been cancelled
Dockle / dockle (push) Has been cancelled
Lint / pnpm_install (push) Has been cancelled
Lint / lint (backend) (push) Has been cancelled
Lint / lint (frontend) (push) Has been cancelled
Lint / lint (frontend-embed) (push) Has been cancelled
Lint / lint (frontend-shared) (push) Has been cancelled
Lint / lint (misskey-bubble-game) (push) Has been cancelled
Lint / lint (sw) (push) Has been cancelled
Lint / typecheck (backend) (push) Has been cancelled
Lint / typecheck (misskey-js) (push) Has been cancelled
Lint / typecheck (sw) (push) Has been cancelled
Release Manager: sync changelog with PR / edit (push) Has been cancelled
Storybook / build (push) Has been cancelled
Test (backend) / unit (22.11.0) (push) Has been cancelled
Test (backend) / e2e (22.11.0) (push) Has been cancelled
Test (federation) / test (22.11.0) (push) Has been cancelled
Test (frontend) / vitest (22.11.0) (push) Has been cancelled
Test (frontend) / e2e (chrome, 22.11.0) (push) Has been cancelled
Test (misskey.js) / test (22.11.0) (push) Has been cancelled
Test (production install and build) / production (22.11.0) (push) Has been cancelled
* fix(frontend): serverContextの型エラーを修正 * add comment
This commit is contained in:
parent
3e0fcaeca8
commit
0804092426
@ -46,9 +46,10 @@ import { clipsCache } from '@/cache.js';
|
|||||||
import { isSupportShare } from '@/scripts/navigator.js';
|
import { isSupportShare } from '@/scripts/navigator.js';
|
||||||
import { copyToClipboard } from '@/scripts/copy-to-clipboard.js';
|
import { copyToClipboard } from '@/scripts/copy-to-clipboard.js';
|
||||||
import { genEmbedCode } from '@/scripts/get-embed-code.js';
|
import { genEmbedCode } from '@/scripts/get-embed-code.js';
|
||||||
import { getServerContext } from '@/server-context.js';
|
import { assertServerContext, serverContext } from '@/server-context.js';
|
||||||
|
|
||||||
const CTX_CLIP = getServerContext('clip');
|
// contextは非ログイン状態の情報しかないためログイン時は利用できない
|
||||||
|
const CTX_CLIP = $i && assertServerContext(serverContext, 'clip') ? serverContext.clip : null;
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
clipId: string,
|
clipId: string,
|
||||||
|
@ -63,9 +63,11 @@ import { dateString } from '@/filters/date.js';
|
|||||||
import MkClipPreview from '@/components/MkClipPreview.vue';
|
import MkClipPreview from '@/components/MkClipPreview.vue';
|
||||||
import { defaultStore } from '@/store.js';
|
import { defaultStore } from '@/store.js';
|
||||||
import { pleaseLogin } from '@/scripts/please-login.js';
|
import { pleaseLogin } from '@/scripts/please-login.js';
|
||||||
import { getServerContext } from '@/server-context.js';
|
import { serverContext, assertServerContext } from '@/server-context.js';
|
||||||
|
import { $i } from '@/account.js';
|
||||||
|
|
||||||
const CTX_NOTE = getServerContext('note');
|
// contextは非ログイン状態の情報しかないためログイン時は利用できない
|
||||||
|
const CTX_NOTE = $i && assertServerContext(serverContext, 'note') ? serverContext.note : null;
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
noteId: string;
|
noteId: string;
|
||||||
|
@ -39,7 +39,7 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';
|
|||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
import { $i } from '@/account.js';
|
import { $i } from '@/account.js';
|
||||||
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
|
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
|
||||||
import { getServerContext } from '@/server-context.js';
|
import { serverContext, assertServerContext } from '@/server-context.js';
|
||||||
|
|
||||||
const XHome = defineAsyncComponent(() => import('./home.vue'));
|
const XHome = defineAsyncComponent(() => import('./home.vue'));
|
||||||
const XTimeline = defineAsyncComponent(() => import('./index.timeline.vue'));
|
const XTimeline = defineAsyncComponent(() => import('./index.timeline.vue'));
|
||||||
@ -53,7 +53,8 @@ const XFlashs = defineAsyncComponent(() => import('./flashs.vue'));
|
|||||||
const XGallery = defineAsyncComponent(() => import('./gallery.vue'));
|
const XGallery = defineAsyncComponent(() => import('./gallery.vue'));
|
||||||
const XRaw = defineAsyncComponent(() => import('./raw.vue'));
|
const XRaw = defineAsyncComponent(() => import('./raw.vue'));
|
||||||
|
|
||||||
const CTX_USER = getServerContext('user');
|
// contextは非ログイン状態の情報しかないためログイン時は利用できない
|
||||||
|
const CTX_USER = $i && assertServerContext(serverContext, 'user') ? serverContext.user : null;
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
acct: string;
|
acct: string;
|
||||||
|
@ -2,22 +2,20 @@
|
|||||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import { $i } from '@/account.js';
|
|
||||||
|
|
||||||
const providedContextEl = document.getElementById('misskey_clientCtx');
|
const providedContextEl = document.getElementById('misskey_clientCtx');
|
||||||
|
|
||||||
export type ServerContext = {
|
export type ServerContext = {
|
||||||
clip?: Misskey.entities.Clip;
|
clip?: Misskey.entities.Clip;
|
||||||
note?: Misskey.entities.Note;
|
note?: Misskey.entities.Note;
|
||||||
user?: Misskey.entities.UserLite;
|
user?: Misskey.entities.UserDetailed;
|
||||||
} | null;
|
} | null;
|
||||||
|
|
||||||
export const serverContext: ServerContext = (providedContextEl && providedContextEl.textContent) ? JSON.parse(providedContextEl.textContent) : 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 {
|
export function assertServerContext<K extends keyof NonNullable<ServerContext>>(ctx: ServerContext, entity: K): ctx is Required<Pick<NonNullable<ServerContext>, K>> {
|
||||||
// contextは非ログイン状態の情報しかないためログイン時は利用できない
|
if (ctx == null) return false;
|
||||||
if ($i) return null;
|
return entity in ctx && ctx[entity] != null;
|
||||||
|
|
||||||
return serverContext ? (serverContext[entity] ?? null) : null;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user