feat(client): メンションにユーザーのアバターを表示するように

Resolve #350
This commit is contained in:
syuilo
2021-10-24 21:02:50 +09:00
parent dfd92efa89
commit 09f4885f89
5 changed files with 41 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import { networkChart } from '@/services/chart/index';
import { genAvatar } from '@/misc/gen-avatar';
import { createTemp } from '@/misc/create-temp';
import { publishMainStream } from '@/services/stream';
import { parseAcct } from '@/misc/acct';
export const serverLogger = new Logger('server', 'gray', false);
@ -68,7 +69,22 @@ router.use(activityPub.routes());
router.use(nodeinfo.routes());
router.use(wellKnown.routes());
router.get('/avatar/:x', async ctx => {
router.get('/avatar/@:acct', async ctx => {
const { username, host } = parseAcct(ctx.params.acct);
const user = await Users.findOne({
usernameLower: username.toLowerCase(),
host: host === config.host ? null : host,
isSuspended: false
});
if (user) {
ctx.redirect(Users.getAvatarUrl(user));
} else {
ctx.redirect('/static-assets/user-unknown.png');
}
});
router.get('/random-avatar/:x', async ctx => {
const [temp] = await createTemp();
await genAvatar(ctx.params.x, fs.createWriteStream(temp));
ctx.set('Content-Type', 'image/png');