From 5b2f5b4e47ca4e263cf73b4baa49a767910c237c Mon Sep 17 00:00:00 2001 From: ThatOneCalculator Date: Wed, 8 Feb 2023 11:15:40 -0800 Subject: [PATCH] Revert "compatible with Mi v13" This reverts commit 6e4ec1ebc3fe547aff0e9614239bbe1a0b59dfc0. --- megalodon/package.json | 4 +- megalodon/src/misskey.ts | 2 +- megalodon/src/misskey/api_client.ts | 70 ++++++++++--------------- megalodon/src/misskey/entities/emoji.ts | 3 -- megalodon/src/misskey/entities/user.ts | 2 +- package.json | 7 +-- pnpm-workspace.yaml | 4 ++ 7 files changed, 36 insertions(+), 56 deletions(-) create mode 100644 pnpm-workspace.yaml diff --git a/megalodon/package.json b/megalodon/package.json index a054e52..cf1fb05 100644 --- a/megalodon/package.json +++ b/megalodon/package.json @@ -1,6 +1,6 @@ { - "name": "@cutls/megalodon", - "version": "5.1.15", + "name": "@thatonecalculator/megalodon", + "version": "5.1.2", "description": "Mastodon API client for node.js and browser", "main": "./lib/src/index.js", "typings": "./lib/src/index.d.ts", diff --git a/megalodon/src/misskey.ts b/megalodon/src/misskey.ts index afa7299..db5ee4a 100644 --- a/megalodon/src/misskey.ts +++ b/megalodon/src/misskey.ts @@ -2100,7 +2100,7 @@ export default class Misskey implements MegalodonInterface { */ public async getInstanceCustomEmojis(): Promise>> { return this.client - .post('/api/emojis') + .post('/api/meta') .then(res => ({ ...res, data: res.data.emojis.map(e => MisskeyAPI.Converter.emoji(e)) })) } diff --git a/megalodon/src/misskey/api_client.ts b/megalodon/src/misskey/api_client.ts index a7ca54b..0e30b20 100644 --- a/megalodon/src/misskey/api_client.ts +++ b/megalodon/src/misskey/api_client.ts @@ -10,7 +10,6 @@ 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 { @@ -19,7 +18,6 @@ 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 @@ -52,21 +50,7 @@ namespace MisskeyAPI { } } - export const emojiConverter = (e: MisskeyEntity.EmojiKeyValue | MisskeyEntity.Emoji[]) => { - if (!e) return [] - if (isEmojiArr(e)) return e - const emojiArr: MisskeyEntity.Emoji[] = Object.entries(e).map(([key, value]) => { - return { - name: key, - host: null, - url: value, - aliases: [] - } - }) - return emojiArr - } - - export const user = (u: Entity.User, host: string): MegalodonEntity.Account => { + export const user = (u: Entity.User): MegalodonEntity.Account => { let acct = u.username let acctUrl = `https://${host || u.host || 'example.com'}/@${u.username}` if (host || u.host) { @@ -86,10 +70,10 @@ namespace MisskeyAPI { note: '', url: acctUrl, avatar: u.avatarUrl, - avatar_static: u.avatarUrl, - header: u.avatarUrl, - header_static: u.avatarUrl, - emojis: emojiConverter(u.emojis).map(e => emoji(e)), + avatar_static: u.avatarColor, + header: '', + header_static: '', + emojis: u.emojis.map(e => emoji(e)), moved: null, fields: [], bot: false @@ -107,22 +91,22 @@ namespace MisskeyAPI { id: u.id, username: u.username, acct: acct, - display_name: u.name || u.username, - locked: !!u.isLocked, - created_at: u.createdAt || new Date().toISOString(), - followers_count: u.followersCount || 0, - following_count: u.followingCount || 0, - statuses_count: u.notesCount || 0, - note: u.description || '', - url: acctUrl, - avatar: u.avatarUrl || 'https://http.cat/404', - avatar_static: u.avatarUrl || 'https://http.cat/404', - header: u.bannerUrl || u.avatarUrl || 'https://http.cat/404', - header_static: u.bannerUrl || u.avatarUrl || 'https://http.cat/404', - emojis: emojiConverter(u.emojis).map(e => emoji(e)), + display_name: u.name, + locked: u.isLocked, + created_at: u.createdAt, + followers_count: u.followersCount, + following_count: u.followingCount, + statuses_count: u.notesCount, + note: u.description, + url: acct, + avatar: u.avatarUrl, + avatar_static: u.avatarColor, + header: u.bannerUrl, + header_static: u.bannerColor, + emojis: u.emojis.map(e => emoji(e)), moved: null, fields: [], - bot: u.isBot || false + bot: u.isBot } } @@ -243,13 +227,13 @@ namespace MisskeyAPI { reblog: n.renote ? note(n.renote, host) : 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, @@ -572,7 +556,7 @@ namespace MisskeyAPI { if (!this.accessToken) { throw new Error('accessToken is required') } - const url = this.baseUrl + '/streaming' + const url = `${this.baseUrl}/streaming` const streaming = new WebSocket(url, channel, this.accessToken, listId, this.userAgent, this.proxyConfig) process.nextTick(() => { streaming.start() diff --git a/megalodon/src/misskey/entities/emoji.ts b/megalodon/src/misskey/entities/emoji.ts index 033db67..e0bcfe0 100644 --- a/megalodon/src/misskey/entities/emoji.ts +++ b/megalodon/src/misskey/entities/emoji.ts @@ -5,7 +5,4 @@ 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 c648be0..4ea7bde 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 | EmojiKeyValue + emojis: Array } } diff --git a/package.json b/package.json index 62845be..352055c 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,3 @@ { - "private": true, - "workspaces": [ - "megalodon", - "example/typescript", - "example/browser" - ] + "private": true } diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 0000000..d247a0e --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,4 @@ +packages: + - 'megalodon' + - 'example/typescript' + - 'example/browser'