Skip to content

Commit bd0d22f

Browse files
committed
feat(api): create post with link
1 parent 85a6d5a commit bd0d22f

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

src/api/posts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const create = <T = Posts.CreateResponse>(
1919
pictureKeys: options.pictureKeys ?? [],
2020
syncToPersonalUpdate: options.syncToPersonalUpdates ?? true,
2121
submitToTopic: options.topicId,
22+
linkInfo: options.linkInfo,
2223
},
2324
})
2425
)

src/types/entity.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { LiteralUnion } from '../utils/typings'
2+
13
/**
24
* 头像图片
35
*/
@@ -152,7 +154,7 @@ export interface School {
152154
* - `PUBLIC`: 公开
153155
* - `ALUMNI_ONLY`: 仅校友可见
154156
*/
155-
privacyType: 'PUBLIC' | 'ALUMNI_ONLY'
157+
privacyType: LiteralUnion<'PUBLIC' | 'ALUMNI_ONLY'>
156158
}
157159

158160
/**
@@ -490,42 +492,60 @@ export interface LinkInfo {
490492
export type ReadTrackInfo = Record<string, any>
491493

492494
export interface ActionItem {
493-
type: string
495+
type: LiteralUnion<'COMMENT' | 'LIKE' | 'FOLLOW'>
494496
users: SimpleUser[]
495497
usersCount: number
496498
id: string
497499
content: string
498500
pictures: any[]
499501
enablePictureComments: boolean
500-
status: string
502+
status: LiteralUnion<'NORMAL' | 'DELETED'>
501503
targetId: string
502-
targetType: string
504+
targetType: LiteralUnion<TargetType>
503505
collapsible: boolean
504506
collapsed: boolean
505507
}
506508

509+
export type TargetType = PostTypeRaw | 'STORY'
510+
507511
export interface ReferenceItem {
508512
id: string
509513
type: string
510514
content: string
511-
status: string
515+
status: LiteralUnion<'NORMAL' | 'DELETED'>
512516
targetId: string
513-
targetType: string
517+
targetType: LiteralUnion<TargetType>
514518
/** 引用图片地址 */
515519
referenceImageUrl?: string
516520
}
517521

518522
export interface Notification {
519523
id: string
520-
type: string
524+
type: LiteralUnion<
525+
| 'LIKE_STORY'
526+
| 'REPLIED_TO_STORY_COMMENT'
527+
| 'COMMENT_STORY'
528+
| 'LIKE_PERSONAL_UPDATE'
529+
| 'COMMENT_PERSONAL_UPDATE'
530+
| 'REPLIED_TO_PERSONAL_UPDATE_COMMENT'
531+
| 'LIKE_PERSONAL_UPDATE_COMMENT'
532+
| 'COMMENT_AND_REPOST'
533+
| 'USER_RESPECT'
534+
| 'MENTION'
535+
| 'USER_FOLLOWED'
536+
| 'USER_SILENT_FOLLOWED'
537+
| 'PERSONAL_UPDATE_REPOSTED'
538+
| 'LIKE_AVATAR'
539+
| 'AVATAR_GREET'
540+
>
521541
createdAt: string
522542
updatedAt: string
523543
stoppable: boolean
524544
stopped: boolean
525-
actionType: string
545+
actionType: LiteralUnion<'actionType' | 'USER_LIST'>
526546
actionItem: ActionItem
527547
linkUrl: string
528-
linkType: string
548+
linkType: LiteralUnion<PostTypeRaw>
529549
referenceItem: ReferenceItem
530550
}
531551

src/types/options.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { LiteralUnion } from '../utils/typings'
2+
13
/**
24
* @description 分页选项
35
*/
@@ -44,6 +46,16 @@ export interface CreatePostOption {
4446
* @default `undefined`
4547
*/
4648
topicId?: string
49+
50+
linkInfo?: {
51+
type: LiteralUnion<'NORMAL' | 'AUDIO'>
52+
pictureUrl: string
53+
urlsInText: []
54+
linkType: LiteralUnion<'default'>
55+
title: string
56+
linkUrl: string
57+
supplementary: boolean
58+
}
4759
}
4860

4961
/**

src/utils/typings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type LiteralUnion<T extends U, U = string> = T | (U & {})

0 commit comments

Comments
 (0)