diff options
| author | Ivan Chen <ivan@tagg.id> | 2021-03-16 13:11:06 -0400 |
|---|---|---|
| committer | Ivan Chen <ivan@tagg.id> | 2021-03-17 18:38:08 -0400 |
| commit | 593347d11dfa0d7c9d32cb79c2639041ce07d849 (patch) | |
| tree | cc789fc7dddff3fcec2eb5ea221a1d0c3749a8bf /src/services | |
| parent | 07a15098625786451270e30e61e2d6e78c02d4db (diff) | |
using s3 url instead of image passed from backend
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/UserProfileService.ts | 49 |
1 files changed, 14 insertions, 35 deletions
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index dd77db9f..05fd5f82 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -77,43 +77,22 @@ export const loadProfileInfo = async (token: string, userId: string) => { } }; -export const loadAvatar = async (userId: string, thumbnail: boolean) => { - try { - const token = await AsyncStorage.getItem('token'); - const url = thumbnail - ? PROFILE_PHOTO_THUMBNAIL_ENDPOINT - : PROFILE_PHOTO_ENDPOINT; - const response = await RNFetchBlob.config({ - fileCache: true, - appendExt: 'jpg', - }).fetch('GET', url + `${userId}/`, { - Authorization: 'Token ' + token, - }); - const status = response.info().status; - if (status === 200) { - return response.path(); - } else { - return ''; - } - } catch (error) { - console.log(error); - return ''; - } -}; - -export const loadCover = async (token: string, userId: string) => { +export const getProfilePic = async ( + token: string, + userId: string, + type: 'large' | 'small', +) => { try { - let response = await RNFetchBlob.config({ - fileCache: true, - appendExt: 'jpg', - }).fetch('GET', HEADER_PHOTO_ENDPOINT + `${userId}/`, { - Authorization: 'Token ' + token, + const url = + type === 'small' ? PROFILE_PHOTO_ENDPOINT : HEADER_PHOTO_ENDPOINT; + const response = await fetch(url + `${userId}/`, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, }); - const status = response.info().status; - if (status === 200) { - return response.path(); - } else { - return ''; + if (response.status === 200) { + return (await response.json()).url; } } catch (error) { console.log(error); |
