@mx-space/api-client 1.19.0 → 1.19.1
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/package.json +5 -2
- package/controllers/ack.ts +0 -42
- package/controllers/activity.ts +0 -108
- package/controllers/aggregate.ts +0 -75
- package/controllers/ai.ts +0 -70
- package/controllers/base.ts +0 -36
- package/controllers/category.ts +0 -118
- package/controllers/comment.ts +0 -71
- package/controllers/index.ts +0 -97
- package/controllers/link.ts +0 -46
- package/controllers/note.ts +0 -128
- package/controllers/page.ts +0 -64
- package/controllers/post.ts +0 -93
- package/controllers/project.ts +0 -27
- package/controllers/recently.ts +0 -82
- package/controllers/say.ts +0 -40
- package/controllers/search.ts +0 -108
- package/controllers/severless.ts +0 -31
- package/controllers/snippet.ts +0 -35
- package/controllers/subscribe.ts +0 -58
- package/controllers/topic.ts +0 -37
- package/controllers/user.ts +0 -61
- package/dtos/comment.ts +0 -12
- package/dtos/index.ts +0 -1
- package/index.ts +0 -12
- package/interfaces/adapter.ts +0 -36
- package/interfaces/client.ts +0 -20
- package/interfaces/controller.ts +0 -5
- package/interfaces/instance.ts +0 -8
- package/interfaces/options.ts +0 -1
- package/interfaces/params.ts +0 -4
- package/interfaces/request.ts +0 -87
- package/interfaces/types.ts +0 -3
- package/mod-dts.mjs +0 -21
- package/models/activity.ts +0 -133
- package/models/aggregate.ts +0 -97
- package/models/ai.ts +0 -17
- package/models/auth.ts +0 -9
- package/models/base.ts +0 -48
- package/models/category.ts +0 -25
- package/models/comment.ts +0 -44
- package/models/index.ts +0 -20
- package/models/link.ts +0 -25
- package/models/note.ts +0 -41
- package/models/page.ts +0 -20
- package/models/post.ts +0 -28
- package/models/project.ts +0 -12
- package/models/reader.ts +0 -9
- package/models/recently.ts +0 -24
- package/models/say.ts +0 -7
- package/models/setting.ts +0 -73
- package/models/snippet.ts +0 -19
- package/models/subscribe.ts +0 -5
- package/models/topic.ts +0 -9
- package/models/user.ts +0 -27
- package/test.d.ts +0 -3
- package/tsconfig.json +0 -37
- package/tsdown.config.ts +0 -18
- package/vitest.config.ts +0 -13
package/controllers/note.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
4
|
-
import type { SelectFields } from '~/interfaces/types'
|
|
5
|
-
import type { PaginateResult } from '~/models/base'
|
|
6
|
-
import type {
|
|
7
|
-
NoteModel,
|
|
8
|
-
NoteWrappedPayload,
|
|
9
|
-
NoteWrappedWithLikedPayload,
|
|
10
|
-
} from '~/models/note'
|
|
11
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
12
|
-
import type { HTTPClient } from '../core/client'
|
|
13
|
-
import type { SortOptions } from './base'
|
|
14
|
-
|
|
15
|
-
declare module '../core/client' {
|
|
16
|
-
interface HTTPClient<
|
|
17
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
18
|
-
ResponseWrapper = unknown,
|
|
19
|
-
> {
|
|
20
|
-
note: NoteController<ResponseWrapper>
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type NoteListOptions = {
|
|
25
|
-
select?: SelectFields<keyof NoteModel>
|
|
26
|
-
year?: number
|
|
27
|
-
sortBy?: 'weather' | 'mood' | 'title' | 'created' | 'modified'
|
|
28
|
-
sortOrder?: 1 | -1
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class NoteController<ResponseWrapper> implements IController {
|
|
32
|
-
base = 'notes'
|
|
33
|
-
name = 'note'
|
|
34
|
-
|
|
35
|
-
constructor(private client: HTTPClient) {
|
|
36
|
-
autoBind(this)
|
|
37
|
-
}
|
|
38
|
-
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
39
|
-
return this.client.proxy(this.base)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 最新日记
|
|
44
|
-
*/
|
|
45
|
-
getLatest() {
|
|
46
|
-
return this.proxy.latest.get<NoteWrappedWithLikedPayload>()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 获取一篇日记,根据 Id 查询需要鉴权
|
|
51
|
-
* @param id id | nid
|
|
52
|
-
* @param password 访问密码
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
|
-
getNoteById(
|
|
56
|
-
id: string,
|
|
57
|
-
): Promise<RequestProxyResult<NoteModel, ResponseWrapper>>
|
|
58
|
-
getNoteById(id: number): Promise<NoteWrappedPayload>
|
|
59
|
-
getNoteById(id: number, password: string): Promise<NoteWrappedPayload>
|
|
60
|
-
getNoteById(
|
|
61
|
-
id: number,
|
|
62
|
-
password: undefined,
|
|
63
|
-
singleResult: true,
|
|
64
|
-
): Promise<RequestProxyResult<NoteModel, ResponseWrapper>>
|
|
65
|
-
getNoteById(
|
|
66
|
-
id: number,
|
|
67
|
-
password: string,
|
|
68
|
-
singleResult: true,
|
|
69
|
-
): Promise<RequestProxyResult<NoteModel, ResponseWrapper>>
|
|
70
|
-
getNoteById(...rest: any[]): any {
|
|
71
|
-
const [id, password = undefined, singleResult = false] = rest
|
|
72
|
-
|
|
73
|
-
if (typeof id === 'number') {
|
|
74
|
-
return this.proxy.nid(id.toString()).get<NoteWrappedWithLikedPayload>({
|
|
75
|
-
params: { password, single: singleResult ? '1' : undefined },
|
|
76
|
-
})
|
|
77
|
-
} else {
|
|
78
|
-
return this.proxy(id).get<NoteModel>()
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 日记列表分页
|
|
84
|
-
*/
|
|
85
|
-
|
|
86
|
-
getList(page = 1, perPage = 10, options: NoteListOptions = {}) {
|
|
87
|
-
const { select, sortBy, sortOrder, year } = options
|
|
88
|
-
return this.proxy.get<PaginateResult<NoteModel>>({
|
|
89
|
-
params: {
|
|
90
|
-
page,
|
|
91
|
-
size: perPage,
|
|
92
|
-
select: select?.join(' '),
|
|
93
|
-
sortBy,
|
|
94
|
-
sortOrder,
|
|
95
|
-
year,
|
|
96
|
-
},
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 获取当前日记的上下各 n / 2 篇日记
|
|
102
|
-
*/
|
|
103
|
-
getMiddleList(id: string, size = 5) {
|
|
104
|
-
return this.proxy.list(id).get<{
|
|
105
|
-
data: Pick<
|
|
106
|
-
NoteModel,
|
|
107
|
-
'id' | 'title' | 'nid' | 'created' | 'isPublished'
|
|
108
|
-
>[]
|
|
109
|
-
size: number
|
|
110
|
-
}>({
|
|
111
|
-
params: { size },
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* 获取专栏内的所有日记
|
|
117
|
-
*/
|
|
118
|
-
getNoteByTopicId(
|
|
119
|
-
topicId: string,
|
|
120
|
-
page = 1,
|
|
121
|
-
size = 10,
|
|
122
|
-
sortOptions: SortOptions = {},
|
|
123
|
-
) {
|
|
124
|
-
return this.proxy.topics(topicId).get<PaginateResult<NoteModel>>({
|
|
125
|
-
params: { page, size, ...sortOptions },
|
|
126
|
-
})
|
|
127
|
-
}
|
|
128
|
-
}
|
package/controllers/page.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { IRequestHandler } from '~/interfaces/request'
|
|
4
|
-
import type { SelectFields } from '~/interfaces/types'
|
|
5
|
-
import type { PaginateResult } from '~/models/base'
|
|
6
|
-
import type { PageModel } from '~/models/page'
|
|
7
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
8
|
-
import type { HTTPClient } from '../core'
|
|
9
|
-
|
|
10
|
-
declare module '../core/client' {
|
|
11
|
-
interface HTTPClient<
|
|
12
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
13
|
-
ResponseWrapper = unknown,
|
|
14
|
-
> {
|
|
15
|
-
page: PageController<ResponseWrapper>
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type PageListOptions = {
|
|
20
|
-
select?: SelectFields<keyof PageModel>
|
|
21
|
-
sortBy?: 'order' | 'subtitle' | 'title' | 'created' | 'modified'
|
|
22
|
-
sortOrder?: 1 | -1
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class PageController<ResponseWrapper> implements IController {
|
|
26
|
-
constructor(private readonly client: HTTPClient) {
|
|
27
|
-
autoBind(this)
|
|
28
|
-
}
|
|
29
|
-
base = 'pages'
|
|
30
|
-
name = 'page'
|
|
31
|
-
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
32
|
-
return this.client.proxy(this.base)
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* 页面列表
|
|
36
|
-
*/
|
|
37
|
-
getList(page = 1, perPage = 10, options: PageListOptions = {}) {
|
|
38
|
-
const { select, sortBy, sortOrder } = options
|
|
39
|
-
return this.proxy.get<PaginateResult<PageModel>>({
|
|
40
|
-
params: {
|
|
41
|
-
page,
|
|
42
|
-
size: perPage,
|
|
43
|
-
select: select?.join(' '),
|
|
44
|
-
sortBy,
|
|
45
|
-
sortOrder,
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 页面详情
|
|
52
|
-
*/
|
|
53
|
-
getById(id: string) {
|
|
54
|
-
return this.proxy(id).get<PageModel>()
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 根据路径获取页面
|
|
58
|
-
* @param slug 路径
|
|
59
|
-
* @returns
|
|
60
|
-
*/
|
|
61
|
-
getBySlug(slug: string) {
|
|
62
|
-
return this.proxy.slug(slug).get<PageModel>({})
|
|
63
|
-
}
|
|
64
|
-
}
|
package/controllers/post.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
4
|
-
import type { SelectFields } from '~/interfaces/types'
|
|
5
|
-
import type { ModelWithLiked, PaginateResult } from '~/models/base'
|
|
6
|
-
import type { PostModel } from '~/models/post'
|
|
7
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
8
|
-
import type { HTTPClient } from '../core/client'
|
|
9
|
-
|
|
10
|
-
declare module '../core/client' {
|
|
11
|
-
interface HTTPClient<
|
|
12
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
13
|
-
ResponseWrapper = unknown,
|
|
14
|
-
> {
|
|
15
|
-
post: PostController<ResponseWrapper>
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type PostListOptions = {
|
|
20
|
-
select?: SelectFields<keyof PostModel>
|
|
21
|
-
year?: number
|
|
22
|
-
sortBy?: 'categoryId' | 'title' | 'created' | 'modified'
|
|
23
|
-
sortOrder?: 1 | -1
|
|
24
|
-
truncate?: number
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class PostController<ResponseWrapper> implements IController {
|
|
28
|
-
constructor(private client: HTTPClient) {
|
|
29
|
-
autoBind(this)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
base = 'posts'
|
|
33
|
-
|
|
34
|
-
name = 'post'
|
|
35
|
-
|
|
36
|
-
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
37
|
-
return this.client.proxy(this.base)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 获取文章列表分页
|
|
42
|
-
* @param page
|
|
43
|
-
* @param perPage
|
|
44
|
-
* @returns
|
|
45
|
-
*/
|
|
46
|
-
getList(page = 1, perPage = 10, options: PostListOptions = {}) {
|
|
47
|
-
const { select, sortBy, sortOrder, year, truncate } = options
|
|
48
|
-
return this.proxy.get<PaginateResult<PostModel>>({
|
|
49
|
-
params: {
|
|
50
|
-
page,
|
|
51
|
-
size: perPage,
|
|
52
|
-
select: select?.join(' '),
|
|
53
|
-
sortBy,
|
|
54
|
-
sortOrder,
|
|
55
|
-
year,
|
|
56
|
-
truncate,
|
|
57
|
-
},
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 根据分类和路径查找文章
|
|
63
|
-
* @param categoryName
|
|
64
|
-
* @param slug
|
|
65
|
-
*/
|
|
66
|
-
getPost(
|
|
67
|
-
categoryName: string,
|
|
68
|
-
slug: string,
|
|
69
|
-
): RequestProxyResult<ModelWithLiked<PostModel>, ResponseWrapper>
|
|
70
|
-
/**
|
|
71
|
-
* 根据 ID 查找文章
|
|
72
|
-
* @param id
|
|
73
|
-
*/
|
|
74
|
-
getPost(id: string): RequestProxyResult<PostModel, ResponseWrapper>
|
|
75
|
-
getPost(idOrCategoryName: string, slug?: string): any {
|
|
76
|
-
if (arguments.length == 1) {
|
|
77
|
-
return this.proxy(idOrCategoryName).get<PostModel>()
|
|
78
|
-
} else {
|
|
79
|
-
return this.proxy(idOrCategoryName)(slug).get<PostModel>()
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 获取最新的文章
|
|
85
|
-
*/
|
|
86
|
-
getLatest() {
|
|
87
|
-
return this.proxy.latest.get<ModelWithLiked<PostModel>>()
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
getFullUrl(slug: string) {
|
|
91
|
-
return this.proxy('get-url')(slug).get<{ path: string }>()
|
|
92
|
-
}
|
|
93
|
-
}
|
package/controllers/project.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { ProjectModel } from '~/models/project'
|
|
3
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
4
|
-
import type { HTTPClient } from '../core'
|
|
5
|
-
import { BaseCrudController } from './base'
|
|
6
|
-
|
|
7
|
-
declare module '../core/client' {
|
|
8
|
-
interface HTTPClient<
|
|
9
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
10
|
-
ResponseWrapper = unknown,
|
|
11
|
-
> {
|
|
12
|
-
project: ProjectController<ResponseWrapper>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class ProjectController<ResponseWrapper> extends BaseCrudController<
|
|
17
|
-
ProjectModel,
|
|
18
|
-
ResponseWrapper
|
|
19
|
-
> {
|
|
20
|
-
constructor(protected readonly client: HTTPClient) {
|
|
21
|
-
super(client)
|
|
22
|
-
autoBind(this)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
base = 'projects'
|
|
26
|
-
name = 'project'
|
|
27
|
-
}
|
package/controllers/recently.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { IRequestHandler } from '~/interfaces/request'
|
|
4
|
-
import type { RecentlyModel } from '~/models/recently'
|
|
5
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
6
|
-
import type { HTTPClient } from '../core'
|
|
7
|
-
|
|
8
|
-
declare module '../core/client' {
|
|
9
|
-
interface HTTPClient<
|
|
10
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
11
|
-
ResponseWrapper = unknown,
|
|
12
|
-
> {
|
|
13
|
-
recently: RecentlyController<ResponseWrapper>
|
|
14
|
-
shorthand: RecentlyController<ResponseWrapper>
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export enum RecentlyAttitudeResultEnum {
|
|
19
|
-
Inc = 1,
|
|
20
|
-
Dec = -1,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export enum RecentlyAttitudeEnum {
|
|
24
|
-
Up,
|
|
25
|
-
Down,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class RecentlyController<ResponseWrapper> implements IController {
|
|
29
|
-
base = 'recently'
|
|
30
|
-
name = ['recently', 'shorthand']
|
|
31
|
-
|
|
32
|
-
constructor(private readonly client: HTTPClient) {
|
|
33
|
-
autoBind(this)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
37
|
-
return this.client.proxy(this.base)
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 获取最新一条
|
|
41
|
-
*/
|
|
42
|
-
getLatestOne() {
|
|
43
|
-
return this.proxy.latest.get<RecentlyModel & { comments: number }>()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
getAll() {
|
|
47
|
-
return this.proxy.all.get<{
|
|
48
|
-
data: RecentlyModel[] & { comments: number }
|
|
49
|
-
}>()
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getList({
|
|
53
|
-
before,
|
|
54
|
-
after,
|
|
55
|
-
size,
|
|
56
|
-
}: {
|
|
57
|
-
before?: string | undefined
|
|
58
|
-
after?: string | undefined
|
|
59
|
-
size?: number | number
|
|
60
|
-
} = {}) {
|
|
61
|
-
return this.proxy.get<{ data: RecentlyModel[] & { comments: number } }>({
|
|
62
|
-
params: {
|
|
63
|
-
before,
|
|
64
|
-
after,
|
|
65
|
-
size,
|
|
66
|
-
},
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
getById(id: string) {
|
|
71
|
-
return this.proxy(id).get<RecentlyModel & { comments: number }>()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** 表态:点赞,点踩 */
|
|
75
|
-
attitude(id: string, attitude: RecentlyAttitudeEnum) {
|
|
76
|
-
return this.proxy.attitude(id).get<{ code: RecentlyAttitudeResultEnum }>({
|
|
77
|
-
params: {
|
|
78
|
-
attitude,
|
|
79
|
-
},
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
}
|
package/controllers/say.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { IRequestHandler } from '~/interfaces/request'
|
|
4
|
-
import type { SayModel } from '~/models/say'
|
|
5
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
6
|
-
import type { HTTPClient } from '../core'
|
|
7
|
-
import { BaseCrudController } from './base'
|
|
8
|
-
|
|
9
|
-
declare module '../core/client' {
|
|
10
|
-
interface HTTPClient<
|
|
11
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
12
|
-
ResponseWrapper = unknown,
|
|
13
|
-
> {
|
|
14
|
-
say: SayController<ResponseWrapper>
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class SayController<ResponseWrapper>
|
|
19
|
-
extends BaseCrudController<SayModel, ResponseWrapper>
|
|
20
|
-
implements IController
|
|
21
|
-
{
|
|
22
|
-
base = 'says'
|
|
23
|
-
name = 'say'
|
|
24
|
-
|
|
25
|
-
constructor(protected client: HTTPClient) {
|
|
26
|
-
super(client)
|
|
27
|
-
autoBind(this)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
31
|
-
return this.client.proxy(this.base)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 获取随机一条
|
|
36
|
-
*/
|
|
37
|
-
getRandom() {
|
|
38
|
-
return this.proxy.random.get<{ data: SayModel | null }>()
|
|
39
|
-
}
|
|
40
|
-
}
|
package/controllers/search.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
4
|
-
import type { PaginateResult } from '~/models/base'
|
|
5
|
-
import type { NoteModel } from '~/models/note'
|
|
6
|
-
import type { PageModel } from '~/models/page'
|
|
7
|
-
import type { PostModel } from '~/models/post'
|
|
8
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
9
|
-
import type { HTTPClient } from '../core'
|
|
10
|
-
|
|
11
|
-
declare module '../core/client' {
|
|
12
|
-
interface HTTPClient<
|
|
13
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
14
|
-
ResponseWrapper = unknown,
|
|
15
|
-
> {
|
|
16
|
-
search: SearchController<ResponseWrapper>
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type SearchType = 'post' | 'note'
|
|
21
|
-
|
|
22
|
-
export type SearchOption = {
|
|
23
|
-
orderBy?: string
|
|
24
|
-
order?: number
|
|
25
|
-
rawAlgolia?: boolean
|
|
26
|
-
}
|
|
27
|
-
export class SearchController<ResponseWrapper> implements IController {
|
|
28
|
-
base = 'search'
|
|
29
|
-
name = 'search'
|
|
30
|
-
|
|
31
|
-
constructor(private readonly client: HTTPClient) {
|
|
32
|
-
autoBind(this)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
36
|
-
return this.client.proxy(this.base)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
search(
|
|
40
|
-
type: 'note',
|
|
41
|
-
keyword: string,
|
|
42
|
-
options?: Omit<SearchOption, 'rawAlgolia'>,
|
|
43
|
-
): Promise<
|
|
44
|
-
RequestProxyResult<
|
|
45
|
-
PaginateResult<
|
|
46
|
-
Pick<NoteModel, 'modified' | 'id' | 'title' | 'created' | 'nid'>
|
|
47
|
-
>,
|
|
48
|
-
ResponseWrapper
|
|
49
|
-
>
|
|
50
|
-
>
|
|
51
|
-
search(
|
|
52
|
-
type: 'post',
|
|
53
|
-
keyword: string,
|
|
54
|
-
options?: Omit<SearchOption, 'rawAlgolia'>,
|
|
55
|
-
): Promise<
|
|
56
|
-
RequestProxyResult<
|
|
57
|
-
PaginateResult<
|
|
58
|
-
Pick<
|
|
59
|
-
PostModel,
|
|
60
|
-
'modified' | 'id' | 'title' | 'created' | 'slug' | 'category'
|
|
61
|
-
>
|
|
62
|
-
>,
|
|
63
|
-
ResponseWrapper
|
|
64
|
-
>
|
|
65
|
-
>
|
|
66
|
-
search(
|
|
67
|
-
type: SearchType,
|
|
68
|
-
keyword: string,
|
|
69
|
-
options: Omit<SearchOption, 'rawAlgolia'> = {},
|
|
70
|
-
): any {
|
|
71
|
-
return this.proxy(type).get({
|
|
72
|
-
params: { keyword, ...options },
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* 从 algolya 搜索
|
|
77
|
-
* https://www.algolia.com/doc/api-reference/api-methods/search/
|
|
78
|
-
* @param keyword
|
|
79
|
-
* @param options
|
|
80
|
-
* @returns
|
|
81
|
-
*/
|
|
82
|
-
searchByAlgolia(keyword: string, options?: SearchOption) {
|
|
83
|
-
return this.proxy('algolia').get<
|
|
84
|
-
RequestProxyResult<
|
|
85
|
-
PaginateResult<
|
|
86
|
-
| (Pick<
|
|
87
|
-
PostModel,
|
|
88
|
-
'modified' | 'id' | 'title' | 'created' | 'slug' | 'category'
|
|
89
|
-
> & { type: 'post' })
|
|
90
|
-
| (Pick<
|
|
91
|
-
NoteModel,
|
|
92
|
-
'id' | 'created' | 'id' | 'modified' | 'title' | 'nid'
|
|
93
|
-
> & { type: 'note' })
|
|
94
|
-
| (Pick<
|
|
95
|
-
PageModel,
|
|
96
|
-
'id' | 'title' | 'created' | 'modified' | 'slug'
|
|
97
|
-
> & { type: 'page' })
|
|
98
|
-
> & {
|
|
99
|
-
/**
|
|
100
|
-
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
101
|
-
*/
|
|
102
|
-
raw?: any
|
|
103
|
-
},
|
|
104
|
-
ResponseWrapper
|
|
105
|
-
>
|
|
106
|
-
>({ params: { keyword, ...options } })
|
|
107
|
-
}
|
|
108
|
-
}
|
package/controllers/severless.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { IRequestHandler } from '~/interfaces/request'
|
|
4
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
5
|
-
import type { HTTPClient } from '../core'
|
|
6
|
-
|
|
7
|
-
declare module '../core/client' {
|
|
8
|
-
interface HTTPClient<
|
|
9
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
10
|
-
ResponseWrapper = unknown,
|
|
11
|
-
> {
|
|
12
|
-
serverless: ServerlessController<ResponseWrapper>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class ServerlessController<ResponseWrapper> implements IController {
|
|
17
|
-
base = 'serverless'
|
|
18
|
-
name = 'serverless'
|
|
19
|
-
|
|
20
|
-
constructor(protected client: HTTPClient) {
|
|
21
|
-
autoBind(this)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
25
|
-
return this.client.proxy(this.base)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getByReferenceAndName<T = unknown>(reference: string, name: string) {
|
|
29
|
-
return this.proxy(reference)(name).get<T>()
|
|
30
|
-
}
|
|
31
|
-
}
|
package/controllers/snippet.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { IRequestHandler } from '~/interfaces/request'
|
|
4
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
5
|
-
import type { HTTPClient } from '../core'
|
|
6
|
-
|
|
7
|
-
declare module '../core/client' {
|
|
8
|
-
interface HTTPClient<
|
|
9
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
10
|
-
ResponseWrapper = unknown,
|
|
11
|
-
> {
|
|
12
|
-
snippet: SnippetController<ResponseWrapper>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class SnippetController<ResponseWrapper> implements IController {
|
|
17
|
-
base = 'snippets'
|
|
18
|
-
name = 'snippet'
|
|
19
|
-
|
|
20
|
-
constructor(protected client: HTTPClient) {
|
|
21
|
-
autoBind(this)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
25
|
-
return this.client.proxy(this.base)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// getById(id: string) {
|
|
29
|
-
// return this.proxy(id).get<Omit<SnippetModel, 'data'>>()
|
|
30
|
-
// }
|
|
31
|
-
|
|
32
|
-
getByReferenceAndName<T = unknown>(reference: string, name: string) {
|
|
33
|
-
return this.proxy(reference)(name).get<T>()
|
|
34
|
-
}
|
|
35
|
-
}
|
package/controllers/subscribe.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { IRequestHandler } from '~/interfaces/request'
|
|
4
|
-
import type { SubscribeType } from '~/models/subscribe'
|
|
5
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
6
|
-
import type { HTTPClient } from '../core'
|
|
7
|
-
|
|
8
|
-
declare module '../core/client' {
|
|
9
|
-
interface HTTPClient<
|
|
10
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
11
|
-
ResponseWrapper = unknown,
|
|
12
|
-
> {
|
|
13
|
-
subscribe: SubscribeController<ResponseWrapper>
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class SubscribeController<ResponseWrapper> implements IController {
|
|
18
|
-
base = 'subscribe'
|
|
19
|
-
name = 'subscribe'
|
|
20
|
-
|
|
21
|
-
constructor(protected client: HTTPClient) {
|
|
22
|
-
autoBind(this)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
26
|
-
return this.client.proxy(this.base)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 检查开启状态
|
|
31
|
-
*/
|
|
32
|
-
check() {
|
|
33
|
-
return this.proxy.status.get<{
|
|
34
|
-
enable: boolean
|
|
35
|
-
bitMap: Record<SubscribeType, number>
|
|
36
|
-
allowBits: number[]
|
|
37
|
-
allowTypes: SubscribeType[]
|
|
38
|
-
}>()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
subscribe(email: string, types: SubscribeType[]) {
|
|
42
|
-
return this.proxy.post<never>({
|
|
43
|
-
data: {
|
|
44
|
-
email,
|
|
45
|
-
types,
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
unsubscribe(email: string, cancelToken: string) {
|
|
51
|
-
return this.proxy.unsubscribe.get<string>({
|
|
52
|
-
params: {
|
|
53
|
-
email,
|
|
54
|
-
cancelToken,
|
|
55
|
-
},
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
}
|