get user info

This commit is contained in:
Sayem Chowdhury 2021-03-08 13:36:54 +06:00
parent 6c9a801aef
commit cdeff63b85
4 changed files with 44 additions and 0 deletions

View File

@ -20,6 +20,16 @@ import * as api from 'd-fi-core';
// Init api with arl from cookie
await api.initDeezerApi(arl_cookie);
// Verify user
try {
const user = await api.getUser();
// Successfully logged in
console.log('Logged in as ' + user.BLOG_NAME);
} catch (err) {
// Invalid arl cookie set
console.error(err.message);
}
// GET Track Object
const track = await api.getTrackInfo(song_id);

View File

@ -13,6 +13,7 @@ import type {
searchType,
trackTypePublicApi,
albumTypePublicApi,
userType,
} from './types';
// expire cache in 60 minutes
@ -163,3 +164,19 @@ type searchTypesProp = 'ALBUM' | 'ARTIST' | 'TRACK' | 'PLAYLIST' | 'RADIO' | 'SH
*/
export const searchMusic = (query: string, types: searchTypesProp[] = ['TRACK'], nb = 15): Promise<searchType> =>
request({query, nb, types}, 'mobile_suggest');
/**
* Get details about current user
*/
export const getUser = async (): Promise<userType> => {
const {
data: {error, results},
} = await axios.get('/gateway.php', {params: {method: 'user_getInfo'}});
if (Object.keys(results).length > 0) {
return results;
}
const errorMessage = Object.entries(error).join(', ');
throw new Error(errorMessage);
};

View File

@ -4,3 +4,4 @@ export * from './playlist';
export * from './profile';
export * from './search';
export * from './tracks';
export * from './user';

16
src/types/user.ts Normal file
View File

@ -0,0 +1,16 @@
export interface userType {
USER_ID: string;
EMAIL: string;
FIRSTNAME: string;
LASTNAME: string;
BIRTHDAY: string;
BLOG_NAME: string;
SEX: string;
ADDRESS?: string;
CITY?: string;
ZIP?: string;
COUNTRY: string;
LANG: string;
PHONE?: string;
__TYPE__: 'user';
}