From 1f8c7358891bd1f9db5cefda09bb2054d0a88ab7 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sun, 2 Jul 2023 18:41:01 +0200 Subject: [PATCH] [mastodon-client] megalodon compat changes --- .../api/mastodon/ApiMastodonCompatibleService.ts | 6 +----- .../src/server/api/mastodon/endpoints/account.ts | 4 ++-- .../backend/src/server/api/mastodon/endpoints/meta.ts | 6 +++--- .../src/server/api/mastodon/endpoints/search.ts | 4 ++-- .../src/server/api/mastodon/endpoints/status.ts | 10 +++++----- packages/backend/src/server/index.ts | 2 +- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/ApiMastodonCompatibleService.ts b/packages/backend/src/server/api/mastodon/ApiMastodonCompatibleService.ts index df85f2162..e31314e13 100644 --- a/packages/backend/src/server/api/mastodon/ApiMastodonCompatibleService.ts +++ b/packages/backend/src/server/api/mastodon/ApiMastodonCompatibleService.ts @@ -18,11 +18,7 @@ export function getClient( const accessTokenArr = authorization?.split(" ") ?? [null]; const accessToken = accessTokenArr[accessTokenArr.length - 1]; const generator = (megalodon as any).default; - const client = generator( - "misskey", - BASE_URL, - accessToken, - ) as MegalodonInterface; + const client = generator(BASE_URL, accessToken) as MegalodonInterface; return client; } diff --git a/packages/backend/src/server/api/mastodon/endpoints/account.ts b/packages/backend/src/server/api/mastodon/endpoints/account.ts index 23d46eea6..c2cbb630a 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/account.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/account.ts @@ -42,8 +42,8 @@ export function apiAccountMastodon(router: Router): void { acct.url = `${BASE_URL}/@${acct.url}`; acct.note = acct.note || ""; acct.avatar_static = acct.avatar; - acct.header = acct.header || "https://http.cat/404"; - acct.header_static = acct.header || "https://http.cat/404"; + acct.header = acct.header || "/static-assets/transparent.png"; + acct.header_static = acct.header || "/static-assets/transparent.png"; acct.source = { note: acct.note, fields: acct.fields, diff --git a/packages/backend/src/server/api/mastodon/endpoints/meta.ts b/packages/backend/src/server/api/mastodon/endpoints/meta.ts index c68a09585..8499d62bb 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/meta.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/meta.ts @@ -24,7 +24,7 @@ export async function getInstance(response: Entity.Instance) { status_count: await totalStatuses, domain_count: response.stats.domain_count, }, - thumbnail: response.thumbnail || "https://http.cat/404", + thumbnail: response.thumbnail || "/static-assets/transparent.png", languages: meta.langs, registrations: !meta.disableRegistration || response.registrations, approval_required: !response.registrations, @@ -96,8 +96,8 @@ export async function getInstance(response: Entity.Instance) { 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", + header: "/static-assets/transparent.png", + header_static: "/static-assets/transparent.png", followers_count: -1, following_count: 0, statuses_count: 0, diff --git a/packages/backend/src/server/api/mastodon/endpoints/search.ts b/packages/backend/src/server/api/mastodon/endpoints/search.ts index e1aec3488..9a07db4dc 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/search.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/search.ts @@ -103,7 +103,7 @@ async function getHighlight( i: accessToken, }); const data: MisskeyEntity.Note[] = api.data; - return data.map((note) => Converter.note(note, domain)); + return data.map((note) => new Converter(BASE_URL).note(note, domain)); } catch (e: any) { console.log(e); console.log(e.response.data); @@ -131,7 +131,7 @@ async function getFeaturedUser( return data.map((u) => { return { source: "past_interactions", - account: Converter.userDetail(u, host), + account: new Converter(BASE_URL).userDetail(u, host), }; }); } catch (e: any) { diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 86fabb59b..759faeef9 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -449,8 +449,8 @@ export function statusModel( const now = new Date().toISOString(); return { id: "9atm5frjhb", - uri: "https://http.cat/404", // "" - url: "https://http.cat/404", // "", + uri: "/static-assets/transparent.png", // "" + url: "/static-assets/transparent.png", // "", account: { id: "9arzuvv0sw", username: "Reactions", @@ -462,11 +462,11 @@ export function statusModel( following_count: 0, statuses_count: 0, note: "", - url: "https://http.cat/404", + url: "/static-assets/transparent.png", avatar: "/static-assets/badges/info.png", avatar_static: "/static-assets/badges/info.png", - header: "https://http.cat/404", // "" - header_static: "https://http.cat/404", // "" + header: "/static-assets/transparent.png", // "" + header_static: "/static-assets/transparent.png", // "" emojis: [], fields: [], moved: null, diff --git a/packages/backend/src/server/index.ts b/packages/backend/src/server/index.ts index cd2d13219..270a8666d 100644 --- a/packages/backend/src/server/index.ts +++ b/packages/backend/src/server/index.ts @@ -166,7 +166,7 @@ mastoRouter.post("/oauth/token", async (ctx) => { let client_id: any = body.client_id; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const generator = (megalodon as any).default; - const client = generator("misskey", BASE_URL, null) as MegalodonInterface; + const client = generator(BASE_URL, null) as MegalodonInterface; let m = null; let token = null; if (body.code) {