Skip to content

Commit

Permalink
Merge pull request #462
Browse files Browse the repository at this point in the history
* Fix: Frontend

* Fix: SPDX P1

* Fix: TypeCheck

* Fix: aws-sdk/client-s3

* Fix: test死んでいるので。

* Fix: SPDX
  • Loading branch information
mirielnet authored May 13, 2024
1 parent 11c2e56 commit 3241db6
Show file tree
Hide file tree
Showing 25 changed files with 833 additions and 588 deletions.
5 changes: 5 additions & 0 deletions packages/backend/migration/1696604572677-poll-vote-poll.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project and cherrypick-contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class PollVotePoll1696604572677 {
name = 'PollVotePoll1696604572677';

Expand Down
4 changes: 4 additions & 0 deletions packages/backend/migration/1697737204579-deleteCreatedAt.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project and cherrypick-contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class DeleteCreatedAt1697737204579 {
name = 'DeleteCreatedAt1697737204579'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project and cherrypick-contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class RemoteAvaterDecoration1699432324194 {
name = 'RemoteAvaterDecoration1699432324194'

Expand Down
5 changes: 5 additions & 0 deletions packages/backend/migration/1704185628000-note-updated-at2.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project and cherrypick-contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class NoteUpdatedAt1704185628000 {
name = 'NoteUpdatedAt1704185628000'

Expand Down
6 changes: 3 additions & 3 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"watch": "node ./scripts/watch.mjs",
"restart": "pnpm build && pnpm start",
"dev": "node ./scripts/dev.mjs",
"typecheck": "tsc --noEmit && tsc -p test --noEmit",
"typecheck": "tsc --noEmit",
"eslint": "eslint --quiet \"src/**/*.ts\"",
"lint": "pnpm typecheck && pnpm eslint",
"jest": "cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --forceExit --config jest.config.unit.cjs",
Expand Down Expand Up @@ -66,8 +66,8 @@
"utf-8-validate": "6.0.3"
},
"dependencies": {
"@aws-sdk/client-s3": "3.412.0",
"@aws-sdk/lib-storage": "3.412.0",
"@aws-sdk/client-s3": "3.540.0",
"@aws-sdk/lib-storage": "3.413.0",
"@bull-board/api": "5.14.2",
"@bull-board/fastify": "5.14.2",
"@bull-board/ui": "5.14.2",
Expand Down
23 changes: 4 additions & 19 deletions packages/backend/src/core/AntennaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { bindThis } from '@/decorators.js';
import type { GlobalEvents } from '@/core/GlobalEventService.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import type { OnApplicationShutdown } from '@nestjs/common';
import { deserializeAntenna } from './deserializeAntenna.js';

@Injectable()
export class AntennaService implements OnApplicationShutdown {
Expand Down Expand Up @@ -58,30 +59,14 @@ export class AntennaService implements OnApplicationShutdown {
const { type, body } = obj.message as GlobalEvents['internal']['payload'];
switch (type) {
case 'antennaCreated':
this.antennas.push({ // TODO: このあたりのデシリアライズ処理は各modelファイル内に関数としてexportしたい
...body,
lastUsedAt: new Date(body.lastUsedAt),
user: null, // joinなカラムは通常取ってこないので
userList: null, // joinなカラムは通常取ってこないので
});
this.antennas.push(deserializeAntenna(body));
break;
case 'antennaUpdated': {
const idx = this.antennas.findIndex(a => a.id === body.id);
if (idx >= 0) {
this.antennas[idx] = { // TODO: このあたりのデシリアライズ処理は各modelファイル内に関数としてexportしたい
...body,
lastUsedAt: new Date(body.lastUsedAt),
user: null, // joinなカラムは通常取ってこないので
userList: null, // joinなカラムは通常取ってこないので
};
this.antennas[idx] = deserializeAntenna(body);
} else {
// サーバ起動時にactiveじゃなかった場合、リストに持っていないので追加する必要あり
this.antennas.push({ // TODO: このあたりのデシリアライズ処理は各modelファイル内に関数としてexportしたい
...body,
lastUsedAt: new Date(body.lastUsedAt),
user: null, // joinなカラムは通常取ってこないので
userList: null, // joinなカラムは通常取ってこないので
});
this.antennas.push(deserializeAntenna(body));
}
}
break;
Expand Down
15 changes: 15 additions & 0 deletions packages/backend/src/core/deserializeAntenna.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: cherrypick-contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

import type { MiAntenna } from '@/models/Antenna.js';

export function deserializeAntenna(body: any): MiAntenna {
return {
...body,
lastUsedAt: new Date(body.lastUsedAt),
user: null,
userList: null,
};
}
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ export const packedRolePoliciesSchema = {
type: 'integer',
optional: false, nullable: false,
},
canEditNote: {
type: 'boolean',
optional: false, nullable: false,
},
},
} as const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,45 @@ import { IdService } from '@/core/IdService.js';

export const meta = {
tags: ['admin'],

requireCredential: true,

secure: true,
requireAdmin: true,

kind: 'arr-create', // ここにkindプロパティを追加
res: {
type: 'object',
properties: {
name: {
type: 'string',
nullable: false, optional: false,
nullable: false,
optional: false,
},
targetUserPattern: {
type: 'string',
nullable: true, optional: false,
nullable: true,
optional: false,
},
reporterPattern: {
type: 'string',
nullable: true, optional: false,
nullable: true,
optional: false,
},
reportContentPattern: {
type: 'string',
nullable: true, optional: false,
nullable: true,
optional: false,
},
expiresAt: {
type: 'string',
nullable: false, optional: false,
nullable: false,
optional: false,
},
forward: {
type: 'boolean',
nullable: false, optional: false,
nullable: false,
optional: false,
},
},
},

errors: {
invalidRegularExpressionForTargetUser: {
message: 'Invalid regular expression for target user.',
Expand Down Expand Up @@ -116,12 +120,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const previousMonth = expirationDate.getUTCMonth();
(ps.expiresAt === '1hour' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 hour')); } :
ps.expiresAt === '12hours' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('12 hours')); } :
ps.expiresAt === '1day' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 day')); } :
ps.expiresAt === '1week' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 week')); } :
ps.expiresAt === '1month' ? function () { expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 1 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 1 + 1) / 12))); } :
ps.expiresAt === '3months' ? function () {expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 3 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 3 + 1) / 12))); } :
ps.expiresAt === '6months' ? function () { expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 6 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 6 + 1) / 12))); } :
ps.expiresAt === '1year' ? function () { expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + 1); } : function () { expirationDate = null; })();
ps.expiresAt === '1day' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 day')); } :
ps.expiresAt === '1week' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 week')); } :
ps.expiresAt === '1month' ? function () { expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 1 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 1 + 1) / 12))); } :
ps.expiresAt === '3months' ? function () {expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 3 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 3 + 1) / 12))); } :
ps.expiresAt === '6months' ? function () { expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 6 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 6 + 1) / 12))); } :
ps.expiresAt === '1year' ? function () { expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + 1); } : function () { expirationDate = null; })();

return await this.abuseReportResolverRepository.insert({
id: this.idService.gen(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { ApiError } from '../../../error.js';

export const meta = {
requireCrendential: true,

kind: 'arr-delete', // ここにkindプロパティを追加
requireAdmin: true,
secure: true,

errors: {
resolverNotFound: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import type { AbuseReportResolversRepository } from '@/models/_.js';

export const meta = {
requireCredential: true,

kind: 'arr-list', // ここにkindプロパティを追加
secure: true,
requireAdmin: true,

res: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { ApiError } from '../../../error.js';

export const meta = {
requireCredential: true,

kind: 'arr-update', // ここにkindプロパティを追加
secure: true,
requireAdmin: true,

errors: {
Expand Down Expand Up @@ -102,12 +103,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
const previousMonth = expirationDate.getUTCMonth();
(ps.expiresAt === '1hour' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 hour')); } :
ps.expiresAt === '12hours' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('12 hours')); } :
ps.expiresAt === '1day' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 day')); } :
ps.expiresAt === '1week' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 week')); } :
ps.expiresAt === '1month' ? function () { expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 1 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 1 + 1) / 12))); } :
ps.expiresAt === '3months' ? function () {expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 3 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 3 + 1) / 12))); } :
ps.expiresAt === '6months' ? function () { expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 6 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 6 + 1) / 12))); } :
ps.expiresAt === '1year' ? function () { expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + 1); } : function () { expirationDate = null; })();
ps.expiresAt === '1day' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 day')); } :
ps.expiresAt === '1week' ? function () { expirationDate!.setTime(expirationDate!.getTime() + ms('1 week')); } :
ps.expiresAt === '1month' ? function () { expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 1 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 1 + 1) / 12))); } :
ps.expiresAt === '3months' ? function () {expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 3 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 3 + 1) / 12))); } :
ps.expiresAt === '6months' ? function () { expirationDate!.setUTCMonth((expirationDate!.getUTCMonth() + 6 + 1) % 12 - 1); expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + (Math.floor((previousMonth + 6 + 1) / 12))); } :
ps.expiresAt === '1year' ? function () { expirationDate!.setUTCFullYear(expirationDate!.getUTCFullYear() + 1); } : function () { expirationDate = null; })();

properties.expiresAt = ps.expiresAt;
properties.expirationDate = expirationDate;
Expand Down
10 changes: 7 additions & 3 deletions packages/backend/src/server/api/endpoints/messaging/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
}

return await Promise.all(messages.map(message => this.messagingMessageEntityService.pack(message, me, {
return Promise.all(messages.map(message => this.messagingMessageEntityService.pack(message, me, {
populateRecipient: false,
})));
} else if (ps.groupId != null) {
Expand Down Expand Up @@ -160,13 +160,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

// Mark all as read
if (ps.markAsRead) {
this.messagingService.readGroupMessagingMessage(me.id, recipientGroup.id, messages.map(x => x.id));
await this.messagingService.readGroupMessagingMessage(me.id, recipientGroup.id, messages.map(x => x.id));
}

return await Promise.all(messages.map(message => this.messagingMessageEntityService.pack(message, me, {
return Promise.all(messages.map(message => this.messagingMessageEntityService.pack(message, me, {
populateGroup: false,
})));
}

// 必要に応じて適切な戻り値を提供する
return []; // デフォルトの戻り値を返す
});
}
}

26 changes: 13 additions & 13 deletions packages/backend/src/server/api/endpoints/notes/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
translator: translatorServices,
};
} else if (instance.translatorType === 'ctav3') {
if (instance.ctav3SaKey == null) return 204;
else if (instance.ctav3ProjectId == null) return 204;
else if (instance.ctav3Location == null) return 204;
if (instance.ctav3SaKey == null) return Promise.resolve(204);
else if (instance.ctav3ProjectId == null) return Promise.resolve(204);
else if (instance.ctav3Location == null) return Promise.resolve(204);
translationResult = await this.apiCloudTranslationAdvanced(
(note.cw ? note.cw + '\n' : '') + note.text, targetLang, instance.ctav3SaKey, instance.ctav3ProjectId, instance.ctav3Location, instance.ctav3Model, instance.ctav3Glossary, instance.translatorType,
);
} else {
throw new Error('Unsupported translator type');
}

return {
sourceLang: translationResult.sourceLang,
text: translationResult.text,
translator: translationResult.translator,
};
return Promise.resolve({
sourceLang: translationResult.sourceLang || '',
text: translationResult.text || '',
translator: translationResult.translator || [],
});
});
}

Expand All @@ -162,11 +162,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});

const json = (await res.json()) as {
translations: {
detected_source_language: string;
text: string;
}[];
};
translations: {
detected_source_language: string;
text: string;
}[];
};

return {
sourceLang: json.translations[0].detected_source_language,
Expand Down
7 changes: 5 additions & 2 deletions packages/backend/src/server/api/endpoints/notes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const paramDef = {
} as const;

@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository,
Expand All @@ -104,7 +104,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private noteEntityService: NoteEntityService,
private noteUpdateService: NoteUpdateService,
) {
super(meta, paramDef, async (ps, me) => {
super({
...meta,
requireRolePolicy: "canEditNote", // 修正された部分
}, paramDef, async (ps, me) => {
const note = await this.getterService.getNote(ps.noteId).catch(err => {
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
throw err;
Expand Down
Loading

0 comments on commit 3241db6

Please sign in to comment.