Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
♻️ Make gravatar optional (fixed #1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Jan 9, 2021
1 parent 243857f commit b3418d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/config/configuration.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,8 @@ export interface Configuration {
googleMaps: {
apiKey: string;
};

gravatar: {
enabled: boolean;
};
}
3 changes: 3 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ const configuration: Configuration = {
googleMaps: {
apiKey: process.env.GOOGLE_MAPS_API_KEY,
},
gravatar: {
enabled: bool(process.env.PASSWORD_PWNED_CHECK, true),
},
};

const configFunction: ConfigFactory<Configuration> = () => configuration;
Expand Down
22 changes: 12 additions & 10 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,18 @@ export class AuthService {
} catch (error) {}
}

for await (const emailString of [email, emailSafe]) {
const md5Email = createHash('md5').update(emailString).digest('hex');
try {
const img = await got(
`https://www.gravatar.com/avatar/${md5Email}?d=404`,
{ responseType: 'buffer' },
);
if (img.body.byteLength > 1)
data.profilePictureUrl = `https://www.gravatar.com/avatar/${md5Email}?d=mp`;
} catch (error) {}
if (this.configService.get<boolean>('gravatar.enabled')) {
for await (const emailString of [email, emailSafe]) {
const md5Email = createHash('md5').update(emailString).digest('hex');
try {
const img = await got(
`https://www.gravatar.com/avatar/${md5Email}?d=404`,
{ responseType: 'buffer' },
);
if (img.body.byteLength > 1)
data.profilePictureUrl = `https://www.gravatar.com/avatar/${md5Email}?d=mp`;
} catch (error) {}
}
}

let id: number | undefined = undefined;
Expand Down

0 comments on commit b3418d0

Please sign in to comment.