@@ -2,31 +2,43 @@ import { logger } from '@poppinss/cliui'
2
2
import { createCommand } from 'commander'
3
3
import { JikeClient } from 'jike-sdk/node'
4
4
import open from 'open'
5
+ import { PROFILE_URL } from '../../constants'
6
+ import { errorAndExit } from '../../utils/log'
5
7
import { filterUsers } from '../../utils/user'
6
8
7
9
interface ViewOptions {
8
- username : string
9
- mobile : boolean
10
+ username ? : string
11
+ platform ?: keyof typeof PROFILE_URL
10
12
}
11
13
12
14
export const view = createCommand ( 'view' )
15
+ . aliases ( [ 'v' , 'info' , 'i' ] )
13
16
. argument ( '[username]' , 'the username of user' )
14
17
. description ( 'open user profile in browser' )
15
- . option ( '-m, --mobile' , 'view page for mobile phone' )
16
- . action ( ( username ?: string ) => viewUser ( username ) )
18
+ . option (
19
+ '-p, --platform <platform>' ,
20
+ 'supports web, mobile and mac, default is web' ,
21
+ 'web'
22
+ )
23
+ . action ( ( username ?: string ) => {
24
+ const opts = view . opts < ViewOptions > ( )
25
+ viewUser ( { ...opts , username } )
26
+ } )
17
27
18
- export const viewUser = async ( username ?: string ) => {
19
- const { mobile } = view . opts < Omit < ViewOptions , 'username' > > ( )
28
+ export const viewUser = async ( { username, platform } : ViewOptions ) => {
20
29
if ( ! username ) {
21
30
const [ user ] = filterUsers ( )
22
31
const client = JikeClient . fromJSON ( user )
23
32
username = await client . getSelf ( ) . getUsername ( )
24
33
}
25
34
26
- const url = mobile
27
- ? `https://m.okjike.com/users/${ username } `
28
- : `https://web.okjike.com/u/${ username } `
35
+ platform ||= 'web'
36
+ if ( ! ( platform in PROFILE_URL ) ) {
37
+ errorAndExit ( new Error ( `invlid platform: ${ platform } ` ) )
38
+ }
29
39
40
+ const url = PROFILE_URL [ platform ] + username
30
41
open ( url )
42
+
31
43
logger . info ( `${ url } opened!` )
32
44
}
0 commit comments