@mx-space/api-client 0.6.3 → 0.7.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.cjs.js +18 -0
- package/build/index.cjs.js.map +1 -1
- package/build/index.cjs.min.js.map +1 -1
- package/build/index.d.ts +42 -18
- package/build/index.esm.js +18 -0
- package/build/index.esm.js.map +1 -1
- package/build/index.esm.min.js.map +1 -1
- package/build/index.umd.js +18 -0
- package/build/index.umd.js.map +1 -1
- package/build/index.umd.min.js.map +1 -1
- package/esm/controllers/aggregate.d.ts +5 -0
- package/esm/controllers/aggregate.js.map +1 -1
- package/esm/controllers/category.d.ts +5 -0
- package/esm/controllers/category.js.map +1 -1
- package/esm/controllers/comment.d.ts +5 -0
- package/esm/controllers/comment.js.map +1 -1
- package/esm/controllers/link.d.ts +6 -0
- package/esm/controllers/link.js.map +1 -1
- package/esm/controllers/note.d.ts +5 -0
- package/esm/controllers/note.js.map +1 -1
- package/esm/controllers/page.d.ts +5 -0
- package/esm/controllers/page.js.map +1 -1
- package/esm/controllers/post.d.ts +5 -0
- package/esm/controllers/post.js.map +1 -1
- package/esm/controllers/project.d.ts +5 -0
- package/esm/controllers/project.js.map +1 -1
- package/esm/controllers/recently.d.ts +6 -0
- package/esm/controllers/recently.js.map +1 -1
- package/esm/controllers/say.d.ts +5 -0
- package/esm/controllers/say.js.map +1 -1
- package/esm/controllers/search.d.ts +7 -2
- package/esm/controllers/search.js.map +1 -1
- package/esm/controllers/snippet.d.ts +5 -0
- package/esm/controllers/snippet.js.map +1 -1
- package/esm/controllers/user.d.ts +6 -0
- package/esm/controllers/user.js.map +1 -1
- package/esm/core/client.d.ts +0 -19
- package/esm/core/client.js +19 -1
- package/esm/core/client.js.map +1 -1
- package/lib/controllers/aggregate.d.ts +5 -0
- package/lib/controllers/aggregate.js.map +1 -1
- package/lib/controllers/category.d.ts +5 -0
- package/lib/controllers/category.js.map +1 -1
- package/lib/controllers/comment.d.ts +5 -0
- package/lib/controllers/comment.js.map +1 -1
- package/lib/controllers/link.d.ts +6 -0
- package/lib/controllers/link.js.map +1 -1
- package/lib/controllers/note.d.ts +5 -0
- package/lib/controllers/note.js.map +1 -1
- package/lib/controllers/page.d.ts +5 -0
- package/lib/controllers/page.js.map +1 -1
- package/lib/controllers/post.d.ts +5 -0
- package/lib/controllers/post.js.map +1 -1
- package/lib/controllers/project.d.ts +5 -0
- package/lib/controllers/project.js.map +1 -1
- package/lib/controllers/recently.d.ts +6 -0
- package/lib/controllers/recently.js.map +1 -1
- package/lib/controllers/say.d.ts +5 -0
- package/lib/controllers/say.js.map +1 -1
- package/lib/controllers/search.d.ts +7 -2
- package/lib/controllers/search.js.map +1 -1
- package/lib/controllers/snippet.d.ts +5 -0
- package/lib/controllers/snippet.js.map +1 -1
- package/lib/controllers/user.d.ts +6 -0
- package/lib/controllers/user.js.map +1 -1
- package/lib/core/client.d.ts +0 -19
- package/lib/core/client.js +18 -0
- package/lib/core/client.js.map +1 -1
- package/package.json +11 -4
- package/src/adaptors/axios.ts +36 -0
- package/src/adaptors/umi-request.ts +30 -0
- package/src/controllers/aggregate.ts +65 -0
- package/src/controllers/base.ts +32 -0
- package/src/controllers/category.ts +107 -0
- package/src/controllers/comment.ts +64 -0
- package/src/controllers/index.ts +66 -0
- package/src/controllers/link.ts +21 -0
- package/src/controllers/note.ts +92 -0
- package/src/controllers/page.ts +59 -0
- package/src/controllers/post.ts +87 -0
- package/src/controllers/project.ts +20 -0
- package/src/controllers/recently.ts +48 -0
- package/src/controllers/say.ts +35 -0
- package/src/controllers/search.ts +101 -0
- package/src/controllers/snippet.ts +31 -0
- package/src/controllers/user.ts +46 -0
- package/src/core/attach-request.ts +43 -0
- package/src/core/client.ts +249 -0
- package/src/core/error.ts +10 -0
- package/src/core/index.ts +2 -0
- package/src/dtos/comment.ts +9 -0
- package/src/index.ts +12 -0
- package/src/interfaces/adapter.ts +30 -0
- package/src/interfaces/client.ts +6 -0
- package/src/interfaces/controller.ts +5 -0
- package/src/interfaces/instance.ts +8 -0
- package/src/interfaces/options.ts +1 -0
- package/src/interfaces/params.ts +4 -0
- package/src/interfaces/request.ts +57 -0
- package/src/models/aggregate.ts +71 -0
- package/src/models/base.ts +43 -0
- package/src/models/category.ts +25 -0
- package/src/models/comment.ts +37 -0
- package/src/models/index.ts +14 -0
- package/src/models/link.ts +23 -0
- package/src/models/note.ts +37 -0
- package/src/models/page.ts +20 -0
- package/src/models/post.ts +16 -0
- package/src/models/project.ts +12 -0
- package/src/models/recently.ts +7 -0
- package/src/models/say.ts +7 -0
- package/src/models/setting.ts +68 -0
- package/src/models/snippet.ts +18 -0
- package/src/models/user.ts +27 -0
- package/src/tsconfig.build.json +6 -0
- package/src/tsconfig.cjs.json +7 -0
- package/src/tsconfig.json +12 -0
- package/src/types/helper.d.ts +3 -0
- package/src/utils/auto-bind.ts +48 -0
- package/src/utils/index.ts +53 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { PaginationParams } from '~/interfaces/params'
|
|
3
|
+
import { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
4
|
+
import { PaginateResult } from '~/models/base'
|
|
5
|
+
import { CommentModel } from '~/models/comment'
|
|
6
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
7
|
+
import { HTTPClient } from '../core'
|
|
8
|
+
import { CommentDto } from '../dtos/comment'
|
|
9
|
+
|
|
10
|
+
declare module '../core/client' {
|
|
11
|
+
interface HTTPClient {
|
|
12
|
+
comment: CommentController
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class CommentController implements IController {
|
|
17
|
+
base = 'comments'
|
|
18
|
+
name = 'comment'
|
|
19
|
+
|
|
20
|
+
constructor(private readonly client: HTTPClient) {
|
|
21
|
+
autoBind(this)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get proxy(): IRequestHandler {
|
|
25
|
+
return this.client.proxy(this.base)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 根据 comment id 获取评论, 包括子评论
|
|
30
|
+
*/
|
|
31
|
+
getById(id: string): RequestProxyResult<CommentModel> {
|
|
32
|
+
return this.proxy(id).get<CommentModel & { ref: string }>()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 获取文章的评论列表
|
|
37
|
+
* @param refId 文章 Id
|
|
38
|
+
*/
|
|
39
|
+
getByRefId(refId: string, pagination: PaginationParams = {}) {
|
|
40
|
+
const { page, size } = pagination
|
|
41
|
+
return this.proxy
|
|
42
|
+
.ref(refId)
|
|
43
|
+
.get<PaginateResult<CommentModel & { ref: string }>>({
|
|
44
|
+
params: { page: page || 1, size: size || 10 },
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 评论
|
|
49
|
+
*/
|
|
50
|
+
comment(refId: string, data: CommentDto) {
|
|
51
|
+
return this.proxy(refId).post<CommentModel>({
|
|
52
|
+
data,
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 回复评论
|
|
58
|
+
*/
|
|
59
|
+
reply(commentId: string, data: CommentDto) {
|
|
60
|
+
return this.proxy.reply(commentId).post<CommentModel>({
|
|
61
|
+
data,
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AggregateController } from './aggregate'
|
|
2
|
+
import { CategoryController } from './category'
|
|
3
|
+
import { CommentController } from './comment'
|
|
4
|
+
import { LinkController } from './link'
|
|
5
|
+
import { NoteController } from './note'
|
|
6
|
+
import { PageController } from './page'
|
|
7
|
+
import { PostController } from './post'
|
|
8
|
+
import { ProjectController } from './project'
|
|
9
|
+
import { RecentlyController } from './recently'
|
|
10
|
+
import { SayController } from './say'
|
|
11
|
+
import { SearchController } from './search'
|
|
12
|
+
import { SnippetController } from './snippet'
|
|
13
|
+
import { UserController } from './user'
|
|
14
|
+
|
|
15
|
+
export const allControllers = [
|
|
16
|
+
AggregateController,
|
|
17
|
+
CategoryController,
|
|
18
|
+
CommentController,
|
|
19
|
+
LinkController,
|
|
20
|
+
NoteController,
|
|
21
|
+
PageController,
|
|
22
|
+
PostController,
|
|
23
|
+
ProjectController,
|
|
24
|
+
RecentlyController,
|
|
25
|
+
SayController,
|
|
26
|
+
SearchController,
|
|
27
|
+
SnippetController,
|
|
28
|
+
UserController,
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
export const allContollerNames = [
|
|
32
|
+
'aggregate',
|
|
33
|
+
'category',
|
|
34
|
+
'comment',
|
|
35
|
+
'link',
|
|
36
|
+
'note',
|
|
37
|
+
'page',
|
|
38
|
+
'post',
|
|
39
|
+
'project',
|
|
40
|
+
'recently',
|
|
41
|
+
'say',
|
|
42
|
+
'search',
|
|
43
|
+
'snippet',
|
|
44
|
+
'user',
|
|
45
|
+
|
|
46
|
+
// alias,
|
|
47
|
+
'friend',
|
|
48
|
+
'master',
|
|
49
|
+
'shorthand',
|
|
50
|
+
] as const
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
AggregateController,
|
|
54
|
+
CategoryController,
|
|
55
|
+
CommentController,
|
|
56
|
+
LinkController,
|
|
57
|
+
NoteController,
|
|
58
|
+
PageController,
|
|
59
|
+
PostController,
|
|
60
|
+
ProjectController,
|
|
61
|
+
RecentlyController,
|
|
62
|
+
SayController,
|
|
63
|
+
SearchController,
|
|
64
|
+
SnippetController,
|
|
65
|
+
UserController,
|
|
66
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { LinkModel } from '~/models/link'
|
|
2
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
3
|
+
import { HTTPClient } from '../core'
|
|
4
|
+
import { BaseCrudController } from './base'
|
|
5
|
+
|
|
6
|
+
declare module '../core/client' {
|
|
7
|
+
interface HTTPClient {
|
|
8
|
+
link: LinkController
|
|
9
|
+
friend: LinkController
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class LinkController extends BaseCrudController<LinkModel> {
|
|
14
|
+
constructor(protected readonly client: HTTPClient) {
|
|
15
|
+
super(client)
|
|
16
|
+
autoBind(this)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
name = ['link', 'friend']
|
|
20
|
+
base = 'links'
|
|
21
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
3
|
+
import { PaginateResult } from '~/models/base'
|
|
4
|
+
import { NoteModel, NoteWrappedPayload } from '~/models/note'
|
|
5
|
+
import { SelectFields } from '~/types/helper'
|
|
6
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
7
|
+
import { HTTPClient } from '../core/client'
|
|
8
|
+
|
|
9
|
+
declare module '../core/client' {
|
|
10
|
+
interface HTTPClient {
|
|
11
|
+
note: NoteController
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type NoteListOptions = {
|
|
16
|
+
select?: SelectFields<keyof NoteModel>
|
|
17
|
+
year?: number
|
|
18
|
+
sortBy?: 'weather' | 'mood' | 'title' | 'created' | 'modified'
|
|
19
|
+
sortOrder?: 1 | -1
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class NoteController implements IController {
|
|
23
|
+
base = 'notes'
|
|
24
|
+
name = 'note'
|
|
25
|
+
|
|
26
|
+
constructor(private client: HTTPClient) {
|
|
27
|
+
autoBind(this)
|
|
28
|
+
}
|
|
29
|
+
get proxy(): IRequestHandler {
|
|
30
|
+
return this.client.proxy(this.base)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 最新日记
|
|
35
|
+
*/
|
|
36
|
+
getLatest(): RequestProxyResult<NoteWrappedPayload> {
|
|
37
|
+
return this.proxy.latest.get<NoteWrappedPayload>()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 获取一篇日记
|
|
42
|
+
* @param id id | nid
|
|
43
|
+
* @param password 访问密码
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
getNoteById(id: string | number, password?: string) {
|
|
47
|
+
if (typeof id === 'number') {
|
|
48
|
+
return this.proxy.nid(id.toString()).get<NoteWrappedPayload>({
|
|
49
|
+
params: { password },
|
|
50
|
+
})
|
|
51
|
+
} else {
|
|
52
|
+
return this.proxy(id).get<NoteWrappedPayload>({ params: { password } })
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 日记列表分页
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
getList(page = 1, perPage = 10, options: NoteListOptions = {}) {
|
|
61
|
+
const { select, sortBy, sortOrder, year } = options
|
|
62
|
+
return this.proxy.get<PaginateResult<NoteModel>>({
|
|
63
|
+
params: {
|
|
64
|
+
page,
|
|
65
|
+
size: perPage,
|
|
66
|
+
select: select?.join(' '),
|
|
67
|
+
sortBy,
|
|
68
|
+
sortOrder,
|
|
69
|
+
year,
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 获取当前日记的上下各 n / 2 篇日记
|
|
76
|
+
*/
|
|
77
|
+
getMiddleList(id: string, size = 5) {
|
|
78
|
+
return this.proxy.list(id).get<{
|
|
79
|
+
data: Pick<NoteModel, 'id' | 'title' | 'nid' | 'created'>[]
|
|
80
|
+
size: number
|
|
81
|
+
}>({
|
|
82
|
+
params: { size },
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 喜欢这篇日记
|
|
88
|
+
*/
|
|
89
|
+
likeIt(id: string | number) {
|
|
90
|
+
return this.proxy.like(id).get<never>()
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { PaginateResult } from '~/models/base'
|
|
3
|
+
import { PageModel } from '~/models/page'
|
|
4
|
+
import { SelectFields } from '~/types/helper'
|
|
5
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
6
|
+
import { HTTPClient } from '../core'
|
|
7
|
+
|
|
8
|
+
declare module '../core/client' {
|
|
9
|
+
interface HTTPClient {
|
|
10
|
+
page: PageController
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type PageListOptions = {
|
|
15
|
+
select?: SelectFields<keyof PageModel>
|
|
16
|
+
sortBy?: 'order' | 'subtitle' | 'title' | 'created' | 'modified'
|
|
17
|
+
sortOrder?: 1 | -1
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class PageController implements IController {
|
|
21
|
+
constructor(private readonly client: HTTPClient) {
|
|
22
|
+
autoBind(this)
|
|
23
|
+
}
|
|
24
|
+
base = 'pages'
|
|
25
|
+
name = 'page'
|
|
26
|
+
get proxy() {
|
|
27
|
+
return this.client.proxy(this.base)
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 页面列表
|
|
31
|
+
*/
|
|
32
|
+
getList(page = 1, perPage = 10, options: PageListOptions = {}) {
|
|
33
|
+
const { select, sortBy, sortOrder } = options
|
|
34
|
+
return this.proxy.get<PaginateResult<PageModel>>({
|
|
35
|
+
params: {
|
|
36
|
+
page,
|
|
37
|
+
size: perPage,
|
|
38
|
+
select: select?.join(' '),
|
|
39
|
+
sortBy,
|
|
40
|
+
sortOrder,
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 页面详情
|
|
47
|
+
*/
|
|
48
|
+
getById(id: string) {
|
|
49
|
+
return this.proxy(id).get<PageModel>()
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 根据路径获取页面
|
|
53
|
+
* @param slug 路径
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
getBySlug(slug: string) {
|
|
57
|
+
return this.proxy.slug(slug).get<PageModel>({})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { RequestProxyResult } from '~/interfaces/request'
|
|
3
|
+
import { PaginateResult } from '~/models/base'
|
|
4
|
+
import { PostModel } from '~/models/post'
|
|
5
|
+
import { SelectFields } from '~/types/helper'
|
|
6
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
7
|
+
import { HTTPClient } from '../core/client'
|
|
8
|
+
|
|
9
|
+
declare module '../core/client' {
|
|
10
|
+
interface HTTPClient {
|
|
11
|
+
post: PostController
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type PostListOptions = {
|
|
16
|
+
select?: SelectFields<keyof PostModel>
|
|
17
|
+
year?: number
|
|
18
|
+
sortBy?: 'categoryId' | 'title' | 'created' | 'modified'
|
|
19
|
+
sortOrder?: 1 | -1
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class PostController implements IController {
|
|
23
|
+
constructor(private client: HTTPClient) {
|
|
24
|
+
autoBind(this)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
base = 'posts'
|
|
28
|
+
|
|
29
|
+
name = 'post'
|
|
30
|
+
|
|
31
|
+
public get proxy() {
|
|
32
|
+
return this.client.proxy(this.base)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 获取文章列表分页
|
|
37
|
+
* @param page
|
|
38
|
+
* @param perPage
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
getList(page = 1, perPage = 10, options: PostListOptions = {}) {
|
|
42
|
+
const { select, sortBy, sortOrder, year } = options
|
|
43
|
+
return this.proxy.get<PaginateResult<PostModel>>({
|
|
44
|
+
params: {
|
|
45
|
+
page,
|
|
46
|
+
size: perPage,
|
|
47
|
+
select: select?.join(' '),
|
|
48
|
+
sortBy,
|
|
49
|
+
sortOrder,
|
|
50
|
+
year,
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 根据分类和路径查找文章
|
|
57
|
+
* @param categoryName
|
|
58
|
+
* @param slug
|
|
59
|
+
*/
|
|
60
|
+
getPost(categoryName: string, slug: string): RequestProxyResult<PostModel>
|
|
61
|
+
/**
|
|
62
|
+
* 根据 ID 查找文章
|
|
63
|
+
* @param id
|
|
64
|
+
*/
|
|
65
|
+
getPost(id: string): RequestProxyResult<PostModel>
|
|
66
|
+
getPost(idOrCategoryName: string, slug?: string): any {
|
|
67
|
+
if (arguments.length == 1) {
|
|
68
|
+
return this.proxy(idOrCategoryName).get<PostModel>()
|
|
69
|
+
} else {
|
|
70
|
+
return this.proxy(idOrCategoryName)(slug).get<PostModel>()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 获取最新的文章
|
|
76
|
+
*/
|
|
77
|
+
getLatest() {
|
|
78
|
+
return this.proxy.latest.get<PostModel>()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 点赞
|
|
83
|
+
*/
|
|
84
|
+
thumbsUp(id: string) {
|
|
85
|
+
return this.proxy('_thumbs-up').get<void>({ params: { id } })
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ProjectModel } from '~/models/project'
|
|
2
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
3
|
+
import { HTTPClient } from '../core'
|
|
4
|
+
import { BaseCrudController } from './base'
|
|
5
|
+
|
|
6
|
+
declare module '../core/client' {
|
|
7
|
+
interface HTTPClient {
|
|
8
|
+
project: ProjectController
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class ProjectController extends BaseCrudController<ProjectModel> {
|
|
13
|
+
constructor(protected readonly client: HTTPClient) {
|
|
14
|
+
super(client)
|
|
15
|
+
autoBind(this)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
base = 'projects'
|
|
19
|
+
name = 'project'
|
|
20
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { RecentlyModel } from '~/models/recently'
|
|
3
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
4
|
+
import { HTTPClient } from '../core'
|
|
5
|
+
|
|
6
|
+
declare module '../core/client' {
|
|
7
|
+
interface HTTPClient {
|
|
8
|
+
recently: RecentlyController
|
|
9
|
+
shorthand: RecentlyController
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class RecentlyController implements IController {
|
|
14
|
+
base = 'recently'
|
|
15
|
+
name = ['recently', 'shorthand']
|
|
16
|
+
|
|
17
|
+
constructor(private readonly client: HTTPClient) {
|
|
18
|
+
autoBind(this)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get proxy() {
|
|
22
|
+
return this.client.proxy(this.base)
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 获取最新一条
|
|
26
|
+
*/
|
|
27
|
+
getLatestOne() {
|
|
28
|
+
return this.proxy.latest.get<RecentlyModel>()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getAll() {
|
|
32
|
+
return this.proxy.all.get<{ data: RecentlyModel[] }>()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getList(
|
|
36
|
+
before?: string | undefined,
|
|
37
|
+
after?: string | undefined,
|
|
38
|
+
size?: number | number,
|
|
39
|
+
) {
|
|
40
|
+
return this.proxy.get<{ data: RecentlyModel[] }>({
|
|
41
|
+
params: {
|
|
42
|
+
before,
|
|
43
|
+
after,
|
|
44
|
+
size,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { SayModel } from '~/models/say'
|
|
3
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
4
|
+
import { HTTPClient } from '../core'
|
|
5
|
+
import { BaseCrudController } from './base'
|
|
6
|
+
|
|
7
|
+
declare module '../core/client' {
|
|
8
|
+
interface HTTPClient {
|
|
9
|
+
say: SayController
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class SayController
|
|
14
|
+
extends BaseCrudController<SayModel>
|
|
15
|
+
implements IController
|
|
16
|
+
{
|
|
17
|
+
base = 'says'
|
|
18
|
+
name = 'say'
|
|
19
|
+
|
|
20
|
+
constructor(protected client: HTTPClient) {
|
|
21
|
+
super(client)
|
|
22
|
+
autoBind(this)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public get proxy() {
|
|
26
|
+
return this.client.proxy(this.base)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 获取随机一条
|
|
31
|
+
*/
|
|
32
|
+
getRandom() {
|
|
33
|
+
return this.proxy.random.get<{ data: SayModel | null }>()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
3
|
+
import { PaginateResult } from '~/models/base'
|
|
4
|
+
import { NoteModel } from '~/models/note'
|
|
5
|
+
import { PostModel } from '~/models/post'
|
|
6
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
7
|
+
import { PageModel } from '..'
|
|
8
|
+
import { HTTPClient } from '../core'
|
|
9
|
+
|
|
10
|
+
declare module '../core/client' {
|
|
11
|
+
interface HTTPClient {
|
|
12
|
+
search: SearchController
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type SearchType = 'post' | 'note'
|
|
17
|
+
|
|
18
|
+
export type SearchOption = {
|
|
19
|
+
orderBy?: string
|
|
20
|
+
order?: number
|
|
21
|
+
rawAlgolia?: boolean
|
|
22
|
+
}
|
|
23
|
+
export class SearchController implements IController {
|
|
24
|
+
base = 'search'
|
|
25
|
+
name = 'search'
|
|
26
|
+
|
|
27
|
+
constructor(private readonly client: HTTPClient) {
|
|
28
|
+
autoBind(this)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get proxy(): IRequestHandler {
|
|
32
|
+
return this.client.proxy(this.base)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
search(
|
|
36
|
+
type: 'note',
|
|
37
|
+
keyword: string,
|
|
38
|
+
options?: Omit<SearchOption, 'rawAlgolia'>,
|
|
39
|
+
): Promise<
|
|
40
|
+
RequestProxyResult<
|
|
41
|
+
PaginateResult<
|
|
42
|
+
Pick<NoteModel, 'modified' | 'id' | 'title' | 'created' | 'nid'>
|
|
43
|
+
>
|
|
44
|
+
>
|
|
45
|
+
>
|
|
46
|
+
search(
|
|
47
|
+
type: 'post',
|
|
48
|
+
keyword: string,
|
|
49
|
+
options?: Omit<SearchOption, 'rawAlgolia'>,
|
|
50
|
+
): Promise<
|
|
51
|
+
RequestProxyResult<
|
|
52
|
+
PaginateResult<
|
|
53
|
+
Pick<
|
|
54
|
+
PostModel,
|
|
55
|
+
'modified' | 'id' | 'title' | 'created' | 'slug' | 'category'
|
|
56
|
+
>
|
|
57
|
+
>
|
|
58
|
+
>
|
|
59
|
+
>
|
|
60
|
+
search(
|
|
61
|
+
type: SearchType,
|
|
62
|
+
keyword: string,
|
|
63
|
+
options: Omit<SearchOption, 'rawAlgolia'> = {},
|
|
64
|
+
): any {
|
|
65
|
+
return this.proxy(type).get({
|
|
66
|
+
params: { keyword, ...options },
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 从 algolya 搜索
|
|
71
|
+
* https://www.algolia.com/doc/api-reference/api-methods/search/
|
|
72
|
+
* @param keyword
|
|
73
|
+
* @param options
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
searchByAlgolia(keyword: string, options?: SearchOption) {
|
|
77
|
+
return this.proxy('algolia').get<
|
|
78
|
+
RequestProxyResult<
|
|
79
|
+
PaginateResult<
|
|
80
|
+
| (Pick<
|
|
81
|
+
PostModel,
|
|
82
|
+
'modified' | 'id' | 'title' | 'created' | 'slug' | 'category'
|
|
83
|
+
> & { type: 'post' })
|
|
84
|
+
| (Pick<
|
|
85
|
+
NoteModel,
|
|
86
|
+
'id' | 'created' | 'id' | 'modified' | 'title' | 'nid'
|
|
87
|
+
> & { type: 'note' })
|
|
88
|
+
| (Pick<
|
|
89
|
+
PageModel,
|
|
90
|
+
'id' | 'title' | 'created' | 'modified' | 'slug'
|
|
91
|
+
> & { type: 'page' })
|
|
92
|
+
> & {
|
|
93
|
+
/**
|
|
94
|
+
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
95
|
+
*/
|
|
96
|
+
raw?: any
|
|
97
|
+
}
|
|
98
|
+
>
|
|
99
|
+
>({ params: { keyword, ...options } })
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { SnippetModel } from '~/models/snippet'
|
|
3
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
4
|
+
import { HTTPClient } from '../core'
|
|
5
|
+
|
|
6
|
+
declare module '../core/client' {
|
|
7
|
+
interface HTTPClient {
|
|
8
|
+
snippet: SnippetController
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class SnippetController implements IController {
|
|
13
|
+
base = 'snippets'
|
|
14
|
+
name = 'snippet'
|
|
15
|
+
|
|
16
|
+
constructor(protected client: HTTPClient) {
|
|
17
|
+
autoBind(this)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get proxy() {
|
|
21
|
+
return this.client.proxy(this.base)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getById<T = unknown>(id: string) {
|
|
25
|
+
return this.proxy(id).get<SnippetModel<T>>()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getByReferenceAndName<T = unknown>(reference: string, name: string) {
|
|
29
|
+
return this.proxy(reference)(name).get<T>()
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { TLogin, UserModel } from '~/models/user'
|
|
3
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
4
|
+
import { HTTPClient } from '../core'
|
|
5
|
+
|
|
6
|
+
declare module '../core/client' {
|
|
7
|
+
interface HTTPClient {
|
|
8
|
+
user: UserController
|
|
9
|
+
master: UserController
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class UserController implements IController {
|
|
14
|
+
constructor(private readonly client: HTTPClient) {
|
|
15
|
+
autoBind(this)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
base = 'master'
|
|
19
|
+
|
|
20
|
+
name = ['user', 'master']
|
|
21
|
+
|
|
22
|
+
public get proxy() {
|
|
23
|
+
return this.client.proxy(this.base)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getMasterInfo() {
|
|
27
|
+
return this.proxy.get<UserModel>()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
login(username: string, password: string) {
|
|
31
|
+
return this.proxy.login.post<TLogin>({
|
|
32
|
+
data: {
|
|
33
|
+
username,
|
|
34
|
+
password,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
checkTokenValid(token: string) {
|
|
40
|
+
return this.proxy.check_logged.get<{ ok: number; isGuest: boolean }>({
|
|
41
|
+
params: {
|
|
42
|
+
token: 'bearer ' + token.replace(/^Bearer\s/i, ''),
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|