diff --git a/app.vue b/app.vue index 166a3d9..a33a17b 100644 --- a/app.vue +++ b/app.vue @@ -19,7 +19,7 @@ provideHeadlessUseId(() => useId()); const code = useRequestURL().searchParams.get("code"); const appData = useAppData(); const tokenData = useTokenData(); -const client = useMegalodon(tokenData); +const client = useClient(tokenData); const instance = useInstance(); const description = useExtendedDescription(client); @@ -28,12 +28,12 @@ useSeoMeta({ return titleChunk ? `${titleChunk} ยท Lysand` : "Lysand"; }, title: computed(() => instance.value?.title ?? ""), - ogImage: computed(() => instance.value?.banner), + ogImage: computed(() => instance.value?.banner.url), twitterTitle: computed(() => instance.value?.title ?? ""), twitterDescription: computed(() => convert(description.value?.content ?? ""), ), - twitterImage: computed(() => instance.value?.banner), + twitterImage: computed(() => instance.value?.banner.url), description: computed(() => convert(description.value?.content ?? "")), ogDescription: computed(() => convert(description.value?.content ?? "")), ogSiteName: "Lysand", @@ -57,7 +57,7 @@ if (code) { new URL("/", useRequestURL().origin).toString(), ) .then((res) => { - tokenData.value = res; + tokenData.value = res.data; // Remove code from URL window.history.replaceState( diff --git a/bun.lockb b/bun.lockb index be20811..45324f7 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/composer/composer.vue b/components/composer/composer.vue index a1d8d42..f1ab932 100644 --- a/components/composer/composer.vue +++ b/components/composer/composer.vue @@ -206,87 +206,64 @@ const canSubmit = computed( content.value?.trim().length <= characterLimit.value, ); const tokenData = useTokenData(); -const client = useMegalodon(tokenData); +const client = useClient(tokenData); const send = async () => { loading.value = true; - - if (respondingType.value === "edit") { - fetch( - new URL( - `/api/v1/statuses/${respondingTo.value?.id}`, - client.value?.baseUrl ?? "", - ).toString(), - { - method: "PUT", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${tokenData.value?.access_token}`, - }, - body: JSON.stringify({ - status: content.value?.trim() ?? "", - content_type: markdown.value - ? "text/markdown" - : "text/plain", - spoiler_text: cw.value ? cwContent.value.trim() : undefined, - sensitive: cw.value, - media_ids: files.value - .filter((file) => !!file.api_id) - .map((file) => file.api_id), - }), - }, - ) - .then(async (res) => { - if (!res.ok) { - throw new Error("Failed to edit status"); - } - - content.value = ""; - loading.value = false; - useEvent("composer:send-edit", await res.json()); - }) - .finally(() => { - useEvent("composer:close"); - }); - return; + if (!tokenData.value || !client.value) { + throw new Error("Not authenticated"); } - fetch(new URL("/api/v1/statuses", client.value?.baseUrl ?? "").toString(), { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${tokenData.value?.access_token}`, - }, - body: JSON.stringify({ + if (respondingType.value === "edit" && respondingTo.value) { + const response = await client.value.editStatus(respondingTo.value.id, { status: content.value?.trim() ?? "", content_type: markdown.value ? "text/markdown" : "text/plain", - in_reply_to_id: - respondingType.value === "reply" - ? respondingTo.value?.id - : null, - quote_id: - respondingType.value === "quote" - ? respondingTo.value?.id - : null, spoiler_text: cw.value ? cwContent.value.trim() : undefined, sensitive: cw.value, media_ids: files.value .filter((file) => !!file.api_id) - .map((file) => file.api_id), - }), - }) - .then(async (res) => { - if (!res.ok) { - throw new Error("Failed to send status"); - } - - content.value = ""; - loading.value = false; - useEvent("composer:send", await res.json()); - }) - .finally(() => { - useEvent("composer:close"); + .map((file) => file.api_id) as string[], }); + + if (!response.data) { + throw new Error("Failed to edit status"); + } + + content.value = ""; + loading.value = false; + useEvent("composer:send-edit", response.data); + useEvent("composer:close"); + return; + } + + const response = await client.value.postStatus( + content.value?.trim() ?? "", + { + content_type: markdown.value ? "text/markdown" : "text/plain", + in_reply_to_id: + respondingType.value === "reply" + ? respondingTo.value?.id + : undefined, + quote_id: + respondingType.value === "quote" + ? respondingTo.value?.id + : undefined, + spoiler_text: cw.value ? cwContent.value.trim() : undefined, + sensitive: cw.value, + media_ids: files.value + .filter((file) => !!file.api_id) + .map((file) => file.api_id) as string[], + }, + ); + + if (!response.data) { + throw new Error("Failed to send status"); + } + + content.value = ""; + loading.value = false; + useEvent("composer:send", response.data as Status); + useEvent("composer:close"); }; const characterLimit = computed( diff --git a/components/composer/file-uploader.vue b/components/composer/file-uploader.vue index e510dec..6cd36a8 100644 --- a/components/composer/file-uploader.vue +++ b/components/composer/file-uploader.vue @@ -74,7 +74,7 @@ const files = defineModel< }); const tokenData = useTokenData(); -const client = useMegalodon(tokenData); +const client = useClient(tokenData); const fileInput = ref(null); const openFilePicker = () => { diff --git a/components/sidebars/navigation.vue b/components/sidebars/navigation.vue index 08a191b..d414159 100644 --- a/components/sidebars/navigation.vue +++ b/components/sidebars/navigation.vue @@ -175,7 +175,7 @@ const loadingAuth = ref(false); const appData = useAppData(); const tokenData = useTokenData(); -const client = useMegalodon(); +const client = useClient(); const me = useMe(); const compose = () => { @@ -191,18 +191,18 @@ const signIn = async () => { website: useBaseUrl().value, }); - if (!output) { + if (!output?.data) { alert("Failed to create app"); return; } - appData.value = output; + appData.value = output.data; const url = await client.value?.generateAuthUrl( - output.client_id, - output.client_secret, + output.data.client_id, + output.data.client_secret, { - scope: ["read", "write", "follow", "push"], + scopes: ["read", "write", "follow", "push"], redirect_uri: new URL("/", useRequestURL().origin).toString(), }, ); diff --git a/components/social-elements/instance/Presentation.vue b/components/social-elements/instance/Presentation.vue index e66c5b8..f020b0a 100644 --- a/components/social-elements/instance/Presentation.vue +++ b/components/social-elements/instance/Presentation.vue @@ -2,8 +2,8 @@
- Instance banner + Instance banner
@@ -11,15 +11,15 @@
-
+

Administrator

- +
\ No newline at end of file diff --git a/components/social-elements/notes/note.vue b/components/social-elements/notes/note.vue index 02c60ae..25c9cbf 100644 --- a/components/social-elements/notes/note.vue +++ b/components/social-elements/notes/note.vue @@ -112,7 +112,7 @@ useListen("composer:send-edit", (note) => { const tokenData = useTokenData(); const isSignedIn = useSignedIn(); const me = useMe(); -const client = useMegalodon(tokenData); +const client = useClient(tokenData); const { loaded, note: outputtedNote, diff --git a/components/social-elements/notes/reply-header.vue b/components/social-elements/notes/reply-header.vue index f9090e2..7bd1402 100644 --- a/components/social-elements/notes/reply-header.vue +++ b/components/social-elements/notes/reply-header.vue @@ -16,6 +16,6 @@ const props = defineProps<{ }>(); const tokenData = useTokenData(); -const client = useMegalodon(tokenData); +const client = useClient(tokenData); const account = useAccount(client, props.account_id); \ No newline at end of file diff --git a/components/social-elements/users/Account.vue b/components/social-elements/users/Account.vue index 1bc4c78..8dc3eed 100644 --- a/components/social-elements/users/Account.vue +++ b/components/social-elements/users/Account.vue @@ -105,7 +105,7 @@ const props = defineProps<{ const skeleton = computed(() => !props.account); const tokenData = useTokenData(); const me = useMe(); -const client = useMegalodon(tokenData); +const client = useClient(tokenData); const accountId = computed(() => props.account?.id ?? null); const { relationship, isLoading } = useRelationship(client, accountId); diff --git a/components/timelines/Account.vue b/components/timelines/Account.vue index eacf4e2..69c3d6f 100644 --- a/components/timelines/Account.vue +++ b/components/timelines/Account.vue @@ -7,7 +7,7 @@ const props = defineProps<{ id?: string; }>(); -const client = useMegalodon(); +const client = useClient(); const timelineParameters = ref({}); const { timeline, loadNext, loadPrev } = useAccountTimeline( client.value, diff --git a/components/timelines/Home.vue b/components/timelines/Home.vue index 9938ea7..2c5b3ec 100644 --- a/components/timelines/Home.vue +++ b/components/timelines/Home.vue @@ -4,7 +4,7 @@ \ No newline at end of file diff --git a/pages/oauth/code.vue b/pages/oauth/code.vue index d30a77d..b0885cf 100644 --- a/pages/oauth/code.vue +++ b/pages/oauth/code.vue @@ -27,7 +27,6 @@