2016-04-08 16:40:52 +00:00
|
|
|
const Lang = imports.lang;
|
2017-07-19 13:20:29 +00:00
|
|
|
const Self = imports.misc.extensionUtils.getCurrentExtension();
|
2016-04-08 16:40:52 +00:00
|
|
|
|
|
|
|
|
// network requests
|
|
|
|
|
const Soup = imports.gi.Soup;
|
|
|
|
|
const Json = imports.gi.Json;
|
|
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
const RWG_SETTINGS_SCHEMA_DESKTOPPER = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.desktopper';
|
|
|
|
|
const RWG_SETTINGS_SCHEMA_UNSPLASH = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.unsplash';
|
2018-04-12 16:36:52 +00:00
|
|
|
const RWG_SETTINGS_SCHEMA_WALLHAVEN = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.wallhaven';
|
2017-10-07 15:08:35 +00:00
|
|
|
const RWG_SETTINGS_SCHEMA_GENERIC_JSON = 'org.gnome.shell.extensions.space.iflow.randomwallpaper.genericJSON';
|
2017-07-20 18:54:23 +00:00
|
|
|
|
|
|
|
|
const SettingsModule = Self.imports.settings;
|
2017-07-20 14:29:13 +00:00
|
|
|
const HistoryModule = Self.imports.history;
|
|
|
|
|
|
2017-07-19 13:20:29 +00:00
|
|
|
const LoggerModule = Self.imports.logger;
|
2017-10-07 15:08:35 +00:00
|
|
|
const JSONPath = Self.imports.jsonpath.jsonpath;
|
2017-07-19 13:20:29 +00:00
|
|
|
|
2018-01-16 18:14:18 +00:00
|
|
|
var BaseAdapter = new Lang.Class({
|
2017-07-19 13:20:29 +00:00
|
|
|
Name: "BaseAdapter",
|
2017-07-20 11:48:13 +00:00
|
|
|
logger: null,
|
2017-07-19 13:20:29 +00:00
|
|
|
|
|
|
|
|
_init: function () {
|
|
|
|
|
this.logger = new LoggerModule.Logger('RWG3', 'BaseAdapter');
|
|
|
|
|
},
|
|
|
|
|
|
2017-07-20 14:29:13 +00:00
|
|
|
/**
|
|
|
|
|
* Retrieves a new url for an image and calls the given callback with an HistoryEntry as parameter.
|
2018-07-29 17:43:28 +00:00
|
|
|
* The history element will be null and the error will be set if an error occurred.
|
|
|
|
|
*
|
|
|
|
|
* @param callback(historyElement, error)
|
2017-07-20 14:29:13 +00:00
|
|
|
*/
|
|
|
|
|
requestRandomImage: function (callback) {
|
2018-07-29 17:43:28 +00:00
|
|
|
this._error("requestRandomImage not implemented", callback);
|
2017-07-20 11:48:13 +00:00
|
|
|
},
|
|
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
fileName: function (uri) {
|
2018-07-27 16:32:17 +00:00
|
|
|
while (this._isURIEncoded(uri)) {
|
|
|
|
|
uri = decodeURIComponent(uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let base = uri.substring(uri.lastIndexOf('/') + 1);
|
2018-01-16 17:51:23 +00:00
|
|
|
if (base.indexOf('?') >= 0) {
|
2017-10-07 17:09:33 +00:00
|
|
|
base = base.substr(0, base.indexOf('?'));
|
|
|
|
|
}
|
2017-07-20 11:48:13 +00:00
|
|
|
return base;
|
2017-07-20 14:29:13 +00:00
|
|
|
},
|
|
|
|
|
|
2018-07-27 16:32:17 +00:00
|
|
|
_isURIEncoded: function (uri) {
|
|
|
|
|
uri = uri || '';
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return uri !== decodeURIComponent(uri);
|
2018-07-27 17:34:10 +00:00
|
|
|
} catch (err) {
|
2018-07-27 16:32:17 +00:00
|
|
|
this.logger.error(err);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-07-29 17:43:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_error: function (err, callback) {
|
|
|
|
|
let error = {"error": err};
|
|
|
|
|
this.logger.error(JSON.stringify(error));
|
|
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback(null, error);
|
|
|
|
|
}
|
2018-07-27 16:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 13:20:29 +00:00
|
|
|
});
|
|
|
|
|
|
2018-01-16 18:14:18 +00:00
|
|
|
var DesktopperAdapter = new Lang.Class({
|
2016-04-08 16:40:52 +00:00
|
|
|
Name: "DesktopperAdapter",
|
2017-07-19 13:20:29 +00:00
|
|
|
Extends: BaseAdapter,
|
2017-07-20 15:09:44 +00:00
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
_settings: null,
|
|
|
|
|
|
|
|
|
|
_init: function () {
|
|
|
|
|
this.parent();
|
|
|
|
|
|
|
|
|
|
this._settings = new SettingsModule.Settings(RWG_SETTINGS_SCHEMA_DESKTOPPER);
|
|
|
|
|
},
|
|
|
|
|
|
2017-07-19 12:23:28 +00:00
|
|
|
requestRandomImage: function (callback) {
|
2016-04-08 16:40:52 +00:00
|
|
|
let session = new Soup.SessionAsync();
|
|
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
let url = 'https://api.desktoppr.co/1/wallpapers/random';
|
|
|
|
|
let allowUnsafe = this._settings.get('allow-unsafe', 'boolean');
|
|
|
|
|
if (allowUnsafe) {
|
|
|
|
|
url += '?safe_filter=all';
|
|
|
|
|
} else {
|
|
|
|
|
url += '?safe_filter=safe';
|
|
|
|
|
}
|
|
|
|
|
url = encodeURI(url);
|
2016-04-08 16:40:52 +00:00
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
let message = Soup.Message.new('GET', url);
|
2016-04-08 16:40:52 +00:00
|
|
|
|
2018-07-29 17:43:28 +00:00
|
|
|
if (message === null) {
|
|
|
|
|
this._error("Could not create request.", callback);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
session.queue_message(message, (session, message) => {
|
2018-07-29 17:43:28 +00:00
|
|
|
try {
|
|
|
|
|
let data = JSON.parse(message.response_body.data);
|
|
|
|
|
let response = data.response;
|
|
|
|
|
let imageDownloadUrl = encodeURI(response.image.url);
|
|
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
let historyEntry = new HistoryModule.HistoryEntry(null, 'desktopper.co', imageDownloadUrl);
|
|
|
|
|
historyEntry.source.sourceUrl = 'https://www.desktoppr.co/';
|
|
|
|
|
callback(historyEntry);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this._error("Could not create request. (" + e + ")", callback);
|
|
|
|
|
return;
|
2017-07-19 12:23:28 +00:00
|
|
|
}
|
2016-04-08 16:40:52 +00:00
|
|
|
});
|
|
|
|
|
}
|
2017-07-19 12:23:28 +00:00
|
|
|
});
|
2016-04-08 16:40:52 +00:00
|
|
|
|
2018-01-16 18:14:18 +00:00
|
|
|
var UnsplashAdapter = new Lang.Class({
|
2017-07-20 15:09:44 +00:00
|
|
|
Name: "UnsplashAdapter",
|
|
|
|
|
Extends: BaseAdapter,
|
|
|
|
|
|
|
|
|
|
sourceName: 'Unsplash',
|
|
|
|
|
sourceUrl: 'https://unsplash.com/',
|
|
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
_settings: null,
|
|
|
|
|
|
|
|
|
|
// query options
|
|
|
|
|
options: {
|
|
|
|
|
'username': '',
|
|
|
|
|
'query': '',
|
2018-07-27 17:34:10 +00:00
|
|
|
'collections': [],
|
2017-07-20 18:54:23 +00:00
|
|
|
'w': 1920,
|
|
|
|
|
'h': 1080,
|
2017-08-09 03:49:49 +00:00
|
|
|
'featured': false
|
2017-07-20 18:54:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_init: function () {
|
|
|
|
|
this.parent();
|
|
|
|
|
|
|
|
|
|
this._settings = new SettingsModule.Settings(RWG_SETTINGS_SCHEMA_UNSPLASH);
|
|
|
|
|
},
|
|
|
|
|
|
2017-07-20 15:09:44 +00:00
|
|
|
requestRandomImage: function (callback) {
|
|
|
|
|
let session = new Soup.SessionAsync();
|
2017-07-20 18:54:23 +00:00
|
|
|
|
|
|
|
|
this._readOptionsFromSettings();
|
|
|
|
|
let optionsString = this._generateOptionsString();
|
2018-01-16 18:21:53 +00:00
|
|
|
let clientParam = 'client_id=64daf439e9b579dd566620c0b07022706522d87b255d06dd01d5470b7f193b8d';
|
2018-01-16 17:51:23 +00:00
|
|
|
|
|
|
|
|
let url = 'https://api.unsplash.com/photos/random?' + optionsString + clientParam;
|
2017-07-20 18:54:23 +00:00
|
|
|
url = encodeURI(url);
|
|
|
|
|
|
2017-07-20 15:09:44 +00:00
|
|
|
let message = Soup.Message.new('GET', url);
|
|
|
|
|
|
2018-07-29 17:43:28 +00:00
|
|
|
if (message === null) {
|
|
|
|
|
this._error("Could not create request.", callback);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 17:51:23 +00:00
|
|
|
let utmParameters = 'utm_source=RandomWallpaperGnome3&utm_medium=referral&utm_campaign=api-credit';
|
2017-07-20 15:09:44 +00:00
|
|
|
|
|
|
|
|
session.queue_message(message, (session, message) => {
|
2018-07-29 17:43:28 +00:00
|
|
|
let downloadMessage = null;
|
|
|
|
|
let authorName, authorUrl, imageLinkUrl;
|
2017-07-20 15:09:44 +00:00
|
|
|
|
2018-07-29 17:43:28 +00:00
|
|
|
try {
|
|
|
|
|
let data = JSON.parse(message.response_body.data);
|
2017-07-20 15:09:44 +00:00
|
|
|
|
2018-07-29 17:43:28 +00:00
|
|
|
authorName = data.user.name;
|
|
|
|
|
authorUrl = encodeURI(data.user.links.html);
|
|
|
|
|
imageLinkUrl = encodeURI(data.urls.raw + '&' + utmParameters);
|
2018-01-16 17:51:23 +00:00
|
|
|
|
2018-07-29 17:43:28 +00:00
|
|
|
let downloadLocation = data.links.download_location + '?' + clientParam;
|
|
|
|
|
downloadMessage = Soup.Message.new('GET', downloadLocation);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this._error("Unexpected response. (" + e + ")", callback);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-01-16 17:51:23 +00:00
|
|
|
|
2018-07-29 17:43:28 +00:00
|
|
|
if (message === null) {
|
|
|
|
|
this._error("Could not create request.", callback);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session.queue_message(downloadMessage, (session, message) => {
|
|
|
|
|
try {
|
|
|
|
|
let downloadData = JSON.parse(message.response_body.data);
|
|
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
let historyEntry = new HistoryModule.HistoryEntry(authorName, this.sourceName, encodeURI(downloadData.url));
|
|
|
|
|
historyEntry.source.sourceUrl = encodeURI(this.sourceUrl + '?' + utmParameters);
|
|
|
|
|
historyEntry.source.authorUrl = encodeURI(authorUrl + '?' + utmParameters);
|
|
|
|
|
historyEntry.source.imageLinkUrl = imageLinkUrl;
|
|
|
|
|
callback(historyEntry);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this._error("Unexpected response. (" + e + ")", callback);
|
|
|
|
|
return;
|
2018-01-16 17:51:23 +00:00
|
|
|
}
|
|
|
|
|
});
|
2017-07-20 15:09:44 +00:00
|
|
|
});
|
2017-07-20 18:54:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_generateOptionsString: function () {
|
|
|
|
|
let options = this.options;
|
|
|
|
|
let optionsString = "";
|
|
|
|
|
|
|
|
|
|
for (let key in options) {
|
|
|
|
|
if (options.hasOwnProperty(key)) {
|
|
|
|
|
if (options[key]) {
|
|
|
|
|
optionsString += key + "=" + options[key] + "&";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return optionsString;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_readOptionsFromSettings: function () {
|
|
|
|
|
this.options.query = this._settings.get('unsplash-keyword', 'string');
|
|
|
|
|
|
2018-07-27 17:34:10 +00:00
|
|
|
this.options.username = this._settings.get('unsplash-username', 'string');
|
2017-08-09 03:49:49 +00:00
|
|
|
if (this.options.username && this.options.username[0] === '@') {
|
2017-07-20 18:54:23 +00:00
|
|
|
this.options.username = this.options.username.substring(1); // remove @ prefix
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-27 17:34:10 +00:00
|
|
|
this.options.collections = this._settings.get('unsplash-collections', 'string').split(',').map(
|
|
|
|
|
(elem) => {
|
|
|
|
|
return elem.trim();
|
|
|
|
|
});
|
|
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
this.options.w = this._settings.get('image-width', 'int');
|
|
|
|
|
this.options.h = this._settings.get('image-height', 'int');
|
2017-08-09 03:49:49 +00:00
|
|
|
|
|
|
|
|
this.options.featured = this._settings.get('featured-only', 'boolean');
|
2017-07-20 15:09:44 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2018-04-12 16:36:52 +00:00
|
|
|
var WallhavenAdapter = new Lang.Class({
|
|
|
|
|
Name: "WallhavenAdapter",
|
2017-07-19 13:20:29 +00:00
|
|
|
Extends: BaseAdapter,
|
2017-07-20 18:54:23 +00:00
|
|
|
_settings: null,
|
2016-04-08 16:40:52 +00:00
|
|
|
|
|
|
|
|
// query options
|
|
|
|
|
options: {
|
|
|
|
|
'q': '',
|
|
|
|
|
'purity': '110', // SFW, sketchy
|
|
|
|
|
'sorting': 'random',
|
2017-07-20 18:54:23 +00:00
|
|
|
'categories': '111', // General, Anime, People
|
2017-07-19 12:23:28 +00:00
|
|
|
'resolutions': ['1920x1200', '2560x1440']
|
2016-04-08 16:40:52 +00:00
|
|
|
},
|
|
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
_init: function () {
|
|
|
|
|
this.parent();
|
2017-02-03 16:38:01 +00:00
|
|
|
|
2018-04-12 16:36:52 +00:00
|
|
|
this._settings = new SettingsModule.Settings(RWG_SETTINGS_SCHEMA_WALLHAVEN);
|
2017-07-20 18:54:23 +00:00
|
|
|
},
|
2016-04-08 16:40:52 +00:00
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
requestRandomImage: function (callback) {
|
|
|
|
|
let session = new Soup.SessionAsync();
|
2016-04-08 16:40:52 +00:00
|
|
|
|
2017-07-20 18:54:23 +00:00
|
|
|
this._readOptionsFromSettings();
|
|
|
|
|
let optionsString = this._generateOptionsString();
|
2017-07-19 12:23:28 +00:00
|
|
|
let url = 'http://alpha.wallhaven.cc/search?' + optionsString;
|
2017-07-20 18:54:23 +00:00
|
|
|
url = encodeURI(url);
|
2017-02-03 16:38:01 +00:00
|
|
|
|
2016-04-08 16:40:52 +00:00
|
|
|
let message = Soup.Message.new('GET', url);
|
|
|
|
|
|
2017-07-20 11:48:13 +00:00
|
|
|
session.queue_message(message, (session, message) => {
|
2016-04-08 16:40:52 +00:00
|
|
|
let body = message.response_body.data;
|
2017-02-03 16:38:01 +00:00
|
|
|
let urlArray = body.match(new RegExp(/http[s]*:\/\/alpha.wallhaven.cc\/wallpaper\/[0-9]+/g));
|
2016-04-08 16:40:52 +00:00
|
|
|
|
|
|
|
|
// remove dublicates from array
|
2017-07-19 12:23:28 +00:00
|
|
|
let uniqueUrlArray = urlArray.filter(function (item, pos) {
|
2016-04-08 16:40:52 +00:00
|
|
|
return urlArray.indexOf(item) == pos;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// get a random entry from the array
|
2017-07-20 11:48:13 +00:00
|
|
|
let url = uniqueUrlArray[Math.floor(Math.random() * uniqueUrlArray.length)];
|
2016-04-08 16:40:52 +00:00
|
|
|
|
|
|
|
|
message = Soup.Message.new('GET', url);
|
|
|
|
|
|
2018-07-29 17:43:28 +00:00
|
|
|
if (message === null) {
|
|
|
|
|
this._error("Could not create request.", callback);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-04-08 16:40:52 +00:00
|
|
|
|
2018-07-29 17:43:28 +00:00
|
|
|
session.queue_message(message, () => {
|
|
|
|
|
try {
|
|
|
|
|
let body = message.response_body.data;
|
|
|
|
|
let imageDownloadUrl = body.match(new RegExp(/\/\/wallpapers.wallhaven.cc\/wallpapers\/full\/.*?"/))[0];
|
|
|
|
|
imageDownloadUrl = imageDownloadUrl.slice(0, -1);
|
|
|
|
|
imageDownloadUrl = 'http:' + imageDownloadUrl;
|
|
|
|
|
imageDownloadUrl = encodeURI(imageDownloadUrl);
|
|
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
let historyEntry = new HistoryModule.HistoryEntry(null, 'wallhaven.cc', imageDownloadUrl);
|
|
|
|
|
historyEntry.source.sourceUrl = 'https://alpha.wallhaven.cc/';
|
|
|
|
|
historyEntry.source.imageLinkUrl = url;
|
|
|
|
|
callback(historyEntry);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this._error("Unexpected response. (" + e + ")", callback);
|
|
|
|
|
return;
|
2017-07-19 12:23:28 +00:00
|
|
|
}
|
2016-04-08 16:40:52 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
});
|
2017-07-20 18:54:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_generateOptionsString: function () {
|
|
|
|
|
let options = this.options;
|
|
|
|
|
let optionsString = "";
|
|
|
|
|
|
|
|
|
|
for (let key in options) {
|
|
|
|
|
if (options.hasOwnProperty(key)) {
|
|
|
|
|
if (Array.isArray(options[key])) {
|
|
|
|
|
optionsString += key + "=" + options[key].join() + "&";
|
|
|
|
|
} else {
|
|
|
|
|
if (options[key]) {
|
|
|
|
|
optionsString += key + "=" + options[key] + "&";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return optionsString;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_readOptionsFromSettings: function () {
|
2018-04-12 16:36:52 +00:00
|
|
|
this.options.q = this._settings.get('wallhaven-keyword', 'string');
|
2017-07-20 18:54:23 +00:00
|
|
|
|
|
|
|
|
this.options.resolutions = this._settings.get('resolutions', 'string').split(',');
|
|
|
|
|
this.options.resolutions = this.options.resolutions.map((elem) => {
|
|
|
|
|
return elem.trim();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let categories = [];
|
|
|
|
|
categories.push(+this._settings.get('category-general', 'boolean')); // + is implicit conversion to int
|
|
|
|
|
categories.push(+this._settings.get('category-anime', 'boolean'));
|
|
|
|
|
categories.push(+this._settings.get('category-people', 'boolean'));
|
|
|
|
|
this.options.categories = categories.join('');
|
|
|
|
|
|
|
|
|
|
let purity = [];
|
|
|
|
|
purity.push(+this._settings.get('allow-sfw', 'boolean'));
|
|
|
|
|
purity.push(+this._settings.get('allow-sketchy', 'boolean'));
|
2018-04-12 16:36:52 +00:00
|
|
|
purity.push(0); // required by wallhaven
|
2017-07-20 18:54:23 +00:00
|
|
|
this.options.purity = purity.join('');
|
2016-04-08 16:40:52 +00:00
|
|
|
}
|
2017-07-19 12:23:28 +00:00
|
|
|
});
|
2017-10-07 15:08:35 +00:00
|
|
|
|
2018-01-16 18:14:18 +00:00
|
|
|
var GenericJsonAdapter = new Lang.Class({
|
2017-10-07 15:08:35 +00:00
|
|
|
Name: "GenericJsonAdapter",
|
|
|
|
|
Extends: BaseAdapter,
|
|
|
|
|
|
|
|
|
|
_settings: null,
|
2017-10-07 17:09:33 +00:00
|
|
|
_jsonPathParser: null,
|
2017-10-07 15:08:35 +00:00
|
|
|
|
|
|
|
|
_init: function () {
|
|
|
|
|
this.parent();
|
2017-10-07 17:09:33 +00:00
|
|
|
this._jsonPathParser = new JSONPath.JSONPathParser();
|
2017-10-07 15:08:35 +00:00
|
|
|
this._settings = new SettingsModule.Settings(RWG_SETTINGS_SCHEMA_GENERIC_JSON);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
requestRandomImage: function (callback) {
|
|
|
|
|
let session = new Soup.SessionAsync();
|
|
|
|
|
|
|
|
|
|
let url = this._settings.get("generic-json-request-url", "string");
|
|
|
|
|
url = encodeURI(url);
|
|
|
|
|
|
|
|
|
|
let message = Soup.Message.new('GET', url);
|
|
|
|
|
|
2018-07-29 17:43:28 +00:00
|
|
|
if (message === null) {
|
|
|
|
|
this._error("Could not create request.", callback);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-07 15:08:35 +00:00
|
|
|
session.queue_message(message, (session, message) => {
|
2018-07-29 17:43:28 +00:00
|
|
|
try {
|
|
|
|
|
let response = JSON.parse(message.response_body.data);
|
|
|
|
|
let JSONPath = this._settings.get("generic-json-response-path", "string");
|
|
|
|
|
let imageDownloadUrl = this._jsonPathParser.access(response, JSONPath);
|
|
|
|
|
imageDownloadUrl = this._settings.get("generic-json-url-prefix", "string") + imageDownloadUrl;
|
|
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
|
let historyEntry = new HistoryModule.HistoryEntry(null, 'Generic JSON Source', imageDownloadUrl);
|
|
|
|
|
historyEntry.source.sourceUrl = imageDownloadUrl;
|
|
|
|
|
callback(historyEntry);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this._error("Unexpected response. (" + e + ")", callback);
|
|
|
|
|
return;
|
2017-10-07 15:08:35 +00:00
|
|
|
}
|
|
|
|
|
});
|
2017-10-07 17:09:33 +00:00
|
|
|
|
2017-10-07 15:08:35 +00:00
|
|
|
}
|
|
|
|
|
});
|