Revert "compatible with Mi v13"

This reverts commit 6e4ec1ebc3.
This commit is contained in:
ThatOneCalculator 2023-02-08 11:15:40 -08:00
parent ec4769a461
commit 5b2f5b4e47
No known key found for this signature in database
GPG key ID: 8703CACD01000000
7 changed files with 36 additions and 56 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "@cutls/megalodon", "name": "@thatonecalculator/megalodon",
"version": "5.1.15", "version": "5.1.2",
"description": "Mastodon API client for node.js and browser", "description": "Mastodon API client for node.js and browser",
"main": "./lib/src/index.js", "main": "./lib/src/index.js",
"typings": "./lib/src/index.d.ts", "typings": "./lib/src/index.d.ts",

View file

@ -2100,7 +2100,7 @@ export default class Misskey implements MegalodonInterface {
*/ */
public async getInstanceCustomEmojis(): Promise<Response<Array<Entity.Emoji>>> { public async getInstanceCustomEmojis(): Promise<Response<Array<Entity.Emoji>>> {
return this.client return this.client
.post<MisskeyAPI.Entity.APIEmoji>('/api/emojis') .post<MisskeyAPI.Entity.Meta>('/api/meta')
.then(res => ({ ...res, data: res.data.emojis.map(e => MisskeyAPI.Converter.emoji(e)) })) .then(res => ({ ...res, data: res.data.emojis.map(e => MisskeyAPI.Converter.emoji(e)) }))
} }

View file

@ -10,7 +10,6 @@ import MegalodonEntity from '../entity'
import WebSocket from './web_socket' import WebSocket from './web_socket'
import MisskeyNotificationType from './notification' import MisskeyNotificationType from './notification'
import NotificationType from '../notification' import NotificationType from '../notification'
export const isEmojiArr = (item: any): item is MisskeyEntity.Emoji[] => Array.isArray(item)
namespace MisskeyAPI { namespace MisskeyAPI {
export namespace Entity { export namespace Entity {
@ -19,7 +18,6 @@ namespace MisskeyAPI {
export type Choice = MisskeyEntity.Choice export type Choice = MisskeyEntity.Choice
export type CreatedNote = MisskeyEntity.CreatedNote export type CreatedNote = MisskeyEntity.CreatedNote
export type Emoji = MisskeyEntity.Emoji export type Emoji = MisskeyEntity.Emoji
export type EmojiKeyValue = MisskeyEntity.EmojiKeyValue
export type Favorite = MisskeyEntity.Favorite export type Favorite = MisskeyEntity.Favorite
export type File = MisskeyEntity.File export type File = MisskeyEntity.File
export type Follower = MisskeyEntity.Follower export type Follower = MisskeyEntity.Follower
@ -52,21 +50,7 @@ namespace MisskeyAPI {
} }
} }
export const emojiConverter = (e: MisskeyEntity.EmojiKeyValue | MisskeyEntity.Emoji[]) => { export const user = (u: Entity.User): MegalodonEntity.Account => {
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 => {
let acct = u.username let acct = u.username
let acctUrl = `https://${host || u.host || 'example.com'}/@${u.username}` let acctUrl = `https://${host || u.host || 'example.com'}/@${u.username}`
if (host || u.host) { if (host || u.host) {
@ -86,10 +70,10 @@ namespace MisskeyAPI {
note: '', note: '',
url: acctUrl, url: acctUrl,
avatar: u.avatarUrl, avatar: u.avatarUrl,
avatar_static: u.avatarUrl, avatar_static: u.avatarColor,
header: u.avatarUrl, header: '',
header_static: u.avatarUrl, header_static: '',
emojis: emojiConverter(u.emojis).map(e => emoji(e)), emojis: u.emojis.map(e => emoji(e)),
moved: null, moved: null,
fields: [], fields: [],
bot: false bot: false
@ -107,22 +91,22 @@ namespace MisskeyAPI {
id: u.id, id: u.id,
username: u.username, username: u.username,
acct: acct, acct: acct,
display_name: u.name || u.username, display_name: u.name,
locked: !!u.isLocked, locked: u.isLocked,
created_at: u.createdAt || new Date().toISOString(), created_at: u.createdAt,
followers_count: u.followersCount || 0, followers_count: u.followersCount,
following_count: u.followingCount || 0, following_count: u.followingCount,
statuses_count: u.notesCount || 0, statuses_count: u.notesCount,
note: u.description || '', note: u.description,
url: acctUrl, url: acct,
avatar: u.avatarUrl || 'https://http.cat/404', avatar: u.avatarUrl,
avatar_static: u.avatarUrl || 'https://http.cat/404', avatar_static: u.avatarColor,
header: u.bannerUrl || u.avatarUrl || 'https://http.cat/404', header: u.bannerUrl,
header_static: u.bannerUrl || u.avatarUrl || 'https://http.cat/404', header_static: u.bannerColor,
emojis: emojiConverter(u.emojis).map(e => emoji(e)), emojis: u.emojis.map(e => emoji(e)),
moved: null, moved: null,
fields: [], fields: [],
bot: u.isBot || false bot: u.isBot
} }
} }
@ -243,13 +227,13 @@ namespace MisskeyAPI {
reblog: n.renote ? note(n.renote, host) : null, reblog: n.renote ? note(n.renote, host) : null,
content: n.text content: n.text
? n.text ? n.text
.replace(/&/g, '&amp;') .replace(/&/g, '&amp;')
.replace(/</g, '&lt;') .replace(/</g, '&lt;')
.replace(/>/g, '&gt;') .replace(/>/g, '&gt;')
.replace(/"/g, '&quot;') .replace(/"/g, '&quot;')
.replace(/'/g, '&#39;') .replace(/'/g, '&#39;')
.replace(/`/g, '&#x60;') .replace(/`/g, '&#x60;')
.replace(/\r?\n/g, '<br>') .replace(/\r?\n/g, '<br>')
: '', : '',
plain_content: n.text ? n.text : null, plain_content: n.text ? n.text : null,
created_at: n.createdAt, created_at: n.createdAt,
@ -572,7 +556,7 @@ namespace MisskeyAPI {
if (!this.accessToken) { if (!this.accessToken) {
throw new Error('accessToken is required') 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) const streaming = new WebSocket(url, channel, this.accessToken, listId, this.userAgent, this.proxyConfig)
process.nextTick(() => { process.nextTick(() => {
streaming.start() streaming.start()

View file

@ -5,7 +5,4 @@ namespace MisskeyEntity {
url: string url: string
aliases: Array<string> aliases: Array<string>
} }
export type EmojiKeyValue = {
[key: string]: string
}
} }

View file

@ -8,6 +8,6 @@ namespace MisskeyEntity {
host: string | null host: string | null
avatarUrl: string avatarUrl: string
avatarColor: string avatarColor: string
emojis: Array<Emoji> | EmojiKeyValue emojis: Array<Emoji>
} }
} }

View file

@ -1,8 +1,3 @@
{ {
"private": true, "private": true
"workspaces": [
"megalodon",
"example/typescript",
"example/browser"
]
} }

4
pnpm-workspace.yaml Normal file
View file

@ -0,0 +1,4 @@
packages:
- 'megalodon'
- 'example/typescript'
- 'example/browser'