aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/services')
-rw-r--r--src/services/UserProfileService.ts49
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);