Skip to content

Commit c07bb13

Browse files
committed
fix: post feeds
1 parent f5136c0 commit c07bb13

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/command/post/feed.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createCommand } from 'commander'
2-
import { limit } from 'jike-sdk'
2+
import { ApiOptions, limit } from 'jike-sdk'
33
import { logger } from '@poppinss/cliui'
44
import {
55
createClient,
@@ -9,7 +9,7 @@ import {
99
} from '../../utils/user'
1010
import { displayImage, printIfRaw, renderDivider } from '../../utils/terminal'
1111
import { isMacOS } from '../../utils/os'
12-
import type { Entity } from 'jike-sdk'
12+
import type { Entity, JikePostWithDetail } from 'jike-sdk'
1313

1414
interface FeedOptions {
1515
count?: number
@@ -43,7 +43,9 @@ const viewFeeds = async (opts: FeedOptions) => {
4343
process.stdout.write(`${texts.join('\n')}\n`)
4444
}
4545

46-
async function renderPost(p: Entity.FollowingUpdate) {
46+
async function renderPost(
47+
p: JikePostWithDetail | ({ actionTime: string } & Entity.PersonalUpdate)
48+
) {
4749
const texts: string[] = []
4850
if (p.type === 'PERSONAL_UPDATE') {
4951
switch (p.action) {
@@ -65,37 +67,37 @@ async function renderPost(p: Entity.FollowingUpdate) {
6567
default:
6668
texts.push(`unsupported action: ${p.action}`)
6769
}
68-
} else if (p.type === 'ORIGINAL_POST') {
70+
} else if (p.type === ApiOptions.PostType.ORIGINAL) {
71+
const detail = p.detail
6972
const link = isMacOS
7073
? logger.colors.gray(
7174
logger.colors.underline(`jike://page.jk/originalPost/${p.id}`)
7275
)
7376
: ''
7477
texts.push(
75-
(await displayImage(p.user.avatarImage.thumbnailUrl, 3)).result,
76-
`${displayUser(p.user)}${
77-
p.topic ? ` [${p.topic.content}]` : ''
78+
(await displayImage(detail.user.avatarImage.thumbnailUrl, 3)).result,
79+
`${displayUser(detail.user)}${
80+
detail.topic ? ` [${detail.topic.content}]` : ''
7881
}: ${link}`,
79-
p.content
82+
detail.content
8083
)
81-
if (p.pictures && p.pictures.length > 0) {
84+
if (detail.pictures && detail.pictures.length > 0) {
8285
const images = await Promise.all(
83-
p.pictures.map((p) =>
86+
(detail.pictures as Entity.Picture[]).map((p) =>
8487
displayImage(p.middlePicUrl).then(({ result }) => `${result}\n`)
8588
)
8689
)
8790
texts.push(...images)
8891
}
89-
if (p.linkInfo) {
92+
if (detail.linkInfo) {
9093
texts.push(
91-
(await displayImage(p.linkInfo.pictureUrl)).result,
92-
`分享链接 [${p.linkInfo.title}](${logger.colors.blue(
93-
logger.colors.underline(p.linkInfo.linkUrl)
94+
(await displayImage(detail.linkInfo.pictureUrl)).result,
95+
`分享链接 [${detail.linkInfo.title}](${logger.colors.blue(
96+
logger.colors.underline(detail.linkInfo.linkUrl)
9497
)})`
9598
)
9699
}
97100
} else {
98-
// @ts-expect-error
99101
texts.push(`UNSUPPORTED: ${p.type}`)
100102
}
101103

0 commit comments

Comments
 (0)