synapse-react-client
Version:
[](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client) [](https://badge.fury.io/js/synaps
104 lines • 4.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProfilePic = exports.getColor = exports.getUserProfileWithProfilePicAttached = void 0;
var tslib_1 = require("tslib");
var __1 = require("..");
var synapseTypes_1 = require("../synapseTypes/");
var getEndpoint_1 = require("./getEndpoint");
/*
Utility functions for UserCards
*/
function getUserProfileWithProfilePicAttached(principalIds) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var userProfiles, profilesWithPictures;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, __1.SynapseClient.getUserProfiles(principalIds)];
case 1:
userProfiles = _a.sent();
profilesWithPictures = userProfiles.list.map(function (profile) {
if (profile.profilePicureFileHandleId) {
return (0, tslib_1.__assign)((0, tslib_1.__assign)({}, profile), { clientPreSignedURL: (0, getEndpoint_1.getEndpoint)(getEndpoint_1.BackendDestinationEnum.REPO_ENDPOINT) + "/repo/v1/userProfile/" + profile.ownerId + "/image/preview?redirect=true" });
}
else {
return profile;
}
});
return [2 /*return*/, { list: profilesWithPictures }];
}
});
});
}
exports.getUserProfileWithProfilePicAttached = getUserProfileWithProfilePicAttached;
function getProfilePic(userProfile, token) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var fileHandleAssociationList, request, fileHandleList, firstElement;
return (0, tslib_1.__generator)(this, function (_a) {
switch (_a.label) {
case 0:
if (!!userProfile.profilePicureFileHandleId) return [3 /*break*/, 1];
return [2 /*return*/, { userProfile: userProfile }];
case 1:
fileHandleAssociationList = [
{
associateObjectId: userProfile.ownerId,
associateObjectType: synapseTypes_1.FileHandleAssociateType.UserProfileAttachment,
fileHandleId: userProfile.profilePicureFileHandleId,
},
];
request = {
includeFileHandles: false,
includePreSignedURLs: true,
includePreviewPreSignedURLs: false,
requestedFiles: fileHandleAssociationList,
};
return [4 /*yield*/, __1.SynapseClient.getFiles(request, token)];
case 2:
fileHandleList = _a.sent();
firstElement = fileHandleList.requestedFiles[0];
return [2 /*return*/, {
userProfile: userProfile,
preSignedURL: firstElement.preSignedURL,
}];
}
});
});
}
exports.getProfilePic = getProfilePic;
var COLORS = [
'chocolate',
'black',
'firebrick',
'maroon',
'olive',
'green',
'forestgreen',
'darkturquoise',
'teal',
'blue',
'navy',
'darkmagenta',
'purple',
'blue',
'orangered',
'blueviolet',
];
var hash = function (userName) {
var val = userName
.split('')
.reduce(function (prevHash, currVal) {
return ((prevHash << 5) - prevHash + currVal.charCodeAt(0)) | 0;
}, 0);
return Math.abs(val);
};
var getColor = function (userName) {
var hashedUserName = hash(userName);
return COLORS[hashedUserName % COLORS.length];
};
exports.getColor = getColor;
exports.default = {
getUserProfileWithProfilePicAttached: getUserProfileWithProfilePicAttached,
getColor: getColor,
getProfilePic: getProfilePic,
};
//# sourceMappingURL=getUserData.js.map