Skip to content

Commit a10b765

Browse files
committed
Update API URL and add API Key option
1 parent 6fc8aae commit a10b765

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

bin/filepreviews

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ program
1212
program
1313
.option('-D, --debug', 'Enable debug logging.')
1414
.option('-V, --version', 'Show version.')
15+
.option('-K, --apiKey [key]', 'Use FilePreviews.io application API Key')
1516
.option('-m, --metadata [values]', 'Eg: exif,ocr,psd,all')
1617
.option('-f, --format [values]', 'Eg: png, jpg')
1718
.option('-h, --height [value]', 'Height value')
@@ -41,7 +42,11 @@ program
4142
}
4243

4344
if (url.isWebUri(fileURL)) {
44-
var preview = new FilePreviews({debug: program.debug});
45+
var preview = new FilePreviews({
46+
debug: program.debug,
47+
apiKey: program.apiKey
48+
});
49+
4550
preview.generate(fileURL, options, function(err, result) {
4651
console.log(JSON.stringify(result, null, ' '));
4752
});

lib/index.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
var request = require('request');
44

5-
var API_URL = 'https://blimp-previews.herokuapp.com/?url=',
6-
RESULTS_URL = 'https://s3.amazonaws.com/demo.filepreviews.io/',
5+
var API_URL = 'https://api.filepreviews.io/v1/?url=',
76
FilePreviews;
87

98
FilePreviews = function(options) {
109
options = options || {};
1110

1211
this.debug = options.debug || false;
13-
this.resultsUrl = options.resultsUrl || RESULTS_URL;
12+
this.apiKey = options.apiKey;
1413
};
1514

1615
FilePreviews.prototype.generate = function(url, options, callback) {
@@ -33,10 +32,22 @@ FilePreviews.prototype.submitJobToAPI = function(url, options, callback) {
3332
}
3433
}
3534

36-
var error = 'API request error: ';
37-
this._log('API request to: ' + this.getAPIRequestURL(url, options));
35+
var error = 'API request error: ',
36+
requestUrl = this.getAPIRequestURL(url, options);
3837

39-
request.get(this.getAPIRequestURL(url, options), function(err, result) {
38+
this._log('API request to: ' + requestUrl);
39+
40+
var requestOptions = {
41+
url: requestUrl
42+
};
43+
44+
if (this.apiKey) {
45+
requestOptions.headers = {
46+
'X-API-Key': this.apiKey
47+
};
48+
}
49+
50+
request.get(requestOptions, function(err, result) {
4051
if (err) console.error(err);
4152

4253
if (result.statusCode === 200 || result.statusCode === 403) {

0 commit comments

Comments
 (0)