some requested changes to linkAttribution.

This commit is contained in:
piuvas 2025-05-27 17:12:02 -03:00
parent 4234a68b3e
commit 56db26f236
No known key found for this signature in database
3 changed files with 26 additions and 29 deletions

View file

@ -28,15 +28,16 @@ import { ApNoteService } from '@/core/activitypub/models/ApNoteService.js';
import { AuthenticateService, AuthenticationError } from '@/server/api/AuthenticateService.js'; import { AuthenticateService, AuthenticationError } from '@/server/api/AuthenticateService.js';
import { SkRateLimiterService } from '@/server/SkRateLimiterService.js'; import { SkRateLimiterService } from '@/server/SkRateLimiterService.js';
import { BucketRateLimit, Keyed, sendRateLimitHeaders } from '@/misc/rate-limit-utils.js'; import { BucketRateLimit, Keyed, sendRateLimitHeaders } from '@/misc/rate-limit-utils.js';
import type { MiLocalUser, MiUser } from '@/models/User.js'; import type { MiLocalUser } from '@/models/User.js';
import { getIpHash } from '@/misc/get-ip-hash.js'; import { getIpHash } from '@/misc/get-ip-hash.js';
import { isRetryableError } from '@/misc/is-retryable-error.js'; import { isRetryableError } from '@/misc/is-retryable-error.js';
import * as Acct from '@/misc/acct.js';
import type { FastifyRequest, FastifyReply } from 'fastify'; import type { FastifyRequest, FastifyReply } from 'fastify';
export type LocalSummalyResult = SummalyResult & { export type LocalSummalyResult = SummalyResult & {
haveNoteLocally?: boolean; haveNoteLocally?: boolean;
linkAttribution?: { linkAttribution?: {
user: MiUser, userId: string,
} }
}; };
@ -435,36 +436,25 @@ export class UrlPreviewService {
private async validateLinkAttribution(summary: LocalSummalyResult) { private async validateLinkAttribution(summary: LocalSummalyResult) {
if (!summary.fediverseCreator) return; if (!summary.fediverseCreator) return;
if (!URL.canParse(summary.url)) return;
const url = URL.parse(summary.url); const url = URL.parse(summary.url);
if (!url) return;
let fediverseCreator = summary.fediverseCreator;
// expecting either '@username@host' or 'username@host'
if (fediverseCreator.startsWith('@')) {
fediverseCreator = fediverseCreator.substring(1);
}
const array = fediverseCreator.split('@'); const acct = Acct.parse(summary.fediverseCreator);
if (acct.host?.toLowerCase() === this.config.host) {
// make sure we only have username@host. acct.host = null;
if (array.length !== 2) return;
const username = array[0].toLowerCase();
let host: string | null = array[1];
if (host.toLowerCase() === this.config.host) {
host = null;
} }
try { try {
const user = await this.remoteUserResolveService.resolveUser(username, host); const user = await this.remoteUserResolveService.resolveUser(acct.username, acct.host);
const attributionDomains = user.attributionDomains; const attributionDomains = user.attributionDomains;
if (attributionDomains.some(x => `.${url.host.toLowerCase()}`.endsWith(`.${x}`))) { if (attributionDomains.some(x => `.${url?.host.toLowerCase()}`.endsWith(`.${x}`))) {
summary.linkAttribution = { summary.linkAttribution = {
user: user, userId: user.id,
}; };
} }
} catch { } catch {
this.logger.warn('user not found: ' + fediverseCreator); this.logger.debug('User not found: ' + summary.fediverseCreator);
} }
} }

View file

@ -65,14 +65,17 @@ SPDX-License-Identifier: AGPL-3.0-only
</footer> </footer>
</article> </article>
</component> </component>
<I18n v-if="linkAttribution" :src="i18n.ts.writtenBy" :class="$style.linkAttribution" tag="p">
<I18n v-if="attributionUser" :src="i18n.ts.writtenBy" :class="$style.linkAttribution" tag="p">
<template #user> <template #user>
<MkA v-user-preview="linkAttribution.user.id" :to="userPage(linkAttribution.user)"> <MkA v-user-preview="attributionUser.id" :to="userPage(attributionUser)">
<MkAvatar :class="$style.linkAttributionIcon" :user="linkAttribution.user"/> <MkAvatar :class="$style.linkAttributionIcon" :user="attributionUser"/>
<MkUserName :user="linkAttribution.user" style="color: var(--MI_THEME-accent)"/> <MkUserName :user="attributionUser" style="color: var(--MI_THEME-accent)"/>
</MkA> </MkA>
</template> </template>
</I18n> </I18n>
<p v-else-if="linkAttribution" :class="$style.linkAttributionIcon"><MkEllipsis/></p>
<template v-if="showActions"> <template v-if="showActions">
<div v-if="tweetId" :class="$style.action"> <div v-if="tweetId" :class="$style.action">
<MkButton :small="true" inline @click="tweetExpanded = true"> <MkButton :small="true" inline @click="tweetExpanded = true">
@ -107,7 +110,6 @@ import { i18n } from '@/i18n.js';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { deviceKind } from '@/utility/device-kind.js'; import { deviceKind } from '@/utility/device-kind.js';
import MkButton from '@/components/MkButton.vue'; import MkButton from '@/components/MkButton.vue';
import MkImgWithBlurhash from '@/components/MkImgWithBlurhash.vue';
import { transformPlayerUrl } from '@/utility/player-url-transform.js'; import { transformPlayerUrl } from '@/utility/player-url-transform.js';
import { store } from '@/store.js'; import { store } from '@/store.js';
import { prefer } from '@/preferences.js'; import { prefer } from '@/preferences.js';
@ -157,8 +159,9 @@ const player = ref<SummalyResult['player']>({
allow: [], allow: [],
}); });
const linkAttribution = ref<{ const linkAttribution = ref<{
user: Misskey.entities.User, userId: string,
} | null>(null); } | null>(null);
const attributionUser = ref<Misskey.entities.User | null>(null);
const playerEnabled = ref(false); const playerEnabled = ref(false);
const tweetId = ref<string | null>(null); const tweetId = ref<string | null>(null);
const tweetExpanded = ref(props.detail); const tweetExpanded = ref(props.detail);
@ -237,7 +240,7 @@ function refresh(withFetch = false) {
.then(async (info: SummalyResult & { .then(async (info: SummalyResult & {
haveNoteLocally?: boolean, haveNoteLocally?: boolean,
linkAttribution?: { linkAttribution?: {
user: Misskey.entities.User userId: string,
} }
} | null) => { } | null) => {
unknownUrl.value = info == null; unknownUrl.value = info == null;
@ -255,6 +258,10 @@ function refresh(withFetch = false) {
sensitive.value = info?.sensitive ?? false; sensitive.value = info?.sensitive ?? false;
activityPub.value = info?.activityPub ?? null; activityPub.value = info?.activityPub ?? null;
linkAttribution.value = info?.linkAttribution ?? null; linkAttribution.value = info?.linkAttribution ?? null;
if (linkAttribution.value) {
misskeyApi('users/show', { userId: linkAttribution.value.userId })
.then(u => attributionUser.value = u);
}
theNote.value = null; theNote.value = null;
if (info?.haveNoteLocally) { if (info?.haveNoteLocally) {

View file

@ -38,7 +38,7 @@ const autochange = ref(false);
const tutorialTag = '`<meta name="fediverse:creator" content="' + $i.username + '@' + toUnicode(hostRaw) + '" />`'; const tutorialTag = '`<meta name="fediverse:creator" content="' + $i.username + '@' + toUnicode(hostRaw) + '" />`';
async function save() { async function save() {
let domains = attributionDomains.value const domains = attributionDomains.value
.trim().split('\n') .trim().split('\n')
.map(el => el.trim().toLowerCase()) .map(el => el.trim().toLowerCase())
.filter(el => el); .filter(el => el);