-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.js
99 lines (80 loc) · 2.35 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// include closure
var path = require('path');
var ee = require('@google/earthengine');
var fs = require('fs')
var request = require('request');
// define stubs for the classes used in the Code Editor
global.ee = ee;
global.print = function(arg) { if(arg) { console.log(arg); } }
if(!global.Map) {
global.Map = function(arg) {}
}
global.Map.addLayer = function(arg) {}
global.Map.addCenterObject = function(arg) {}
global.Map.getBounds = function(arg) {}
global.Map.getCenter = function(arg) {}
global.Map.setCenter = function(arg) {}
global.Map.centerObject = function(arg) {}
global.Map.setOptions = function(arg) {}
global.Chart = function(arg) {}
global.Chart.image = function(arg) {}
global.Chart.image.histogram = function(arg) {}
global.commandLine = true
global.ui = function(arg) {}
global.ui.Chart = function(arg) { console.log('ui.Chart is not implemented yet') }
global.ui.Chart.image = global.ui.Chart
global.ui.Chart.image.doySeries = global.ui.Chart
global.ui.Chart.image.doySeriesByYear = global.ui.Chart
global.ui.Chart.image.doySeriesByRegion = global.ui.Chart
// First, checks if it isn't implemented yet.
if (!global.String.prototype.format) {
global.String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
global.download = function(url, path, onsuccess) {
var finished = false;
var downloadAsync = function(uri, filename, callback){
request.head(uri, function(err, res, body){
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};
downloadAsync(url, path, function(){
if(onsuccess) {
onsuccess(url, path)
}
finished = true;
});
while(!finished) {
require('deasync').sleep(100);
}
}
global.validate_zip = function(path, onsuccess) {
var JSZip = require("jszip");
var finished = false;
// read a zip file
fs.readFile(path, function(err, data) {
if (err) throw err;
var zip = new JSZip(data);
onsuccess(path)
finished = true;
});
while(!finished) {
require('deasync').sleep(100);
}
}
global.save = function(text, path) {
fs.writeFile(path, text, function(err) {
if(err) {
console.log(err);
}
});
}
// setup authorization
gee = require('./authenticate')