Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

network-avatar-picker

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

network-avatar-picker - npm Package Compare versions

Comparing version 1.3.0 to 1.3.2

50

lib/networks/index.js
'use strict';
var cheerio = require('cheerio');
var avatarServiceFactory = require('../utils/avatarService');
var _require = require('../utils/requestService'),
getPromisified = _require.getPromisified;
var _require = require('../utils/avatarService'),
downloadImage = _require.downloadImage;
var _require2 = require('../utils/errorsService'),
handleRequestErrors = _require2.handleRequestErrors;
var _require2 = require('../utils/requestService'),
getPromisified = _require2.getPromisified;
var getImageUrl = function getImageUrl(type, username) {
if (type === 'twitter') {
var _require3 = require('../utils/errorsService'),
handleRequestErrors = _require3.handleRequestErrors;
var getImageUrl = function getImageUrl(network, username) {
if (network === 'twitter') {
return 'https://twitter.com/' + username + '/profile_image?size=original';
}
if (type === 'tumblr') {
} else if (network === 'tumblr') {
return 'https://api.tumblr.com/v2/blog/' + username + '/avatar';
}
if (type === 'facebook') {
} else if (network === 'facebook') {
return 'https://graph.facebook.com/' + username + '/picture?type=large';
}
throw new Error('Bad network');
};
var extractImageUrl = async function extractImageUrl(url, network) {
var getUserProfileUrl = function getUserProfileUrl(network, username) {
return 'https://www.' + network + '.com/' + username;
};
var extractProfileImageUrl = async function extractProfileImageUrl(network, username) {
try {
var response = await getPromisified({ url: url, encoding: null });
if (!network || network !== 'instagram' && network !== 'vimeo') {
throw new Error('Bad network');
}
var profileUrl = getUserProfileUrl(network, username);
var response = await getPromisified({ url: profileUrl, encoding: null });
handleRequestErrors(response, network);

@@ -46,12 +55,8 @@ var $ = cheerio.load(response.body);

var getUserProfileUrl = function getUserProfileUrl(type, username) {
return 'https://www.' + type + '.com/' + username;
};
var picker = {
getAvatar: async function getAvatar(username) {
try {
var type = this.getNetworkType();
var imageUrl = type === 'vimeo' || type === 'instagram' ? await extractImageUrl(getUserProfileUrl(type, username), type) : getImageUrl(type, username);
return this.avatarService.downloadImage(imageUrl, type);
var network = this.getNetworkType();
var imageUrl = network === 'vimeo' || network === 'instagram' ? await extractProfileImageUrl(network, username) : getImageUrl(network, username);
return downloadImage(imageUrl, network);
} catch (error) {

@@ -64,10 +69,7 @@ throw error;

module.exports.init = function (type) {
var avatarService = avatarServiceFactory.init();
return Object.assign(Object.create(picker), {
getNetworkType: function getNetworkType() {
return type;
},
avatarService: avatarService
}
});
};

@@ -9,21 +9,17 @@ 'use strict';

function init() {
var downloadImage = async function downloadImage(url, network) {
try {
var response = await getPromisified({ url: url, encoding: null });
handleRequestErrors(response, network);
if (network === 'twitter' && response.headers && response.headers['content-type'] && response.headers['content-type'].includes('text/html')) {
throw new Error('Get ' + network + ' avatar no response body.');
}
return response.body;
} catch (error) {
throw error;
var downloadImage = async function downloadImage(url, network) {
try {
var response = await getPromisified({ url: url, encoding: null });
handleRequestErrors(response, network);
if (network === 'twitter' && response.headers && response.headers['content-type'] && response.headers['content-type'].includes('text/html')) {
throw new Error('Get ' + network + ' avatar no response body.');
}
};
return response.body;
} catch (error) {
throw error;
}
};
return Object.freeze({
downloadImage: downloadImage
});
}
module.exports.init = init;
module.exports = {
downloadImage: downloadImage
};
{
"name": "network-avatar-picker",
"version": "1.3.0",
"version": "1.3.2",
"description": "A picker for user's networks profile image.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc