import { useMusicApi } from '../hooks' ; const musicApi = useMusicApi ( ) ; async function getUser ( uid , cookie ? ) { try { const { body } = await musicApi . user_detail ( { uid , cookie } ) ; if ( body . code !== 200 ) { throw body ; } const profile = body ; return { id : profile . userId , name : profile . nickname , signature : profile . signature , avatar : profile . avatarUrl , followed : profile . followed , followers : profile . followeds , following : profile . follows , } ; } catch ( e ) { console . error ( e ) ; } return { } ; } async function getPlayList ( uid , cookie ? ) { try { const { body } = await musicApi . user_playlist ( { uid , cookie } ) ; if ( body . code !== 200 ) { throw body ; } const playlist = body . playlist ; return playlist . map ( ( e ) => ( { id : e . id . toString ( ) , name : e . name , cover : e . coverImgUrl , played : e . playCount , size : e . trackCount , link : `/player/0/${ e . id }` , } ) ) ; } catch ( e ) { console . error ( e ) ; } return [ ] ; } async function getUserDetail ( uid , cookie ? ) { const [ profile , playlists ] = await Promise . all ( [ getUser ( uid , cookie ) , getPlayList ( uid , cookie ) ] ) ; return { profile , playlists , } ; } export { getUserDetail } ;