@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mx-space/api-client",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.1",
|
|
4
4
|
"description": "A api client for mx-space server@next",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
},
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"author": "Innei",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
11
14
|
"main": "dist/index.cjs",
|
|
12
15
|
"module": "dist/index.js",
|
|
13
|
-
"types": "dist/index.d.
|
|
16
|
+
"types": "dist/index.d.mts",
|
|
14
17
|
"exports": {
|
|
15
18
|
".": {
|
|
16
19
|
"types": "./dist/index.d.mts",
|
package/controllers/ack.ts
DELETED
|
@@ -1,42 +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
|
-
ack: AckController<ResponseWrapper>
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @support core >= 4.4.0
|
|
18
|
-
*/
|
|
19
|
-
export class AckController<ResponseWrapper> implements IController {
|
|
20
|
-
base = 'ack'
|
|
21
|
-
name = 'ack'
|
|
22
|
-
|
|
23
|
-
constructor(private client: HTTPClient) {
|
|
24
|
-
autoBind(this)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
28
|
-
return this.client.proxy(this.base)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
read(type: 'post' | 'note', id: string) {
|
|
32
|
-
return this.proxy.post<never>({
|
|
33
|
-
data: {
|
|
34
|
-
type: 'read',
|
|
35
|
-
payload: {
|
|
36
|
-
type,
|
|
37
|
-
id,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
}
|
package/controllers/activity.ts
DELETED
|
@@ -1,108 +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 { AuthUser } from '~/models'
|
|
5
|
-
import type {
|
|
6
|
-
ActivityPresence,
|
|
7
|
-
LastYearPublication,
|
|
8
|
-
RecentActivities,
|
|
9
|
-
RoomsData,
|
|
10
|
-
} from '~/models/activity'
|
|
11
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
12
|
-
import type { HTTPClient } from '../core'
|
|
13
|
-
|
|
14
|
-
declare module '../core/client' {
|
|
15
|
-
interface HTTPClient<
|
|
16
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
17
|
-
ResponseWrapper = unknown,
|
|
18
|
-
> {
|
|
19
|
-
activity: ActivityController<ResponseWrapper>
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @support core >= 4.3.0
|
|
25
|
-
*/
|
|
26
|
-
export class ActivityController<ResponseWrapper> implements IController {
|
|
27
|
-
base = 'activity'
|
|
28
|
-
name = 'activity'
|
|
29
|
-
|
|
30
|
-
constructor(private client: HTTPClient) {
|
|
31
|
-
autoBind(this)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
35
|
-
return this.client.proxy(this.base)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
likeIt(type: 'Post' | 'Note', id: string) {
|
|
39
|
-
return this.proxy.like.post<never>({
|
|
40
|
-
data: {
|
|
41
|
-
type: type.toLowerCase(),
|
|
42
|
-
id,
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @support core >= 5.0.0
|
|
50
|
-
*/
|
|
51
|
-
getPresence(roomName: string) {
|
|
52
|
-
return this.proxy.presence.get<{
|
|
53
|
-
data: Record<string, ActivityPresence>
|
|
54
|
-
readers: Record<string, AuthUser>
|
|
55
|
-
}>({
|
|
56
|
-
params: {
|
|
57
|
-
room_name: roomName,
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
* @support core >= 5.0.0
|
|
65
|
-
*/
|
|
66
|
-
updatePresence({
|
|
67
|
-
identity,
|
|
68
|
-
position,
|
|
69
|
-
roomName,
|
|
70
|
-
sid,
|
|
71
|
-
ts,
|
|
72
|
-
displayName,
|
|
73
|
-
readerId,
|
|
74
|
-
}: {
|
|
75
|
-
roomName: string
|
|
76
|
-
position: number
|
|
77
|
-
identity: string
|
|
78
|
-
sid: string
|
|
79
|
-
|
|
80
|
-
displayName?: string
|
|
81
|
-
ts?: number
|
|
82
|
-
readerId?: string
|
|
83
|
-
}) {
|
|
84
|
-
return this.proxy.presence.update.post({
|
|
85
|
-
data: {
|
|
86
|
-
identity,
|
|
87
|
-
position,
|
|
88
|
-
ts: ts || Date.now(),
|
|
89
|
-
roomName,
|
|
90
|
-
sid,
|
|
91
|
-
readerId,
|
|
92
|
-
displayName,
|
|
93
|
-
},
|
|
94
|
-
})
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async getRoomsInfo() {
|
|
98
|
-
return this.proxy.rooms.get<RoomsData>()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async getRecentActivities() {
|
|
102
|
-
return this.proxy.recent.get<RecentActivities>()
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async getLastYearPublication(): Promise<LastYearPublication> {
|
|
106
|
-
return this.proxy(`last-year`).publication.get<LastYearPublication>()
|
|
107
|
-
}
|
|
108
|
-
}
|
package/controllers/aggregate.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { SortOrder } from '~/interfaces/options'
|
|
4
|
-
import type { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
5
|
-
import type {
|
|
6
|
-
AggregateRootWithTheme,
|
|
7
|
-
AggregateStat,
|
|
8
|
-
AggregateTop,
|
|
9
|
-
TimelineData,
|
|
10
|
-
TimelineType,
|
|
11
|
-
} from '~/models/aggregate'
|
|
12
|
-
import { sortOrderToNumber } from '~/utils'
|
|
13
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
14
|
-
import type { HTTPClient } from '../core'
|
|
15
|
-
|
|
16
|
-
declare module '../core/client' {
|
|
17
|
-
interface HTTPClient<
|
|
18
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
19
|
-
ResponseWrapper = unknown,
|
|
20
|
-
> {
|
|
21
|
-
aggregate: AggregateController<ResponseWrapper>
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class AggregateController<ResponseWrapper> implements IController {
|
|
26
|
-
base = 'aggregate'
|
|
27
|
-
name = 'aggregate'
|
|
28
|
-
constructor(private client: HTTPClient) {
|
|
29
|
-
autoBind(this)
|
|
30
|
-
}
|
|
31
|
-
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
32
|
-
return this.client.proxy(this.base)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 获取聚合数据
|
|
37
|
-
*/
|
|
38
|
-
getAggregateData<Theme>(
|
|
39
|
-
theme?: string,
|
|
40
|
-
): RequestProxyResult<AggregateRootWithTheme<Theme>, ResponseWrapper> {
|
|
41
|
-
return this.proxy.get<AggregateRootWithTheme<Theme>>({
|
|
42
|
-
params: {
|
|
43
|
-
theme,
|
|
44
|
-
},
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 获取最新发布的内容
|
|
50
|
-
*/
|
|
51
|
-
getTop(size = 5) {
|
|
52
|
-
return this.proxy.top.get<AggregateTop>({ params: { size } })
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
getTimeline(options?: {
|
|
56
|
-
sort?: SortOrder
|
|
57
|
-
type?: TimelineType
|
|
58
|
-
year?: number
|
|
59
|
-
}) {
|
|
60
|
-
const { sort, type, year } = options || {}
|
|
61
|
-
return this.proxy.timeline.get<{ data: TimelineData }>({
|
|
62
|
-
params: {
|
|
63
|
-
sort: sort && sortOrderToNumber(sort),
|
|
64
|
-
type,
|
|
65
|
-
year,
|
|
66
|
-
},
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* 获取聚合数据统计
|
|
71
|
-
*/
|
|
72
|
-
getStat() {
|
|
73
|
-
return this.proxy.stat.get<AggregateStat>()
|
|
74
|
-
}
|
|
75
|
-
}
|
package/controllers/ai.ts
DELETED
|
@@ -1,70 +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
|
-
import type { AIDeepReadingModel, AISummaryModel } from '../models/ai'
|
|
7
|
-
|
|
8
|
-
declare module '../core/client' {
|
|
9
|
-
interface HTTPClient<
|
|
10
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
11
|
-
ResponseWrapper = unknown,
|
|
12
|
-
> {
|
|
13
|
-
ai: AIController<ResponseWrapper>
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @support core >= 5.6.0
|
|
19
|
-
*/
|
|
20
|
-
export class AIController<ResponseWrapper> implements IController {
|
|
21
|
-
base = 'ai'
|
|
22
|
-
name = 'ai'
|
|
23
|
-
|
|
24
|
-
constructor(private client: HTTPClient) {
|
|
25
|
-
autoBind(this)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
29
|
-
return this.client.proxy(this.base)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
async getSummary({
|
|
33
|
-
articleId,
|
|
34
|
-
lang = 'zh-CN',
|
|
35
|
-
onlyDb,
|
|
36
|
-
}: {
|
|
37
|
-
articleId: string
|
|
38
|
-
lang?: string
|
|
39
|
-
onlyDb?: boolean
|
|
40
|
-
}) {
|
|
41
|
-
return this.proxy.summaries.article(articleId).get<AISummaryModel>({
|
|
42
|
-
params: {
|
|
43
|
-
lang,
|
|
44
|
-
onlyDb,
|
|
45
|
-
},
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async generateSummary(articleId: string, lang = 'zh-CN', token = '') {
|
|
50
|
-
return this.proxy.summaries.generate.post<AISummaryModel>({
|
|
51
|
-
params: {
|
|
52
|
-
token,
|
|
53
|
-
},
|
|
54
|
-
data: {
|
|
55
|
-
lang,
|
|
56
|
-
refId: articleId,
|
|
57
|
-
},
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Core >= 8.3.0
|
|
63
|
-
* @param articleId
|
|
64
|
-
*/
|
|
65
|
-
async getDeepReading(articleId: string) {
|
|
66
|
-
return this.proxy('deep-readings')
|
|
67
|
-
.article(articleId)
|
|
68
|
-
.get<AIDeepReadingModel>()
|
|
69
|
-
}
|
|
70
|
-
}
|
package/controllers/base.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
2
|
-
import type { PaginateResult } from '~/models/base'
|
|
3
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
4
|
-
import type { HTTPClient } from '../core'
|
|
5
|
-
|
|
6
|
-
export type SortOptions = {
|
|
7
|
-
sortBy?: string
|
|
8
|
-
sortOrder?: 1 | -1 | 'asc' | 'desc'
|
|
9
|
-
}
|
|
10
|
-
export abstract class BaseCrudController<T, ResponseWrapper> {
|
|
11
|
-
base!: string
|
|
12
|
-
constructor(protected client: HTTPClient) {
|
|
13
|
-
autoBind(this)
|
|
14
|
-
}
|
|
15
|
-
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
16
|
-
return this.client.proxy(this.base)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getById(id: string): RequestProxyResult<T, ResponseWrapper> {
|
|
20
|
-
return this.proxy(id).get<T>()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getAll() {
|
|
24
|
-
return this.proxy.all.get<{ data: T[] }>()
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 带分页的查询
|
|
28
|
-
* @param page
|
|
29
|
-
* @param perPage
|
|
30
|
-
*/
|
|
31
|
-
getAllPaginated(page?: number, perPage?: number, sortOption?: SortOptions) {
|
|
32
|
-
return this.proxy.get<PaginateResult<T>>({
|
|
33
|
-
params: { page, size: perPage, ...sortOption },
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
}
|
package/controllers/category.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type {
|
|
4
|
-
IRequestHandler,
|
|
5
|
-
RequestProxyResult,
|
|
6
|
-
ResponseProxyExtraRaw,
|
|
7
|
-
} from '~/interfaces/request'
|
|
8
|
-
import { attachRawFromOneToAnthor, destructureData } from '~/utils'
|
|
9
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
10
|
-
import type { HTTPClient } from '../core/client'
|
|
11
|
-
import { RequestError } from '../core/error'
|
|
12
|
-
import type {
|
|
13
|
-
CategoryEntries,
|
|
14
|
-
CategoryModel,
|
|
15
|
-
CategoryWithChildrenModel,
|
|
16
|
-
TagModel,
|
|
17
|
-
} from '../models/category'
|
|
18
|
-
import { CategoryType } from '../models/category'
|
|
19
|
-
import type { PostModel } from '../models/post'
|
|
20
|
-
|
|
21
|
-
declare module '../core/client' {
|
|
22
|
-
interface HTTPClient<
|
|
23
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
24
|
-
ResponseWrapper = unknown,
|
|
25
|
-
> {
|
|
26
|
-
category: CategoryController<ResponseWrapper>
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class CategoryController<ResponseWrapper> implements IController {
|
|
31
|
-
name = 'category'
|
|
32
|
-
base = 'categories'
|
|
33
|
-
constructor(private client: HTTPClient) {
|
|
34
|
-
autoBind(this)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
38
|
-
return this.client.proxy(this.base)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getAllCategories(): RequestProxyResult<
|
|
42
|
-
{ data: CategoryModel[] },
|
|
43
|
-
ResponseWrapper
|
|
44
|
-
> {
|
|
45
|
-
return this.proxy.get({
|
|
46
|
-
params: {
|
|
47
|
-
type: CategoryType.Category,
|
|
48
|
-
},
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getAllTags(): RequestProxyResult<{ data: TagModel[] }, ResponseWrapper> {
|
|
53
|
-
return this.proxy.get<{ data: TagModel[] }>({
|
|
54
|
-
params: {
|
|
55
|
-
type: CategoryType.Tag,
|
|
56
|
-
},
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async getCategoryDetail(
|
|
61
|
-
id: string,
|
|
62
|
-
): Promise<ResponseProxyExtraRaw<CategoryWithChildrenModel>>
|
|
63
|
-
async getCategoryDetail(
|
|
64
|
-
ids: string[],
|
|
65
|
-
): Promise<ResponseProxyExtraRaw<Map<string, CategoryWithChildrenModel>>>
|
|
66
|
-
async getCategoryDetail(ids: string | string[]): Promise<any> {
|
|
67
|
-
if (typeof ids === 'string') {
|
|
68
|
-
const data = await this.proxy.get<CategoryEntries>({
|
|
69
|
-
params: {
|
|
70
|
-
ids,
|
|
71
|
-
},
|
|
72
|
-
})
|
|
73
|
-
const result = Object.values(data.entries)[0]
|
|
74
|
-
attachRawFromOneToAnthor(data, result)
|
|
75
|
-
return result
|
|
76
|
-
} else if (Array.isArray(ids)) {
|
|
77
|
-
const data = await this.proxy.get<CategoryEntries>({
|
|
78
|
-
params: {
|
|
79
|
-
ids: ids.join(','),
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
const entries = data?.entries
|
|
83
|
-
if (!entries) {
|
|
84
|
-
throw new RequestError(
|
|
85
|
-
'data structure error',
|
|
86
|
-
500,
|
|
87
|
-
data.$request.path,
|
|
88
|
-
data,
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const map = new Map<string, CategoryWithChildrenModel>(
|
|
93
|
-
Object.entries(entries).map(([id, value]) => [id.toLowerCase(), value]),
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
attachRawFromOneToAnthor(data, map)
|
|
97
|
-
return map
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async getCategoryByIdOrSlug(idOrSlug: string) {
|
|
102
|
-
const res = await this.proxy(idOrSlug).get<CategoryWithChildrenModel>()
|
|
103
|
-
return destructureData(res) as typeof res
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async getTagByName(name: string) {
|
|
107
|
-
const res = await this.proxy(name).get<{
|
|
108
|
-
tag: string
|
|
109
|
-
data: Pick<PostModel, 'id' | 'title' | 'slug' | 'category' | 'created'>[]
|
|
110
|
-
}>({
|
|
111
|
-
params: {
|
|
112
|
-
tag: 1,
|
|
113
|
-
},
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
return res
|
|
117
|
-
}
|
|
118
|
-
}
|
package/controllers/comment.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { IController } from '~/interfaces/controller'
|
|
3
|
-
import type { PaginationParams } from '~/interfaces/params'
|
|
4
|
-
import type { IRequestHandler } from '~/interfaces/request'
|
|
5
|
-
import type { ReaderModel } from '~/models'
|
|
6
|
-
import type { PaginateResult } from '~/models/base'
|
|
7
|
-
import type { CommentModel } from '~/models/comment'
|
|
8
|
-
import { autoBind } from '~/utils/auto-bind'
|
|
9
|
-
import type { HTTPClient } from '../core'
|
|
10
|
-
import type { CommentDto } from '../dtos/comment'
|
|
11
|
-
|
|
12
|
-
declare module '../core/client' {
|
|
13
|
-
interface HTTPClient<
|
|
14
|
-
T extends IRequestAdapter = IRequestAdapter,
|
|
15
|
-
ResponseWrapper = unknown,
|
|
16
|
-
> {
|
|
17
|
-
comment: CommentController<ResponseWrapper>
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class CommentController<ResponseWrapper> implements IController {
|
|
22
|
-
base = 'comments'
|
|
23
|
-
name = 'comment'
|
|
24
|
-
|
|
25
|
-
constructor(private readonly client: HTTPClient) {
|
|
26
|
-
autoBind(this)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
30
|
-
return this.client.proxy(this.base)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 根据 comment id 获取评论,包括子评论
|
|
35
|
-
*/
|
|
36
|
-
getById(id: string) {
|
|
37
|
-
return this.proxy(id).get<CommentModel & { ref: string }>()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 获取文章的评论列表
|
|
42
|
-
* @param refId 文章 Id
|
|
43
|
-
*/
|
|
44
|
-
getByRefId(refId: string, pagination: PaginationParams = {}) {
|
|
45
|
-
const { page, size } = pagination
|
|
46
|
-
return this.proxy.ref(refId).get<
|
|
47
|
-
PaginateResult<CommentModel & { ref: string }> & {
|
|
48
|
-
readers: Record<string, ReaderModel>
|
|
49
|
-
}
|
|
50
|
-
>({
|
|
51
|
-
params: { page: page || 1, size: size || 10 },
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* 评论
|
|
56
|
-
*/
|
|
57
|
-
comment(refId: string, data: CommentDto) {
|
|
58
|
-
return this.proxy(refId).post<CommentModel>({
|
|
59
|
-
data,
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 回复评论
|
|
65
|
-
*/
|
|
66
|
-
reply(commentId: string, data: CommentDto) {
|
|
67
|
-
return this.proxy.reply(commentId).post<CommentModel>({
|
|
68
|
-
data,
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
}
|
package/controllers/index.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { AckController } from './ack'
|
|
2
|
-
import { ActivityController } from './activity'
|
|
3
|
-
import { AggregateController } from './aggregate'
|
|
4
|
-
import { AIController } from './ai'
|
|
5
|
-
import { CategoryController } from './category'
|
|
6
|
-
import { CommentController } from './comment'
|
|
7
|
-
import { LinkController } from './link'
|
|
8
|
-
import { NoteController } from './note'
|
|
9
|
-
import { PageController } from './page'
|
|
10
|
-
import { PostController } from './post'
|
|
11
|
-
import { ProjectController } from './project'
|
|
12
|
-
import {
|
|
13
|
-
RecentlyAttitudeEnum,
|
|
14
|
-
RecentlyAttitudeResultEnum,
|
|
15
|
-
RecentlyController,
|
|
16
|
-
} from './recently'
|
|
17
|
-
import { SayController } from './say'
|
|
18
|
-
import { SearchController } from './search'
|
|
19
|
-
import { ServerlessController } from './severless'
|
|
20
|
-
import { SnippetController } from './snippet'
|
|
21
|
-
import { SubscribeController } from './subscribe'
|
|
22
|
-
import { TopicController } from './topic'
|
|
23
|
-
import { UserController } from './user'
|
|
24
|
-
|
|
25
|
-
export const allControllers = [
|
|
26
|
-
AckController,
|
|
27
|
-
ActivityController,
|
|
28
|
-
AggregateController,
|
|
29
|
-
AIController,
|
|
30
|
-
CategoryController,
|
|
31
|
-
CommentController,
|
|
32
|
-
LinkController,
|
|
33
|
-
NoteController,
|
|
34
|
-
PageController,
|
|
35
|
-
PostController,
|
|
36
|
-
ProjectController,
|
|
37
|
-
RecentlyController,
|
|
38
|
-
SayController,
|
|
39
|
-
SearchController,
|
|
40
|
-
ServerlessController,
|
|
41
|
-
SnippetController,
|
|
42
|
-
SubscribeController,
|
|
43
|
-
TopicController,
|
|
44
|
-
UserController,
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
export const allControllerNames = [
|
|
48
|
-
'ai',
|
|
49
|
-
'ack',
|
|
50
|
-
'activity',
|
|
51
|
-
'aggregate',
|
|
52
|
-
'category',
|
|
53
|
-
'comment',
|
|
54
|
-
'link',
|
|
55
|
-
'note',
|
|
56
|
-
'page',
|
|
57
|
-
'post',
|
|
58
|
-
'project',
|
|
59
|
-
'topic',
|
|
60
|
-
'recently',
|
|
61
|
-
'say',
|
|
62
|
-
'search',
|
|
63
|
-
'snippet',
|
|
64
|
-
'serverless',
|
|
65
|
-
'subscribe',
|
|
66
|
-
'user',
|
|
67
|
-
|
|
68
|
-
// alias,
|
|
69
|
-
'friend',
|
|
70
|
-
'master',
|
|
71
|
-
'shorthand',
|
|
72
|
-
] as const
|
|
73
|
-
|
|
74
|
-
export {
|
|
75
|
-
AckController,
|
|
76
|
-
ActivityController,
|
|
77
|
-
AggregateController,
|
|
78
|
-
AIController,
|
|
79
|
-
CategoryController,
|
|
80
|
-
CommentController,
|
|
81
|
-
LinkController,
|
|
82
|
-
NoteController,
|
|
83
|
-
PageController,
|
|
84
|
-
PostController,
|
|
85
|
-
ProjectController,
|
|
86
|
-
// Enum
|
|
87
|
-
RecentlyAttitudeEnum,
|
|
88
|
-
RecentlyAttitudeResultEnum,
|
|
89
|
-
RecentlyController,
|
|
90
|
-
SayController,
|
|
91
|
-
SearchController,
|
|
92
|
-
ServerlessController,
|
|
93
|
-
SnippetController,
|
|
94
|
-
SubscribeController,
|
|
95
|
-
TopicController,
|
|
96
|
-
UserController,
|
|
97
|
-
}
|
package/controllers/link.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { IRequestAdapter } from '~/interfaces/adapter'
|
|
2
|
-
import type { LinkModel } from '~/models/link'
|
|
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
|
-
link: LinkController<ResponseWrapper>
|
|
13
|
-
friend: LinkController<ResponseWrapper>
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class LinkController<ResponseWrapper> extends BaseCrudController<
|
|
18
|
-
LinkModel,
|
|
19
|
-
ResponseWrapper
|
|
20
|
-
> {
|
|
21
|
-
constructor(protected readonly client: HTTPClient) {
|
|
22
|
-
super(client)
|
|
23
|
-
autoBind(this)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 是否可以申请友链
|
|
27
|
-
async canApplyLink() {
|
|
28
|
-
const { can } = await this.proxy.audit.get<{ can: boolean }>()
|
|
29
|
-
return can
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 申请友链
|
|
33
|
-
async applyLink(
|
|
34
|
-
data: Pick<
|
|
35
|
-
LinkModel,
|
|
36
|
-
'avatar' | 'name' | 'description' | 'url' | 'email'
|
|
37
|
-
> & {
|
|
38
|
-
author: string
|
|
39
|
-
},
|
|
40
|
-
) {
|
|
41
|
-
return await this.proxy.audit.post<never>({ data })
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
name = ['link', 'friend']
|
|
45
|
-
base = 'links'
|
|
46
|
-
}
|