refs #125 Implement instance methods for misskey

This commit is contained in:
AkiraFukushima 2020-03-08 23:06:27 +09:00
parent 39304b573b
commit 27ad42816c
6 changed files with 143 additions and 0 deletions

View file

@ -1748,4 +1748,71 @@ export default class Misskey {
}))
}
}
// ======================================
// instance
// ======================================
/**
* POST /api/meta
* POST /api/stats
*/
public async getInstance(): Promise<Response<Entity.Instance>> {
const meta = await this.client.post<MisskeyAPI.Entity.Meta>('/api/meta').then(res => res.data)
return this.client
.post<MisskeyAPI.Entity.Stats>('/api/stats')
.then(res => ({ ...res, data: MisskeyAPI.Converter.meta(meta, res.data) }))
}
public async getInstancePeers(): Promise<Response<Array<string>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
public async getInstanceActivity(): Promise<Response<Array<Entity.Activity>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
// ======================================
// instance/trends
// ======================================
/**
* POST /api/hashtags/trend
*/
public async getInstanceTrends(_limit?: number | null): Promise<Response<Array<Entity.Tag>>> {
return this.client
.post<Array<MisskeyAPI.Entity.Hashtag>>('/api/hashtags/trend')
.then(res => ({ ...res, data: res.data.map(h => MisskeyAPI.Converter.hashtag(h)) }))
}
// ======================================
// instance/directory
// ======================================
public async getInstanceDirectory(
_limit?: number | null,
_offset?: number | null,
_order?: 'active' | 'new' | null,
_local?: boolean | null
): Promise<Response<Array<Entity.Account>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
}
// ======================================
// instance/custom_emojis
// ======================================
/**
* POST /api/meta
*/
public async getInstanceCustomEmojis(): Promise<Response<Array<Entity.Emoji>>> {
return this.client
.post<MisskeyAPI.Entity.Meta>('/api/meta')
.then(res => ({ ...res, data: res.data.emojis.map(e => MisskeyAPI.Converter.emoji(e)) }))
}
}

View file

@ -18,7 +18,9 @@ namespace MisskeyAPI {
export type Follower = MisskeyEntity.Follower
export type Following = MisskeyEntity.Following
export type FollowRequest = MisskeyEntity.FollowRequest
export type Hashtag = MisskeyEntity.Hashtag
export type List = MisskeyEntity.List
export type Meta = MisskeyEntity.Meta
export type Mute = MisskeyEntity.Mute
export type Note = MisskeyEntity.Note
export type Notification = MisskeyEntity.Notification
@ -28,6 +30,7 @@ namespace MisskeyAPI {
export type UserDetail = MisskeyEntity.UserDetail
export type UserKey = MisskeyEntity.UserKey
export type Session = MisskeyEntity.Session
export type Stats = MisskeyEntity.Stats
}
export namespace Converter {
@ -291,6 +294,42 @@ namespace MisskeyAPI {
}
return notification
}
export const stats = (s: Entity.Stats): MegalodonEntity.Stats => {
return {
user_count: s.usersCount,
status_count: s.notesCount,
domain_count: s.instances
}
}
export const meta = (m: Entity.Meta, s: Entity.Stats): MegalodonEntity.Instance => {
const wss = m.uri.replace(/^https:\/\//, 'wss://')
return {
uri: m.uri,
title: m.name,
description: m.description,
email: m.maintainerEmail,
version: m.version,
thumbnail: m.bannerUrl,
urls: {
streaming_api: `${wss}/streaming`
},
stats: stats(s),
languages: m.langs,
contact_account: null,
max_toot_chars: m.maxNoteTextLength,
registrations: !m.disableRegistration
}
}
export const hashtag = (h: Entity.Hashtag): MegalodonEntity.Tag => {
return {
name: h.tag,
url: h.tag,
history: null
}
}
}
export const DEFAULT_SCOPE = [

View file

@ -0,0 +1,7 @@
namespace MisskeyEntity {
export type Hashtag = {
tag: string
chart: Array<number>
usersCount: number
}
}

View file

@ -0,0 +1,18 @@
/// <reference path="emoji.ts" />
namespace MisskeyEntity {
export type Meta = {
maintainerName: string
maintainerEmail: string
name: string
version: string
uri: string
description: string
langs: Array<string>
disableRegistration: boolean
disableLocalTimeline: boolean
bannerUrl: string
maxNoteTextLength: 300
emojis: Array<Emoji>
}
}

View file

@ -0,0 +1,9 @@
namespace MisskeyEntity {
export type Stats = {
notesCount: number
originalNotesCount: number
usersCount: number
originalUsersCount: number
instances: number
}
}

View file

@ -7,7 +7,9 @@
/// <reference path="entities/follower.ts" />
/// <reference path="entities/following.ts" />
/// <reference path="entities/followRequest.ts" />
/// <reference path="entities/hashtag.ts" />
/// <reference path="entities/list.ts" />
/// <reference path="entities/meta.ts" />
/// <reference path="entities/mute.ts" />
/// <reference path="entities/note.ts" />
/// <reference path="entities/notification.ts" />
@ -17,5 +19,6 @@
/// <reference path="entities/userDetail.ts" />
/// <reference path="entities/userkey.ts" />
/// <reference path="entities/session.ts" />
/// <reference path="entities/stats.ts" />
export default MisskeyEntity