This commit is contained in:
mattyatea 2023-10-14 17:10:41 +09:00
parent 3d79428b35
commit 9818d1ab9e
7 changed files with 130 additions and 131 deletions

View File

@ -3,9 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Inject, Injectable, OnModuleInit, forwardRef } from '@nestjs/common';
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import {DataSource, IsNull } from 'typeorm';
import { DataSource, IsNull } from 'typeorm';
import type { MiLocalUser, MiPartialLocalUser, MiPartialRemoteUser, MiRemoteUser, MiUser } from '@/models/User.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
import { QueueService } from '@/core/QueueService.js';
@ -28,9 +28,8 @@ import { MetaService } from '@/core/MetaService.js';
import { CacheService } from '@/core/CacheService.js';
import type { Config } from '@/config.js';
import { AccountMoveService } from '@/core/AccountMoveService.js';
import { shouldSilenceInstance } from '@/misc/should-block-instance.js';
import Logger from '../logger.js';
import { shouldSilenceInstance } from "@/misc/should-block-instance.js";
const logger = new Logger('following/create');
@ -133,7 +132,7 @@ export class UserFollowingService implements OnModuleInit {
followee.isLocked ||
(followeeProfile.carefulBot && follower.isBot) ||
(this.userEntityService.isLocalUser(follower) && this.userEntityService.isRemoteUser(followee) && process.env.FORCE_FOLLOW_REMOTE_USER_FOR_TESTING !== 'true') ||
( this.userEntityService.isLocalUser(followee) && this.userEntityService.isRemoteUser(follower) && await shouldSilenceInstance(follower.host,this.db))
( this.userEntityService.isLocalUser(followee) && this.userEntityService.isRemoteUser(follower) && await shouldSilenceInstance(follower.host, this.db))
) {
let autoAccept = false;

View File

@ -3,16 +3,15 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import {Inject, Injectable} from '@nestjs/common';
import { Inject, Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import type { Packed } from '@/misc/json-schema.js';
import type { } from '@/models/Blocking.js';
import type { MiInstance } from '@/models/Instance.js';
import { MetaService } from '@/core/MetaService.js';
import { bindThis } from '@/decorators.js';
import { shouldSilenceInstance } from '@/misc/should-block-instance.js';
import { DI } from '@/di-symbols.js';
import { UtilityService } from '../UtilityService.js';
import {shouldSilenceInstance} from "@/misc/should-block-instance.js";
import { DataSource } from 'typeorm';
import {DI} from "@/di-symbols.js";
@Injectable()
export class InstanceEntityService {
@ -49,7 +48,7 @@ export class InstanceEntityService {
description: instance.description,
maintainerName: instance.maintainerName,
maintainerEmail: instance.maintainerEmail,
isSilenced: await shouldSilenceInstance(instance.host,this.db),
isSilenced: await shouldSilenceInstance(instance.host, this.db),
iconUrl: instance.iconUrl,
faviconUrl: instance.faviconUrl,
themeColor: instance.themeColor,

View File

@ -1,16 +1,16 @@
import { DataSource } from 'typeorm';
import { MiMeta } from "@/models/Meta.js";
import { MiMeta } from '@/models/Meta.js';
let cache: MiMeta;
export async function fetchMeta(noCache = false , db: DataSource): Promise<MiMeta> {
export async function fetchMeta(noCache = false, db: DataSource): Promise<MiMeta> {
if (!noCache && cache) return cache;
return await db.transaction(async (transactionalEntityManager) => {
// New IDs are prioritized because multiple records may have been created due to past bugs.
const metas = await transactionalEntityManager.find(MiMeta, {
order: {
id: "DESC",
id: 'DESC',
},
});
@ -25,9 +25,9 @@ export async function fetchMeta(noCache = false , db: DataSource): Promise<MiMet
.upsert(
MiMeta,
{
id: "x",
id: 'x',
},
["id"],
['id'],
)
.then((x) =>
transactionalEntityManager.findOneByOrFail(MiMeta, x.identifiers[0]),

View File

@ -1,14 +1,14 @@
import { fetchMeta } from "@/misc/fetch-meta.js";
import type { MiInstance } from "@/models/Instance.js";
import type { MiMeta } from "@/models/Meta.js";
import { DataSource } from "typeorm";
import { DataSource } from 'typeorm';
import { fetchMeta } from '@/misc/fetch-meta.js';
import type { MiInstance } from '@/models/Instance.js';
import type { MiMeta } from '@/models/Meta.js';
export async function shouldSilenceInstance(
host: MiInstance["host"],
host: MiInstance['host'],
db : DataSource,
meta?: MiMeta,
): Promise<boolean> {
const { silencedHosts } = meta ?? (await fetchMeta(true,db));
const { silencedHosts } = meta ?? (await fetchMeta(true, db));
return silencedHosts.some(
(limitedHost: string) => host === limitedHost || host.endsWith(`.${limitedHost}`),
);

View File

@ -3,11 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import {Injectable} from '@nestjs/common';
import type {MiMeta} from '@/models/Meta.js';
import {ModerationLogService} from '@/core/ModerationLogService.js';
import {Endpoint} from '@/server/api/endpoint-base.js';
import {MetaService} from '@/core/MetaService.js';
import { Injectable } from '@nestjs/common';
import type { MiMeta } from '@/models/Meta.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { MetaService } from '@/core/MetaService.js';
export const meta = {
tags: ['admin'],
@ -19,117 +19,117 @@ export const meta = {
export const paramDef = {
type: 'object',
properties: {
disableRegistration: {type: 'boolean', nullable: true},
disableRegistration: { type: 'boolean', nullable: true },
pinnedUsers: {
type: 'array', nullable: true, items: {
type: 'string',
}
},
},
hiddenTags: {
type: 'array', nullable: true, items: {
type: 'string',
}
},
},
blockedHosts: {
type: 'array', nullable: true, items: {
type: 'string',
}
},
},
sensitiveWords: {
type: 'array', nullable: true, items: {
type: 'string',
}
},
},
themeColor: {type: 'string', nullable: true, pattern: '^#[0-9a-fA-F]{6}$'},
mascotImageUrl: {type: 'string', nullable: true},
bannerUrl: {type: 'string', nullable: true},
serverErrorImageUrl: {type: 'string', nullable: true},
infoImageUrl: {type: 'string', nullable: true},
notFoundImageUrl: {type: 'string', nullable: true},
iconUrl: {type: 'string', nullable: true},
app192IconUrl: {type: 'string', nullable: true},
app512IconUrl: {type: 'string', nullable: true},
backgroundImageUrl: {type: 'string', nullable: true},
logoImageUrl: {type: 'string', nullable: true},
name: {type: 'string', nullable: true},
shortName: {type: 'string', nullable: true},
description: {type: 'string', nullable: true},
defaultLightTheme: {type: 'string', nullable: true},
defaultDarkTheme: {type: 'string', nullable: true},
cacheRemoteFiles: {type: 'boolean'},
cacheRemoteSensitiveFiles: {type: 'boolean'},
emailRequiredForSignup: {type: 'boolean'},
enableHcaptcha: {type: 'boolean'},
hcaptchaSiteKey: {type: 'string', nullable: true},
hcaptchaSecretKey: {type: 'string', nullable: true},
enableRecaptcha: {type: 'boolean'},
recaptchaSiteKey: {type: 'string', nullable: true},
recaptchaSecretKey: {type: 'string', nullable: true},
enableTurnstile: {type: 'boolean'},
turnstileSiteKey: {type: 'string', nullable: true},
turnstileSecretKey: {type: 'string', nullable: true},
sensitiveMediaDetection: {type: 'string', enum: ['none', 'all', 'local', 'remote']},
sensitiveMediaDetectionSensitivity: {type: 'string', enum: ['medium', 'low', 'high', 'veryLow', 'veryHigh']},
setSensitiveFlagAutomatically: {type: 'boolean'},
enableSensitiveMediaDetectionForVideos: {type: 'boolean'},
proxyAccountId: {type: 'string', format: 'misskey:id', nullable: true},
maintainerName: {type: 'string', nullable: true},
maintainerEmail: {type: 'string', nullable: true},
themeColor: { type: 'string', nullable: true, pattern: '^#[0-9a-fA-F]{6}$' },
mascotImageUrl: { type: 'string', nullable: true },
bannerUrl: { type: 'string', nullable: true },
serverErrorImageUrl: { type: 'string', nullable: true },
infoImageUrl: { type: 'string', nullable: true },
notFoundImageUrl: { type: 'string', nullable: true },
iconUrl: { type: 'string', nullable: true },
app192IconUrl: { type: 'string', nullable: true },
app512IconUrl: { type: 'string', nullable: true },
backgroundImageUrl: { type: 'string', nullable: true },
logoImageUrl: { type: 'string', nullable: true },
name: { type: 'string', nullable: true },
shortName: { type: 'string', nullable: true },
description: { type: 'string', nullable: true },
defaultLightTheme: { type: 'string', nullable: true },
defaultDarkTheme: { type: 'string', nullable: true },
cacheRemoteFiles: { type: 'boolean' },
cacheRemoteSensitiveFiles: { type: 'boolean' },
emailRequiredForSignup: { type: 'boolean' },
enableHcaptcha: { type: 'boolean' },
hcaptchaSiteKey: { type: 'string', nullable: true },
hcaptchaSecretKey: { type: 'string', nullable: true },
enableRecaptcha: { type: 'boolean' },
recaptchaSiteKey: { type: 'string', nullable: true },
recaptchaSecretKey: { type: 'string', nullable: true },
enableTurnstile: { type: 'boolean' },
turnstileSiteKey: { type: 'string', nullable: true },
turnstileSecretKey: { type: 'string', nullable: true },
sensitiveMediaDetection: { type: 'string', enum: ['none', 'all', 'local', 'remote'] },
sensitiveMediaDetectionSensitivity: { type: 'string', enum: ['medium', 'low', 'high', 'veryLow', 'veryHigh'] },
setSensitiveFlagAutomatically: { type: 'boolean' },
enableSensitiveMediaDetectionForVideos: { type: 'boolean' },
proxyAccountId: { type: 'string', format: 'misskey:id', nullable: true },
maintainerName: { type: 'string', nullable: true },
maintainerEmail: { type: 'string', nullable: true },
langs: {
type: 'array', items: {
type: 'string',
}
},
},
summalyProxy: {type: 'string', nullable: true},
deeplAuthKey: {type: 'string', nullable: true},
deeplIsPro: {type: 'boolean'},
enableEmail: {type: 'boolean'},
email: {type: 'string', nullable: true},
smtpSecure: {type: 'boolean'},
smtpHost: {type: 'string', nullable: true},
smtpPort: {type: 'integer', nullable: true},
smtpUser: {type: 'string', nullable: true},
smtpPass: {type: 'string', nullable: true},
enableServiceWorker: {type: 'boolean'},
swPublicKey: {type: 'string', nullable: true},
swPrivateKey: {type: 'string', nullable: true},
tosUrl: {type: 'string', nullable: true},
repositoryUrl: {type: 'string'},
feedbackUrl: {type: 'string'},
impressumUrl: {type: 'string'},
privacyPolicyUrl: {type: 'string'},
useObjectStorage: {type: 'boolean'},
objectStorageBaseUrl: {type: 'string', nullable: true},
objectStorageBucket: {type: 'string', nullable: true},
objectStoragePrefix: {type: 'string', nullable: true},
objectStorageEndpoint: {type: 'string', nullable: true},
objectStorageRegion: {type: 'string', nullable: true},
objectStoragePort: {type: 'integer', nullable: true},
objectStorageAccessKey: {type: 'string', nullable: true},
objectStorageSecretKey: {type: 'string', nullable: true},
objectStorageUseSSL: {type: 'boolean'},
objectStorageUseProxy: {type: 'boolean'},
objectStorageSetPublicRead: {type: 'boolean'},
objectStorageS3ForcePathStyle: {type: 'boolean'},
enableIpLogging: {type: 'boolean'},
enableActiveEmailValidation: {type: 'boolean'},
enableChartsForRemoteUser: {type: 'boolean'},
enableChartsForFederatedInstances: {type: 'boolean'},
enableServerMachineStats: {type: 'boolean'},
enableIdenticonGeneration: {type: 'boolean'},
serverRules: {type: 'array', items: {type: 'string'}},
preservedUsernames: {type: 'array', items: {type: 'string'}},
manifestJsonOverride: {type: 'string'},
perLocalUserUserTimelineCacheMax: {type: 'integer'},
perRemoteUserUserTimelineCacheMax: {type: 'integer'},
perUserHomeTimelineCacheMax: {type: 'integer'},
perUserListTimelineCacheMax: {type: 'integer'},
notesPerOneAd: {type: 'integer'},
summalyProxy: { type: 'string', nullable: true },
deeplAuthKey: { type: 'string', nullable: true },
deeplIsPro: { type: 'boolean' },
enableEmail: { type: 'boolean' },
email: { type: 'string', nullable: true },
smtpSecure: { type: 'boolean' },
smtpHost: { type: 'string', nullable: true },
smtpPort: { type: 'integer', nullable: true },
smtpUser: { type: 'string', nullable: true },
smtpPass: { type: 'string', nullable: true },
enableServiceWorker: { type: 'boolean' },
swPublicKey: { type: 'string', nullable: true },
swPrivateKey: { type: 'string', nullable: true },
tosUrl: { type: 'string', nullable: true },
repositoryUrl: { type: 'string' },
feedbackUrl: { type: 'string' },
impressumUrl: { type: 'string' },
privacyPolicyUrl: { type: 'string' },
useObjectStorage: { type: 'boolean' },
objectStorageBaseUrl: { type: 'string', nullable: true },
objectStorageBucket: { type: 'string', nullable: true },
objectStoragePrefix: { type: 'string', nullable: true },
objectStorageEndpoint: { type: 'string', nullable: true },
objectStorageRegion: { type: 'string', nullable: true },
objectStoragePort: { type: 'integer', nullable: true },
objectStorageAccessKey: { type: 'string', nullable: true },
objectStorageSecretKey: { type: 'string', nullable: true },
objectStorageUseSSL: { type: 'boolean' },
objectStorageUseProxy: { type: 'boolean' },
objectStorageSetPublicRead: { type: 'boolean' },
objectStorageS3ForcePathStyle: { type: 'boolean' },
enableIpLogging: { type: 'boolean' },
enableActiveEmailValidation: { type: 'boolean' },
enableChartsForRemoteUser: { type: 'boolean' },
enableChartsForFederatedInstances: { type: 'boolean' },
enableServerMachineStats: { type: 'boolean' },
enableIdenticonGeneration: { type: 'boolean' },
serverRules: { type: 'array', items: { type: 'string' } },
preservedUsernames: { type: 'array', items: { type: 'string' } },
manifestJsonOverride: { type: 'string' },
perLocalUserUserTimelineCacheMax: { type: 'integer' },
perRemoteUserUserTimelineCacheMax: { type: 'integer' },
perUserHomeTimelineCacheMax: { type: 'integer' },
perUserListTimelineCacheMax: { type: 'integer' },
notesPerOneAd: { type: 'integer' },
silencedHosts: {
type: "array",
type: 'array',
nullable: true,
items: {
type: "string",
type: 'string',
},
},
},
@ -165,11 +165,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.sensitiveWords = ps.sensitiveWords.filter(Boolean);
}
if (Array.isArray(ps.silencedHosts)) {
let lastValue = "";
let lastValue = '';
set.silencedHosts = ps.silencedHosts.sort().filter((h) => {
const lv = lastValue;
lastValue = h;
return h !== "" && h !== lv && !set.blockedHosts?.includes(h);
return h !== '' && h !== lv && !set.blockedHosts?.includes(h);
});
}
if (ps.themeColor !== undefined) {

View File

@ -76,7 +76,7 @@ const pagination = {
state === 'publishing' ? { publishing: true } :
state === 'suspended' ? { suspended: true } :
state === 'blocked' ? { blocked: true } :
state === 'silenced' ? {silenced: true} :
state === 'silenced' ? { silenced: true } :
state === 'notResponding' ? { notResponding: true } :
{}),
})),
@ -85,7 +85,7 @@ const pagination = {
function getStatus(instance) {
if (instance.isSuspended) return 'Suspended';
if (instance.isBlocked) return 'Blocked';
if (instance.isSilenced) return 'Silenced'
if (instance.isSilenced) return 'Silenced';
if (instance.isNotResponding) return 'Error';
return 'Alive';
}

View File

@ -5,8 +5,8 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<MkStickyContainer>
<template #header><XHeader :actions="headerActions" v-model:tab="tab" :tabs="headerTabs"/></template>
<MkSpacer :contentMax="700" :marginMin="16" :marginMax="32" >
<template #header><XHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template>
<MkSpacer :contentMax="700" :marginMin="16" :marginMax="32">
<FormSuspense :p="init">
<MkTextarea v-if="tab === 'block'" v-model="blockedHosts">
<span>{{ i18n.ts.blockedInstances }}</span>
@ -14,9 +14,11 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkTextarea>
<MkTextarea v-else-if="tab === 'silence'" v-model="silencedHosts" class="_formBlock">
<span>{{ i18n.ts.silencedInstances }}</span>
<template #caption>{{
<template #caption>
{{
i18n.ts.silencedInstancesDescription
}}</template>
}}
</template>
</MkTextarea>
<MkButton primary @click="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
</FormSuspense>
@ -25,7 +27,6 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { } from 'vue';
import XHeader from './_header_.vue';
import MkButton from '@/components/MkButton.vue';
import MkTextarea from '@/components/MkTextarea.vue';
@ -36,8 +37,8 @@ import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
let blockedHosts: string = $ref('');
let silencedHosts: string = $ref("");
let tab = $ref("block");
let silencedHosts: string = $ref('');
let tab = $ref('block');
async function init() {
const meta = await os.api('admin/meta');
@ -48,7 +49,7 @@ async function init() {
function save() {
os.apiWithDialog('admin/update-meta', {
blockedHosts: blockedHosts.split('\n') || [],
silencedHosts: silencedHosts.split("\n") || [],
silencedHosts: silencedHosts.split('\n') || [],
}).then(() => {
fetchInstance();
@ -59,14 +60,14 @@ const headerActions = $computed(() => []);
const headerTabs = $computed(() => [
{
key: "block",
key: 'block',
title: i18n.ts.block,
icon: "ph-prohibit ph-bold ph-lg",
icon: 'ph-prohibit ph-bold ph-lg',
},
{
key: "silence",
key: 'silence',
title: i18n.ts.silence,
icon: "ph-eye-slash ph-bold ph-lg",
icon: 'ph-eye-slash ph-bold ph-lg',
},
]);