refs #125 Divide misskey entities under misskey API

This commit is contained in:
AkiraFukushima 2020-02-17 23:44:42 +09:00
parent 65b7b7d3ca
commit 4e189bc04e
7 changed files with 61 additions and 23 deletions

View file

@ -96,8 +96,8 @@ export default class Misskey {
"secret": "string"
}
*/
return MisskeyAPI.Client.post<MisskeyAPI.App>('/api/app/create', params, this.baseUrl, this.proxyConfig).then(
(res: Response<MisskeyAPI.App>) => {
return MisskeyAPI.Client.post<MisskeyAPI.Entity.App>('/api/app/create', params, this.baseUrl, this.proxyConfig).then(
(res: Response<MisskeyAPI.Entity.App>) => {
const appData: OAuth.AppDataFromServer = {
id: res.data.id,
name: res.data.name,
@ -114,10 +114,10 @@ export default class Misskey {
/**
* POST /api/auth/session/generate
*/
public async generateAuthUrlAndToken(clientSecret: string): Promise<MisskeyAPI.Session> {
return MisskeyAPI.Client.post<MisskeyAPI.Session>('/api/auth/session/generate', {
public async generateAuthUrlAndToken(clientSecret: string): Promise<MisskeyAPI.Entity.Session> {
return MisskeyAPI.Client.post<MisskeyAPI.Entity.Session>('/api/auth/session/generate', {
appSecret: clientSecret
}).then((res: Response<MisskeyAPI.Session>) => res.data)
}).then((res: Response<MisskeyAPI.Entity.Session>) => res.data)
}
// ======================================
@ -147,7 +147,7 @@ export default class Misskey {
session_token: string,
_redirect_uri: string
): Promise<OAuth.TokenData> {
return MisskeyAPI.Client.post<MisskeyAPI.UserKey>('/api/auth/session/userkey', {
return MisskeyAPI.Client.post<MisskeyAPI.Entity.UserKey>('/api/auth/session/userkey', {
appSecret: client_secret,
token: session_token
}).then(res => {

View file

@ -2,8 +2,16 @@ import axios, { AxiosResponse, CancelTokenSource, AxiosRequestConfig } from 'axi
import { DEFAULT_UA } from '@/default'
import proxyAgent, { ProxyConfig } from '@/proxy_config'
import Response from '@/response'
import MisskeyEntity from './entity'
namespace MisskeyAPI {
export namespace Entity {
export type App = MisskeyEntity.App
export type User = MisskeyEntity.User
export type UserKey = MisskeyEntity.UserKey
export type Session = MisskeyEntity.Session
}
export const DEFAULT_SCOPE = [
'read:account',
'write:account',
@ -128,23 +136,6 @@ namespace MisskeyAPI {
return this.cancelTokenSource.cancel('Request is canceled by user')
}
}
export type App = {
id: string
name: string
callbackUrl: string
permission: Array<string>
secret: string
}
export type Session = {
token: string
url: string
}
export type UserKey = {
accessToken: string
}
}
export default MisskeyAPI

View file

@ -0,0 +1,9 @@
namespace Entity {
export type App = {
id: string
name: string
callbackUrl: string
permission: Array<string>
secret: string
}
}

View file

@ -0,0 +1,6 @@
namespace Entity {
export type Session = {
token: string
url: string
}
}

View file

@ -0,0 +1,18 @@
namespace Entity {
export type User = {
id: string
username: string
name: string
host: string
description: string
createdAt: string
followersCount: number
followingCount: number
notesCount: number
isBot: boolean
isCat: boolean
isAdmim: boolean
isVerified: boolean
isLocked: boolean
}
}

View file

@ -0,0 +1,8 @@
/// <reference path="user.ts" />
namespace Entity {
export type UserKey = {
accessToken: string
user: User
}
}

6
src/misskey/entity.ts Normal file
View file

@ -0,0 +1,6 @@
/// <reference path="entities/app.ts" />
/// <reference path="entities/user.ts" />
/// <reference path="entities/userkey.ts" />
/// <reference path="entities/session.ts" />
export default Entity