@stendahls/libravatar-server
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "@stendahls/libravatar-server", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "A node implementation of the Libravatar API", | ||
@@ -5,0 +5,0 @@ "main": "server.js", |
@@ -10,2 +10,4 @@ const fs = require( 'fs' ); | ||
const cache = {}; | ||
module.exports = async ( emailHash, targetSize ) => { | ||
@@ -28,3 +30,6 @@ await elvisClient.login( process.env.ELVIS_PROVIDER_USER, process.env.ELVIS_PROVIDER_PASSWORD ); | ||
if ( emailHash.length === 64 ) { | ||
hashes[ hash.sha256( email ) ] = searchResult.previewUrl; | ||
hashes[ hash.sha256( email ) ] = { | ||
url: searchResult.previewUrl, | ||
assetModified: searchResult.metadata.assetModified.value, | ||
}; | ||
@@ -34,3 +39,6 @@ return true; | ||
hashes[ hash.md5( email ) ] = searchResult.previewUrl; | ||
hashes[ hash.md5( email ) ] = { | ||
url: searchResult.previewUrl, | ||
assetModified: searchResult.metadata.assetModified.value, | ||
}; | ||
@@ -45,4 +53,11 @@ return true; | ||
let chunks = []; | ||
const readStream = elvisClient.stream( hashes[ emailHash ] ); | ||
if ( cache[ emailHash ] && cache[ emailHash ].assetModified >= hashes[ emailHash ].assetModified ) { | ||
return sharp( cache[ emailHash ].data ) | ||
.resize( targetSize, targetSize ) | ||
.toBuffer(); | ||
} | ||
const readStream = elvisClient.stream( hashes[ emailHash ].url ); | ||
readStream.on( 'data', ( chunk ) => { | ||
@@ -54,3 +69,8 @@ chunks.push( chunk ); | ||
readStream.on( 'end', () => { | ||
const avatarImage = sharp( Buffer.concat( chunks ) ) | ||
cache[ emailHash ] = { | ||
assetModified: hashes[ emailHash ].assetModified, | ||
data: Buffer.concat( chunks ), | ||
}; | ||
const avatarImage = sharp( cache[ emailHash ].data ) | ||
.resize( targetSize, targetSize ) | ||
@@ -57,0 +77,0 @@ .toBuffer(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15985
311