-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathremovd.js
65 lines (50 loc) · 1.25 KB
/
removd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require('dotenv').config();
const once = require('./lib/once');
const batch = require('./lib/batch');
const balance = require('./lib/balance');
function check(workflow, options) {
const api_key = process.env.REMOVD_API_KEY || options.apikey;
if (!api_key) {
return {
error: 'Missing remove.bg service API key'
};
}
if (workflow === 'account') {
return balance(options);
}
if (!options) {
return {
error: 'Missing paremeters'
};
}
if (!options.source) {
return {
error: `Missing source ${(workflow === 'url') ? workflow : 'file'}`
};
}
options.workflow = workflow;
if (typeof options.source === 'string') {
return once(options);
}
if (typeof options.source === 'object' && options.source.length) {
return batch(options);
}
}
function file(options) {
return check(arguments.callee.name, options);
}
function url(options) {
return check(arguments.callee.name, options);
}
function base64(options) {
return check(arguments.callee.name, options);
}
function account(options) {
return check(arguments.callee.name, options);
}
module.exports = {
file,
url,
base64,
account
};