Skip to content

Commit

Permalink
ノートの翻訳機能を削除
Browse files Browse the repository at this point in the history
  • Loading branch information
adzukimame committed Dec 7, 2024
1 parent f5a51b4 commit 20b5cca
Show file tree
Hide file tree
Showing 26 changed files with 20 additions and 506 deletions.
13 changes: 13 additions & 0 deletions packages/backend/migration/1733587862446-RemoveNoteTranslate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default class RemoveNoteTranslate1733587862446 {
name = 'RemoveNoteTranslate1733587862446'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "deeplAuthKey"`);
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "deeplIsPro"`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "deeplIsPro" boolean NOT NULL DEFAULT false`);
await queryRunner.query(`ALTER TABLE "meta" ADD "deeplAuthKey" character varying(1024)`);
}
}
3 changes: 0 additions & 3 deletions packages/backend/src/core/RoleService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export type RolePolicies = {
inviteExpirationTime: number;
canManageCustomEmojis: boolean;
canSearchNotes: boolean;
canUseTranslator: boolean;
driveCapacityMb: number;
alwaysMarkNsfw: boolean;
canUpdateBioMedia: boolean;
Expand All @@ -66,7 +65,6 @@ export const DEFAULT_POLICIES: RolePolicies = {
inviteExpirationTime: 0,
canManageCustomEmojis: false,
canSearchNotes: false,
canUseTranslator: true,
driveCapacityMb: 100,
alwaysMarkNsfw: false,
canUpdateBioMedia: true,
Expand Down Expand Up @@ -355,7 +353,6 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
inviteExpirationTime: calc('inviteExpirationTime', vs => Math.max(...vs)),
canManageCustomEmojis: calc('canManageCustomEmojis', vs => vs.some(v => v === true)),
canSearchNotes: calc('canSearchNotes', vs => vs.some(v => v === true)),
canUseTranslator: calc('canUseTranslator', vs => vs.some(v => v === true)),
driveCapacityMb: calc('driveCapacityMb', vs => Math.max(...vs)),
alwaysMarkNsfw: calc('alwaysMarkNsfw', vs => vs.some(v => v === true)),
canUpdateBioMedia: calc('canUpdateBioMedia', vs => vs.some(v => v === true)),
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/core/entities/MetaEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ export class MetaEntityService {
defaultDarkTheme,
enableEmail: instance.enableEmail,

translatorAvailable: instance.deeplAuthKey != null,

serverRules: instance.serverRules,

policies: { ...DEFAULT_POLICIES, ...instance.policies },
Expand Down
11 changes: 0 additions & 11 deletions packages/backend/src/models/Meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,6 @@ export class MiMeta {
})
public smtpPass: string | null;

@Column('varchar', {
length: 1024,
nullable: true,
})
public deeplAuthKey: string | null;

@Column('boolean', {
default: false,
})
public deeplIsPro: boolean;

@Column('varchar', {
length: 1024,
nullable: true,
Expand Down
4 changes: 0 additions & 4 deletions packages/backend/src/models/json-schema/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ export const packedMetaLiteSchema = {
type: 'boolean',
optional: false, nullable: false,
},
translatorAvailable: {
type: 'boolean',
optional: false, nullable: false,
},
mediaProxy: {
type: 'string',
optional: false, nullable: false,
Expand Down
4 changes: 0 additions & 4 deletions packages/backend/src/models/json-schema/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ export const packedRolePoliciesSchema = {
type: 'boolean',
optional: false, nullable: false,
},
canUseTranslator: {
type: 'boolean',
optional: false, nullable: false,
},
driveCapacityMb: {
type: 'integer',
optional: false, nullable: false,
Expand Down
4 changes: 0 additions & 4 deletions packages/backend/src/server/api/EndpointsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ import * as ep___notes_state from './endpoints/notes/state.js';
import * as ep___notes_threadMuting_create from './endpoints/notes/thread-muting/create.js';
import * as ep___notes_threadMuting_delete from './endpoints/notes/thread-muting/delete.js';
import * as ep___notes_timeline from './endpoints/notes/timeline.js';
import * as ep___notes_translate from './endpoints/notes/translate.js';
import * as ep___notes_unrenote from './endpoints/notes/unrenote.js';
import * as ep___notes_userListTimeline from './endpoints/notes/user-list-timeline.js';
import * as ep___notifications_create from './endpoints/notifications/create.js';
Expand Down Expand Up @@ -537,7 +536,6 @@ const $notes_state: Provider = { provide: 'ep:notes/state', useClass: ep___notes
const $notes_threadMuting_create: Provider = { provide: 'ep:notes/thread-muting/create', useClass: ep___notes_threadMuting_create.default };
const $notes_threadMuting_delete: Provider = { provide: 'ep:notes/thread-muting/delete', useClass: ep___notes_threadMuting_delete.default };
const $notes_timeline: Provider = { provide: 'ep:notes/timeline', useClass: ep___notes_timeline.default };
const $notes_translate: Provider = { provide: 'ep:notes/translate', useClass: ep___notes_translate.default };
const $notes_unrenote: Provider = { provide: 'ep:notes/unrenote', useClass: ep___notes_unrenote.default };
const $notes_userListTimeline: Provider = { provide: 'ep:notes/user-list-timeline', useClass: ep___notes_userListTimeline.default };
const $notifications_create: Provider = { provide: 'ep:notifications/create', useClass: ep___notifications_create.default };
Expand Down Expand Up @@ -834,7 +832,6 @@ const $users_updateMemo: Provider = { provide: 'ep:users/update-memo', useClass:
$notes_threadMuting_create,
$notes_threadMuting_delete,
$notes_timeline,
$notes_translate,
$notes_unrenote,
$notes_userListTimeline,
$notifications_create,
Expand Down Expand Up @@ -1125,7 +1122,6 @@ const $users_updateMemo: Provider = { provide: 'ep:users/update-memo', useClass:
$notes_threadMuting_create,
$notes_threadMuting_delete,
$notes_timeline,
$notes_translate,
$notes_unrenote,
$notes_userListTimeline,
$notifications_create,
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/server/api/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ import * as ep___notes_state from './endpoints/notes/state.js';
import * as ep___notes_threadMuting_create from './endpoints/notes/thread-muting/create.js';
import * as ep___notes_threadMuting_delete from './endpoints/notes/thread-muting/delete.js';
import * as ep___notes_timeline from './endpoints/notes/timeline.js';
import * as ep___notes_translate from './endpoints/notes/translate.js';
import * as ep___notes_unrenote from './endpoints/notes/unrenote.js';
import * as ep___notes_userListTimeline from './endpoints/notes/user-list-timeline.js';
import * as ep___notifications_create from './endpoints/notifications/create.js';
Expand Down Expand Up @@ -536,7 +535,6 @@ const eps = [
['notes/thread-muting/create', ep___notes_threadMuting_create],
['notes/thread-muting/delete', ep___notes_threadMuting_delete],
['notes/timeline', ep___notes_timeline],
['notes/translate', ep___notes_translate],
['notes/unrenote', ep___notes_unrenote],
['notes/user-list-timeline', ep___notes_userListTimeline],
['notifications/create', ep___notifications_create],
Expand Down
15 changes: 0 additions & 15 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ export const meta = {
type: 'boolean',
optional: false, nullable: false,
},
translatorAvailable: {
type: 'boolean',
optional: false, nullable: false,
},
silencedHosts: {
type: 'array',
optional: false,
Expand Down Expand Up @@ -367,14 +363,6 @@ export const meta = {
type: 'string',
optional: false, nullable: true,
},
deeplAuthKey: {
type: 'string',
optional: false, nullable: true,
},
deeplIsPro: {
type: 'boolean',
optional: false, nullable: false,
},
defaultDarkTheme: {
type: 'string',
optional: false, nullable: true,
Expand Down Expand Up @@ -553,7 +541,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
defaultLightTheme: instance.defaultLightTheme,
defaultDarkTheme: instance.defaultDarkTheme,
enableEmail: instance.enableEmail,
translatorAvailable: instance.deeplAuthKey != null,
cacheRemoteFiles: instance.cacheRemoteFiles,
cacheRemoteSensitiveFiles: instance.cacheRemoteSensitiveFiles,
pinnedUsers: instance.pinnedUsers,
Expand Down Expand Up @@ -592,8 +579,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
objectStorageUseProxy: instance.objectStorageUseProxy,
objectStorageSetPublicRead: instance.objectStorageSetPublicRead,
objectStorageS3ForcePathStyle: instance.objectStorageS3ForcePathStyle,
deeplAuthKey: instance.deeplAuthKey,
deeplIsPro: instance.deeplIsPro,
enableIpLogging: instance.enableIpLogging,
enableActiveEmailValidation: instance.enableActiveEmailValidation,
enableVerifymailApi: instance.enableVerifymailApi,
Expand Down
14 changes: 0 additions & 14 deletions packages/backend/src/server/api/endpoints/admin/update-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ export const paramDef = {
type: 'string',
},
},
deeplAuthKey: { type: 'string', nullable: true },
deeplIsPro: { type: 'boolean' },
enableEmail: { type: 'boolean' },
email: { type: 'string', nullable: true },
smtpSecure: { type: 'boolean' },
Expand Down Expand Up @@ -488,18 +486,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.objectStorageS3ForcePathStyle = ps.objectStorageS3ForcePathStyle;
}

if (ps.deeplAuthKey !== undefined) {
if (ps.deeplAuthKey === '') {
set.deeplAuthKey = null;
} else {
set.deeplAuthKey = ps.deeplAuthKey;
}
}

if (ps.deeplIsPro !== undefined) {
set.deeplIsPro = ps.deeplIsPro;
}

if (ps.enableIpLogging !== undefined) {
set.enableIpLogging = ps.enableIpLogging;
}
Expand Down
126 changes: 0 additions & 126 deletions packages/backend/src/server/api/endpoints/notes/translate.ts

This file was deleted.

57 changes: 0 additions & 57 deletions packages/backend/test/e2e/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,61 +979,4 @@ describe('Note', () => {
assert.strictEqual(mainNote.repliesCount, 0);
});
});

describe('notes/translate', () => {
describe('翻訳機能の利用が許可されていない場合', () => {
let cannotTranslateRole: misskey.entities.Role;

beforeAll(async () => {
cannotTranslateRole = await role(root, {}, { canUseTranslator: false });
await api('admin/roles/assign', { roleId: cannotTranslateRole.id, userId: alice.id }, root);
});

test('翻訳機能の利用が許可されていない場合翻訳できない', async () => {
const aliceNote = await post(alice, { text: 'Hello' });
const res = await api('notes/translate', {
noteId: aliceNote.id,
targetLang: 'ja',
}, alice);

assert.strictEqual(res.status, 400);
assert.strictEqual(castAsError(res.body).error.code, 'UNAVAILABLE');
});

afterAll(async () => {
await api('admin/roles/unassign', { roleId: cannotTranslateRole.id, userId: alice.id }, root);
});
});

test('存在しないノートは翻訳できない', async () => {
const res = await api('notes/translate', { noteId: 'foo', targetLang: 'ja' }, alice);

assert.strictEqual(res.status, 400);
assert.strictEqual(castAsError(res.body).error.code, 'NO_SUCH_NOTE');
});

test('不可視なノートは翻訳できない', async () => {
const aliceNote = await post(alice, { visibility: 'followers', text: 'Hello' });
const bobTranslateAttempt = await api('notes/translate', { noteId: aliceNote.id, targetLang: 'ja' }, bob);

assert.strictEqual(bobTranslateAttempt.status, 400);
assert.strictEqual(castAsError(bobTranslateAttempt.body).error.code, 'CANNOT_TRANSLATE_INVISIBLE_NOTE');
});

test('text: null なノートを翻訳すると空のレスポンスが返ってくる', async () => {
const aliceNote = await post(alice, { text: null, poll: { choices: ['kinoko', 'takenoko'] } });
const res = await api('notes/translate', { noteId: aliceNote.id, targetLang: 'ja' }, alice);

assert.strictEqual(res.status, 204);
});

test('サーバーに DeepL 認証キーが登録されていない場合翻訳できない', async () => {
const aliceNote = await post(alice, { text: 'Hello' });
const res = await api('notes/translate', { noteId: aliceNote.id, targetLang: 'ja' }, alice);

// NOTE: デフォルトでは登録されていないので落ちる
assert.strictEqual(res.status, 400);
assert.strictEqual(castAsError(res.body).error.code, 'UNAVAILABLE');
});
});
});
Loading

0 comments on commit 20b5cca

Please sign in to comment.