Skip to content

Commit

Permalink
Merge pull request #734 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Jan 12, 2025
2 parents d54fca9 + 5b072a3 commit 7c50aae
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 61 deletions.
2 changes: 1 addition & 1 deletion lib/routes/misskey/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions lib/routes/misskey/user-timeline.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -38,7 +38,7 @@ Examples:
handler,
};

async function handler(ctx) {
async function handler(ctx): Promise<Data> {
const username = ctx.req.param('username');
const [, pureUsername, site] = username.match(/@?(\w+)@(\w+\.\w+)/) || [];
if (!pureUsername || !site) {
Expand All @@ -57,14 +57,15 @@ 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,
});

return {
title: `User timeline for ${username} on ${site}`,
link: `https://${site}/@${pureUsername}`,
image: avatarUrl || '',
item: utils.parseNotes(accountData, site),
};
}
17 changes: 10 additions & 7 deletions lib/routes/misskey/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -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,
Expand All @@ -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`;
Expand All @@ -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 };
42 changes: 0 additions & 42 deletions lib/routes/watasuke/blog.ts

This file was deleted.

8 changes: 0 additions & 8 deletions lib/routes/watasuke/namespace.ts

This file was deleted.

0 comments on commit 7c50aae

Please sign in to comment.