Skip to content

Commit 010a1f1

Browse files
authored
feat(api): add stories (#70)
1 parent 89a8516 commit 010a1f1

File tree

6 files changed

+103
-1
lines changed

6 files changed

+103
-1
lines changed

src/api/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as personalUpdate from './personal-update'
66
import * as notifications from './notifications'
77
import * as comments from './comments'
88
import * as upload from './upload'
9+
import * as stories from './stories'
910

1011
/**
1112
* API
@@ -17,6 +18,7 @@ import * as upload from './upload'
1718
* - {@link api/notifications | `notifications`}: 通知
1819
* - {@link api/comments | `comments`}: 评论
1920
* - {@link api/upload | `upload`}: 上传
21+
* - {@link api/stories | `stories`}: 日记
2022
*/
2123
export const api = {
2224
users,
@@ -27,6 +29,7 @@ export const api = {
2729
notifications,
2830
comments,
2931
upload,
32+
stories,
3033
}
3134
/**
3235
* API 集合

src/api/stories.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { request, toResponse } from '../request'
2+
import type { Stories } from '../types/api-responses'
3+
4+
/**
5+
* 获取关注用户日记列表
6+
*/
7+
export const followingFeed = async <T = Stories.FollowingFeedResponse>() =>
8+
toResponse<T>(request.get('1.0/stories/followingFeed'))
9+
10+
/**
11+
* 获取用户的日记详情
12+
* @param username 用户名
13+
*/
14+
export const listUserStories = async <T = Stories.ListUserStoriesResponse>(
15+
username: string
16+
) =>
17+
toResponse<T>(
18+
request.get('1.0/stories/listUserStories', {
19+
searchParams: {
20+
username,
21+
},
22+
})
23+
)

src/types/api-responses.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
PostDetail,
88
Profile as ProfileEntity,
99
RecommendPost,
10+
StoryDetails,
1011
TabIcons,
1112
User,
1213
} from './entity'
@@ -179,3 +180,13 @@ export namespace RecommendFeed {
179180
}
180181
}
181182
}
183+
184+
export namespace Stories {
185+
export interface FollowingFeedResponse {
186+
data: { type: 'USER_STORY'; user: User }[]
187+
}
188+
189+
export interface ListUserStoriesResponse {
190+
data: StoryDetails[]
191+
}
192+
}

src/types/entity/other.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
UrlsInText,
88
} from './post'
99
import type { User } from './user'
10+
import type { LiteralUnion } from '../../utils/typings'
1011

1112
export type PostTypeRaw = 'ORIGINAL_POST' | 'REPOST'
1213
export type TargetType = PostTypeRaw | 'STORY'
@@ -160,3 +161,47 @@ export interface RecommendPost {
160161
createdAt: Date
161162
type: string
162163
}
164+
165+
export interface StoryPic {
166+
key: string
167+
thumbnailUrl: string
168+
smallPicUrl: string
169+
middlePicUrl: string
170+
picUrl: string
171+
format: string
172+
cropperPosX: number
173+
cropperPosY: number
174+
width: number
175+
height: number
176+
}
177+
export interface StoryVideo {
178+
duration: number
179+
height: number
180+
type: string
181+
width: number
182+
image: {
183+
format: string
184+
picUrl: string
185+
thumbnailUrl: string
186+
}
187+
}
188+
189+
export interface StoryDetails {
190+
id: string
191+
type: 'STORY'
192+
storyType: LiteralUnion<'PICTURE' | 'VIDEO'>
193+
user: User
194+
emoji?: string
195+
video?: StoryVideo
196+
thumbnailVideo?: StoryVideo
197+
status: string
198+
picture: StoryPic
199+
liked: boolean
200+
likeCount: number
201+
commentCount: number
202+
viewerCount: number
203+
createdAt: string
204+
likedUsers: []
205+
enablePictureComments: boolean
206+
isFeatured: boolean
207+
}

tests/api/stories.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { api, isSuccess, setApiConfig } from '../../src'
3+
import { config } from '../config'
4+
5+
describe('stories should work', () => {
6+
setApiConfig(config)
7+
8+
it('followingFeed should work', async () => {
9+
const result = await api.stories.followingFeed()
10+
expect(isSuccess(result)).toBe(true)
11+
})
12+
13+
it('listUserStories should work', async () => {
14+
const result = await api.stories.listUserStories(
15+
'c00cf715-b71b-464b-9dcc-d73e01878137'
16+
)
17+
expect(isSuccess(result)).toBe(true)
18+
})
19+
})

typedoc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"src/api/user-relation.ts",
99
"src/api/users.ts",
1010
"src/api/comments.ts",
11-
"src/api/upload.ts"
11+
"src/api/upload.ts",
12+
"src/api/stories.ts"
1213
],
1314
"out": "docs",
1415
"name": "Ⓙ Jike SDK",

0 commit comments

Comments
 (0)