From 3855fef54b4f01f6861ea22de95aa81d4b8ff343 Mon Sep 17 00:00:00 2001 From: teidesu Date: Fri, 24 May 2024 15:05:28 +0300 Subject: [PATCH] feat(sharkey): no-remote-users.patch --- hosts/koi/containers/sharkey/Dockerfile | 1 + .../sharkey/patches/no-remote-users.patch | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 hosts/koi/containers/sharkey/patches/no-remote-users.patch diff --git a/hosts/koi/containers/sharkey/Dockerfile b/hosts/koi/containers/sharkey/Dockerfile index ace9264..773bf6f 100644 --- a/hosts/koi/containers/sharkey/Dockerfile +++ b/hosts/koi/containers/sharkey/Dockerfile @@ -38,6 +38,7 @@ RUN git apply /patches/unfollow-notification.patch RUN git apply /patches/webhook-notification.patch # motivation: https://very.stupid.fish/notes/9shhrn2qncid008s RUN git apply /patches/index-everything.patch +RUN git apply /patches/no-remote-users.patch RUN cp -f /patches/robots.txt packages/backend/assets/robots.txt # end patch diff --git a/hosts/koi/containers/sharkey/patches/no-remote-users.patch b/hosts/koi/containers/sharkey/patches/no-remote-users.patch new file mode 100644 index 0000000..9e6a971 --- /dev/null +++ b/hosts/koi/containers/sharkey/patches/no-remote-users.patch @@ -0,0 +1,71 @@ +diff --git a/packages/backend/src/server/api/endpoints/users/show.ts b/packages/backend/src/server/api/endpoints/users/show.ts +index bd81989..8aaf8ca 100644 +--- a/packages/backend/src/server/api/endpoints/users/show.ts ++++ b/packages/backend/src/server/api/endpoints/users/show.ts +@@ -97,6 +97,8 @@ export default class extends Endpoint { // eslint- + const isModerator = await this.roleService.isModerator(me); + ps.username = ps.username?.trim(); + ++ const authed = me !== null ++ + if (ps.userIds) { + if (ps.userIds.length === 0) { + return []; +@@ -112,7 +114,10 @@ export default class extends Endpoint { // eslint- + // リクエストされた通りに並べ替え + const _users: MiUser[] = []; + for (const id of ps.userIds) { +- _users.push(users.find(x => x.id === id)!); ++ const user = users.find(x => x.id === id) ++ if (user && (authed || user.host === null)) { ++ _users.push(user); ++ } + } + + return await Promise.all(_users.map(u => this.userEntityService.pack(u, me, { +@@ -137,6 +142,14 @@ export default class extends Endpoint { // eslint- + throw new ApiError(meta.errors.noSuchUser); + } + ++ if (!authed && user.host !== null) { ++ throw new ApiError({ ++ code: 'X_REMOTE_REDIRECT', ++ message: 'Redirect to remote user', ++ id: 'X_REMOTE_REDIRECT', ++ }, user.uri); ++ } ++ + if (user.host == null) { + if (me == null && ip != null) { + this.perUserPvChart.commitByVisitor(user, ip); +diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts +index cb41c4f..8199e3c 100644 +--- a/packages/backend/src/server/web/ClientServerService.ts ++++ b/packages/backend/src/server/web/ClientServerService.ts +@@ -526,6 +526,11 @@ export class ClientServerService { + + if (user != null) { + const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id }); ++ if (user.host !== null) { ++ reply.redirect(301, profile.url); ++ return; ++ } ++ + const meta = await this.metaService.fetch(); + const me = profile.fields + ? profile.fields +diff --git a/packages/frontend/src/pages/user/index.vue b/packages/frontend/src/pages/user/index.vue +index ebe4176..0cd39f3 100644 +--- a/packages/frontend/src/pages/user/index.vue ++++ b/packages/frontend/src/pages/user/index.vue +@@ -70,6 +70,10 @@ function fetchUser(): void { + misskeyApi('users/show', Misskey.acct.parse(props.acct)).then(u => { + user.value = u; + }).catch(err => { ++ if (err.code === 'X_REMOTE_REDIRECT') { ++ location.replace(err.info); ++ return; ++ } + error.value = err; + }); + }