From e35f3eef56f4779ba56170652472f835aedc5fd2 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 afb3af6cbc..e5f3853bdb 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 f9fc1d7137ac1258fc730df5049eaf9da07911cb 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 e5f3853bdb..ee9ccf52aa 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 cd6a1d09f5e807ed319046d81bb7edc53f53fa11 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 3c438aa2fc..e643e24c9f 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 e118a28542ad2fb6d8d3dc37a80bae0224074a8e 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 0000000000..f1427db7be --- /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 e8e726ab3b..8ab714af30 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 95fcac3e553928efba4604ffe70989386fce1f5b 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 e8da6c5a73..bc3c0ffd67 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 abff66eada7b2c0a88a9769338d2d08eaba3fc17 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 7ae9e10fba..bb178506b7 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 11ef2273ca..2e035d1695 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 005d0800ac..476a0c29f0 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 fa23360f13d8657a4aef75f758064f780e132c32 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 ddfcc3de17..f2905ec354 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 8ab714af30..eb8006c1c5 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 51e1fc4e63..b39c8b37b8 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 a7045cecfbd09301340c6f9dff83f367d81ef246 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 bc3c0ffd67..da1e886ac1 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 edc563838532596e8db9f052b09d55c2f567b401 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 f2905ec354..6a8f81e409 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 085de45d02d2a734b52156001acbd5ea9a26bc73 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 f1427db7be..5f9dfd7d95 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 4173f5c364..6ee6dc05a5 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 c0766ec5f5..a0277d86ec 100644 --- a/packages/client/src/components/MkNoteSub.vue +++ b/packages/client/src/components/MkNoteSub.vue @@ -16,10 +16,14 @@
+ + - +function onModalClosed() { + emit('closed'); +} + From 7132ad2285beaa08bc3adde85439e246c21e59b1 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 840a1aee25..b88dee380e 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 6663824666..2765a99270 100644 --- a/packages/client/src/components/MkModalWindow.vue +++ b/packages/client/src/components/MkModalWindow.vue @@ -1,19 +1,19 @@ From 302e452572128deefc6bc07d1f80836f1b6a7319 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 ec55d15f70..1bcfa81a5f 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 362484f5fc..dc61e577b1 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 d3516bf4ca..0e6bdf3182 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 cc7be70bdf1a522ce99a2c34b5a2025f2d8c7b59 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 dfc5115cad..00d34e9495 100644 --- a/packages/client/src/components/MkWaitingDialog.vue +++ b/packages/client/src/components/MkWaitingDialog.vue @@ -1,18 +1,18 @@ - From b8499df5eb10f0f4c26ee94dc7d5039abc904349 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 6f5ca6618b..d1df6af4c1 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 1d2e638571b769737c0f15a79337ef716b8a2796 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 b88dee380e..80cfaf8da4 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 961837b226..f47632d40f 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 0868cba3d1..91ab737830 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 19c88fc68bca7ce5afa20185d8b316bdec02a2af 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 d1df6af4c1..a3fc37751a 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 0a3e39b6ec048dc6cb448a60dd86ea0d4cdccc68 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 a3fc37751a..640b722d22 100644 --- a/packages/client/src/components/MkUpdated.vue +++ b/packages/client/src/components/MkUpdated.vue @@ -15,6 +15,7 @@ - From 684f2e883a6dfea32cddec239a577a033e9b94bf 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 5fba6f8a63..a19acbaa14 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 f5537af8a12369b859daa0366735371addbfe31f 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 3ea3ff67e7..0f58d3acfc 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 a72ac2c7e0..0ba1e42297 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 d0a3c2c2b7af5539ad26a5b09f6e393d03b8b3d0 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 0ba1e42297..2ab834b64d 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 42a0c1b4a184ac610bf99732883987c76fd38294 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 2ab834b64d..89c733bd17 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 bb27ce997ea0526bf51b635b6b5808d655d28198 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 89c733bd17..7da2a2d7b0 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 726e469e23439639126755aab19f9445c5f62416 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 a19acbaa14..7ca6625f43 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 3281b194e41c7d8e8d4737cc2a5b4d9c5ad2b184 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 7ca6625f43..e5726fbaee 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 37d6039c1e53b2d32db9809a31606074704c5ff8 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 e5726fbaee..809a9aa117 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 8dd610a6a1581842d1568b341c3152eefe8d2312 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 809a9aa117..0a4ead16f3 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 2c6368afc426a4be32151d5d10ef5eec064cfd8a 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 0a4ead16f3..67f3901e4e 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 2dbbd1d39dc72b1e5a58cd9bbc0372d1599b3b01 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 7da2a2d7b0..b2c6f97815 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 cc44cc9da767a2d9fb3537079e3570bf0370be4f 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 b2c6f97815..c861323647 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 1728419130cb73549db8ec710bfe516d0ac0f520 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 0f58d3acfc..9b6c629245 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 c861323647..3981a17811 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 91df15209a68edfa21e8f387b4a32086824236c2 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 9b6c629245..dcf79d16d0 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 41d696c6ca78317ee2f5210bd9ce53202bd556bd 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 dcf79d16d0..a496641363 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 0be450d95f45d4caad739752f98f05c50c98c9b3 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 a496641363..fbbd16ba08 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 19d84a73ac1d5a706c8e54a01b6688ce6b0b66f0 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 fbbd16ba08..752303e95f 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 eb30b8460dc3b0ed01286ff9622f73e3b8fead27 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 6ba7043069..718b7e177d 100644 --- a/packages/client/src/components/MkNoteSub.vue +++ b/packages/client/src/components/MkNoteSub.vue @@ -1,10 +1,10 @@