server: make more places use shouldBlockInstance
This commit is contained in:
parent
1839efe409
commit
e3701b21db
3 changed files with 9 additions and 12 deletions
|
@ -1,13 +1,12 @@
|
|||
import { db } from '@/db/postgre.js';
|
||||
import { Instance } from '@/models/entities/instance.js';
|
||||
import { Packed } from '@/misc/schema.js';
|
||||
import { fetchMeta } from '@/misc/fetch-meta.js';
|
||||
import { shouldBlockInstance } from '@/misc/should-block-instance.js';
|
||||
|
||||
export const InstanceRepository = db.getRepository(Instance).extend({
|
||||
async pack(
|
||||
instance: Instance,
|
||||
): Promise<Packed<'FederationInstance'>> {
|
||||
const meta = await fetchMeta();
|
||||
return {
|
||||
id: instance.id,
|
||||
caughtAt: instance.caughtAt.toISOString(),
|
||||
|
@ -20,7 +19,7 @@ export const InstanceRepository = db.getRepository(Instance).extend({
|
|||
lastCommunicatedAt: instance.lastCommunicatedAt.toISOString(),
|
||||
isNotResponding: instance.isNotResponding,
|
||||
isSuspended: instance.isSuspended,
|
||||
isBlocked: meta.blockedHosts.includes(instance.host),
|
||||
isBlocked: await shouldBlockInstance(instance.host),
|
||||
softwareName: instance.softwareName,
|
||||
softwareVersion: instance.softwareVersion,
|
||||
openRegistrations: instance.openRegistrations,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import post from '@/services/note/create.js';
|
||||
import { CacheableRemoteUser } from '@/models/entities/user.js';
|
||||
import { extractDbHost } from '@/misc/convert-host.js';
|
||||
import { fetchMeta } from '@/misc/fetch-meta.js';
|
||||
import { getApLock } from '@/misc/app-lock.js';
|
||||
import { StatusError } from '@/misc/fetch.js';
|
||||
import { Notes } from '@/models/index.js';
|
||||
|
@ -10,6 +9,7 @@ import { apLogger } from '@/remote/activitypub/logger.js';
|
|||
import { fetchNote, resolveNote } from '@/remote/activitypub/models/note.js';
|
||||
import Resolver from '@/remote/activitypub/resolver.js';
|
||||
import { IAnnounce, getApId } from '@/remote/activitypub/type.js';
|
||||
import { shouldBlockInstance } from '@/misc/should-block-instance.js';
|
||||
|
||||
export default async function(resolver: Resolver, actor: CacheableRemoteUser, activity: IAnnounce, targetUri: string): Promise<void> {
|
||||
const uri = getApId(activity);
|
||||
|
@ -19,8 +19,7 @@ export default async function(resolver: Resolver, actor: CacheableRemoteUser, ac
|
|||
}
|
||||
|
||||
// Cancel if the announced from host is blocked.
|
||||
const meta = await fetchMeta();
|
||||
if (meta.blockedHosts.includes(extractDbHost(uri))) return;
|
||||
if (await shouldBlockInstance(extractDbHost(uri))) return;
|
||||
|
||||
const unlock = await getApLock(uri);
|
||||
|
||||
|
|
|
@ -12,11 +12,11 @@ import { Emojis, Polls, MessagingMessages } from '@/models/index.js';
|
|||
import { Note } from '@/models/entities/note.js';
|
||||
import { Emoji } from '@/models/entities/emoji.js';
|
||||
import { genId } from '@/misc/gen-id.js';
|
||||
import { fetchMeta } from '@/misc/fetch-meta.js';
|
||||
import { getApLock } from '@/misc/app-lock.js';
|
||||
import { createMessage } from '@/services/messages/create.js';
|
||||
import { StatusError } from '@/misc/fetch.js';
|
||||
import { fromHtml } from '@/mfm/from-html.js';
|
||||
import { shouldBlockInstance } from '@/misc/should-block-instance.js';
|
||||
import { parseAudience } from '../audience.js';
|
||||
import { IObject, getOneApId, getApId, getOneApHrefNullable, validPost, IPost, isEmoji, getApType } from '../type.js';
|
||||
import DbResolver from '../db-resolver.js';
|
||||
|
@ -28,7 +28,7 @@ import { extractApHashtags } from './tag.js';
|
|||
import { extractPollFromQuestion } from './question.js';
|
||||
import { extractApMentions } from './mention.js';
|
||||
|
||||
export function validateNote(object: any, uri: string) {
|
||||
export function validateNote(object: any, uri: string): Error | null {
|
||||
const expectHost = extractDbHost(uri);
|
||||
|
||||
if (object == null) {
|
||||
|
@ -270,14 +270,13 @@ export async function resolveNote(value: string | IObject, resolver?: Resolver):
|
|||
const uri = typeof value === 'string' ? value : value.id;
|
||||
if (uri == null) throw new Error('missing uri');
|
||||
|
||||
// ブロックしてたら中断
|
||||
const meta = await fetchMeta();
|
||||
if (meta.blockedHosts.includes(extractDbHost(uri))) throw new StatusError('host blocked', 451, `host ${extractDbHost(uri)} is blocked`);
|
||||
// Interrupt if blocked.
|
||||
if (await shouldBlockInstance(extractDbHost(uri))) throw new StatusError('host blocked', 451, `host ${extractDbHost(uri)} is blocked`);
|
||||
|
||||
const unlock = await getApLock(uri);
|
||||
|
||||
try {
|
||||
//#region このサーバーに既に登録されていたらそれを返す
|
||||
//#region If already registered on this server, return it.
|
||||
const exist = await fetchNote(uri);
|
||||
|
||||
if (exist) {
|
||||
|
|
Loading…
Reference in a new issue