@mx-space/api-client 0.6.2 → 0.7.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/adaptors/axios.ts +36 -0
- package/adaptors/umi-request.ts +30 -0
- package/build/index.cjs.js +34 -13
- package/build/index.cjs.js.map +1 -1
- package/build/index.cjs.min.js +1 -1
- package/build/index.cjs.min.js.map +1 -1
- package/build/index.esm.js +34 -13
- package/build/index.esm.js.map +1 -1
- package/build/index.esm.min.js +1 -1
- package/build/index.esm.min.js.map +1 -1
- package/build/index.umd.js +34 -13
- package/build/index.umd.js.map +1 -1
- package/build/index.umd.min.js +1 -1
- package/build/index.umd.min.js.map +1 -1
- package/controllers/aggregate.ts +65 -0
- package/controllers/base.ts +32 -0
- package/controllers/category.ts +107 -0
- package/controllers/comment.ts +64 -0
- package/controllers/index.ts +66 -0
- package/controllers/link.ts +21 -0
- package/controllers/note.ts +92 -0
- package/controllers/page.ts +59 -0
- package/controllers/post.ts +87 -0
- package/controllers/project.ts +20 -0
- package/controllers/recently.ts +48 -0
- package/controllers/say.ts +35 -0
- package/controllers/search.ts +101 -0
- package/controllers/snippet.ts +31 -0
- package/controllers/user.ts +46 -0
- package/core/attach-request.ts +43 -0
- package/core/client.ts +249 -0
- package/core/error.ts +10 -0
- package/core/index.ts +2 -0
- package/coverage/clover.xml +563 -0
- package/coverage/coverage-final.json +30 -0
- package/coverage/lcov-report/adaptors/axios.ts.html +193 -0
- package/coverage/lcov-report/adaptors/index.html +131 -0
- package/coverage/lcov-report/adaptors/umi-request.ts.html +175 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/controllers/aggregate.ts.html +280 -0
- package/coverage/lcov-report/controllers/base.ts.html +181 -0
- package/coverage/lcov-report/controllers/category.ts.html +406 -0
- package/coverage/lcov-report/controllers/comment.ts.html +277 -0
- package/coverage/lcov-report/controllers/index.html +326 -0
- package/coverage/lcov-report/controllers/index.ts.html +283 -0
- package/coverage/lcov-report/controllers/link.ts.html +148 -0
- package/coverage/lcov-report/controllers/note.ts.html +361 -0
- package/coverage/lcov-report/controllers/page.ts.html +262 -0
- package/coverage/lcov-report/controllers/post.ts.html +346 -0
- package/coverage/lcov-report/controllers/project.ts.html +145 -0
- package/coverage/lcov-report/controllers/recently.ts.html +229 -0
- package/coverage/lcov-report/controllers/say.ts.html +190 -0
- package/coverage/lcov-report/controllers/search.ts.html +388 -0
- package/coverage/lcov-report/controllers/snippet.ts.html +178 -0
- package/coverage/lcov-report/controllers/user.ts.html +223 -0
- package/coverage/lcov-report/core/attach-request.ts.html +214 -0
- package/coverage/lcov-report/core/client.ts.html +832 -0
- package/coverage/lcov-report/core/error.ts.html +115 -0
- package/coverage/lcov-report/core/index.html +161 -0
- package/coverage/lcov-report/core/index.ts.html +91 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +191 -0
- package/coverage/lcov-report/models/aggregate.ts.html +298 -0
- package/coverage/lcov-report/models/category.ts.html +160 -0
- package/coverage/lcov-report/models/index.html +131 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +196 -0
- package/coverage/lcov-report/utils/auto-bind.ts.html +229 -0
- package/coverage/lcov-report/utils/index.html +131 -0
- package/coverage/lcov-report/utils/index.ts.html +244 -0
- package/coverage/lcov.info +1153 -0
- package/dtos/comment.ts +9 -0
- package/esm/adaptors/axios.d.ts +1 -1
- package/esm/adaptors/axios.js +4 -17
- package/esm/adaptors/axios.js.map +1 -1
- package/esm/adaptors/umi-request.d.ts +1 -1
- package/esm/adaptors/umi-request.js.map +1 -1
- package/esm/controllers/aggregate.d.ts +9 -4
- package/esm/controllers/aggregate.js +2 -2
- package/esm/controllers/aggregate.js.map +1 -1
- package/esm/controllers/base.d.ts +2 -2
- package/esm/controllers/base.js +1 -1
- package/esm/controllers/base.js.map +1 -1
- package/esm/controllers/category.d.ts +7 -2
- package/esm/controllers/category.js +3 -3
- package/esm/controllers/category.js.map +1 -1
- package/esm/controllers/comment.d.ts +10 -5
- package/esm/controllers/comment.js +1 -1
- package/esm/controllers/comment.js.map +1 -1
- package/esm/controllers/index.js.map +1 -1
- package/esm/controllers/link.d.ts +7 -1
- package/esm/controllers/link.js +1 -1
- package/esm/controllers/link.js.map +1 -1
- package/esm/controllers/note.d.ts +10 -5
- package/esm/controllers/note.js +2 -2
- package/esm/controllers/note.js.map +1 -1
- package/esm/controllers/page.d.ts +9 -4
- package/esm/controllers/page.js +2 -2
- package/esm/controllers/page.js.map +1 -1
- package/esm/controllers/post.d.ts +10 -5
- package/esm/controllers/post.js +2 -2
- package/esm/controllers/post.js.map +1 -1
- package/esm/controllers/project.d.ts +6 -1
- package/esm/controllers/project.js +1 -1
- package/esm/controllers/project.js.map +1 -1
- package/esm/controllers/recently.d.ts +8 -2
- package/esm/controllers/recently.js +1 -1
- package/esm/controllers/recently.js.map +1 -1
- package/esm/controllers/say.d.ts +7 -2
- package/esm/controllers/say.js +1 -1
- package/esm/controllers/say.js.map +1 -1
- package/esm/controllers/search.d.ts +12 -7
- package/esm/controllers/search.js +3 -3
- package/esm/controllers/search.js.map +1 -1
- package/esm/controllers/snippet.d.ts +7 -2
- package/esm/controllers/snippet.js +1 -1
- package/esm/controllers/snippet.js.map +1 -1
- package/esm/controllers/user.d.ts +8 -2
- package/esm/controllers/user.js +1 -1
- package/esm/controllers/user.js.map +1 -1
- package/esm/core/{attachRequest.d.ts → attach-request.d.ts} +0 -0
- package/esm/core/{attachRequest.js → attach-request.js} +1 -1
- package/esm/core/attach-request.js.map +1 -0
- package/esm/core/client.d.ts +5 -24
- package/esm/core/client.js +29 -8
- package/esm/core/client.js.map +1 -1
- package/esm/core/error.js.map +1 -1
- package/esm/core/index.js.map +1 -1
- package/esm/dtos/comment.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/interfaces/adapter.d.ts +13 -0
- package/esm/interfaces/adapter.js +2 -0
- package/esm/interfaces/adapter.js.map +1 -0
- package/esm/interfaces/client.d.ts +1 -1
- package/esm/interfaces/client.js.map +1 -1
- package/esm/interfaces/controller.js.map +1 -1
- package/esm/interfaces/instance.d.ts +0 -12
- package/esm/interfaces/instance.js.map +1 -1
- package/esm/interfaces/options.js.map +1 -1
- package/esm/interfaces/params.js.map +1 -1
- package/esm/interfaces/request.js.map +1 -1
- package/esm/models/aggregate.js.map +1 -1
- package/esm/models/base.js.map +1 -1
- package/esm/models/category.js.map +1 -1
- package/esm/models/comment.js.map +1 -1
- package/esm/models/index.js.map +1 -1
- package/esm/models/link.js.map +1 -1
- package/esm/models/note.js.map +1 -1
- package/esm/models/page.js.map +1 -1
- package/esm/models/post.js.map +1 -1
- package/esm/models/project.js.map +1 -1
- package/esm/models/recently.js.map +1 -1
- package/esm/models/say.js.map +1 -1
- package/esm/models/setting.js.map +1 -1
- package/esm/models/snippet.js.map +1 -1
- package/esm/models/user.js.map +1 -1
- package/esm/utils/auto-bind.js.map +1 -1
- package/esm/utils/index.d.ts +1 -1
- package/esm/utils/index.js +2 -2
- package/esm/utils/index.js.map +1 -1
- package/index.ts +12 -0
- package/interfaces/adapter.ts +30 -0
- package/interfaces/client.ts +6 -0
- package/interfaces/controller.ts +5 -0
- package/interfaces/instance.ts +8 -0
- package/interfaces/options.ts +1 -0
- package/interfaces/params.ts +4 -0
- package/interfaces/request.ts +57 -0
- package/jest.config.js +12 -0
- package/lib/adaptors/axios.d.ts +1 -1
- package/lib/adaptors/axios.js +4 -17
- package/lib/adaptors/axios.js.map +1 -1
- package/lib/adaptors/umi-request.d.ts +1 -1
- package/lib/adaptors/umi-request.js.map +1 -1
- package/lib/controllers/aggregate.d.ts +9 -4
- package/lib/controllers/aggregate.js.map +1 -1
- package/lib/controllers/base.d.ts +2 -2
- package/lib/controllers/base.js.map +1 -1
- package/lib/controllers/category.d.ts +7 -2
- package/lib/controllers/category.js +1 -1
- package/lib/controllers/category.js.map +1 -1
- package/lib/controllers/comment.d.ts +10 -5
- package/lib/controllers/comment.js.map +1 -1
- package/lib/controllers/index.js.map +1 -1
- package/lib/controllers/link.d.ts +7 -1
- package/lib/controllers/link.js.map +1 -1
- package/lib/controllers/note.d.ts +10 -5
- package/lib/controllers/note.js +1 -1
- package/lib/controllers/note.js.map +1 -1
- package/lib/controllers/page.d.ts +9 -4
- package/lib/controllers/page.js +1 -1
- package/lib/controllers/page.js.map +1 -1
- package/lib/controllers/post.d.ts +10 -5
- package/lib/controllers/post.js +1 -1
- package/lib/controllers/post.js.map +1 -1
- package/lib/controllers/project.d.ts +6 -1
- package/lib/controllers/project.js.map +1 -1
- package/lib/controllers/recently.d.ts +8 -2
- package/lib/controllers/recently.js.map +1 -1
- package/lib/controllers/say.d.ts +7 -2
- package/lib/controllers/say.js.map +1 -1
- package/lib/controllers/search.d.ts +12 -7
- package/lib/controllers/search.js +2 -2
- package/lib/controllers/search.js.map +1 -1
- package/lib/controllers/snippet.d.ts +7 -2
- package/lib/controllers/snippet.js.map +1 -1
- package/lib/controllers/user.d.ts +8 -2
- package/lib/controllers/user.js.map +1 -1
- package/lib/core/{attachRequest.d.ts → attach-request.d.ts} +0 -0
- package/lib/core/{attachRequest.js → attach-request.js} +1 -1
- package/lib/core/attach-request.js.map +1 -0
- package/lib/core/client.d.ts +5 -24
- package/lib/core/client.js +28 -7
- package/lib/core/client.js.map +1 -1
- package/lib/core/error.js.map +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/dtos/comment.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/interfaces/adapter.d.ts +13 -0
- package/lib/interfaces/adapter.js +3 -0
- package/lib/interfaces/adapter.js.map +1 -0
- package/lib/interfaces/client.d.ts +1 -1
- package/lib/interfaces/client.js.map +1 -1
- package/lib/interfaces/controller.js.map +1 -1
- package/lib/interfaces/instance.d.ts +0 -12
- package/lib/interfaces/instance.js.map +1 -1
- package/lib/interfaces/options.js.map +1 -1
- package/lib/interfaces/params.js.map +1 -1
- package/lib/interfaces/request.js.map +1 -1
- package/lib/models/aggregate.js.map +1 -1
- package/lib/models/base.js.map +1 -1
- package/lib/models/category.js.map +1 -1
- package/lib/models/comment.js.map +1 -1
- package/lib/models/index.js.map +1 -1
- package/lib/models/link.js.map +1 -1
- package/lib/models/note.js.map +1 -1
- package/lib/models/page.js.map +1 -1
- package/lib/models/post.js.map +1 -1
- package/lib/models/project.js.map +1 -1
- package/lib/models/recently.js.map +1 -1
- package/lib/models/say.js.map +1 -1
- package/lib/models/setting.js.map +1 -1
- package/lib/models/snippet.js.map +1 -1
- package/lib/models/user.js.map +1 -1
- package/lib/utils/auto-bind.js.map +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +2 -2
- package/lib/utils/index.js.map +1 -1
- package/models/aggregate.ts +71 -0
- package/models/base.ts +43 -0
- package/models/category.ts +25 -0
- package/models/comment.ts +37 -0
- package/models/index.ts +14 -0
- package/models/link.ts +23 -0
- package/models/note.ts +37 -0
- package/models/page.ts +20 -0
- package/models/post.ts +16 -0
- package/models/project.ts +12 -0
- package/models/recently.ts +7 -0
- package/models/say.ts +7 -0
- package/models/setting.ts +68 -0
- package/models/snippet.ts +18 -0
- package/models/user.ts +27 -0
- package/package.json +8 -42
- package/tsconfig.build.json +6 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +8 -27
- package/types/helper.d.ts +3 -0
- package/utils/auto-bind.ts +48 -0
- package/utils/index.ts +53 -0
- package/build/index.d.ts +0 -932
- package/esm/core/attachRequest.js.map +0 -1
- package/lib/core/attachRequest.js.map +0 -1
- package/readme.md +0 -84
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { SortOrder } from '~/interfaces/options'
|
|
3
|
+
import { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
4
|
+
import {
|
|
5
|
+
AggregateRoot,
|
|
6
|
+
AggregateStat,
|
|
7
|
+
AggregateTop,
|
|
8
|
+
TimelineData,
|
|
9
|
+
TimelineType,
|
|
10
|
+
} from '~/models/aggregate'
|
|
11
|
+
import { sortOrderToNumber } from '~/utils'
|
|
12
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
13
|
+
import { HTTPClient } from '../core'
|
|
14
|
+
|
|
15
|
+
declare module '../core/client' {
|
|
16
|
+
interface HTTPClient {
|
|
17
|
+
aggregate: AggregateController
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class AggregateController implements IController {
|
|
22
|
+
base = 'aggregate'
|
|
23
|
+
name = 'aggregate'
|
|
24
|
+
constructor(private client: HTTPClient) {
|
|
25
|
+
autoBind(this)
|
|
26
|
+
}
|
|
27
|
+
public get proxy(): IRequestHandler {
|
|
28
|
+
return this.client.proxy(this.base)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 获取聚合数据
|
|
33
|
+
*/
|
|
34
|
+
getAggregateData(): RequestProxyResult<AggregateRoot> {
|
|
35
|
+
return this.proxy.get<AggregateRoot>()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 获取最新发布的内容
|
|
40
|
+
*/
|
|
41
|
+
getTop(size = 5) {
|
|
42
|
+
return this.proxy.top.get<AggregateTop>({ params: { size } })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getTimeline(options?: {
|
|
46
|
+
sort?: SortOrder
|
|
47
|
+
type?: TimelineType
|
|
48
|
+
year?: number
|
|
49
|
+
}) {
|
|
50
|
+
const { sort, type, year } = options || {}
|
|
51
|
+
return this.proxy.timeline.get<{ data: TimelineData }>({
|
|
52
|
+
params: {
|
|
53
|
+
sort: sort && sortOrderToNumber(sort),
|
|
54
|
+
type,
|
|
55
|
+
year,
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 获取聚合数据统计
|
|
61
|
+
*/
|
|
62
|
+
getStat() {
|
|
63
|
+
return this.proxy.stat.get<AggregateStat>()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
2
|
+
import { PaginateResult } from '~/models/base'
|
|
3
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
4
|
+
import { HTTPClient } from '../core'
|
|
5
|
+
|
|
6
|
+
export abstract class BaseCrudController<T> {
|
|
7
|
+
base!: string
|
|
8
|
+
constructor(protected client: HTTPClient) {
|
|
9
|
+
autoBind(this)
|
|
10
|
+
}
|
|
11
|
+
public get proxy(): IRequestHandler {
|
|
12
|
+
return this.client.proxy(this.base)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getById(id: string): RequestProxyResult<T> {
|
|
16
|
+
return this.proxy(id).get<T>()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getAll() {
|
|
20
|
+
return this.proxy.all.get<{ data: T[] }>()
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 带分页的查询
|
|
24
|
+
* @param page
|
|
25
|
+
* @param perPage
|
|
26
|
+
*/
|
|
27
|
+
getAllPaginated(page?: number, perPage?: number) {
|
|
28
|
+
return this.proxy.get<PaginateResult<T>>({
|
|
29
|
+
params: { page, size: perPage },
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { IController } from '~/interfaces/controller'
|
|
2
|
+
import { RequestProxyResult, ResponseProxyExtraRaw } from '~/interfaces/request'
|
|
3
|
+
import { attachRawFromOneToAnthor, destructureData } from '~/utils'
|
|
4
|
+
import { autoBind } from '~/utils/auto-bind'
|
|
5
|
+
import { HTTPClient } from '../core/client'
|
|
6
|
+
import { RequestError } from '../core/error'
|
|
7
|
+
import {
|
|
8
|
+
CategoryEntries,
|
|
9
|
+
CategoryModel,
|
|
10
|
+
CategoryType,
|
|
11
|
+
CategoryWithChildrenModel,
|
|
12
|
+
TagModel,
|
|
13
|
+
} from '../models/category'
|
|
14
|
+
import { PostModel } from '../models/post'
|
|
15
|
+
|
|
16
|
+
declare module '../core/client' {
|
|
17
|
+
interface HTTPClient {
|
|
18
|
+
category: CategoryController
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class CategoryController implements IController {
|
|
23
|
+
name = 'category'
|
|
24
|
+
base = 'categories'
|
|
25
|
+
constructor(private client: HTTPClient) {
|
|
26
|
+
autoBind(this)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public get proxy() {
|
|
30
|
+
return this.client.proxy(this.base)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getAllCategories(): RequestProxyResult<{ data: CategoryModel[] }> {
|
|
34
|
+
return this.proxy.get({
|
|
35
|
+
params: {
|
|
36
|
+
type: CategoryType.Category,
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getAllTags(): RequestProxyResult<{ data: TagModel[] }> {
|
|
42
|
+
return this.proxy.get<{ data: TagModel[] }>({
|
|
43
|
+
params: {
|
|
44
|
+
type: CategoryType.Tag,
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async getCategoryDetail(
|
|
50
|
+
id: string,
|
|
51
|
+
): Promise<ResponseProxyExtraRaw<CategoryWithChildrenModel>>
|
|
52
|
+
async getCategoryDetail(
|
|
53
|
+
ids: string[],
|
|
54
|
+
): Promise<ResponseProxyExtraRaw<Map<string, CategoryWithChildrenModel>>>
|
|
55
|
+
async getCategoryDetail(ids: string | string[]): Promise<any> {
|
|
56
|
+
if (typeof ids === 'string') {
|
|
57
|
+
const data = await this.proxy.get<CategoryEntries>({
|
|
58
|
+
params: {
|
|
59
|
+
ids: ids,
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
const result = Object.values(data.entries)[0]
|
|
63
|
+
attachRawFromOneToAnthor(data, result)
|
|
64
|
+
return result
|
|
65
|
+
} else if (Array.isArray(ids)) {
|
|
66
|
+
const data = await this.proxy.get<CategoryEntries>({
|
|
67
|
+
params: {
|
|
68
|
+
ids: ids.join(','),
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
const entries = data?.entries
|
|
72
|
+
if (!entries) {
|
|
73
|
+
throw new RequestError(
|
|
74
|
+
'data structure error',
|
|
75
|
+
500,
|
|
76
|
+
data.$request.path,
|
|
77
|
+
data,
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const map = new Map<string, CategoryWithChildrenModel>(
|
|
82
|
+
Object.entries(entries).map(([id, value]) => [id.toLowerCase(), value]),
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
attachRawFromOneToAnthor(data, map)
|
|
86
|
+
return map
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async getCategoryByIdOrSlug(idOrSlug: string) {
|
|
91
|
+
const res = await this.proxy(idOrSlug).get<CategoryWithChildrenModel>()
|
|
92
|
+
return destructureData(res) as typeof res
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async getTagByName(name: string) {
|
|
96
|
+
const res = await this.proxy(name).get<{
|
|
97
|
+
tag: string
|
|
98
|
+
data: Pick<PostModel, 'id' | 'title' | 'slug' | 'category' | 'created'>[]
|
|
99
|
+
}>({
|
|
100
|
+
params: {
|
|
101
|
+
tag: 1,
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
return res
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -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
|
+
}
|