@stendahls/libravatar-server
Advanced tools
Comparing version 1.6.0 to 1.7.0
{ | ||
"name": "@stendahls/libravatar-server", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "A node implementation of the Libravatar API", | ||
@@ -18,2 +18,3 @@ "main": "server.js", | ||
"got": "^9.6.0", | ||
"is-url": "^1.2.4", | ||
"sharp": "^0.23.0" | ||
@@ -20,0 +21,0 @@ }, |
#!/usr/bin/env node | ||
require( 'dotenv' ).config(); | ||
const path = require( 'path' ); | ||
const express = require( 'express' ); | ||
const sharp = require( 'sharp' ); | ||
const providers = require( './providers/' ); | ||
const silhouetteImage = require('./modules/silhouetteImage'); | ||
const isUrl = require('is-url'); | ||
@@ -152,3 +152,2 @@ const app = express(); | ||
let defaultFallback = false; | ||
let defaultKey = `${ targetSize }x${ targetSize }`; | ||
@@ -164,11 +163,16 @@ if ( request.query.d ) { | ||
if ( defaultFallback ) { | ||
console.log(defaultFallback); | ||
if ( defaultFallback === '404' ) { | ||
response.sendStatus( 404 ); | ||
return true; | ||
} | ||
// Special values for default fallback | ||
// https://wiki.libravatar.org/api/ | ||
// Each case can either set `avatarImage` to | ||
// set the avatar image to return | ||
// or return true to stop checking | ||
if (defaultFallback === '404') { | ||
response.sendStatus( 404 ); | ||
return true; | ||
} | ||
if (defaultFallback === 'mm') { | ||
avatarImage = await silhouetteImage.get(targetSize); | ||
} | ||
// If `defaultFallback` is a url, redirect to it | ||
if ( isUrl(defaultFallback) ) { | ||
response.redirect( 302, defaultFallback ); | ||
@@ -179,10 +183,6 @@ | ||
if ( defaultImageCache[ defaultKey ] ) { | ||
avatarImage = defaultImageCache[ defaultKey ]; | ||
} else { | ||
avatarImage = await sharp( path.join( __dirname, 'assets', 'default.jpg' ) ) | ||
.resize( targetSize, targetSize ) | ||
.toBuffer(); | ||
defaultImageCache[ defaultKey ] = avatarImage; | ||
// After checking all default fallbacks, fallback | ||
// to getting a silhouetteImage instead | ||
if (!avatarImage) { | ||
avatarImage = await silhouetteImage.get(targetSize); | ||
} | ||
@@ -189,0 +189,0 @@ } |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
19914
12
423
0
5
+ Addedis-url@^1.2.4
+ Addedis-url@1.2.4(transitive)