Skip to content

Commit

Permalink
fix(tms): toMeEntity でトークンが取得できないことがある問題
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyme committed Apr 30, 2024
1 parent 2d23e45 commit 5f93074
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/frontend/src/scripts/tms/to-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import * as Misskey from 'misskey-js';
import * as mfm from 'mfm-js';
import { toASCII } from 'punycode';
import { $i, getAccounts } from '@/account.js';
import { $i } from '@/account.js';
import { defaultStore } from '@/store.js';
import { unique } from '@/scripts/array.js';
import { deepClone } from '@/scripts/clone.js';
import { getAccountFromId } from '@/scripts/get-account-from-id.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { TmsError } from '@/scripts/tms/error.js';
import { getAppearNote } from '@/scripts/tms/get-appear-note.js';
Expand Down Expand Up @@ -83,14 +84,21 @@ const toMeEntity = async (fromId?: string | null): Promise<MeEntity> => {
throw new TmsError(errors.meIdIsRequired);
}

const token = (await getAccounts()).find(({ id }) => id === meId)?.token ?? null;
const token = await getAccountToken(meId);
if (token == null) {
throw new TmsError(errors.tokenIsRequired);
}

return { meId, token } as const satisfies MeEntity;
};

const getAccountToken = async (meId: MeEntity['meId']): Promise<MeEntity['token'] | null> => {
if ($i?.id === meId && $i.token != null) {
return $i.token;
}
return getAccountFromId(meId).then(x => x?.token ?? null);
};

const toNoteEntity = async (noteEntityOrId: NoteEntityOrId, { token }: MeEntity): Promise<NoteEntity> => {
if (typeof noteEntityOrId === 'string') {
const fetchedNote = await misskeyApi('notes/show', { noteId: noteEntityOrId }, token).catch(() => null);
Expand Down

0 comments on commit 5f93074

Please sign in to comment.