mirror of
https://github.com/misskey-dev/misskey.git
synced 2025-01-13 01:11:07 +09:00
refactor(ApNoteService.ts
): よりよい型定義
`res`が`null`でないことは確認されているようだったので`null`とのunionはなくした
This commit is contained in:
parent
1af9392914
commit
c234f3afe1
@ -197,12 +197,10 @@ export class ApNoteService {
|
|||||||
let quote: Note | undefined | null;
|
let quote: Note | undefined | null;
|
||||||
|
|
||||||
if (note._misskey_quote || note.quoteUrl) {
|
if (note._misskey_quote || note.quoteUrl) {
|
||||||
const tryResolveNote = async (uri: string): Promise<{
|
const tryResolveNote = async (uri: string): Promise<
|
||||||
status: 'ok';
|
| { status: 'ok'; res: Note }
|
||||||
res: Note | null;
|
| { status: 'permerror' | 'temperror' }
|
||||||
} | {
|
> => {
|
||||||
status: 'permerror' | 'temperror';
|
|
||||||
}> => {
|
|
||||||
if (typeof uri !== 'string' || !uri.match(/^https?:/)) return { status: 'permerror' };
|
if (typeof uri !== 'string' || !uri.match(/^https?:/)) return { status: 'permerror' };
|
||||||
try {
|
try {
|
||||||
const res = await this.resolveNote(uri);
|
const res = await this.resolveNote(uri);
|
||||||
@ -226,7 +224,7 @@ export class ApNoteService {
|
|||||||
const uris = unique([note._misskey_quote, note.quoteUrl].filter((x): x is string => typeof x === 'string'));
|
const uris = unique([note._misskey_quote, note.quoteUrl].filter((x): x is string => typeof x === 'string'));
|
||||||
const results = await Promise.all(uris.map(uri => tryResolveNote(uri)));
|
const results = await Promise.all(uris.map(uri => tryResolveNote(uri)));
|
||||||
|
|
||||||
quote = results.filter((x): x is { status: 'ok', res: Note | null } => x.status === 'ok').map(x => x.res).find(x => x);
|
quote = results.filter((x): x is { status: 'ok', res: Note } => x.status === 'ok').map(x => x.res).at(0);
|
||||||
if (!quote) {
|
if (!quote) {
|
||||||
if (results.some(x => x.status === 'temperror')) {
|
if (results.some(x => x.status === 'temperror')) {
|
||||||
throw new Error('quote resolve failed');
|
throw new Error('quote resolve failed');
|
||||||
|
Loading…
Reference in New Issue
Block a user