1
0

add: converter export from megalodon

This commit is contained in:
Mar0xy
2023-09-24 04:17:09 +02:00
parent f151ab2258
commit 72ff1ffc9d
3 changed files with 21 additions and 7 deletions
+3
View File
@@ -0,0 +1,3 @@
import MisskeyAPI from "./misskey/api_client";
export default MisskeyAPI.Converter;
+3 -1
View File
@@ -10,6 +10,7 @@ import Misskey from './misskey'
import Entity from './entity' import Entity from './entity'
import NotificationType from './notification' import NotificationType from './notification'
import FilterContext from './filter_context' import FilterContext from './filter_context'
import Converter from './converter'
export { export {
Response, Response,
@@ -25,7 +26,8 @@ export {
Mastodon, Mastodon,
Pleroma, Pleroma,
Misskey, Misskey,
Entity Entity,
Converter
} }
export default generator export default generator
+15 -6
View File
@@ -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 let acct = u.username
if (u.host) { if (u.host) {
acct = `${u.username}@${u.host}` acct = `${u.username}@${u.host}`
} }
if (host) {
acct = `${u.username}@${host}`
}
return { return {
id: u.id, id: u.id,
username: u.username, 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 let acct = u.username
if (u.host) { if (u.host) {
acct = `${u.username}@${u.host}` acct = `${u.username}@${u.host}`
} }
if (host) {
acct = `${u.username}@${host}`
}
return { return {
id: u.id, id: u.id,
username: u.username, 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 { return {
id: n.id, id: n.id,
uri: n.uri ? n.uri : '', uri: n.uri ? n.uri : host ? `https://${host}/notes/${n.id}` : '',
url: n.uri ? n.uri : '', url: n.uri ? n.uri : host ? `https://${host}/notes/${n.id}` : '',
account: user(n.user), account: user(n.user, host ? host : null),
in_reply_to_id: n.replyId, in_reply_to_id: n.replyId,
in_reply_to_account_id: null, in_reply_to_account_id: null,
reblog: n.renote ? note(n.renote) : null, reblog: n.renote ? note(n.renote) : null,