2016-03-18 09:19:46 +00:00
|
|
|
"use strict";
|
2016-05-23 06:15:47 +00:00
|
|
|
require("typings-global");
|
2016-07-17 15:34:15 +00:00
|
|
|
const plugins = require("./smartfile.plugins");
|
|
|
|
const SmartfileInterpreter = require("./smartfile.interpreter");
|
2016-03-19 21:07:59 +00:00
|
|
|
exports.toFs = function (from, toPath) {
|
2016-09-20 15:56:49 +00:00
|
|
|
let done = plugins.q.defer();
|
|
|
|
let stream = plugins.request(from).pipe(plugins.fsExtra.createWriteStream(toPath));
|
2016-03-19 21:07:59 +00:00
|
|
|
stream.on('finish', function () {
|
|
|
|
done.resolve(toPath);
|
2016-03-18 09:19:46 +00:00
|
|
|
});
|
2016-03-18 16:34:31 +00:00
|
|
|
return done.promise;
|
2016-03-18 09:19:46 +00:00
|
|
|
};
|
2016-03-19 21:07:59 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param fromArg
|
|
|
|
* @returns {any}
|
|
|
|
*/
|
2016-03-18 16:34:31 +00:00
|
|
|
exports.toObject = function (fromArg) {
|
2016-09-17 21:11:44 +00:00
|
|
|
let done = plugins.q.defer();
|
2016-03-18 16:34:31 +00:00
|
|
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
2016-07-17 15:34:15 +00:00
|
|
|
let returnObject;
|
2016-09-20 15:56:49 +00:00
|
|
|
if (!error && response.statusCode === 200) {
|
2016-06-23 16:31:55 +00:00
|
|
|
returnObject = SmartfileInterpreter.objectFile(bodyString, SmartfileInterpreter.filetype(fromArg));
|
2016-03-20 16:36:38 +00:00
|
|
|
done.resolve(returnObject);
|
2016-03-18 16:34:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log('could not get remote file from ' + fromArg);
|
2016-03-20 16:36:38 +00:00
|
|
|
returnObject = undefined;
|
|
|
|
done.reject(returnObject);
|
2016-03-18 16:34:31 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return done.promise;
|
|
|
|
};
|
2016-03-19 21:07:59 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param fromArg
|
|
|
|
* @returns {any}
|
|
|
|
*/
|
2016-07-17 15:34:15 +00:00
|
|
|
exports.toString = (fromArg) => {
|
2016-09-17 21:11:44 +00:00
|
|
|
let done = plugins.q.defer();
|
2016-03-19 21:07:59 +00:00
|
|
|
plugins.request.get(fromArg, function (error, response, bodyString) {
|
2016-09-20 15:56:49 +00:00
|
|
|
if (!error && response.statusCode === 200) {
|
2016-03-19 21:07:59 +00:00
|
|
|
done.resolve(bodyString);
|
|
|
|
}
|
|
|
|
else {
|
2016-03-20 16:36:38 +00:00
|
|
|
plugins.beautylog.error('could not get remote file from ' + fromArg);
|
2016-03-19 21:07:59 +00:00
|
|
|
bodyString = undefined;
|
|
|
|
done.reject(bodyString);
|
|
|
|
}
|
2016-03-18 16:34:31 +00:00
|
|
|
});
|
|
|
|
return done.promise;
|
2016-03-18 09:19:46 +00:00
|
|
|
};
|
2016-10-27 16:55:18 +00:00
|
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRmaWxlLnJlbW90ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZmlsZS5yZW1vdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2QiwrQ0FBK0M7QUFDL0MsZ0VBQWdFO0FBRXJELFFBQUEsSUFBSSxHQUFHLFVBQVMsSUFBWSxFQUFDLE1BQWM7SUFDbEQsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUM1QixJQUFJLE1BQU0sR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLGlCQUFpQixDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUE7S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