This commit is contained in:
tamaina 2023-05-29 16:01:04 +00:00
parent 9135d2757e
commit bc15dde742
5 changed files with 240 additions and 275 deletions

View file

@ -6,280 +6,17 @@ import type { Config } from '@/config.js';
import { DI } from '@/di-symbols.js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
export const meta = {
tags: ['meta'],
requireCredential: true,
requireAdmin: true,
res: {
type: 'object',
optional: false, nullable: false,
properties: {
cacheRemoteFiles: {
type: 'boolean',
optional: false, nullable: false,
},
emailRequiredForSignup: {
type: 'boolean',
optional: false, nullable: false,
},
enableHcaptcha: {
type: 'boolean',
optional: false, nullable: false,
},
hcaptchaSiteKey: {
type: 'string',
optional: false, nullable: true,
},
enableRecaptcha: {
type: 'boolean',
optional: false, nullable: false,
},
recaptchaSiteKey: {
type: 'string',
optional: false, nullable: true,
},
enableTurnstile: {
type: 'boolean',
optional: false, nullable: false,
},
turnstileSiteKey: {
type: 'string',
optional: false, nullable: true,
},
swPublickey: {
type: 'string',
optional: false, nullable: true,
},
mascotImageUrl: {
type: 'string',
optional: false, nullable: true,
default: '/assets/ai.png',
},
bannerUrl: {
type: 'string',
optional: false, nullable: true,
},
errorImageUrl: {
type: 'string',
optional: false, nullable: true,
default: 'https://xn--931a.moe/aiart/yubitun.png',
},
iconUrl: {
type: 'string',
optional: false, nullable: true,
},
enableEmail: {
type: 'boolean',
optional: false, nullable: false,
},
enableServiceWorker: {
type: 'boolean',
optional: false, nullable: false,
},
translatorAvailable: {
type: 'boolean',
optional: false, nullable: false,
},
userStarForReactionFallback: {
type: 'boolean',
optional: true, nullable: false,
},
pinnedUsers: {
type: 'array',
optional: true, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
hiddenTags: {
type: 'array',
optional: true, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
blockedHosts: {
type: 'array',
optional: true, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
sensitiveWords: {
type: 'array',
optional: true, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
preservedUsernames: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'string',
optional: false, nullable: false,
},
},
hcaptchaSecretKey: {
type: 'string',
optional: true, nullable: true,
},
recaptchaSecretKey: {
type: 'string',
optional: true, nullable: true,
},
turnstileSecretKey: {
type: 'string',
optional: true, nullable: true,
},
sensitiveMediaDetection: {
type: 'string',
optional: true, nullable: false,
},
sensitiveMediaDetectionSensitivity: {
type: 'string',
optional: true, nullable: false,
},
setSensitiveFlagAutomatically: {
type: 'boolean',
optional: true, nullable: false,
},
enableSensitiveMediaDetectionForVideos: {
type: 'boolean',
optional: true, nullable: false,
},
proxyAccountId: {
type: 'string',
optional: true, nullable: true,
format: 'id',
},
summaryProxy: {
type: 'string',
optional: true, nullable: true,
},
email: {
type: 'string',
optional: true, nullable: true,
},
smtpSecure: {
type: 'boolean',
optional: true, nullable: false,
},
smtpHost: {
type: 'string',
optional: true, nullable: true,
},
smtpPort: {
type: 'number',
optional: true, nullable: true,
},
smtpUser: {
type: 'string',
optional: true, nullable: true,
},
smtpPass: {
type: 'string',
optional: true, nullable: true,
},
swPrivateKey: {
type: 'string',
optional: true, nullable: true,
},
useObjectStorage: {
type: 'boolean',
optional: true, nullable: false,
},
objectStorageBaseUrl: {
type: 'string',
optional: true, nullable: true,
},
objectStorageBucket: {
type: 'string',
optional: true, nullable: true,
},
objectStoragePrefix: {
type: 'string',
optional: true, nullable: true,
},
objectStorageEndpoint: {
type: 'string',
optional: true, nullable: true,
},
objectStorageRegion: {
type: 'string',
optional: true, nullable: true,
},
objectStoragePort: {
type: 'number',
optional: true, nullable: true,
},
objectStorageAccessKey: {
type: 'string',
optional: true, nullable: true,
},
objectStorageSecretKey: {
type: 'string',
optional: true, nullable: true,
},
objectStorageUseSSL: {
type: 'boolean',
optional: true, nullable: false,
},
objectStorageUseProxy: {
type: 'boolean',
optional: true, nullable: false,
},
objectStorageSetPublicRead: {
type: 'boolean',
optional: true, nullable: false,
},
enableIpLogging: {
type: 'boolean',
optional: true, nullable: false,
},
enableActiveEmailValidation: {
type: 'boolean',
optional: true, nullable: false,
},
enableChartsForRemoteUser: {
type: 'boolean',
optional: false, nullable: false,
},
enableChartsForFederatedInstances: {
type: 'boolean',
optional: false, nullable: false,
},
policies: {
type: 'object',
optional: false, nullable: false,
},
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'admin/meta'> {
name = 'admin/meta' as const;
constructor(
@Inject(DI.config)
private config: Config,
private metaService: MetaService,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
const instance = await this.metaService.fetch(true);
return {
@ -314,6 +51,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
enableEmail: instance.enableEmail,
enableServiceWorker: instance.enableServiceWorker,
translatorAvailable: instance.deeplAuthKey != null,
policies: { ...DEFAULT_POLICIES, ...instance.policies },
cacheRemoteFiles: instance.cacheRemoteFiles,
pinnedUsers: instance.pinnedUsers,
hiddenTags: instance.hiddenTags,
@ -355,7 +94,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
enableActiveEmailValidation: instance.enableActiveEmailValidation,
enableChartsForRemoteUser: instance.enableChartsForRemoteUser,
enableChartsForFederatedInstances: instance.enableChartsForFederatedInstances,
policies: { ...DEFAULT_POLICIES, ...instance.policies },
};
});
}

View file

@ -291,9 +291,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
iconUrl: instance.iconUrl,
backgroundImageUrl: instance.backgroundImageUrl,
logoImageUrl: instance.logoImageUrl,
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH,
defaultLightTheme: instance.defaultLightTheme,
defaultDarkTheme: instance.defaultDarkTheme,
enableEmail: instance.enableEmail,
enableServiceWorker: instance.enableServiceWorker,
translatorAvailable: instance.deeplAuthKey != null,
policies: { ...DEFAULT_POLICIES, ...instance.policies },
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH,
ads: ads.map(ad => ({
id: ad.id,
url: ad.url,
@ -301,15 +306,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
ratio: ad.ratio,
imageUrl: ad.imageUrl,
})),
enableEmail: instance.enableEmail,
enableServiceWorker: instance.enableServiceWorker,
translatorAvailable: instance.deeplAuthKey != null,
serverRules: instance.serverRules,
policies: { ...DEFAULT_POLICIES, ...instance.policies },
mediaProxy: this.config.mediaProxy,
...(ps.detail ? {

View file

@ -1,3 +1,4 @@
import { JSONSchema7 } from 'schema-type';
import { IEndpointMeta } from './endpoints.types';
import { localUsernameSchema, passwordSchema } from './schemas/user';
@ -1535,6 +1536,19 @@ export const endpoints = {
},
}],
},
'admin/meta': {
tags: ['meta'],
requireCredential: true,
requireAdmin: true,
defines: [{
req: undefined,
res: {
$ref: 'https://misskey-hub.net/api/schemas/InstanceMetaAdmin',
},
}],
}
} as const satisfies { [x: string]: IEndpointMeta; };
/**

View file

@ -43,6 +43,10 @@ import {
packedRolePolicySchema,
packedRoleCondFormulaSchema,
} from './schemas/role.js';
import {
InstanceMetaSharedSchema,
InstanceMetaAdminSchema,
} from './schemas/instance-meta.js';
import { Error, ApiError } from './schemas/error.js';
import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type';
@ -89,6 +93,8 @@ export const refs = {
RolePolicy: packedRolePolicySchema,
RoleCondFormula: packedRoleCondFormulaSchema,
AbuseUserReport: packedAbuseUserReportSchema,
InstanceMetaShared: InstanceMetaSharedSchema,
InstanceMetaAdmin: InstanceMetaAdminSchema,
Error: Error,
ApiError: ApiError,

View file

@ -0,0 +1,209 @@
import type { JSONSchema7, JSONSchema7Definition } from 'schema-type';
export const InstanceMetaSharedSchema = {
$id: 'https://misskey-hub.net/api/schemas/InstanceMetaShared',
type: 'object',
properties: {
maintainerName: { type: ['string', 'null'] },
maintainerEmail: { type: ['string', 'null'] },
version: { type: 'string' },
name: { type: ['string', 'null'] },
uri: { type: 'string' },
description: { type: ['string', 'null'] },
langs: {
type: 'array',
items: { type: 'string' },
},
tosUrl: { type: ['string', 'null'] },
repositoryUrl: { type: 'string' },
feedbackUrl: { type: ['string', 'null'] },
disableRegistration: { type: 'boolean' },
emailRequiredForSignup: { type: 'boolean' },
enableHcaptcha: { type: 'boolean' },
hcaptchaSiteKey: { type: ['string', 'null'] },
enableRecaptcha: { type: 'boolean' },
recaptchaSiteKey: { type: ['string', 'null'] },
enableTurnstile: { type: 'boolean' },
turnstileSiteKey: { type: ['string', 'null'] },
swPublickey: { type: ['string', 'null'] },
themeColor: { type: ['string', 'null'] },
mascotImageUrl: {
type: ['string', 'null'],
default: '/assets/ai.png',
},
bannerUrl: { type: ['string', 'null'] },
errorImageUrl: {
type: ['string', 'null'],
default: 'https://xn--931a.moe/aiart/yubitun.png',
},
iconUrl: { type: ['string', 'null'] },
backgroundImageUrl: { type: ['string', 'null'] },
logoImageUrl: { type: ['string', 'null'] },
defaultLightTheme: { type: ['string', 'null'] },
defaultDarkTheme: { type: ['string', 'null'] },
enableEmail: { type: 'boolean' },
enableServiceWorker: { type: 'boolean' },
translatorAvailable: { type: 'boolean' },
policies: {
type: 'object',
},
},
required: [
'maintainerName',
'maintainerEmail',
'version',
'name',
'uri',
'description',
'langs',
'tosUrl',
'repositoryUrl',
'feedbackUrl',
'disableRegistration',
'emailRequiredForSignup',
'enableHcaptcha',
'hcaptchaSiteKey',
'enableRecaptcha',
'recaptchaSiteKey',
'enableTurnstile',
'turnstileSiteKey',
'swPublickey',
'themeColor',
'mascotImageUrl',
'bannerUrl',
'errorImageUrl',
'iconUrl',
'backgroundImageUrl',
'logoImageUrl',
'defaultLightTheme',
'defaultDarkTheme',
'enableEmail',
'enableServiceWorker',
'translatorAvailable',
'policies',
],
} as const satisfies JSONSchema7Definition;
export const InstanceMetaAdminSchema = {
$id: 'https://misskey-hub.net/api/schemas/InstanceMetaAdmin',
allOf: [
{ $ref: 'https://misskey-hub.net/api/schemas/InstanceMetaShared' },
{
type: 'object',
properties: {
cacheRemoteFiles: { type: 'boolean' },
pinnedUsers: {
type: 'array',
items: {
type: 'string',
},
},
hiddenTags: {
type: 'array',
items: {
type: 'string',
},
},
blockedHosts: {
type: 'array',
items: {
type: 'string',
},
},
sensitiveWords: {
type: 'array',
items: {
type: 'string',
},
},
preservedUsernames: {
type: 'array',
items: {
type: 'string',
},
},
hcaptchaSecretKey: { type: ['string', 'null'] },
recaptchaSecretKey: { type: ['string', 'null'] },
turnstileSecretKey: { type: ['string', 'null'] },
sensitiveMediaDetection: { type: 'string', enum: ['none', 'all', 'local', 'remote'] },
sensitiveMediaDetectionSensitivity: { type: 'string', enum: ['medium', 'low', 'high', 'veryLow', 'veryHigh'] },
setSensitiveFlagAutomatically: { type: 'boolean' },
enableSensitiveMediaDetectionForVideos: { type: 'boolean' },
proxyAccountId: {
$ref: 'https://misskey-hub.net/api/schemas/Id',
},
summaryProxy: { type: ['string', 'null'] },
email: { type: ['string', 'null'] },
smtpSecure: { type: 'boolean' },
smtpHost: { type: ['string', 'null'] },
smtpPort: { type: ['number', 'null'] },
smtpUser: { type: ['string', 'null'] },
smtpPass: { type: ['string', 'null'] },
swPrivateKey: { type: ['string', 'null'] },
useObjectStorage: { type: 'boolean' },
objectStorageBaseUrl: { type: ['string', 'null'] },
objectStorageBucket: { type: ['string', 'null'] },
objectStoragePrefix: { type: ['string', 'null'] },
objectStorageEndpoint: { type: ['string', 'null'] },
objectStorageRegion: { type: ['string', 'null'] },
objectStoragePort: { type: ['number', 'null'] },
objectStorageAccessKey: { type: ['string', 'null'] },
objectStorageSecretKey: { type: ['string', 'null'] },
objectStorageUseSSL: { type: 'boolean' },
objectStorageUseProxy: { type: 'boolean' },
objectStorageSetPublicRead: { type: 'boolean' },
objectStorageS3ForcePathStyle: { type: 'boolean' },
deeplAuthKey: { type: ['string', 'null'] },
deeplIsPro: { type: 'boolean' },
enableIpLogging: { type: 'boolean' },
enableActiveEmailValidation: { type: 'boolean' },
enableChartsForRemoteUser: { type: 'boolean' },
enableChartsForFederatedInstances: { type: 'boolean' },
} satisfies Record<string, JSONSchema7>,
required: [
'cacheRemoteFiles',
'pinnedUsers',
'hiddenTags',
'blockedHosts',
'sensitiveWords',
'preservedUsernames',
'hcaptchaSecretKey',
'recaptchaSecretKey',
'turnstileSecretKey',
'sensitiveMediaDetection',
'sensitiveMediaDetectionSensitivity',
'setSensitiveFlagAutomatically',
'enableSensitiveMediaDetectionForVideos',
'proxyAccountId',
'summalyProxy',
'email',
'smtpSecure',
'smtpHost',
'smtpPort',
'smtpUser',
'smtpPass',
'swPrivateKey',
'useObjectStorage',
'objectStorageBaseUrl',
'objectStorageBucket',
'objectStoragePrefix',
'objectStorageEndpoint',
'objectStorageRegion',
'objectStoragePort',
'objectStorageAccessKey',
'objectStorageSecretKey',
'objectStorageUseSSL',
'objectStorageUseProxy',
'objectStorageSetPublicRead',
'objectStorageS3ForcePathStyle',
'deeplAuthKey',
'deeplIsPro',
'enableIpLogging',
'enableActiveEmailValidation',
'enableChartsForRemoteUser',
'enableChartsForFederatedInstances',
],
},
]
} as const satisfies JSONSchema7Definition;