From 1104db515e075e007e414b3ff070b7a89c6ebba0 Mon Sep 17 00:00:00 2001 From: Kio-td Date: Sat, 11 Feb 2023 06:13:55 -0500 Subject: [PATCH 001/582] Semi-Kill #9531 --- packages/backend/src/remote/activitypub/models/note.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index afb3af6cb..e5f3853bd 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -115,6 +115,16 @@ export async function createNote( logger.info(`Creating the Note: ${note.id}`); + // Skip if note is made before 2007 (1yr before Fedi was created) + if (note.published) { + const DateChecker = new Date(note.published) + if (DateChecker.getFullYear() < 2007) { + logger.warn('Note somehow made before Activitypub was created; discarding'); + return null; + } + } + + // Fetch author const actor = (await resolvePerson( getOneApId(note.attributedTo), From 4ff3b39ba376fc50d0357414ffd208524a5ed209 Mon Sep 17 00:00:00 2001 From: Kio-td Date: Sat, 11 Feb 2023 06:26:05 -0500 Subject: [PATCH 002/582] Discard if 3 days in the future --- packages/backend/src/remote/activitypub/models/note.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index e5f3853bd..ee9ccf52a 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -116,12 +116,19 @@ export async function createNote( logger.info(`Creating the Note: ${note.id}`); // Skip if note is made before 2007 (1yr before Fedi was created) + // OR skip if note is made 3 days in advance if (note.published) { const DateChecker = new Date(note.published) + const FutureCheck = new Date() + FutureCheck.setDate(FutureCheck.getDate() + 3) // Allow some wiggle room for misconfigured hosts if (DateChecker.getFullYear() < 2007) { logger.warn('Note somehow made before Activitypub was created; discarding'); return null; } + if (DateChecker < FutureCheck) { + logger.warn('Note somehow made after today; discarding') + return null; + } } From 7465e8461df40c5f4024ecf10118a425f8b12049 Mon Sep 17 00:00:00 2001 From: Kio-td Date: Sat, 11 Feb 2023 07:18:56 -0500 Subject: [PATCH 003/582] Fix bad math --- 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 3c438aa2f..e643e24c9 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -135,7 +135,7 @@ export async function createNote( logger.warn('Note somehow made before Activitypub was created; discarding'); return null; } - if (DateChecker < FutureCheck) { + if (DateChecker > FutureCheck) { logger.warn('Note somehow made after today; discarding') return null; } From 3265c1ea9de93a8c800db087e4da05489800eaf0 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 12 Feb 2023 20:14:05 -0800 Subject: [PATCH 004/582] =?UTF-8?q?feat:=20=E2=9C=A8=20Add=20in=20Misskey?= =?UTF-8?q?=20v13's=20reacted=20users=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/MkReactedUsersDialog.vue | 98 +++++++++++++++++++ packages/client/src/scripts/get-note-menu.ts | 11 +++ 2 files changed, 109 insertions(+) create mode 100644 packages/client/src/components/MkReactedUsersDialog.vue diff --git a/packages/client/src/components/MkReactedUsersDialog.vue b/packages/client/src/components/MkReactedUsersDialog.vue new file mode 100644 index 000000000..f1427db7b --- /dev/null +++ b/packages/client/src/components/MkReactedUsersDialog.vue @@ -0,0 +1,98 @@ + + + + + diff --git a/packages/client/src/scripts/get-note-menu.ts b/packages/client/src/scripts/get-note-menu.ts index e8e726ab3..8ab714af3 100644 --- a/packages/client/src/scripts/get-note-menu.ts +++ b/packages/client/src/scripts/get-note-menu.ts @@ -223,6 +223,12 @@ export function getNoteMenu(props: { }); } + function showReactions(): void { + os.popup(defineAsyncComponent(() => import('@/components/MkReactedUsersDialog.vue')), { + noteId: appearNote.id, + }, {}, 'closed'); + } + async function translate(): Promise { if (props.translation.value != null) return; props.translating.value = true; @@ -252,6 +258,11 @@ export function getNoteMenu(props: { null, ] : []), + { + icon: "ph-smiley-bold ph-lg", + text: i18n.ts.reaction, + action: showReactions, + }, { icon: "ph-clipboard-text-bold ph-lg", text: i18n.ts.copyContent, From 72319e8f1fcf44ba15bccce4b977ee95641422ec Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 12 Feb 2023 20:15:33 -0800 Subject: [PATCH 005/582] dev6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e8da6c5a7..bc3c0ffd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "calckey", - "version": "13.2.0-dev4", + "version": "13.2.0-dev6", "codename": "aqua", "repository": { "type": "git", From 428dac79c8e144f1869bdfe1b514b4fd231d53f7 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 12 Feb 2023 20:18:45 -0800 Subject: [PATCH 006/582] fix: :bug: first user gets admin Closes #9620 Co-authored-by: @Johann150 --- packages/backend/src/server/api/common/signup.ts | 1 + .../backend/src/server/api/endpoints/admin/accounts/create.ts | 1 + packages/backend/src/server/api/endpoints/meta.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/backend/src/server/api/common/signup.ts b/packages/backend/src/server/api/common/signup.ts index 7ae9e10fb..bb178506b 100644 --- a/packages/backend/src/server/api/common/signup.ts +++ b/packages/backend/src/server/api/common/signup.ts @@ -107,6 +107,7 @@ export async function signup(opts: { isAdmin: (await Users.countBy({ host: IsNull(), + isAdmin: true, })) === 0, }), ); diff --git a/packages/backend/src/server/api/endpoints/admin/accounts/create.ts b/packages/backend/src/server/api/endpoints/admin/accounts/create.ts index 11ef2273c..2e035d169 100644 --- a/packages/backend/src/server/api/endpoints/admin/accounts/create.ts +++ b/packages/backend/src/server/api/endpoints/admin/accounts/create.ts @@ -35,6 +35,7 @@ export default define(meta, paramDef, async (ps, _me) => { const noUsers = (await Users.countBy({ host: IsNull(), + isAdmin: true, })) === 0; if (!(noUsers || me?.isAdmin)) throw new Error("access denied"); diff --git a/packages/backend/src/server/api/endpoints/meta.ts b/packages/backend/src/server/api/endpoints/meta.ts index 005d0800a..476a0c29f 100644 --- a/packages/backend/src/server/api/endpoints/meta.ts +++ b/packages/backend/src/server/api/endpoints/meta.ts @@ -489,6 +489,7 @@ export default define(meta, paramDef, async (ps, me) => { requireSetup: (await Users.countBy({ host: IsNull(), + isAdmin: true, })) === 0, } : {}), From 2bd38a64f0f93127a49e1381efd021b4322c4a84 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 12 Feb 2023 20:25:23 -0800 Subject: [PATCH 007/582] feat: :sparkles: add position, scale , fg, and bg MFM from v13 --- packages/client/src/components/mfm.ts | 29 ++++++++++++++++++++ packages/client/src/scripts/get-note-menu.ts | 13 +++++++-- packages/client/src/scripts/mfm-tags.ts | 4 +++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/packages/client/src/components/mfm.ts b/packages/client/src/components/mfm.ts index ddfcc3de1..f2905ec35 100644 --- a/packages/client/src/components/mfm.ts +++ b/packages/client/src/components/mfm.ts @@ -254,6 +254,35 @@ export default defineComponent({ style = `transform: ${rotate}(${degrees}deg); transform-origin: center center;`; break; } + case "position": { + if (!defaultStore.state.advancedMfm) break; + const x = parseFloat(token.props.args.x ?? "0"); + const y = parseFloat(token.props.args.y ?? "0"); + style = `transform: translateX(${x}em) translateY(${y}em);`; + break; + } + case "scale": { + if (!defaultStore.state.advancedMfm) { + style = ""; + break; + } + const x = Math.min(parseFloat(token.props.args.x ?? "1"), 5); + const y = Math.min(parseFloat(token.props.args.y ?? "1"), 5); + style = `transform: scale(${x}, ${y});`; + break; + } + case "fg": { + let color = token.props.args.color; + if (!/^[0-9a-f]{3,6}$/i.test(color)) color = "f00"; + style = `color: #${color};`; + break; + } + case "bg": { + let color = token.props.args.color; + if (!/^[0-9a-f]{3,6}$/i.test(color)) color = "f00"; + style = `background-color: #${color};`; + break; + } } if (style == null) { return h("span", {}, [ diff --git a/packages/client/src/scripts/get-note-menu.ts b/packages/client/src/scripts/get-note-menu.ts index 8ab714af3..eb8006c1c 100644 --- a/packages/client/src/scripts/get-note-menu.ts +++ b/packages/client/src/scripts/get-note-menu.ts @@ -224,9 +224,16 @@ export function getNoteMenu(props: { } function showReactions(): void { - os.popup(defineAsyncComponent(() => import('@/components/MkReactedUsersDialog.vue')), { - noteId: appearNote.id, - }, {}, 'closed'); + os.popup( + defineAsyncComponent( + () => import("@/components/MkReactedUsersDialog.vue"), + ), + { + noteId: appearNote.id, + }, + {}, + "closed", + ); } async function translate(): Promise { diff --git a/packages/client/src/scripts/mfm-tags.ts b/packages/client/src/scripts/mfm-tags.ts index 51e1fc4e6..b39c8b37b 100644 --- a/packages/client/src/scripts/mfm-tags.ts +++ b/packages/client/src/scripts/mfm-tags.ts @@ -10,6 +10,10 @@ export const MFM_TAGS = [ "x2", "x3", "x4", + "scale", + "position", + "fg", + "bg", "font", "blur", "rainbow", From c32128c2da9590dafb8122ddb6bf085b676f7664 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 12 Feb 2023 20:25:45 -0800 Subject: [PATCH 008/582] dev7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc3c0ffd6..da1e886ac 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "calckey", - "version": "13.2.0-dev6", + "version": "13.2.0-dev7", "codename": "aqua", "repository": { "type": "git", From 8d052f8e0ef71aa5f36b8d7334f2a2e00b908ae1 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 12 Feb 2023 20:29:34 -0800 Subject: [PATCH 009/582] remove defaultStore check in MFM --- packages/client/src/components/mfm.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/client/src/components/mfm.ts b/packages/client/src/components/mfm.ts index f2905ec35..6a8f81e40 100644 --- a/packages/client/src/components/mfm.ts +++ b/packages/client/src/components/mfm.ts @@ -255,17 +255,12 @@ export default defineComponent({ break; } case "position": { - if (!defaultStore.state.advancedMfm) break; const x = parseFloat(token.props.args.x ?? "0"); const y = parseFloat(token.props.args.y ?? "0"); style = `transform: translateX(${x}em) translateY(${y}em);`; break; } case "scale": { - if (!defaultStore.state.advancedMfm) { - style = ""; - break; - } const x = Math.min(parseFloat(token.props.args.x ?? "1"), 5); const y = Math.min(parseFloat(token.props.args.y ?? "1"), 5); style = `transform: scale(${x}, ${y});`; From 51ba8304821700dfc5b497160c0224c5ab1c9ffe Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sun, 12 Feb 2023 20:46:56 -0800 Subject: [PATCH 010/582] fix --- packages/client/src/components/MkReactedUsersDialog.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/client/src/components/MkReactedUsersDialog.vue b/packages/client/src/components/MkReactedUsersDialog.vue index f1427db7b..5f9dfd7d9 100644 --- a/packages/client/src/components/MkReactedUsersDialog.vue +++ b/packages/client/src/components/MkReactedUsersDialog.vue @@ -17,7 +17,11 @@ - + - + diff --git a/packages/client/src/widgets/user-list.vue b/packages/client/src/widgets/user-list.vue index 4173f5c36..6ee6dc05a 100644 --- a/packages/client/src/widgets/user-list.vue +++ b/packages/client/src/widgets/user-list.vue @@ -2,7 +2,7 @@ - +
{{ i18n.ts._widgets._userList.chooseList }} @@ -14,7 +14,7 @@
- + - + diff --git a/packages/client/src/components/MkNoteSub.vue b/packages/client/src/components/MkNoteSub.vue index c0766ec5f..a0277d86e 100644 --- a/packages/client/src/components/MkNoteSub.vue +++ b/packages/client/src/components/MkNoteSub.vue @@ -16,10 +16,14 @@
+ + - +function onModalClosed() { + emit('closed'); +} + From 3e78ff2439a2ed5ec939cb0ff9b647c974d1eab5 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 18 Feb 2023 16:16:24 -0800 Subject: [PATCH 078/582] fix?? --- packages/client/src/components/MkModal.vue | 14 +++---- .../client/src/components/MkModalWindow.vue | 38 ++++++++++--------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/packages/client/src/components/MkModal.vue b/packages/client/src/components/MkModal.vue index 840a1aee2..b88dee380 100644 --- a/packages/client/src/components/MkModal.vue +++ b/packages/client/src/components/MkModal.vue @@ -7,9 +7,9 @@ :leave-to-class="$style['transition_' + transitionName + '_leaveTo']" :duration="transitionDuration" appear @after-leave="emit('closed')" @enter="emit('opening')" @after-enter="onOpened" > -
+
-
+
@@ -33,7 +33,7 @@ function getFixedContainer(el: Element | null): Element | null { } } -type ModalTypes = 'popup' | 'dialog' | 'drawer'; +type ModalTypes = 'popup' | 'dialog' | 'dialog:top' | 'drawer'; const props = withDefaults(defineProps<{ manualShowing?: boolean | null; @@ -194,21 +194,21 @@ const align = () => { } } else { // 画面から横にはみ出る場合 - if (left + width - window.pageXOffset > window.innerWidth) { - left = window.innerWidth - width + window.pageXOffset - 1; + if (left + width - window.scrollX > window.innerWidth) { + left = window.innerWidth - width + window.scrollX - 1; } const underSpace = (window.innerHeight - MARGIN) - (top - window.pageYOffset); const upperSpace = (srcRect.top - MARGIN); // 画面から縦にはみ出る場合 - if (top + height - window.pageYOffset > (window.innerHeight - MARGIN)) { + if (top + height - window.scrollY > (window.innerHeight - MARGIN)) { if (props.noOverlap && props.anchor.x === 'center') { if (underSpace >= (upperSpace / 3)) { maxHeight = underSpace; } else { maxHeight = upperSpace; - top = window.pageYOffset + ((upperSpace + MARGIN) - height); + top = window.scrollY + ((upperSpace + MARGIN) - height); } } else { top = (window.innerHeight - MARGIN) - height + window.pageYOffset - 1; diff --git a/packages/client/src/components/MkModalWindow.vue b/packages/client/src/components/MkModalWindow.vue index 666382466..2765a9927 100644 --- a/packages/client/src/components/MkModalWindow.vue +++ b/packages/client/src/components/MkModalWindow.vue @@ -1,19 +1,19 @@ From d5e28cb129def31bca0b75980b38ee60b775ed2e Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 18 Feb 2023 19:48:25 -0800 Subject: [PATCH 082/582] fix --- packages/client/src/components/MkDialog.vue | 2 +- .../src/components/global/MkLoading.vue | 8 +++ packages/client/src/os.ts | 51 ++++++++++++------- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/packages/client/src/components/MkDialog.vue b/packages/client/src/components/MkDialog.vue index ec55d15f7..1bcfa81a5 100644 --- a/packages/client/src/components/MkDialog.vue +++ b/packages/client/src/components/MkDialog.vue @@ -9,7 +9,7 @@ - +
diff --git a/packages/client/src/components/global/MkLoading.vue b/packages/client/src/components/global/MkLoading.vue index 362484f5f..dc61e577b 100644 --- a/packages/client/src/components/global/MkLoading.vue +++ b/packages/client/src/components/global/MkLoading.vue @@ -15,10 +15,12 @@ const props = withDefaults(defineProps<{ inline?: boolean; colored?: boolean; mini?: boolean; + em?: boolean; }>(), { inline: false, colored: true, mini: false, + em: false, }); @@ -70,6 +72,12 @@ const props = withDefaults(defineProps<{ padding: 16px; --size: 32px; } + &.em { + display: inline-block; + vertical-align: middle; + padding: 0; + --size: 1em; + } } .container { diff --git a/packages/client/src/os.ts b/packages/client/src/os.ts index d3516bf4c..0e6bdf318 100644 --- a/packages/client/src/os.ts +++ b/packages/client/src/os.ts @@ -7,8 +7,8 @@ import * as Misskey from "calckey-js"; import { apiUrl, url } from "@/config"; import MkPostFormDialog from "@/components/MkPostFormDialog.vue"; import MkWaitingDialog from "@/components/MkWaitingDialog.vue"; -import MkToast from '@/components/MkToast.vue'; -import MkDialog from '@/components/MkDialog.vue'; +import MkToast from "@/components/MkToast.vue"; +import MkDialog from "@/components/MkDialog.vue"; import { MenuItem } from "@/types/menu"; import { $i } from "@/account"; @@ -248,41 +248,56 @@ export function modalPageWindow(path: string) { } export function toast(message: string) { - popup(MkToast, { - message, - }, {}, 'closed'); + popup( + MkToast, + { + message, + }, + {}, + "closed", + ); } export function alert(props: { - type?: 'error' | 'info' | 'success' | 'warning' | 'waiting' | 'question'; + type?: "error" | "info" | "success" | "warning" | "waiting" | "question"; title?: string | null; text?: string | null; }): Promise { return new Promise((resolve, reject) => { - popup(MkDialog, props, { - done: result => { - resolve(); + popup( + MkDialog, + props, + { + done: (result) => { + resolve(); + }, }, - }, 'closed'); + "closed", + ); }); } export function confirm(props: { - type: 'error' | 'info' | 'success' | 'warning' | 'waiting' | 'question'; + type: "error" | "info" | "success" | "warning" | "waiting" | "question"; title?: string | null; text?: string | null; okText?: string; cancelText?: string; }): Promise<{ canceled: boolean }> { return new Promise((resolve, reject) => { - popup(MkDialog, { - ...props, - showCancelButton: true, - }, { - done: result => { - resolve(result ? result : { canceled: true }); + popup( + MkDialog, + { + ...props, + showCancelButton: true, }, - }, 'closed'); + { + done: (result) => { + resolve(result ? result : { canceled: true }); + }, + }, + "closed", + ); }); } From 20cc13434cffd831dd9aded85cfc05e6981dbd42 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 18 Feb 2023 19:55:18 -0800 Subject: [PATCH 083/582] fix --- .../client/src/components/MkWaitingDialog.vue | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/packages/client/src/components/MkWaitingDialog.vue b/packages/client/src/components/MkWaitingDialog.vue index dfc5115ca..00d34e949 100644 --- a/packages/client/src/components/MkWaitingDialog.vue +++ b/packages/client/src/components/MkWaitingDialog.vue @@ -1,18 +1,18 @@ - From 8008721c3ef8fe433cbd775ad5a5562e862609cd Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 18 Feb 2023 19:58:42 -0800 Subject: [PATCH 084/582] fix MkUpdated --- packages/client/src/components/MkUpdated.vue | 42 ++++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/client/src/components/MkUpdated.vue b/packages/client/src/components/MkUpdated.vue index 6f5ca6618..d1df6af4c 100644 --- a/packages/client/src/components/MkUpdated.vue +++ b/packages/client/src/components/MkUpdated.vue @@ -1,15 +1,15 @@ @@ -39,7 +39,8 @@ console.log(data); From b43ee5481896a0da7cf25fb4720bf26abfe56600 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 18 Feb 2023 20:01:00 -0800 Subject: [PATCH 085/582] style --- packages/client/src/components/MkModal.vue | 4 ++-- .../client/src/pages/admin/overview.federation.vue | 4 ++-- packages/client/src/pages/admin/overview.stats.vue | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/client/src/components/MkModal.vue b/packages/client/src/components/MkModal.vue index b88dee380..80cfaf8da 100644 --- a/packages/client/src/components/MkModal.vue +++ b/packages/client/src/components/MkModal.vue @@ -341,12 +341,12 @@ defineExpose({ .transition_modal-popup_enterActive, .transition_modal-popup_leaveActive { > .bg { - transition: opacity 0.1s !important; + transition: opacity 0.2s !important; } > .content { transform-origin: var(--transformOrigin); - transition: opacity 0.1s cubic-bezier(0, 0, 0.2, 1), transform 0.1s cubic-bezier(0, 0, 0.2, 1) !important; + transition: opacity 0.2s cubic-bezier(0, 0, 0.2, 1), transform 0.2s cubic-bezier(0, 0, 0.2, 1) !important; } } .transition_modal-popup_enterFrom, diff --git a/packages/client/src/pages/admin/overview.federation.vue b/packages/client/src/pages/admin/overview.federation.vue index 961837b22..f47632d40 100644 --- a/packages/client/src/pages/admin/overview.federation.vue +++ b/packages/client/src/pages/admin/overview.federation.vue @@ -147,14 +147,14 @@ onMounted(async () => { &.sub { > .icon { - background: #907aa955; + background: #907aa922; color: #c4a7e7; } } &.pub { > .icon { - background: #56949f55; + background: #56949f22; color: #9ccfd8; } } diff --git a/packages/client/src/pages/admin/overview.stats.vue b/packages/client/src/pages/admin/overview.stats.vue index 0868cba3d..91ab73783 100644 --- a/packages/client/src/pages/admin/overview.stats.vue +++ b/packages/client/src/pages/admin/overview.stats.vue @@ -106,35 +106,35 @@ onMounted(async () => { &.users { > .icon { - background: #56949f55; + background: #56949f22; color: #9ccfd8; } } &.notes { > .icon { - background: #28698355; + background: #28698322; color: #31748f; } } &.instances { > .icon { - background: #d7827e55; + background: #d7827e22; color: #ebbcba; } } &.emojis { > .icon { - background: #ea9d3455; + background: #ea9d3422; color: #f6c177; } } &.online { > .icon { - background: #907aa955; + background: #907aa922; color: #c4a7e7; } } From d33570ad8f5ae2e659b7de5883316ea1cbf5bcf6 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 18 Feb 2023 20:02:58 -0800 Subject: [PATCH 086/582] fix broken style --- packages/client/src/components/MkUpdated.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/src/components/MkUpdated.vue b/packages/client/src/components/MkUpdated.vue index d1df6af4c..a3fc37751 100644 --- a/packages/client/src/components/MkUpdated.vue +++ b/packages/client/src/components/MkUpdated.vue @@ -63,7 +63,7 @@ console.log(data); margin: 8px 0 0 0; } -> .releaseNotes { +.releaseNotes { > img { border-radius: 10px; } From 5c7a9f66ebaaca00f4814809713d913324d427b5 Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Sat, 18 Feb 2023 20:09:14 -0800 Subject: [PATCH 087/582] testing --- packages/client/src/components/MkUpdated.vue | 4 +++- packages/client/src/init.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/client/src/components/MkUpdated.vue b/packages/client/src/components/MkUpdated.vue index a3fc37751..640b722d2 100644 --- a/packages/client/src/components/MkUpdated.vue +++ b/packages/client/src/components/MkUpdated.vue @@ -15,6 +15,7 @@ - From e2ad9a94ec7079e3f0c17502cd89b1bbfe9715b2 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Wed, 22 Feb 2023 09:44:47 +0100 Subject: [PATCH 102/582] fix mastodon api stats --- .../backend/src/server/api/mastodon/endpoints/meta.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index 5fba6f8a6..a19acbaa1 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -1,9 +1,13 @@ import { Entity } from "@calckey/megalodon"; import { fetchMeta } from "@/misc/fetch-meta.js"; +import { Users, Notes } from "@/models/index.js"; +import { IsNull, MoreThan } from "typeorm"; // TODO: add calckey features export async function getInstance(response: Entity.Instance) { const meta = await fetchMeta(true); + const totalUsers = Users.count({ where: { host: IsNull() } }); + const totalStatuses = Notes.count({ where: { userHost: IsNull() } }); return { uri: response.uri, title: response.title || "", @@ -12,7 +16,11 @@ export async function getInstance(response: Entity.Instance) { email: response.email || "", version: "3.0.0 compatible (Calckey)", urls: response.urls, - stats: response.stats, + stats: { + user_count: totalUsers, + status_count: totalStatuses, + domain_count: response.stats.domain_count + }, thumbnail: response.thumbnail || "", languages: meta.langs, registrations: !meta.disableRegistration || response.registrations, From e4a276a9892937b8c8d97ff74f4023a0c4aa3aaa Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 00:31:14 +0100 Subject: [PATCH 103/582] aaa --- packages/backend/src/server/api/index.ts | 1 + .../src/server/api/mastodon/endpoints/status.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index 3ea3ff67e..0f58d3acf 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -171,6 +171,7 @@ errorRouter.all("(.*)", async (ctx) => { // Register router app.use(mastoRouter.routes()); +app.use(mastoRouter.allowedMethods()); app.use(router.routes()); app.use(errorRouter.routes()); diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index a72ac2c7e..0ba1e4229 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -289,14 +289,16 @@ export function apiStatusMastodon(router: Router): void { const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - const multipartData = await ctx.file; + let multipartData = await ctx.request.files; if (!multipartData) { ctx.body = { error: "No image" }; + ctx.status = 401; return; } - const [path] = await createTemp(); - await pump(multipartData.buffer, fs.createWriteStream(path)); - const image = fs.readFileSync(path); + if ((multipartData as any).file) { + multipartData = (multipartData as any).file; + } + const image = fs.readFileSync((multipartData as any).path); const data = await client.uploadMedia(image); ctx.body = data.data; } catch (e: any) { @@ -313,6 +315,7 @@ export function apiStatusMastodon(router: Router): void { const multipartData = await ctx.file; if (!multipartData) { ctx.body = { error: "No image" }; + ctx.status = 401; return; } const [path] = await createTemp(); From 75bd0baf99193fc61a51952d38c2d8a97bee47aa Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 15:46:12 +0100 Subject: [PATCH 104/582] remove not needed middleware handlers --- .../server/api/mastodon/endpoints/status.ts | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 0ba1e4229..2ab834b64 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -9,8 +9,17 @@ import { emojiRegex, emojiRegexAtStartToEnd } from "@/misc/emoji-regex.js"; import axios from "axios"; const pump = promisify(pipeline); +// Init multer instance +const upload = multer({ + storage: multer.diskStorage({}), + limits: { + fileSize: config.maxFileSize || 262144000, + files: 1, + }, +}); + export function apiStatusMastodon(router: Router): void { - router.post("/v1/statuses", async (ctx, reply) => { + router.post("/v1/statuses", async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -52,7 +61,7 @@ export function apiStatusMastodon(router: Router): void { }); router.get<{ Params: { id: string } }>( "/v1/statuses/:id", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -68,7 +77,7 @@ export function apiStatusMastodon(router: Router): void { ); router.delete<{ Params: { id: string } }>( "/v1/statuses/:id", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -90,7 +99,7 @@ export function apiStatusMastodon(router: Router): void { } router.get<{ Params: { id: string } }>( "/v1/statuses/:id/context", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -123,7 +132,7 @@ export function apiStatusMastodon(router: Router): void { ); router.get<{ Params: { id: string } }>( "/v1/statuses/:id/reblogged_by", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -139,13 +148,13 @@ export function apiStatusMastodon(router: Router): void { ); router.get<{ Params: { id: string } }>( "/v1/statuses/:id/favourited_by", - async (ctx, reply) => { + async (ctx) => { ctx.body = []; }, ); router.post<{ Params: { id: string } }>( "/v1/statuses/:id/favourite", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -167,7 +176,7 @@ export function apiStatusMastodon(router: Router): void { ); router.post<{ Params: { id: string } }>( "/v1/statuses/:id/unfavourite", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -185,7 +194,7 @@ export function apiStatusMastodon(router: Router): void { router.post<{ Params: { id: string } }>( "/v1/statuses/:id/reblog", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -202,7 +211,7 @@ export function apiStatusMastodon(router: Router): void { router.post<{ Params: { id: string } }>( "/v1/statuses/:id/unreblog", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -219,7 +228,7 @@ export function apiStatusMastodon(router: Router): void { router.post<{ Params: { id: string } }>( "/v1/statuses/:id/bookmark", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -236,7 +245,7 @@ export function apiStatusMastodon(router: Router): void { router.post<{ Params: { id: string } }>( "/v1/statuses/:id/unbookmark", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -253,7 +262,7 @@ export function apiStatusMastodon(router: Router): void { router.post<{ Params: { id: string } }>( "/v1/statuses/:id/pin", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -270,7 +279,7 @@ export function apiStatusMastodon(router: Router): void { router.post<{ Params: { id: string } }>( "/v1/statuses/:id/unpin", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -284,7 +293,7 @@ export function apiStatusMastodon(router: Router): void { } }, ); - router.post("/v1/media", async (ctx, reply) => { + router.post("/v1/media", async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -307,7 +316,7 @@ export function apiStatusMastodon(router: Router): void { ctx.body = e.response.data; } }); - router.post("/v2/media", async (ctx, reply) => { + router.post("/v2/media", async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -331,7 +340,7 @@ export function apiStatusMastodon(router: Router): void { }); router.get<{ Params: { id: string } }>( "/v1/media/:id", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -347,7 +356,7 @@ export function apiStatusMastodon(router: Router): void { ); router.put<{ Params: { id: string } }>( "/v1/media/:id", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -366,7 +375,7 @@ export function apiStatusMastodon(router: Router): void { ); router.get<{ Params: { id: string } }>( "/v1/polls/:id", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); @@ -382,7 +391,7 @@ export function apiStatusMastodon(router: Router): void { ); router.post<{ Params: { id: string } }>( "/v1/polls/:id/votes", - async (ctx, reply) => { + async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); From 0ca238d6806278e26183ac46598c1036b9dd2471 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 15:55:28 +0100 Subject: [PATCH 105/582] import multer --- packages/backend/src/server/api/mastodon/endpoints/status.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 2ab834b64..89c733bd1 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -5,6 +5,7 @@ import fs from "fs"; import { pipeline } from "node:stream"; import { promisify } from "node:util"; import { createTemp } from "@/misc/create-temp.js"; +import multer from "@koa/multer"; import { emojiRegex, emojiRegexAtStartToEnd } from "@/misc/emoji-regex.js"; import axios from "axios"; const pump = promisify(pipeline); From 83cc0c9828306813ae51a961e7a91fc690b03c86 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 15:58:54 +0100 Subject: [PATCH 106/582] import config --- packages/backend/src/server/api/mastodon/endpoints/status.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 89c733bd1..7da2a2d7b 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -5,6 +5,7 @@ import fs from "fs"; import { pipeline } from "node:stream"; import { promisify } from "node:util"; import { createTemp } from "@/misc/create-temp.js"; +import config from "@/config/index.js"; import multer from "@koa/multer"; import { emojiRegex, emojiRegexAtStartToEnd } from "@/misc/emoji-regex.js"; import axios from "axios"; From b1d785b486be75a6a98aa2f97ea9d3b5ef400ab3 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 16:12:53 +0100 Subject: [PATCH 107/582] await the instance meta --- packages/backend/src/server/api/mastodon/endpoints/meta.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index a19acbaa1..7ca6625f4 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -17,8 +17,8 @@ export async function getInstance(response: Entity.Instance) { version: "3.0.0 compatible (Calckey)", urls: response.urls, stats: { - user_count: totalUsers, - status_count: totalStatuses, + user_count: (await totalUsers), + status_count: (await totalStatuses), domain_count: response.stats.domain_count }, thumbnail: response.thumbnail || "", From 273b86b9f4126620a50242da9297b84bcf9a6d6b Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 16:26:33 +0100 Subject: [PATCH 108/582] ?? --- packages/backend/src/server/api/mastodon/endpoints/meta.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index 7ca6625f4..e5726fbae 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -89,6 +89,7 @@ export async function getInstance(response: Entity.Instance) { discoverable: false, group: false, created_at: Math.floor(new Date().getTime() / 1000), + createdAt: Math.floor(new Date().getTime() / 1000), note: "Please refer to the original instance for the actual admin contact.", url: "/", avatar: "/static-assets/badges/info.png", From 506709d2eb0b5e70dfddde5f3e8687fb3b57aa13 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 16:32:21 +0100 Subject: [PATCH 109/582] fixed what ever calc did here, masto app didnt --- packages/backend/src/server/api/mastodon/endpoints/meta.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index e5726fbae..809a9aa11 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -88,8 +88,8 @@ export async function getInstance(response: Entity.Instance) { bot: true, discoverable: false, group: false, - created_at: Math.floor(new Date().getTime() / 1000), - createdAt: Math.floor(new Date().getTime() / 1000), + created_at: new Date().toISOString(), + createdAt: new Date().toISOString(), note: "Please refer to the original instance for the actual admin contact.", url: "/", avatar: "/static-assets/badges/info.png", @@ -99,7 +99,7 @@ export async function getInstance(response: Entity.Instance) { followers_count: -1, following_count: 0, statuses_count: 0, - last_status_at: Math.floor(new Date().getTime() / 1000), + last_status_at: new Date().toISOString(), noindex: true, emojis: [], fields: [], From 678c3c24838d4ba7debac0b05b7b2e2e14bebbaa Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 16:34:16 +0100 Subject: [PATCH 110/582] lol --- packages/backend/src/server/api/mastodon/endpoints/meta.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index 809a9aa11..0a4ead16f 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -89,7 +89,6 @@ export async function getInstance(response: Entity.Instance) { discoverable: false, group: false, created_at: new Date().toISOString(), - createdAt: new Date().toISOString(), note: "Please refer to the original instance for the actual admin contact.", url: "/", avatar: "/static-assets/badges/info.png", From 6b97e42a7fe5f5175aa1f5a045e8e5ab487bb736 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 16:42:57 +0100 Subject: [PATCH 111/582] update thingy? --- .../backend/src/server/api/mastodon/endpoints/meta.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index 0a4ead16f..67f3901e4 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -89,10 +89,10 @@ export async function getInstance(response: Entity.Instance) { discoverable: false, group: false, created_at: new Date().toISOString(), - note: "Please refer to the original instance for the actual admin contact.", - url: "/", - avatar: "/static-assets/badges/info.png", - avatar_static: "/static-assets/badges/info.png", + note: "

Please refer to the original instance for the actual admin contact.

", + url: `${response.uri}/`, + avatar: `${response.uri}/static-assets/badges/info.png`, + avatar_static: `${response.uri}/static-assets/badges/info.png`, header: "https://http.cat/404", header_static: "https://http.cat/404", followers_count: -1, From b712b67df3698451735c47892adf97b6e1dc7bd7 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 16:55:38 +0100 Subject: [PATCH 112/582] use multer upload instead --- .../server/api/mastodon/endpoints/status.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 7da2a2d7b..b2c6f9781 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -295,21 +295,18 @@ export function apiStatusMastodon(router: Router): void { } }, ); - router.post("/v1/media", async (ctx) => { + router.post("/v1/media", upload.single("file"), async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - let multipartData = await ctx.request.files; + let multipartData = await ctx.request.file; if (!multipartData) { ctx.body = { error: "No image" }; ctx.status = 401; return; } - if ((multipartData as any).file) { - multipartData = (multipartData as any).file; - } - const image = fs.readFileSync((multipartData as any).path); + const image = fs.readFileSync((multipartData).path); const data = await client.uploadMedia(image); ctx.body = data.data; } catch (e: any) { @@ -318,20 +315,18 @@ export function apiStatusMastodon(router: Router): void { ctx.body = e.response.data; } }); - router.post("/v2/media", async (ctx) => { + router.post("/v2/media", upload.single("file"), async (ctx) => { const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - const multipartData = await ctx.file; + let multipartData = await ctx.request.file; if (!multipartData) { ctx.body = { error: "No image" }; ctx.status = 401; return; } - const [path] = await createTemp(); - await pump(multipartData.buffer, fs.createWriteStream(path)); - const image = fs.readFileSync(path); + const image = fs.readFileSync((multipartData).path); const data = await client.uploadMedia(image); ctx.body = data.data; } catch (e: any) { @@ -340,6 +335,7 @@ export function apiStatusMastodon(router: Router): void { ctx.body = e.response.data; } }); + }); router.get<{ Params: { id: string } }>( "/v1/media/:id", async (ctx) => { From 76a4228de3674d4f97bf73b22eebe852da02c893 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 16:57:21 +0100 Subject: [PATCH 113/582] oh ich hab verkackt --- packages/backend/src/server/api/mastodon/endpoints/status.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index b2c6f9781..c86132364 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -335,7 +335,6 @@ export function apiStatusMastodon(router: Router): void { ctx.body = e.response.data; } }); - }); router.get<{ Params: { id: string } }>( "/v1/media/:id", async (ctx) => { From 50687ef209035589ef6d6b3051dac7a98013f2fe Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 17:02:02 +0100 Subject: [PATCH 114/582] move file upload to new router --- packages/backend/src/server/api/index.ts | 46 ++++++++++++++- .../server/api/mastodon/endpoints/status.ts | 59 +------------------ 2 files changed, 46 insertions(+), 59 deletions(-) diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index 0f58d3acf..9b6c62924 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -7,7 +7,7 @@ import Router from "@koa/router"; import multer from "@koa/multer"; import bodyParser from "koa-bodyparser"; import cors from "@koa/cors"; -import { apiMastodonCompatible } from "./mastodon/ApiMastodonCompatibleService.js"; +import { apiMastodonCompatible, getClient } from "./mastodon/ApiMastodonCompatibleService.js"; import { Instances, AccessTokens, Users } from "@/models/index.js"; import config from "@/config/index.js"; import endpoints from "./endpoints.js"; @@ -39,6 +39,7 @@ app.use(async (ctx, next) => { // Init router const router = new Router(); const mastoRouter = new Router(); +const mastoFileRouter = new Router(); const errorRouter = new Router(); // Init multer instance @@ -68,6 +69,48 @@ mastoRouter.use( }), ); + +mastoFileRouter.post("/v1/media", upload.single("file"), async (ctx) => { + const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; + const accessTokens = ctx.headers.authorization; + const client = getClient(BASE_URL, accessTokens); + try { + let multipartData = await ctx.request.file; + if (!multipartData) { + ctx.body = { error: "No image" }; + ctx.status = 401; + return; + } + const image = fs.readFileSync((multipartData).path); + const data = await client.uploadMedia(image); + ctx.body = data.data; + } catch (e: any) { + console.error(e); + ctx.status = 401; + ctx.body = e.response.data; + } +}); +mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => { + const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; + const accessTokens = ctx.headers.authorization; + const client = getClient(BASE_URL, accessTokens); + try { + let multipartData = await ctx.request.file; + if (!multipartData) { + ctx.body = { error: "No image" }; + ctx.status = 401; + return; + } + const image = fs.readFileSync((multipartData).path); + const data = await client.uploadMedia(image); + ctx.body = data.data; + } catch (e: any) { + console.error(e); + ctx.status = 401; + ctx.body = e.response.data; + } +}); + mastoRouter.use(async (ctx, next) => { if (ctx.request.query) { if (!ctx.request.body || Object.keys(ctx.request.body).length === 0) { @@ -170,6 +213,7 @@ errorRouter.all("(.*)", async (ctx) => { }); // Register router +app.use(mastoFileRouter.routes()); app.use(mastoRouter.routes()); app.use(mastoRouter.allowedMethods()); app.use(router.routes()); diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index c86132364..3981a1781 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -1,24 +1,7 @@ import Router from "@koa/router"; -import megalodon, { MegalodonInterface } from "@calckey/megalodon"; import { getClient } from "../ApiMastodonCompatibleService.js"; -import fs from "fs"; -import { pipeline } from "node:stream"; -import { promisify } from "node:util"; -import { createTemp } from "@/misc/create-temp.js"; -import config from "@/config/index.js"; -import multer from "@koa/multer"; -import { emojiRegex, emojiRegexAtStartToEnd } from "@/misc/emoji-regex.js"; +import { emojiRegexAtStartToEnd } from "@/misc/emoji-regex.js"; import axios from "axios"; -const pump = promisify(pipeline); - -// Init multer instance -const upload = multer({ - storage: multer.diskStorage({}), - limits: { - fileSize: config.maxFileSize || 262144000, - files: 1, - }, -}); export function apiStatusMastodon(router: Router): void { router.post("/v1/statuses", async (ctx) => { @@ -295,46 +278,6 @@ export function apiStatusMastodon(router: Router): void { } }, ); - router.post("/v1/media", upload.single("file"), async (ctx) => { - const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; - const accessTokens = ctx.headers.authorization; - const client = getClient(BASE_URL, accessTokens); - try { - let multipartData = await ctx.request.file; - if (!multipartData) { - ctx.body = { error: "No image" }; - ctx.status = 401; - return; - } - const image = fs.readFileSync((multipartData).path); - const data = await client.uploadMedia(image); - ctx.body = data.data; - } catch (e: any) { - console.error(e); - ctx.status = 401; - ctx.body = e.response.data; - } - }); - router.post("/v2/media", upload.single("file"), async (ctx) => { - const BASE_URL = `${ctx.protocol}://${ctx.hostname}`; - const accessTokens = ctx.headers.authorization; - const client = getClient(BASE_URL, accessTokens); - try { - let multipartData = await ctx.request.file; - if (!multipartData) { - ctx.body = { error: "No image" }; - ctx.status = 401; - return; - } - const image = fs.readFileSync((multipartData).path); - const data = await client.uploadMedia(image); - ctx.body = data.data; - } catch (e: any) { - console.error(e); - ctx.status = 401; - ctx.body = e.response.data; - } - }); router.get<{ Params: { id: string } }>( "/v1/media/:id", async (ctx) => { From bab5577ee580b8611c4a4302fbb320293e597ebb Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 17:07:49 +0100 Subject: [PATCH 115/582] this is the sign I need a break --- packages/backend/src/server/api/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index 9b6c62924..dcf79d16d 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -10,6 +10,7 @@ import cors from "@koa/cors"; import { apiMastodonCompatible, getClient } from "./mastodon/ApiMastodonCompatibleService.js"; import { Instances, AccessTokens, Users } from "@/models/index.js"; import config from "@/config/index.js"; +import fs from "fs"; import endpoints from "./endpoints.js"; import compatibility from "./compatibility.js"; import handler from "./api-handler.js"; From ac6cc1ea45c4cffb66bf4936dbc69c633be7e12f Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 17:13:35 +0100 Subject: [PATCH 116/582] maybe buffer? --- packages/backend/src/server/api/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index dcf79d16d..a49664136 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -82,8 +82,7 @@ mastoFileRouter.post("/v1/media", upload.single("file"), async (ctx) => { ctx.status = 401; return; } - const image = fs.readFileSync((multipartData).path); - const data = await client.uploadMedia(image); + const data = await client.uploadMedia(multipartData.buffer); ctx.body = data.data; } catch (e: any) { console.error(e); @@ -102,8 +101,7 @@ mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => { ctx.status = 401; return; } - const image = fs.readFileSync((multipartData).path); - const data = await client.uploadMedia(image); + const data = await client.uploadMedia(multipartData.buffer); ctx.body = data.data; } catch (e: any) { console.error(e); From 066b4fa78d60d806e77367a80f59b3acba91cf44 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 17:20:34 +0100 Subject: [PATCH 117/582] meow? --- packages/backend/src/server/api/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index a49664136..fbbd16ba0 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -82,7 +82,7 @@ mastoFileRouter.post("/v1/media", upload.single("file"), async (ctx) => { ctx.status = 401; return; } - const data = await client.uploadMedia(multipartData.buffer); + const data = await client.uploadMedia(multipartData); ctx.body = data.data; } catch (e: any) { console.error(e); @@ -101,7 +101,7 @@ mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => { ctx.status = 401; return; } - const data = await client.uploadMedia(multipartData.buffer); + const data = await client.uploadMedia(multipartData); ctx.body = data.data; } catch (e: any) { console.error(e); From f013669e7b1a5fab3274989919a69a204b5f3f62 Mon Sep 17 00:00:00 2001 From: CutestNekoAqua Date: Thu, 23 Feb 2023 17:38:18 +0100 Subject: [PATCH 118/582] aa --- packages/backend/src/server/api/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/index.ts b/packages/backend/src/server/api/index.ts index fbbd16ba0..752303e95 100644 --- a/packages/backend/src/server/api/index.ts +++ b/packages/backend/src/server/api/index.ts @@ -76,13 +76,13 @@ mastoFileRouter.post("/v1/media", upload.single("file"), async (ctx) => { const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - let multipartData = await ctx.request.file; + let multipartData = await ctx.file; if (!multipartData) { ctx.body = { error: "No image" }; ctx.status = 401; return; } - const data = await client.uploadMedia(multipartData); + const data = await client.uploadMedia(multipartData.buffer); ctx.body = data.data; } catch (e: any) { console.error(e); @@ -95,13 +95,13 @@ mastoFileRouter.post("/v2/media", upload.single("file"), async (ctx) => { const accessTokens = ctx.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - let multipartData = await ctx.request.file; + let multipartData = await ctx.file; if (!multipartData) { ctx.body = { error: "No image" }; ctx.status = 401; return; } - const data = await client.uploadMedia(multipartData); + const data = await client.uploadMedia(multipartData.buffer); ctx.body = data.data; } catch (e: any) { console.error(e); From f429766dd5abad2b03d3597c86957669babda1fb Mon Sep 17 00:00:00 2001 From: Freeplay Date: Thu, 23 Feb 2023 16:44:15 -0500 Subject: [PATCH 119/582] bruh why didn't I just do that --- packages/client/src/components/MkNoteSub.vue | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/client/src/components/MkNoteSub.vue b/packages/client/src/components/MkNoteSub.vue index 6ba704306..718b7e177 100644 --- a/packages/client/src/components/MkNoteSub.vue +++ b/packages/client/src/components/MkNoteSub.vue @@ -1,10 +1,10 @@