Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 再アップロードはエンドポイント側でするように #566

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/backend/src/core/CustomEmojiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,7 @@
isSensitive: boolean;
localOnly: boolean;
roleIdsThatCanBeUsedThisEmojiAsReaction: MiRole['id'][];
}, moderator?: MiUser): Promise<MiEmoji> {

Check failure on line 107 in packages/backend/src/core/CustomEmojiService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Block must not be padded by blank lines
// システムユーザーとして再アップロード
if (!data.driveFile.user?.isRoot) {
data.driveFile = await this.driveService.uploadFromUrl({
url: data.driveFile.url,
user: null,
force: true,
});
}

const emoji = await this.emojisRepository.insertOne({
id: this.idService.gen(),
Expand Down
16 changes: 15 additions & 1 deletion packages/backend/src/server/api/endpoints/admin/emoji/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import type { DriveFilesRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
import { DriveService } from '@/core/DriveService.js';
import { EmojiEntityService } from '@/core/entities/EmojiEntityService.js';
import { FILE_TYPE_IMAGE } from '@/const.js';
import { ApiError } from '../../../error.js';
Expand Down Expand Up @@ -80,15 +81,28 @@
@Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository,
private customEmojiService: CustomEmojiService,
private driveService: DriveService,
private emojiEntityService: EmojiEntityService,
) {
super(meta, paramDef, async (ps, me) => {
const driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
let driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
const isDuplicate = await this.customEmojiService.checkDuplicate(ps.name);
if (isDuplicate) throw new ApiError(meta.errors.duplicateName);
if (!FILE_TYPE_IMAGE.includes(driveFile.type)) throw new ApiError(meta.errors.unsupportedFileType);

if (!driveFile.user?.isRoot) {
try {
driveFile = await this.driveService.uploadFromUrl({
url: driveFile.url,
user: null,
force: true,
})

Check failure on line 100 in packages/backend/src/server/api/endpoints/admin/emoji/add.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Missing semicolon
} catch (e) {
throw new ApiError(meta.errors.noSuchFile);
}
}

const emoji = await this.customEmojiService.add({
originalUrl: driveFile.url,
publicUrl: driveFile.webpublicUrl ?? driveFile.url,
Expand Down
Loading