From 6e4ec1ebc3fe547aff0e9614239bbe1a0b59dfc0 Mon Sep 17 00:00:00 2001 From: cutls Date: Sat, 4 Feb 2023 02:14:55 +0900 Subject: [PATCH] compatible with Mi v13 --- megalodon/package.json | 2 +- megalodon/src/misskey.ts | 4 +-- megalodon/src/misskey/api_client.ts | 34 ++++++++++++++++++------- megalodon/src/misskey/entities/emoji.ts | 3 +++ megalodon/src/misskey/entities/user.ts | 2 +- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/megalodon/package.json b/megalodon/package.json index d4b8bac..c1b8335 100644 --- a/megalodon/package.json +++ b/megalodon/package.json @@ -1,5 +1,5 @@ { - "name": "megalodon", + "name": "@cutls/megalodon", "version": "5.1.1", "description": "Mastodon API client for node.js and browser", "main": "./lib/src/index.js", diff --git a/megalodon/src/misskey.ts b/megalodon/src/misskey.ts index 187c0f5..c3288e1 100644 --- a/megalodon/src/misskey.ts +++ b/megalodon/src/misskey.ts @@ -2094,8 +2094,8 @@ export default class Misskey implements MegalodonInterface { */ public async getInstanceCustomEmojis(): Promise>> { return this.client - .post('/api/meta') - .then(res => ({ ...res, data: res.data.emojis.map(e => MisskeyAPI.Converter.emoji(e)) })) + .post('/api/emojis') + .then(res => ({ ...res, data: res.data.map(e => MisskeyAPI.Converter.emoji(e)) })) } // ====================================== diff --git a/megalodon/src/misskey/api_client.ts b/megalodon/src/misskey/api_client.ts index bf820df..5213e38 100644 --- a/megalodon/src/misskey/api_client.ts +++ b/megalodon/src/misskey/api_client.ts @@ -10,6 +10,7 @@ import MegalodonEntity from '../entity' import WebSocket from './web_socket' import MisskeyNotificationType from './notification' import NotificationType from '../notification' +export const isEmojiArr = (item: any): item is MisskeyEntity.Emoji[] => Array.isArray(item) namespace MisskeyAPI { export namespace Entity { @@ -18,6 +19,7 @@ namespace MisskeyAPI { export type Choice = MisskeyEntity.Choice export type CreatedNote = MisskeyEntity.CreatedNote export type Emoji = MisskeyEntity.Emoji + export type EmojiKeyValue = MisskeyEntity.EmojiKeyValue export type Favorite = MisskeyEntity.Favorite export type File = MisskeyEntity.File export type Follower = MisskeyEntity.Follower @@ -49,6 +51,20 @@ namespace MisskeyAPI { } } + export const emojiConverter = (e: MisskeyEntity.EmojiKeyValue | MisskeyEntity.Emoji[]) => { + if (isEmojiArr(e)) return e + const emojiKeys = Object.keys(e) + const emojiArr: MisskeyEntity.Emoji[] = emojiKeys.map((emoji, i) => { + return { + name: emojiKeys[i], + host: null, + url: emoji, + aliases: [] + } + }) + return emojiArr + } + export const user = (u: Entity.User): MegalodonEntity.Account => { let acct = u.username if (u.host) { @@ -70,7 +86,7 @@ namespace MisskeyAPI { avatar_static: u.avatarColor, header: '', header_static: '', - emojis: u.emojis.map(e => emoji(e)), + emojis: emojiConverter(u.emojis).map(e => emoji(e)), moved: null, fields: [], bot: null @@ -98,7 +114,7 @@ namespace MisskeyAPI { avatar_static: u.avatarColor, header: u.bannerUrl, header_static: u.bannerColor, - emojis: u.emojis.map(e => emoji(e)), + emojis: emojiConverter(u.emojis).map(e => emoji(e)), moved: null, fields: [], bot: u.isBot @@ -222,13 +238,13 @@ namespace MisskeyAPI { reblog: n.renote ? note(n.renote) : null, content: n.text ? n.text - .replace(/&/g, '&') - .replace(//g, '>') - .replace(/"/g, '"') - .replace(/'/g, ''') - .replace(/`/g, '`') - .replace(/\r?\n/g, '
') + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, ''') + .replace(/`/g, '`') + .replace(/\r?\n/g, '
') : '', plain_content: n.text ? n.text : null, created_at: n.createdAt, diff --git a/megalodon/src/misskey/entities/emoji.ts b/megalodon/src/misskey/entities/emoji.ts index e0bcfe0..033db67 100644 --- a/megalodon/src/misskey/entities/emoji.ts +++ b/megalodon/src/misskey/entities/emoji.ts @@ -5,4 +5,7 @@ namespace MisskeyEntity { url: string aliases: Array } + export type EmojiKeyValue = { + [key: string]: string + } } diff --git a/megalodon/src/misskey/entities/user.ts b/megalodon/src/misskey/entities/user.ts index 4ea7bde..c648be0 100644 --- a/megalodon/src/misskey/entities/user.ts +++ b/megalodon/src/misskey/entities/user.ts @@ -8,6 +8,6 @@ namespace MisskeyEntity { host: string | null avatarUrl: string avatarColor: string - emojis: Array + emojis: Array | EmojiKeyValue } }