From df62b3786ae5e0eaa829ce38d28308c77d4ebe7e Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Mon, 25 Sep 2023 02:40:04 +0200 Subject: [PATCH] upd: apply host to alot of fields --- .../server/api/mastodon/endpoints/status.ts | 2 +- .../server/api/mastodon/endpoints/timeline.ts | 8 +++---- packages/megalodon/src/megalodon.ts | 11 +++++----- packages/megalodon/src/misskey.ts | 21 ++++++++++--------- packages/megalodon/src/misskey/api_client.ts | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts index 20ef0a76c7..aae551b060 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/status.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts @@ -24,7 +24,7 @@ export class ApiStatusMastodon { const accessTokens = _request.headers.authorization; const client = getClient(BASE_URL, accessTokens); try { - const data = await client.getStatus(convertId(_request.params.id, IdType.SharkeyId)); + const data = await client.getStatus(convertId(_request.params.id, IdType.SharkeyId), BASE_URL); reply.send(convertStatus(data.data)); } catch (e: any) { console.error(e); diff --git a/packages/backend/src/server/api/mastodon/endpoints/timeline.ts b/packages/backend/src/server/api/mastodon/endpoints/timeline.ts index a171205161..70f0a4ad9b 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/timeline.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/timeline.ts @@ -51,8 +51,8 @@ export class ApiTimelineMastodon { try { const query: any = _request.query; const data = query.local === 'true' - ? await client.getLocalTimeline(convertTimelinesArgsId(argsToBools(limitToInt(query)))) - : await client.getPublicTimeline(convertTimelinesArgsId(argsToBools(limitToInt(query)))); + ? await client.getLocalTimeline(convertTimelinesArgsId(argsToBools(limitToInt(query))), BASE_URL) + : await client.getPublicTimeline(convertTimelinesArgsId(argsToBools(limitToInt(query))), BASE_URL); reply.send(data.data.map((status: Entity.Status) => convertStatus(status))); } catch (e: any) { console.error(e); @@ -69,7 +69,7 @@ export class ApiTimelineMastodon { const client = getClient(BASE_URL, accessTokens); try { const query: any = _request.query; - const data = await client.getHomeTimeline(convertTimelinesArgsId(limitToInt(query))); + const data = await client.getHomeTimeline(convertTimelinesArgsId(limitToInt(query)), BASE_URL); reply.send(data.data.map((status: Entity.Status) => convertStatus(status))); } catch (e: any) { console.error(e); @@ -87,7 +87,7 @@ export class ApiTimelineMastodon { try { const query: any = _request.query; const params: any = _request.params; - const data = await client.getTagTimeline(params.hashtag, convertTimelinesArgsId(limitToInt(query))); + const data = await client.getTagTimeline(params.hashtag, convertTimelinesArgsId(limitToInt(query)), BASE_URL); reply.send(data.data.map((status: Entity.Status) => convertStatus(status))); } catch (e: any) { console.error(e); diff --git a/packages/megalodon/src/megalodon.ts b/packages/megalodon/src/megalodon.ts index 19cd5c5551..7550438c56 100644 --- a/packages/megalodon/src/megalodon.ts +++ b/packages/megalodon/src/megalodon.ts @@ -682,7 +682,7 @@ export interface MegalodonInterface { * @param id The target status id. * @return Status */ - getStatus(id: string): Promise> + getStatus(id: string, host?: string): Promise> /** * Edit a given status to change its text, sensitivity, media attachments, or poll. Note that editing a poll’s options will reset the votes. * @@ -925,7 +925,7 @@ export interface MegalodonInterface { max_id?: string since_id?: string min_id?: string - }): Promise>> + }, host?: string): Promise>> /** * View local timeline. * @@ -942,7 +942,7 @@ export interface MegalodonInterface { max_id?: string since_id?: string min_id?: string - }): Promise>> + }, host?: string): Promise>> /** * View hashtag timeline. * @@ -964,7 +964,8 @@ export interface MegalodonInterface { max_id?: string since_id?: string min_id?: string - } + }, + host?: string ): Promise>> /** * View home timeline. @@ -982,7 +983,7 @@ export interface MegalodonInterface { max_id?: string since_id?: string min_id?: string - }): Promise>> + }, host?: string): Promise>> /** * View list timeline. * diff --git a/packages/megalodon/src/misskey.ts b/packages/megalodon/src/misskey.ts index 39c7685915..2891b2cd04 100644 --- a/packages/megalodon/src/misskey.ts +++ b/packages/megalodon/src/misskey.ts @@ -1094,12 +1094,12 @@ export default class Misskey implements MegalodonInterface { /** * POST /api/notes/show */ - public async getStatus(id: string): Promise> { + public async getStatus(id: string, host: string): Promise> { return this.client .post('/api/notes/show', { noteId: id }) - .then(res => ({ ...res, data: MisskeyAPI.Converter.note(res.data) })) + .then(res => ({ ...res, data: MisskeyAPI.Converter.note(res.data, host) })) } public async editStatus( @@ -1449,7 +1449,7 @@ export default class Misskey implements MegalodonInterface { max_id?: string since_id?: string min_id?: string - }): Promise>> { + }, host?: string): Promise>> { let params = {} if (options) { if (options.only_media !== undefined) { @@ -1480,7 +1480,7 @@ export default class Misskey implements MegalodonInterface { } return this.client .post>('/api/notes/global-timeline', params) - .then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n)) })) + .then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n, host)) })) } /** @@ -1492,7 +1492,7 @@ export default class Misskey implements MegalodonInterface { max_id?: string since_id?: string min_id?: string - }): Promise>> { + }, host?: string): Promise>> { let params = {} if (options) { if (options.only_media !== undefined) { @@ -1523,7 +1523,7 @@ export default class Misskey implements MegalodonInterface { } return this.client .post>('/api/notes/local-timeline', params) - .then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n)) })) + .then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n, host)) })) } /** @@ -1538,7 +1538,8 @@ export default class Misskey implements MegalodonInterface { max_id?: string since_id?: string min_id?: string - } + }, + host?: string ): Promise>> { let params = { tag: hashtag @@ -1572,7 +1573,7 @@ export default class Misskey implements MegalodonInterface { } return this.client .post>('/api/notes/search-by-tag', params) - .then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n)) })) + .then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n, host)) })) } /** @@ -1584,7 +1585,7 @@ export default class Misskey implements MegalodonInterface { max_id?: string since_id?: string min_id?: string - }): Promise>> { + }, host?: string): Promise>> { let params = { withFiles: false } @@ -1612,7 +1613,7 @@ export default class Misskey implements MegalodonInterface { } return this.client .post>('/api/notes/timeline', params) - .then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n)) })) + .then(res => ({ ...res, data: res.data.map(n => MisskeyAPI.Converter.note(n, host)) })) } /** diff --git a/packages/megalodon/src/misskey/api_client.ts b/packages/megalodon/src/misskey/api_client.ts index ead094aca0..aa0cabcffb 100644 --- a/packages/megalodon/src/misskey/api_client.ts +++ b/packages/megalodon/src/misskey/api_client.ts @@ -253,7 +253,7 @@ namespace MisskeyAPI { id: n.id, uri: n.uri ? n.uri : host ? `https://${host}/notes/${n.id}` : '', url: n.url ? n.url : host ? `https://${host}/notes/${n.id}` : '', - account: user(n.user, host ? host : null), + account: user(n.user, n.user.host ? n.user.host : host ? host : null), in_reply_to_id: n.replyId, in_reply_to_account_id: null, reblog: n.renote ? note(n.renote) : null,