merge upstream 2025-02-03
This commit is contained in:
commit
a4e86758c1
264 changed files with 15775 additions and 4919 deletions
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { CaptchaService, supportedCaptchaProviders } from '@/core/CaptchaService.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin', 'captcha'],
|
||||
|
||||
requireCredential: true,
|
||||
requireAdmin: true,
|
||||
|
||||
// 実態はmetaの取得であるため
|
||||
kind: 'read:admin:meta',
|
||||
|
||||
res: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
provider: {
|
||||
type: 'string',
|
||||
enum: supportedCaptchaProviders,
|
||||
},
|
||||
hcaptcha: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
siteKey: { type: 'string', nullable: true },
|
||||
secretKey: { type: 'string', nullable: true },
|
||||
},
|
||||
},
|
||||
mcaptcha: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
siteKey: { type: 'string', nullable: true },
|
||||
secretKey: { type: 'string', nullable: true },
|
||||
instanceUrl: { type: 'string', nullable: true },
|
||||
},
|
||||
},
|
||||
recaptcha: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
siteKey: { type: 'string', nullable: true },
|
||||
secretKey: { type: 'string', nullable: true },
|
||||
},
|
||||
},
|
||||
turnstile: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
siteKey: { type: 'string', nullable: true },
|
||||
secretKey: { type: 'string', nullable: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {} as const;
|
||||
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||
constructor(
|
||||
private captchaService: CaptchaService,
|
||||
) {
|
||||
super(meta, paramDef, async () => {
|
||||
return this.captchaService.get();
|
||||
});
|
||||
}
|
||||
}
|
||||
129
packages/backend/src/server/api/endpoints/admin/captcha/save.ts
Normal file
129
packages/backend/src/server/api/endpoints/admin/captcha/save.ts
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { captchaErrorCodes, CaptchaService, supportedCaptchaProviders } from '@/core/CaptchaService.js';
|
||||
import { ApiError } from '@/server/api/error.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin', 'captcha'],
|
||||
|
||||
requireCredential: true,
|
||||
requireAdmin: true,
|
||||
|
||||
// 実態はmetaの更新であるため
|
||||
kind: 'write:admin:meta',
|
||||
|
||||
errors: {
|
||||
invalidProvider: {
|
||||
message: 'Invalid provider.',
|
||||
code: 'INVALID_PROVIDER',
|
||||
id: '14bf7ae1-80cc-4363-acb2-4fd61d086af0',
|
||||
httpStatusCode: 400,
|
||||
},
|
||||
invalidParameters: {
|
||||
message: 'Invalid parameters.',
|
||||
code: 'INVALID_PARAMETERS',
|
||||
id: '26654194-410e-44e2-b42e-460ff6f92476',
|
||||
httpStatusCode: 400,
|
||||
},
|
||||
noResponseProvided: {
|
||||
message: 'No response provided.',
|
||||
code: 'NO_RESPONSE_PROVIDED',
|
||||
id: '40acbba8-0937-41fb-bb3f-474514d40afe',
|
||||
httpStatusCode: 400,
|
||||
},
|
||||
requestFailed: {
|
||||
message: 'Request failed.',
|
||||
code: 'REQUEST_FAILED',
|
||||
id: '0f4fe2f1-2c15-4d6e-b714-efbfcde231cd',
|
||||
httpStatusCode: 500,
|
||||
},
|
||||
verificationFailed: {
|
||||
message: 'Verification failed.',
|
||||
code: 'VERIFICATION_FAILED',
|
||||
id: 'c41c067f-24f3-4150-84b2-b5a3ae8c2214',
|
||||
httpStatusCode: 400,
|
||||
},
|
||||
unknown: {
|
||||
message: 'unknown',
|
||||
code: 'UNKNOWN',
|
||||
id: 'f868d509-e257-42a9-99c1-42614b031a97',
|
||||
httpStatusCode: 500,
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
provider: {
|
||||
type: 'string',
|
||||
enum: supportedCaptchaProviders,
|
||||
},
|
||||
captchaResult: {
|
||||
type: 'string', nullable: true,
|
||||
},
|
||||
sitekey: {
|
||||
type: 'string', nullable: true,
|
||||
},
|
||||
secret: {
|
||||
type: 'string', nullable: true,
|
||||
},
|
||||
instanceUrl: {
|
||||
type: 'string', nullable: true,
|
||||
},
|
||||
},
|
||||
required: ['provider'],
|
||||
} as const;
|
||||
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||
constructor(
|
||||
private captchaService: CaptchaService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps) => {
|
||||
const result = await this.captchaService.save(ps.provider, {
|
||||
sitekey: ps.sitekey,
|
||||
secret: ps.secret,
|
||||
instanceUrl: ps.instanceUrl,
|
||||
captchaResult: ps.captchaResult,
|
||||
});
|
||||
|
||||
if (!result.success) {
|
||||
switch (result.error.code) {
|
||||
case captchaErrorCodes.invalidProvider:
|
||||
throw new ApiError({
|
||||
...meta.errors.invalidProvider,
|
||||
message: result.error.message,
|
||||
});
|
||||
case captchaErrorCodes.invalidParameters:
|
||||
throw new ApiError({
|
||||
...meta.errors.invalidParameters,
|
||||
message: result.error.message,
|
||||
});
|
||||
case captchaErrorCodes.noResponseProvided:
|
||||
throw new ApiError({
|
||||
...meta.errors.noResponseProvided,
|
||||
message: result.error.message,
|
||||
});
|
||||
case captchaErrorCodes.requestFailed:
|
||||
throw new ApiError({
|
||||
...meta.errors.requestFailed,
|
||||
message: result.error.message,
|
||||
});
|
||||
case captchaErrorCodes.verificationFailed:
|
||||
throw new ApiError({
|
||||
...meta.errors.verificationFailed,
|
||||
message: result.error.message,
|
||||
});
|
||||
default:
|
||||
throw new ApiError(meta.errors.unknown);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import type { DriveFilesRepository } from '@/models/_.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
||||
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
|
||||
import { FILE_TYPE_IMAGE } from '@/const.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
|
||||
export const meta = {
|
||||
|
|
@ -24,6 +25,11 @@ export const meta = {
|
|||
code: 'NO_SUCH_FILE',
|
||||
id: 'fc46b5a4-6b92-4c33-ac66-b806659bb5cf',
|
||||
},
|
||||
unsupportedFileType: {
|
||||
message: 'Unsupported file type.',
|
||||
code: 'UNSUPPORTED_FILE_TYPE',
|
||||
id: 'f7599d96-8750-af68-1633-9575d625c1a7',
|
||||
},
|
||||
duplicateName: {
|
||||
message: 'Duplicate name.',
|
||||
code: 'DUPLICATE_NAME',
|
||||
|
|
@ -47,15 +53,21 @@ export const paramDef = {
|
|||
nullable: true,
|
||||
description: 'Use `null` to reset the category.',
|
||||
},
|
||||
aliases: { type: 'array', items: {
|
||||
type: 'string',
|
||||
} },
|
||||
aliases: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
license: { type: 'string', nullable: true },
|
||||
isSensitive: { type: 'boolean' },
|
||||
localOnly: { type: 'boolean' },
|
||||
roleIdsThatCanBeUsedThisEmojiAsReaction: { type: 'array', items: {
|
||||
type: 'string',
|
||||
} },
|
||||
roleIdsThatCanBeUsedThisEmojiAsReaction: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
required: ['name', 'fileId'],
|
||||
} as const;
|
||||
|
|
@ -67,9 +79,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
constructor(
|
||||
@Inject(DI.driveFilesRepository)
|
||||
private driveFilesRepository: DriveFilesRepository,
|
||||
|
||||
private customEmojiService: CustomEmojiService,
|
||||
|
||||
private emojiEntityService: EmojiEntityService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
|
|
@ -78,11 +88,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
|
||||
const isDuplicate = await this.customEmojiService.checkDuplicate(nameNfc);
|
||||
if (isDuplicate) throw new ApiError(meta.errors.duplicateName);
|
||||
if (!FILE_TYPE_IMAGE.includes(driveFile.type)) throw new ApiError(meta.errors.unsupportedFileType);
|
||||
|
||||
if (driveFile.user !== null) await this.driveFilesRepository.update(driveFile.id, { user: null });
|
||||
|
||||
const emoji = await this.customEmojiService.add({
|
||||
driveFile,
|
||||
originalUrl: driveFile.url,
|
||||
publicUrl: driveFile.webpublicUrl ?? driveFile.url,
|
||||
fileType: driveFile.webpublicType ?? driveFile.type,
|
||||
name: nameNfc,
|
||||
category: ps.category?.normalize('NFC') ?? null,
|
||||
aliases: ps.aliases?.map(a => a.normalize('NFC')) ?? [],
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
*/
|
||||
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { IsNull } from 'typeorm';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import type { EmojisRepository } from '@/models/_.js';
|
||||
import type { MiDriveFile } from '@/models/DriveFile.js';
|
||||
|
|
@ -88,10 +87,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
if (isDuplicate) throw new ApiError(meta.errors.duplicateName);
|
||||
|
||||
const addedEmoji = await this.customEmojiService.add({
|
||||
driveFile,
|
||||
originalUrl: driveFile.url,
|
||||
publicUrl: driveFile.webpublicUrl ?? driveFile.url,
|
||||
fileType: driveFile.webpublicType ?? driveFile.type,
|
||||
name: nameNfc,
|
||||
category: emoji.category?.normalize('NFC') ?? null,
|
||||
aliases: emoji.aliases?.map(a => a.normalize('NFC')),
|
||||
aliases: emoji.aliases.map(a => a.normalize('NFC')),
|
||||
host: null,
|
||||
license: emoji.license,
|
||||
isSensitive: emoji.isSensitive,
|
||||
|
|
|
|||
|
|
@ -86,7 +86,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
|
||||
const error = await this.customEmojiService.update({
|
||||
...required,
|
||||
driveFile,
|
||||
originalUrl: driveFile != null ? driveFile.url : undefined,
|
||||
publicUrl: driveFile != null ? (driveFile.webpublicUrl ?? driveFile.url) : undefined,
|
||||
fileType: driveFile != null ? (driveFile.webpublicType ?? driveFile.type) : undefined,
|
||||
category: ps.category?.normalize('NFC'),
|
||||
aliases: ps.aliases?.map(a => a.normalize('NFC')),
|
||||
license: ps.license,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue