1
1
import { createCommand } from 'commander'
2
- import { limit } from 'jike-sdk'
2
+ import { ApiOptions , limit } from 'jike-sdk'
3
3
import { logger } from '@poppinss/cliui'
4
4
import {
5
5
createClient ,
9
9
} from '../../utils/user'
10
10
import { displayImage , printIfRaw , renderDivider } from '../../utils/terminal'
11
11
import { isMacOS } from '../../utils/os'
12
- import type { Entity } from 'jike-sdk'
12
+ import type { Entity , JikePostWithDetail } from 'jike-sdk'
13
13
14
14
interface FeedOptions {
15
15
count ?: number
@@ -43,7 +43,9 @@ const viewFeeds = async (opts: FeedOptions) => {
43
43
process . stdout . write ( `${ texts . join ( '\n' ) } \n` )
44
44
}
45
45
46
- async function renderPost ( p : Entity . FollowingUpdate ) {
46
+ async function renderPost (
47
+ p : JikePostWithDetail | ( { actionTime : string } & Entity . PersonalUpdate )
48
+ ) {
47
49
const texts : string [ ] = [ ]
48
50
if ( p . type === 'PERSONAL_UPDATE' ) {
49
51
switch ( p . action ) {
@@ -65,37 +67,37 @@ async function renderPost(p: Entity.FollowingUpdate) {
65
67
default :
66
68
texts . push ( `unsupported action: ${ p . action } ` )
67
69
}
68
- } else if ( p . type === 'ORIGINAL_POST' ) {
70
+ } else if ( p . type === ApiOptions . PostType . ORIGINAL ) {
71
+ const detail = p . detail
69
72
const link = isMacOS
70
73
? logger . colors . gray (
71
74
logger . colors . underline ( `jike://page.jk/originalPost/${ p . id } ` )
72
75
)
73
76
: ''
74
77
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 } ]` : ''
78
81
} : ${ link } `,
79
- p . content
82
+ detail . content
80
83
)
81
- if ( p . pictures && p . pictures . length > 0 ) {
84
+ if ( detail . pictures && detail . pictures . length > 0 ) {
82
85
const images = await Promise . all (
83
- p . pictures . map ( ( p ) =>
86
+ ( detail . pictures as Entity . Picture [ ] ) . map ( ( p ) =>
84
87
displayImage ( p . middlePicUrl ) . then ( ( { result } ) => `${ result } \n` )
85
88
)
86
89
)
87
90
texts . push ( ...images )
88
91
}
89
- if ( p . linkInfo ) {
92
+ if ( detail . linkInfo ) {
90
93
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 )
94
97
) } )`
95
98
)
96
99
}
97
100
} else {
98
- // @ts -expect-error
99
101
texts . push ( `UNSUPPORTED: ${ p . type } ` )
100
102
}
101
103
0 commit comments