chore: Migrate authentication to new tables (#1929)
This work provides a foundation for a more pluggable authentication system such as the one outlined in #1317. closes #1317
This commit is contained in:
32
server/utils/avatars.js
Normal file
32
server/utils/avatars.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// @flow
|
||||
import crypto from "crypto";
|
||||
import fetch from "isomorphic-fetch";
|
||||
|
||||
export async function generateAvatarUrl({
|
||||
id,
|
||||
domain,
|
||||
name = "Unknown",
|
||||
}: {
|
||||
id: string,
|
||||
domain?: string,
|
||||
name?: string,
|
||||
}) {
|
||||
// attempt to get logo from Clearbit API. If one doesn't exist then
|
||||
// fall back to using tiley to generate a placeholder logo
|
||||
const hash = crypto.createHash("sha256");
|
||||
hash.update(id);
|
||||
const hashedId = hash.digest("hex");
|
||||
|
||||
let cbResponse, cbUrl;
|
||||
if (domain) {
|
||||
cbUrl = `https://logo.clearbit.com/${domain}`;
|
||||
try {
|
||||
cbResponse = await fetch(cbUrl);
|
||||
} catch (err) {
|
||||
// okay
|
||||
}
|
||||
}
|
||||
|
||||
const tileyUrl = `https://tiley.herokuapp.com/avatar/${hashedId}/${name[0]}.png`;
|
||||
return cbUrl && cbResponse && cbResponse.status === 200 ? cbUrl : tileyUrl;
|
||||
}
|
||||
Reference in New Issue
Block a user