diff --git a/lib/routes/misskey/types.ts b/lib/routes/misskey/types.ts index e6b695f429..2aff1cc2f1 100644 --- a/lib/routes/misskey/types.ts +++ b/lib/routes/misskey/types.ts @@ -51,7 +51,7 @@ export interface MisskeyNote { } // https://github.com/misskey-dev/misskey/blob/d2e8dc4fe3c6e90e68001ed1f092d4e3d2454283/packages/backend/src/models/json-schema/user.ts -interface MisskeyUser { +export interface MisskeyUser { id: string; name: string | null; username: string; diff --git a/lib/routes/misskey/user-timeline.ts b/lib/routes/misskey/user-timeline.ts index 3d97eef28a..3cbdc24ad0 100644 --- a/lib/routes/misskey/user-timeline.ts +++ b/lib/routes/misskey/user-timeline.ts @@ -1,4 +1,4 @@ -import { Route, ViewType } from '@/types'; +import { Route, ViewType, Data } from '@/types'; import utils from './utils'; import { config } from '@/config'; import ConfigNotFoundError from '@/errors/types/config-not-found'; @@ -38,7 +38,7 @@ Examples: handler, }; -async function handler(ctx) { +async function handler(ctx): Promise { const username = ctx.req.param('username'); const [, pureUsername, site] = username.match(/@?(\w+)@(\w+\.\w+)/) || []; if (!pureUsername || !site) { @@ -57,7 +57,7 @@ async function handler(ctx) { throw new InvalidParameterError('withRenotes and mediaOnly cannot both be true.'); } - const { accountData } = await utils.getUserTimelineByUsername(pureUsername, site, { + const { accountData, avatarUrl } = await utils.getUserTimelineByUsername(pureUsername, site, { withRenotes, mediaOnly, }); @@ -65,6 +65,7 @@ async function handler(ctx) { return { title: `User timeline for ${username} on ${site}`, link: `https://${site}/@${pureUsername}`, + image: avatarUrl || '', item: utils.parseNotes(accountData, site), }; } diff --git a/lib/routes/misskey/utils.ts b/lib/routes/misskey/utils.ts index 0d852b80f0..5d140c3af6 100644 --- a/lib/routes/misskey/utils.ts +++ b/lib/routes/misskey/utils.ts @@ -7,7 +7,7 @@ import path from 'node:path'; import cache from '@/utils/cache'; import got from '@/utils/got'; -import { MisskeyNote } from './types'; +import { MisskeyNote, MisskeyUser } from './types'; const allowSiteList = ['misskey.io', 'madost.one', 'mk.nixnet.social']; @@ -71,7 +71,7 @@ async function getUserTimelineByUsername(username, site, { withRenotes = false, const searchUrl = `https://${site}/api/users/search-by-username-and-host`; const cacheUid = `misskey_username/${site}/${username}`; - const accountId = await cache.tryGet(cacheUid, async () => { + const userData = (await cache.tryGet(cacheUid, async () => { const searchResponse = await got({ method: 'post', url: searchUrl, @@ -82,13 +82,16 @@ async function getUserTimelineByUsername(username, site, { withRenotes = false, limit: 1, }, }); - const userData = searchResponse.data.find((item) => item.username === username); + const user = searchResponse.data.find((item) => item.username === username); - if (!userData) { + if (!user) { throw new Error(`username ${username} not found`); } - return userData.id; - }); + return user; + })) as MisskeyUser; + + const accountId = userData.id; + const avatarUrl = userData.avatarUrl; // https://misskey.io/api-doc#tag/users/operation/users___notes const usernotesUrl = `https://${site}/api/users/notes`; @@ -106,7 +109,7 @@ async function getUserTimelineByUsername(username, site, { withRenotes = false, }, }); const accountData = usernotesResponse.data; - return { site, accountId, accountData }; + return { site, accountId, accountData, avatarUrl }; } export default { parseNotes, getUserTimelineByUsername, allowSiteList };