Socket
Socket
Sign inDemoInstall

everypixel

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

everypixel - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

t/face.jpg

69

index.js

@@ -5,25 +5,40 @@ "use strict";

const FormData = require("form-data");
// const fs = require("fs");
const {promisify} = require("util");
const { promisify } = require("util");
// const qs = require('qs');
const BASE_URL = "https://api.everypixel.com/v1";
const ENDPOINTS = {
"keywords": "/keywords",
"quality": "/quality",
"quality_ugc": "/quality_ugc",
"faces": "/faces",
keywords: "/keywords",
quality: "/quality",
quality_ugc: "/quality_ugc",
faces: "/faces",
};
function EveryPixel (auth = {"username": "", "password": ""}) {
function EveryPixel(auth = { username: "", password: "" }) {
this.client = axios.create({
baseURL: BASE_URL,
auth: auth || {},
});
// console.log(auth);
return new Proxy(this, {
get: function(target, key, receiver) {
console.log(`getting ${key}!`);
const client = Reflect.get(target, "client", receiver);
this.client = axios.create({
"baseURL": BASE_URL,
"auth": auth || {},
return async function(params) {
if (params.url) {
return await client.get(ENDPOINTS[key], {
params: params,
});
} else if (params.data) {
const form = new FormData();
form.append("data", params.data);
delete params.data;
const headers = await getFormHeaders(form);
return await client.post(ENDPOINTS[key], form, {headers: headers, params: params});
}
};
},
});

@@ -33,30 +48,12 @@ }

EveryPixel.prototype.keywords = async function(params) {
if (params.url) {
return (await this.client.get(ENDPOINTS.keywords, {"params": params})).data;
} else if (params.data) {
const form = new FormData();
form.append("data", params.data);
const headers = await getFormHeaders(form);
return await this.client.post(ENDPOINTS.keywords, form, {headers: headers});
}
};
// Borrow from https://github.com/chux0519/axios-request for getting Content-Length
async function getFormHeaders (form) {
async function getFormHeaders(form) {
const getLen = promisify(form.getLength).bind(form);
const len = await getLen();
return {
...form.getHeaders(),
"Content-Length": len
...form.getHeaders(),
"Content-Length": len,
};
}
module.exports = EveryPixel;
{
"name": "everypixel",
"version": "0.0.1",
"version": "0.1.0",
"description": "JavaScript support for EveryPixel API",

@@ -29,4 +29,3 @@ "main": "index.js",

"axios": "^0.19.0",
"form-data": "^2.4.0",
"qs": "^6.7.0"
"form-data": "^2.4.0"
},

@@ -33,0 +32,0 @@ "devDependencies": {

@@ -8,25 +8,59 @@ "use strict";

var api = new EveryPixel({
"username": "dR6hJL9SiROP5ptdqcg4sTFx",
"password": "vVhatP2WMJoWQ52oHdWsSBnVDRNsZsx3LY0KwcMiIdwtCynY"
"username": "<your-client-id>",
"password": "<your-client-secret>"
});
// test("set default handler to placeholder", async function (t) {
// var ret = await api.keywords({"url": "http://image.everypixel.com/2014.12/67439828186edc79b9be81a4dedea8b03c09a12825b_b.jpg", "num_keywords": 10});
// console.log(ret);
// t.end();
// });
test("Get 10 suggested keywords of online image", async function (t) {
var ret = await api.keywords({"url": "http://image.everypixel.com/2014.12/67439828186edc79b9be81a4dedea8b03c09a12825b_b.jpg", "num_keywords": 10});
console.log(ret.data);
t.end();
});
// var data = {"data": fs.createReadStream(file.path)};
test("set default handler to placeholder", async function (t) {
test("Get 10 suggested keywords of local image file", async function (t) {
var ret = await api.keywords({"data": fs.createReadStream(appRoot + "/t/cat.jpg"), "num_keywords": 10});
console.log(ret);
console.log(ret.data);
t.end();
});
// test("set default handler to placeholder", async function (t) {
// var ret = await api.keywords({"file": appRoot + "/t/cat.jpg", "num_keywords": 10});
// console.log(ret);
// t.end();
// });
test("Get quality score of online image", async function (t) {
var ret = await api.quality({"url": "http://image.everypixel.com/2014.12/67439828186edc79b9be81a4dedea8b03c09a12825b_b.jpg"});
console.log(ret.data);
t.end();
});
test("Get quality score of local image file", async function (t) {
var ret = await api.quality({"data": fs.createReadStream(appRoot + "/t/cat.jpg")});
console.log(ret.data);
t.end();
});
test("Get User-Generated Photo Scoring of online image", async function (t) {
var ret = await api.quality_ugc({"url": "http://image.everypixel.com/2014.12/67439828186edc79b9be81a4dedea8b03c09a12825b_b.jpg"});
console.log(ret.data);
t.end();
});
test("Get User-Generated Photo Scoring of local image file", async function (t) {
var ret = await api.quality_ugc({"data": fs.createReadStream(appRoot + "/t/cat.jpg")});
console.log(ret.data);
t.end();
});
test("Find faces of online image", async function (t) {
var ret = await api.faces({"url": "https://labs.everypixel.com/api/static/i/estest_sample3.jpg"});
console.log(ret.data);
console.log(ret.data.faces);
t.end();
});
test("Find faces of local image file", async function (t) {
var ret = await api.faces({"data": fs.createReadStream(appRoot + "/t/face.jpg")});
console.log(ret.data);
console.log(ret.data.faces);
t.end();
});
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