diff --git a/packages/megalodon/src/converter.ts b/packages/megalodon/src/converter.ts new file mode 100644 index 000000000..f768fc930 --- /dev/null +++ b/packages/megalodon/src/converter.ts @@ -0,0 +1,3 @@ +import MisskeyAPI from "./misskey/api_client"; + +export default MisskeyAPI.Converter; \ No newline at end of file diff --git a/packages/megalodon/src/index.ts b/packages/megalodon/src/index.ts index ae7c45e40..0d2b70c29 100644 --- a/packages/megalodon/src/index.ts +++ b/packages/megalodon/src/index.ts @@ -10,6 +10,7 @@ import Misskey from './misskey' import Entity from './entity' import NotificationType from './notification' import FilterContext from './filter_context' +import Converter from './converter' export { Response, @@ -25,7 +26,8 @@ export { Mastodon, Pleroma, Misskey, - Entity + Entity, + Converter } export default generator diff --git a/packages/megalodon/src/misskey/api_client.ts b/packages/megalodon/src/misskey/api_client.ts index 4883e7a8c..05971e9b7 100644 --- a/packages/megalodon/src/misskey/api_client.ts +++ b/packages/megalodon/src/misskey/api_client.ts @@ -68,11 +68,15 @@ namespace MisskeyAPI { } } - export const user = (u: Entity.User): MegalodonEntity.Account => { + export const user = (u: Entity.User, host: string | null = null): MegalodonEntity.Account => { + host ? host = host.replace("https://", "") : null; let acct = u.username if (u.host) { acct = `${u.username}@${u.host}` } + if (host) { + acct = `${u.username}@${host}` + } return { id: u.id, username: u.username, @@ -100,11 +104,15 @@ namespace MisskeyAPI { } } - export const userDetail = (u: Entity.UserDetail): MegalodonEntity.Account => { + export const userDetail = (u: Entity.UserDetail, host: string | null = null): MegalodonEntity.Account => { + host ? host = host.replace("https://", "") : null; let acct = u.username if (u.host) { acct = `${u.username}@${u.host}` } + if (host) { + acct = `${u.username}@${host}` + } return { id: u.id, username: u.username, @@ -239,12 +247,13 @@ namespace MisskeyAPI { } } - export const note = (n: Entity.Note): MegalodonEntity.Status => { + export const note = (n: Entity.Note, host: string | null = null): MegalodonEntity.Status => { + host ? host = host.replace("https://", "") : null; return { id: n.id, - uri: n.uri ? n.uri : '', - url: n.uri ? n.uri : '', - account: user(n.user), + uri: n.uri ? n.uri : host ? `https://${host}/notes/${n.id}` : '', + url: n.uri ? n.uri : host ? `https://${host}/notes/${n.id}` : '', + account: user(n.user, host ? host : null), in_reply_to_id: n.replyId, in_reply_to_account_id: null, reblog: n.renote ? note(n.renote) : null,