fix: importing remote emojis with used name

Closes transfem-org/Sharkey#164
This commit is contained in:
Mar0xy 2023-11-24 18:19:01 +01:00
parent 04dbf7ebe9
commit 7ba8529141
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828

View file

@ -4,6 +4,7 @@
*/
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 { IdService } from '@/core/IdService.js';
@ -26,6 +27,11 @@ export const meta = {
code: 'NO_SUCH_EMOJI',
id: 'e2785b66-dca3-4087-9cac-b93c541cc425',
},
duplicateName: {
message: 'Duplicate name.',
code: 'DUPLICATE_NAME',
id: 'f7a3462c-4e6e-4069-8421-b9bd4f4c3975',
},
},
res: {
@ -69,6 +75,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchEmoji);
}
const isDuplicate = await this.emojisRepository.findOneBy({ name: emoji.name, host: IsNull() } );
if (isDuplicate) throw new ApiError(meta.errors.duplicateName);
let driveFile: MiDriveFile;
try {