From 08bace6c7db7b34f271c270c0f81d70f0b412438 Mon Sep 17 00:00:00 2001 From: Ehsan Javadynia Date: Tue, 22 Mar 2022 14:48:33 +0100 Subject: [PATCH 1/5] Resolve #7208 (#7226) add decrement replies count on delete note and a test for that --- packages/backend/src/services/note/delete.ts | 4 +++ packages/backend/test/note.ts | 32 ++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/packages/backend/src/services/note/delete.ts b/packages/backend/src/services/note/delete.ts index cf23656f8..356dc3972 100644 --- a/packages/backend/src/services/note/delete.ts +++ b/packages/backend/src/services/note/delete.ts @@ -29,6 +29,10 @@ export default async function(user: User, note: Note, quiet = false) { Notes.decrement({ id: note.renoteId }, 'score', 1); } + if (note.replyId) { + await Notes.decrement({ id: note.replyId }, 'repliesCount', 1); + } + if (!quiet) { publishNoteStream(note.id, 'deleted', { deletedAt: deletedAt, diff --git a/packages/backend/test/note.ts b/packages/backend/test/note.ts index 62cea5208..942b2709d 100644 --- a/packages/backend/test/note.ts +++ b/packages/backend/test/note.ts @@ -333,4 +333,36 @@ describe('Note', () => { assert.strictEqual(res.status, 400); })); }); + + describe('notes/delete', () => { + it('delete a reply', async(async () => { + const mainNoteRes = await request('/notes/create', { + text: 'main post', + }, alice); + const replyOneRes = await request('/notes/create', { + text: 'reply one', + replyId: mainNoteRes.body.createdNote.id + }, alice); + const replyTwoRes = await request('/notes/create', { + text: 'reply two', + replyId: mainNoteRes.body.createdNote.id + }, alice); + + const deleteOneRes = await request('/notes/delete', { + noteId: replyOneRes.body.createdNote.id, + }, alice); + + assert.strictEqual(deleteOneRes.status, 204); + let mainNote = await Notes.findOne({id: mainNoteRes.body.createdNote.id}); + assert.strictEqual(mainNote.repliesCount, 1); + + const deleteTwoRes = await request('/notes/delete', { + noteId: replyTwoRes.body.createdNote.id, + }, alice); + + assert.strictEqual(deleteTwoRes.status, 204); + mainNote = await Notes.findOne({id: mainNoteRes.body.createdNote.id}); + assert.strictEqual(mainNote.repliesCount, 0); + })); + }); }); From 725b78349a9bb34e5f084a802ae7ea5369dc0bd3 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Tue, 22 Mar 2022 18:16:04 +0000 Subject: [PATCH 2/5] recognize null in _misskey_content for notes (#8440) --- packages/backend/src/remote/activitypub/models/note.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index dca64d0a6..0bcc89fbb 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -197,7 +197,7 @@ export async function createNote(value: string | IObject, resolver?: Resolver, s const cw = note.summary === '' ? null : note.summary; // テキストのパース - const text = note._misskey_content || (note.content ? htmlToMfm(note.content, note.tag) : null); + const text = typeof note._misskey_content !== 'undefined' ? note._misskey_content : (note.content ? htmlToMfm(note.content, note.tag) : null); // vote if (reply && reply.hasPoll) { From d0a346ed8ab3fd879d0e1d2635df0b77a9b0bc05 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 25 Mar 2022 01:50:28 +0900 Subject: [PATCH 3/5] refactor: separate meta api for admin or not --- .../src/server/api/endpoints/admin/meta.ts | 401 ++++++++++++++++++ .../backend/src/server/api/endpoints/meta.ts | 184 -------- .../client/src/pages/admin/bot-protection.vue | 2 +- .../client/src/pages/admin/email-settings.vue | 2 +- .../client/src/pages/admin/instance-block.vue | 2 +- .../src/pages/admin/integrations.discord.vue | 2 +- .../src/pages/admin/integrations.github.vue | 2 +- .../src/pages/admin/integrations.twitter.vue | 2 +- .../client/src/pages/admin/integrations.vue | 2 +- .../client/src/pages/admin/object-storage.vue | 2 +- .../client/src/pages/admin/other-settings.vue | 2 +- .../client/src/pages/admin/proxy-account.vue | 2 +- packages/client/src/pages/admin/security.vue | 2 +- packages/client/src/pages/admin/settings.vue | 2 +- 14 files changed, 413 insertions(+), 196 deletions(-) create mode 100644 packages/backend/src/server/api/endpoints/admin/meta.ts diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts new file mode 100644 index 000000000..8d50486ef --- /dev/null +++ b/packages/backend/src/server/api/endpoints/admin/meta.ts @@ -0,0 +1,401 @@ +import config from '@/config/index.js'; +import define from '../../define.js'; +import { fetchMeta } from '@/misc/fetch-meta.js'; +import { MAX_NOTE_TEXT_LENGTH } from '@/const.js'; + +export const meta = { + tags: ['meta'], + + requireCredential: true, + requireAdmin: true, + + res: { + type: 'object', + optional: false, nullable: false, + properties: { + driveCapacityPerLocalUserMb: { + type: 'number', + optional: false, nullable: false, + }, + driveCapacityPerRemoteUserMb: { + type: 'number', + optional: false, nullable: false, + }, + cacheRemoteFiles: { + type: 'boolean', + optional: false, nullable: false, + }, + emailRequiredForSignup: { + type: 'boolean', + optional: false, nullable: false, + }, + enableHcaptcha: { + type: 'boolean', + optional: false, nullable: false, + }, + hcaptchaSiteKey: { + type: 'string', + optional: false, nullable: true, + }, + enableRecaptcha: { + type: 'boolean', + optional: false, nullable: false, + }, + recaptchaSiteKey: { + type: 'string', + optional: false, nullable: true, + }, + swPublickey: { + type: 'string', + optional: false, nullable: true, + }, + mascotImageUrl: { + type: 'string', + optional: false, nullable: false, + default: '/assets/ai.png', + }, + bannerUrl: { + type: 'string', + optional: false, nullable: false, + }, + errorImageUrl: { + type: 'string', + optional: false, nullable: false, + default: 'https://xn--931a.moe/aiart/yubitun.png', + }, + iconUrl: { + type: 'string', + optional: false, nullable: true, + }, + maxNoteTextLength: { + type: 'number', + optional: false, nullable: false, + }, + emojis: { + type: 'array', + optional: false, nullable: false, + items: { + type: 'object', + optional: false, nullable: false, + properties: { + id: { + type: 'string', + optional: false, nullable: false, + format: 'id', + }, + aliases: { + type: 'array', + optional: false, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + }, + }, + category: { + type: 'string', + optional: false, nullable: true, + }, + host: { + type: 'string', + optional: false, nullable: true, + }, + url: { + type: 'string', + optional: false, nullable: false, + format: 'url', + }, + }, + }, + }, + ads: { + type: 'array', + optional: false, nullable: false, + items: { + type: 'object', + optional: false, nullable: false, + properties: { + place: { + type: 'string', + optional: false, nullable: false, + }, + url: { + type: 'string', + optional: false, nullable: false, + format: 'url', + }, + imageUrl: { + type: 'string', + optional: false, nullable: false, + format: 'url', + }, + }, + }, + }, + enableEmail: { + type: 'boolean', + optional: false, nullable: false, + }, + enableTwitterIntegration: { + type: 'boolean', + optional: false, nullable: false, + }, + enableGithubIntegration: { + type: 'boolean', + optional: false, nullable: false, + }, + enableDiscordIntegration: { + type: 'boolean', + optional: false, nullable: false, + }, + enableServiceWorker: { + type: 'boolean', + optional: false, nullable: false, + }, + translatorAvailable: { + type: 'boolean', + optional: false, nullable: false, + }, + proxyAccountName: { + type: 'string', + optional: false, nullable: true, + }, + userStarForReactionFallback: { + type: 'boolean', + optional: true, nullable: false, + }, + pinnedUsers: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + }, + }, + hiddenTags: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + }, + }, + blockedHosts: { + type: 'array', + optional: true, nullable: false, + items: { + type: 'string', + optional: false, nullable: false, + }, + }, + hcaptchaSecretKey: { + type: 'string', + optional: true, nullable: true, + }, + recaptchaSecretKey: { + type: 'string', + optional: true, nullable: true, + }, + proxyAccountId: { + type: 'string', + optional: true, nullable: true, + format: 'id', + }, + twitterConsumerKey: { + type: 'string', + optional: true, nullable: true, + }, + twitterConsumerSecret: { + type: 'string', + optional: true, nullable: true, + }, + githubClientId: { + type: 'string', + optional: true, nullable: true, + }, + githubClientSecret: { + type: 'string', + optional: true, nullable: true, + }, + discordClientId: { + type: 'string', + optional: true, nullable: true, + }, + discordClientSecret: { + type: 'string', + optional: true, nullable: true, + }, + summaryProxy: { + type: 'string', + optional: true, nullable: true, + }, + email: { + type: 'string', + optional: true, nullable: true, + }, + smtpSecure: { + type: 'boolean', + optional: true, nullable: false, + }, + smtpHost: { + type: 'string', + optional: true, nullable: true, + }, + smtpPort: { + type: 'string', + optional: true, nullable: true, + }, + smtpUser: { + type: 'string', + optional: true, nullable: true, + }, + smtpPass: { + type: 'string', + optional: true, nullable: true, + }, + swPrivateKey: { + type: 'string', + optional: true, nullable: true, + }, + useObjectStorage: { + type: 'boolean', + optional: true, nullable: false, + }, + objectStorageBaseUrl: { + type: 'string', + optional: true, nullable: true, + }, + objectStorageBucket: { + type: 'string', + optional: true, nullable: true, + }, + objectStoragePrefix: { + type: 'string', + optional: true, nullable: true, + }, + objectStorageEndpoint: { + type: 'string', + optional: true, nullable: true, + }, + objectStorageRegion: { + type: 'string', + optional: true, nullable: true, + }, + objectStoragePort: { + type: 'number', + optional: true, nullable: true, + }, + objectStorageAccessKey: { + type: 'string', + optional: true, nullable: true, + }, + objectStorageSecretKey: { + type: 'string', + optional: true, nullable: true, + }, + objectStorageUseSSL: { + type: 'boolean', + optional: true, nullable: false, + }, + objectStorageUseProxy: { + type: 'boolean', + optional: true, nullable: false, + }, + objectStorageSetPublicRead: { + type: 'boolean', + optional: true, nullable: false, + }, + }, + }, +} as const; + +export const paramDef = { + type: 'object', + properties: { + }, + required: [], +} as const; + +// eslint-disable-next-line import/no-default-export +export default define(meta, paramDef, async (ps, me) => { + const instance = await fetchMeta(true); + + return { + maintainerName: instance.maintainerName, + maintainerEmail: instance.maintainerEmail, + version: config.version, + name: instance.name, + uri: config.url, + description: instance.description, + langs: instance.langs, + tosUrl: instance.ToSUrl, + repositoryUrl: instance.repositoryUrl, + feedbackUrl: instance.feedbackUrl, + disableRegistration: instance.disableRegistration, + disableLocalTimeline: instance.disableLocalTimeline, + disableGlobalTimeline: instance.disableGlobalTimeline, + driveCapacityPerLocalUserMb: instance.localDriveCapacityMb, + driveCapacityPerRemoteUserMb: instance.remoteDriveCapacityMb, + emailRequiredForSignup: instance.emailRequiredForSignup, + enableHcaptcha: instance.enableHcaptcha, + hcaptchaSiteKey: instance.hcaptchaSiteKey, + enableRecaptcha: instance.enableRecaptcha, + recaptchaSiteKey: instance.recaptchaSiteKey, + swPublickey: instance.swPublicKey, + themeColor: instance.themeColor, + mascotImageUrl: instance.mascotImageUrl, + bannerUrl: instance.bannerUrl, + errorImageUrl: instance.errorImageUrl, + iconUrl: instance.iconUrl, + backgroundImageUrl: instance.backgroundImageUrl, + logoImageUrl: instance.logoImageUrl, + maxNoteTextLength: MAX_NOTE_TEXT_LENGTH, // 後方互換性のため + defaultLightTheme: instance.defaultLightTheme, + defaultDarkTheme: instance.defaultDarkTheme, + enableEmail: instance.enableEmail, + enableTwitterIntegration: instance.enableTwitterIntegration, + enableGithubIntegration: instance.enableGithubIntegration, + enableDiscordIntegration: instance.enableDiscordIntegration, + enableServiceWorker: instance.enableServiceWorker, + translatorAvailable: instance.deeplAuthKey != null, + pinnedPages: instance.pinnedPages, + pinnedClipId: instance.pinnedClipId, + cacheRemoteFiles: instance.cacheRemoteFiles, + + useStarForReactionFallback: instance.useStarForReactionFallback, + pinnedUsers: instance.pinnedUsers, + hiddenTags: instance.hiddenTags, + blockedHosts: instance.blockedHosts, + hcaptchaSecretKey: instance.hcaptchaSecretKey, + recaptchaSecretKey: instance.recaptchaSecretKey, + proxyAccountId: instance.proxyAccountId, + twitterConsumerKey: instance.twitterConsumerKey, + twitterConsumerSecret: instance.twitterConsumerSecret, + githubClientId: instance.githubClientId, + githubClientSecret: instance.githubClientSecret, + discordClientId: instance.discordClientId, + discordClientSecret: instance.discordClientSecret, + summalyProxy: instance.summalyProxy, + email: instance.email, + smtpSecure: instance.smtpSecure, + smtpHost: instance.smtpHost, + smtpPort: instance.smtpPort, + smtpUser: instance.smtpUser, + smtpPass: instance.smtpPass, + swPrivateKey: instance.swPrivateKey, + useObjectStorage: instance.useObjectStorage, + objectStorageBaseUrl: instance.objectStorageBaseUrl, + objectStorageBucket: instance.objectStorageBucket, + objectStoragePrefix: instance.objectStoragePrefix, + objectStorageEndpoint: instance.objectStorageEndpoint, + objectStorageRegion: instance.objectStorageRegion, + objectStoragePort: instance.objectStoragePort, + objectStorageAccessKey: instance.objectStorageAccessKey, + objectStorageSecretKey: instance.objectStorageSecretKey, + objectStorageUseSSL: instance.objectStorageUseSSL, + objectStorageUseProxy: instance.objectStorageUseProxy, + objectStorageSetPublicRead: instance.objectStorageSetPublicRead, + objectStorageS3ForcePathStyle: instance.objectStorageS3ForcePathStyle, + deeplAuthKey: instance.deeplAuthKey, + deeplIsPro: instance.deeplIsPro, + }; +}); diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index 1aff1f63f..79f20cf71 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -290,151 +290,6 @@ export const meta = { }, }, }, - userStarForReactionFallback: { - type: 'boolean', - optional: true, nullable: false, - }, - pinnedUsers: { - type: 'array', - optional: true, nullable: false, - items: { - type: 'string', - optional: false, nullable: false, - }, - }, - hiddenTags: { - type: 'array', - optional: true, nullable: false, - items: { - type: 'string', - optional: false, nullable: false, - }, - }, - blockedHosts: { - type: 'array', - optional: true, nullable: false, - items: { - type: 'string', - optional: false, nullable: false, - }, - }, - hcaptchaSecretKey: { - type: 'string', - optional: true, nullable: true, - }, - recaptchaSecretKey: { - type: 'string', - optional: true, nullable: true, - }, - proxyAccountId: { - type: 'string', - optional: true, nullable: true, - format: 'id', - }, - twitterConsumerKey: { - type: 'string', - optional: true, nullable: true, - }, - twitterConsumerSecret: { - type: 'string', - optional: true, nullable: true, - }, - githubClientId: { - type: 'string', - optional: true, nullable: true, - }, - githubClientSecret: { - type: 'string', - optional: true, nullable: true, - }, - discordClientId: { - type: 'string', - optional: true, nullable: true, - }, - discordClientSecret: { - type: 'string', - optional: true, nullable: true, - }, - summaryProxy: { - type: 'string', - optional: true, nullable: true, - }, - email: { - type: 'string', - optional: true, nullable: true, - }, - smtpSecure: { - type: 'boolean', - optional: true, nullable: false, - }, - smtpHost: { - type: 'string', - optional: true, nullable: true, - }, - smtpPort: { - type: 'string', - optional: true, nullable: true, - }, - smtpUser: { - type: 'string', - optional: true, nullable: true, - }, - smtpPass: { - type: 'string', - optional: true, nullable: true, - }, - swPrivateKey: { - type: 'string', - optional: true, nullable: true, - }, - useObjectStorage: { - type: 'boolean', - optional: true, nullable: false, - }, - objectStorageBaseUrl: { - type: 'string', - optional: true, nullable: true, - }, - objectStorageBucket: { - type: 'string', - optional: true, nullable: true, - }, - objectStoragePrefix: { - type: 'string', - optional: true, nullable: true, - }, - objectStorageEndpoint: { - type: 'string', - optional: true, nullable: true, - }, - objectStorageRegion: { - type: 'string', - optional: true, nullable: true, - }, - objectStoragePort: { - type: 'number', - optional: true, nullable: true, - }, - objectStorageAccessKey: { - type: 'string', - optional: true, nullable: true, - }, - objectStorageSecretKey: { - type: 'string', - optional: true, nullable: true, - }, - objectStorageUseSSL: { - type: 'boolean', - optional: true, nullable: false, - }, - objectStorageUseProxy: { - type: 'boolean', - optional: true, nullable: false, - }, - objectStorageSetPublicRead: { - type: 'boolean', - optional: true, nullable: false, - }, }, }, } as const; @@ -552,45 +407,6 @@ export default define(meta, paramDef, async (ps, me) => { serviceWorker: instance.enableServiceWorker, miauth: true, }; - - if (me && me.isAdmin) { - response.useStarForReactionFallback = instance.useStarForReactionFallback; - response.pinnedUsers = instance.pinnedUsers; - response.hiddenTags = instance.hiddenTags; - response.blockedHosts = instance.blockedHosts; - response.hcaptchaSecretKey = instance.hcaptchaSecretKey; - response.recaptchaSecretKey = instance.recaptchaSecretKey; - response.proxyAccountId = instance.proxyAccountId; - response.twitterConsumerKey = instance.twitterConsumerKey; - response.twitterConsumerSecret = instance.twitterConsumerSecret; - response.githubClientId = instance.githubClientId; - response.githubClientSecret = instance.githubClientSecret; - response.discordClientId = instance.discordClientId; - response.discordClientSecret = instance.discordClientSecret; - response.summalyProxy = instance.summalyProxy; - response.email = instance.email; - response.smtpSecure = instance.smtpSecure; - response.smtpHost = instance.smtpHost; - response.smtpPort = instance.smtpPort; - response.smtpUser = instance.smtpUser; - response.smtpPass = instance.smtpPass; - response.swPrivateKey = instance.swPrivateKey; - response.useObjectStorage = instance.useObjectStorage; - response.objectStorageBaseUrl = instance.objectStorageBaseUrl; - response.objectStorageBucket = instance.objectStorageBucket; - response.objectStoragePrefix = instance.objectStoragePrefix; - response.objectStorageEndpoint = instance.objectStorageEndpoint; - response.objectStorageRegion = instance.objectStorageRegion; - response.objectStoragePort = instance.objectStoragePort; - response.objectStorageAccessKey = instance.objectStorageAccessKey; - response.objectStorageSecretKey = instance.objectStorageSecretKey; - response.objectStorageUseSSL = instance.objectStorageUseSSL; - response.objectStorageUseProxy = instance.objectStorageUseProxy; - response.objectStorageSetPublicRead = instance.objectStorageSetPublicRead; - response.objectStorageS3ForcePathStyle = instance.objectStorageS3ForcePathStyle; - response.deeplAuthKey = instance.deeplAuthKey; - response.deeplIsPro = instance.deeplIsPro; - } } return response; diff --git a/packages/client/src/pages/admin/bot-protection.vue b/packages/client/src/pages/admin/bot-protection.vue index 82ab15531..5e0cdd96a 100644 --- a/packages/client/src/pages/admin/bot-protection.vue +++ b/packages/client/src/pages/admin/bot-protection.vue @@ -84,7 +84,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.enableHcaptcha = meta.enableHcaptcha; this.hcaptchaSiteKey = meta.hcaptchaSiteKey; this.hcaptchaSecretKey = meta.hcaptchaSecretKey; diff --git a/packages/client/src/pages/admin/email-settings.vue b/packages/client/src/pages/admin/email-settings.vue index 6491a453a..7df0b6db1 100644 --- a/packages/client/src/pages/admin/email-settings.vue +++ b/packages/client/src/pages/admin/email-settings.vue @@ -95,7 +95,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.enableEmail = meta.enableEmail; this.email = meta.email; this.smtpSecure = meta.smtpSecure; diff --git a/packages/client/src/pages/admin/instance-block.vue b/packages/client/src/pages/admin/instance-block.vue index 6cadc7df3..4cb8dc604 100644 --- a/packages/client/src/pages/admin/instance-block.vue +++ b/packages/client/src/pages/admin/instance-block.vue @@ -42,7 +42,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.blockedHosts = meta.blockedHosts.join('\n'); }, diff --git a/packages/client/src/pages/admin/integrations.discord.vue b/packages/client/src/pages/admin/integrations.discord.vue index 8fc340150..6b50f1b0a 100644 --- a/packages/client/src/pages/admin/integrations.discord.vue +++ b/packages/client/src/pages/admin/integrations.discord.vue @@ -60,7 +60,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.uri = meta.uri; this.enableDiscordIntegration = meta.enableDiscordIntegration; this.discordClientId = meta.discordClientId; diff --git a/packages/client/src/pages/admin/integrations.github.vue b/packages/client/src/pages/admin/integrations.github.vue index d9db9c00f..67f299e1b 100644 --- a/packages/client/src/pages/admin/integrations.github.vue +++ b/packages/client/src/pages/admin/integrations.github.vue @@ -60,7 +60,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.uri = meta.uri; this.enableGithubIntegration = meta.enableGithubIntegration; this.githubClientId = meta.githubClientId; diff --git a/packages/client/src/pages/admin/integrations.twitter.vue b/packages/client/src/pages/admin/integrations.twitter.vue index 1f8074535..a389c7150 100644 --- a/packages/client/src/pages/admin/integrations.twitter.vue +++ b/packages/client/src/pages/admin/integrations.twitter.vue @@ -60,7 +60,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.uri = meta.uri; this.enableTwitterIntegration = meta.enableTwitterIntegration; this.twitterConsumerKey = meta.twitterConsumerKey; diff --git a/packages/client/src/pages/admin/integrations.vue b/packages/client/src/pages/admin/integrations.vue index 91d03fef3..4db8a9e0a 100644 --- a/packages/client/src/pages/admin/integrations.vue +++ b/packages/client/src/pages/admin/integrations.vue @@ -62,7 +62,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.enableTwitterIntegration = meta.enableTwitterIntegration; this.enableGithubIntegration = meta.enableGithubIntegration; this.enableDiscordIntegration = meta.enableDiscordIntegration; diff --git a/packages/client/src/pages/admin/object-storage.vue b/packages/client/src/pages/admin/object-storage.vue index 6c5be220f..a1ee0761c 100644 --- a/packages/client/src/pages/admin/object-storage.vue +++ b/packages/client/src/pages/admin/object-storage.vue @@ -120,7 +120,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.useObjectStorage = meta.useObjectStorage; this.objectStorageBaseUrl = meta.objectStorageBaseUrl; this.objectStorageBucket = meta.objectStorageBucket; diff --git a/packages/client/src/pages/admin/other-settings.vue b/packages/client/src/pages/admin/other-settings.vue index 6b588e88a..99ea6a5f3 100644 --- a/packages/client/src/pages/admin/other-settings.vue +++ b/packages/client/src/pages/admin/other-settings.vue @@ -44,7 +44,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); }, save() { os.apiWithDialog('admin/update-meta', { diff --git a/packages/client/src/pages/admin/proxy-account.vue b/packages/client/src/pages/admin/proxy-account.vue index 5c4fbffa0..00f14a176 100644 --- a/packages/client/src/pages/admin/proxy-account.vue +++ b/packages/client/src/pages/admin/proxy-account.vue @@ -46,7 +46,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.proxyAccountId = meta.proxyAccountId; if (this.proxyAccountId) { this.proxyAccount = await os.api('users/show', { userId: this.proxyAccountId }); diff --git a/packages/client/src/pages/admin/security.vue b/packages/client/src/pages/admin/security.vue index d06989164..d1c979b3e 100644 --- a/packages/client/src/pages/admin/security.vue +++ b/packages/client/src/pages/admin/security.vue @@ -72,7 +72,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.summalyProxy = meta.summalyProxy; this.enableHcaptcha = meta.enableHcaptcha; this.enableRecaptcha = meta.enableRecaptcha; diff --git a/packages/client/src/pages/admin/settings.vue b/packages/client/src/pages/admin/settings.vue index abd73fd98..f2970d045 100644 --- a/packages/client/src/pages/admin/settings.vue +++ b/packages/client/src/pages/admin/settings.vue @@ -210,7 +210,7 @@ export default defineComponent({ methods: { async init() { - const meta = await os.api('meta', { detail: true }); + const meta = await os.api('admin/meta'); this.name = meta.name; this.description = meta.description; this.tosUrl = meta.tosUrl; From 083b913dd2c9710c9ddd4981c7bf7fa79ed98977 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 25 Mar 2022 01:51:34 +0900 Subject: [PATCH 4/5] refactor --- packages/backend/src/server/activitypub.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/backend/src/server/activitypub.ts b/packages/backend/src/server/activitypub.ts index c0a9b3772..d4871ca9d 100644 --- a/packages/backend/src/server/activitypub.ts +++ b/packages/backend/src/server/activitypub.ts @@ -18,7 +18,6 @@ import { ILocalUser, User } from '@/models/entities/user.js'; import { In } from 'typeorm'; import { renderLike } from '@/remote/activitypub/renderer/like.js'; import { getUserKeypair } from '@/misc/keypair-store.js'; -import { noteCache, userCache } from './activitypub/cache.js'; // Init router const router = new Router(); @@ -66,13 +65,11 @@ router.post('/users/:user/inbox', json(), inbox); router.get('/notes/:note', async (ctx, next) => { if (!isActivityPubReq(ctx)) return await next(); - // TODO: typeorm 3.0にしたら .then(x => x || null) は消せる - // nginxとかでキャッシュしてくれそうだからそもそもnode側でのキャッシュ不要かも? - const note = await noteCache.fetch(ctx.params.note, () => Notes.findOne({ + const note = await Notes.findOne({ id: ctx.params.note, visibility: In(['public' as const, 'home' as const]), localOnly: false, - }).then(x => x || null)); + }); if (note == null) { ctx.status = 404; @@ -167,13 +164,11 @@ router.get('/users/:user', async (ctx, next) => { const userId = ctx.params.user; - // TODO: typeorm 3.0にしたら .then(x => x || null) は消せる - // nginxとかでキャッシュしてくれそうだからそもそもnode側でのキャッシュ不要かも? - const user = await userCache.fetch(userId, () => Users.findOne({ + const user = await Users.findOne({ id: userId, host: null, isSuspended: false, - }).then(x => x || null)); + }); await userInfo(ctx, user); }); From 863b6c48f86c598df9ce4d2d49651f67124e2d45 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 25 Mar 2022 01:53:20 +0900 Subject: [PATCH 5/5] =?UTF-8?q?enhance(client):=20=E3=82=A2=E3=82=AB?= =?UTF-8?q?=E3=82=A6=E3=83=B3=E3=83=88=E6=83=85=E5=A0=B1=E3=81=AE=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=AB=E5=A4=B1=E6=95=97=E3=81=97=E3=81=9F=E3=81=A8?= =?UTF-8?q?=E3=81=8D=E5=BC=B7=E5=88=B6=E3=83=AD=E3=82=B0=E3=82=A2=E3=82=A6?= =?UTF-8?q?=E3=83=88=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8F=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E3=82=92=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/ja-JP.yml | 1 + packages/client/src/account.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index befa92bd3..6326094dd 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -841,6 +841,7 @@ oneHour: "1時間" oneDay: "1日" oneWeek: "1週間" reflectMayTakeTime: "反映されるまで時間がかかる場合があります。" +failedToFetchAccountInformation: "アカウント情報の取得に失敗しました" _emailUnavailable: used: "既に使用されています" diff --git a/packages/client/src/account.ts b/packages/client/src/account.ts index bcc8a43be..ac6e6d7a0 100644 --- a/packages/client/src/account.ts +++ b/packages/client/src/account.ts @@ -89,7 +89,11 @@ function fetchAccount(token): Promise { signout(); }); } else { - signout(); + alert({ + type: 'error', + title: i18n.ts.failedToFetchAccountInformation, + text: JSON.stringify(res.error), + }); } } else { res.token = token;