├── config_demo └── esri.json ├── src ├── util │ ├── create_dir.js │ ├── progressbar │ │ ├── format.js │ │ └── index.js │ ├── xyz.js │ ├── getTileUrl.js │ ├── userAgent.js │ └── freetile_status.js └── app.js ├── bin └── freetile.js ├── package.json ├── README.md ├── .gitignore └── LICENSE /config_demo/esri.json: -------------------------------------------------------------------------------- 1 | { 2 | "bound":[118,32,119,33], 3 | "levels":[1,2,3,4,5,6,7,8,9,10,11,12,13,14], 4 | "parallel":50, 5 | "downPath":"c://esritiles", 6 | "tileformat":"png", 7 | "mapurl":"http://cache1.arcgisonline.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer/tile/{z}/{y}/{x}" 8 | } -------------------------------------------------------------------------------- /src/util/create_dir.js: -------------------------------------------------------------------------------- 1 | var fs=require('fs'); 2 | var path=require('path'); 3 | //根据文件,同步递归创建其上一级目录 4 | function createDirs(file) { 5 | //获取文件根目录 6 | let dirpath=path.dirname(file); 7 | //有路径直接回调走 8 | if(fs.existsSync(dirpath)){ 9 | return true; 10 | }else{ 11 | if(createDirs(dirpath)){ 12 | fs.mkdirSync(dirpath); 13 | return true; 14 | } 15 | } 16 | }; 17 | module.exports=createDirs; -------------------------------------------------------------------------------- /bin/freetile.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const { program } = require('commander'); 3 | const run = require("../src/app"); 4 | //定义命令行帮助命令 5 | program.option('-f, --config_file ', '底图下载配置文件'); 6 | //解析命令行参数 7 | program.parse(process.argv); 8 | console.log(process.argv); 9 | console.log(program); 10 | 11 | const options = program.opts(); 12 | 13 | //检查参数 14 | if (!options.config_file) { 15 | console.log('底图下载配置文件config_file路径必填!'); 16 | process.exit(); 17 | } 18 | const config=require(options.config_file); 19 | run(config); 20 | 21 | 22 | 23 | process.on('uncaughtException', function (err) { 24 | //打印出错误 25 | console.log(err); 26 | //打印出错误的调用栈方便调试 27 | console.log(err.stack); 28 | }); 29 | //process全局对象 30 | process.on('SIGINT', function (e) { 31 | console.log(e); 32 | process.exit(); 33 | }); -------------------------------------------------------------------------------- /src/util/progressbar/format.js: -------------------------------------------------------------------------------- 1 | function format(str, params = []) { 2 | var pattern = /{([\s\S])*?}/gim; 3 | var index = 0; 4 | var params_index = 0; 5 | return str.replace(pattern, (match, tuple, offset) => { 6 | index = offset + match.length; 7 | params_index += 1; 8 | 9 | // 异常格式处理,对于列表和对象类型的param,对外抛出异常 10 | if (typeof params[params_index - 1] == [] || typeof params[params_index - 1] == {}) { 11 | throw TypeError(params[params_index - 1] + "不能为对象类型!"); 12 | } 13 | 14 | if (match.length > 2) { 15 | match = match.slice(1, match.length - 1); 16 | return eval('params[params_index-1].' + match);; 17 | } else { 18 | return params[params_index - 1]; 19 | } 20 | }); 21 | } 22 | 23 | module.exports=format; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "map-tile-downloader", 3 | "version": "1.1.0", 4 | "description": "下载公网地图服务器中以xyz及其形变性质的地图切片,用于离线GIS系统建设使用", 5 | "bin": { 6 | "freetile": "bin/freetile.js" 7 | }, 8 | "scripts": { 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/FreeGIS/map-tile-downloader.git" 14 | }, 15 | "author": "", 16 | "license": "ISC", 17 | "bugs": { 18 | "url": "https://github.com/FreeGIS/map-tile-downloader/issues" 19 | }, 20 | "homepage": "https://github.com/FreeGIS/map-tile-downloader#readme", 21 | "dependencies": { 22 | "cli-color": "^2.0.0", 23 | "commander": "^14.0.0", 24 | "proj4": "^2.9.0", 25 | "single-line-log": "^1.1.2", 26 | "superagent": "^10.2.3" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/util/xyz.js: -------------------------------------------------------------------------------- 1 | const bbox = { 2 | xmin: -20037508.342789244, 3 | ymin: -20037508.342789244, 4 | xmax: 20037508.342789244, 5 | ymax: 20037508.342789244 6 | } 7 | 8 | function getTileByCoors(coor, zoom) { 9 | // 计算coor与bbox左上角坐标 10 | const left = bbox.xmin; 11 | const top = bbox.ymax; 12 | const _width = coor[0] - left; 13 | const _height = top - coor[1]; 14 | let worldTileSize = 0x01 << zoom; 15 | const boundsWidth = bbox.xmax - bbox.xmin; 16 | const boundsHeight = bbox.ymax - bbox.ymin; 17 | const tileGeoSize = Math.max(boundsWidth, boundsHeight) * 1.0 / worldTileSize; 18 | const row = Math.floor(_height / tileGeoSize); 19 | const column = Math.floor(_width / tileGeoSize); 20 | 21 | return { 22 | row, column 23 | } 24 | } 25 | 26 | 27 | function bound2xyzs(bound, tz) { 28 | // 使用左上角,右下角,计算瓦片行列号 29 | const tileinfo1 = getTileByCoors([bound[0], bound[3]], tz); 30 | const tileinfo2 = getTileByCoors([bound[2], bound[1]], tz); 31 | // 部分瓦片规则是从下往上,综合判断即可 32 | const xyz1 = [tileinfo1.column, Math.min(tileinfo1.row, tileinfo2.row), tz]; 33 | const xyz2 = [tileinfo2.column, Math.max(tileinfo1.row, tileinfo2.row), tz]; 34 | return [xyz1, xyz2]; 35 | } 36 | 37 | 38 | module.exports = { bound2xyzs }; -------------------------------------------------------------------------------- /src/util/getTileUrl.js: -------------------------------------------------------------------------------- 1 | const zRegEx = /\{z\}/g; 2 | const xRegEx = /\{x\}/g; 3 | const yRegEx = /\{y\}/g; 4 | 5 | function getTileUrl(template,xyz){ 6 | //console.log(template,xyz); 7 | let match = /\{([a-z])-([a-z])\}/.exec(template); 8 | if (match) { 9 | const startCharCode = match[1].charCodeAt(0); 10 | const stopCharCode = match[2].charCodeAt(0); 11 | let charCode=String.fromCharCode(getRandomServiceId(startCharCode,stopCharCode)); 12 | template=template.replace(match[0], charCode); 13 | } else { 14 | match = match = /\{(\d+)-(\d+)\}/.exec(template); 15 | if (match) { 16 | const start = parseInt(match[1], 10); 17 | const stop = parseInt(match[2], 10); 18 | let charCode=getRandomServiceId(start,stop); 19 | template=template.replace(match[0], charCode.toString()); 20 | } 21 | } 22 | let url=template.replace(zRegEx, xyz[0].toString()) 23 | .replace(xRegEx, xyz[1].toString()) 24 | .replace(yRegEx, xyz[2].toString()); 25 | return url; 26 | } 27 | 28 | //获取随机的地图服务器代号,从而减少对爬取服务器的压力 29 | function getRandomServiceId(startcode,endcode){ 30 | let strcode=startcode+Math.round(Math.random()*(endcode-startcode)); 31 | return strcode; 32 | } 33 | //获取随机token 34 | function getRandomToken(tokens){ 35 | const token_length=tokens.length; 36 | let _index=Math.round(Math.random()*(token_length-1)); 37 | return tokens[_index]; 38 | } 39 | module.exports = {getTileUrl,getRandomToken}; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Map-Tile-DownLoader 2 | ## 一 作用 3 | 4 | 下载公网地图服务器中以xyz及其类xyz形式的地图切片,用于离线GIS系统底图使用。该xyz形式为基于墨卡托投影的坐标系,切片大小为256*256规格。 5 | 6 | ## 二 限制 7 | 8 | 1. xyz切片原点是基于左上角,大部分切片符合这个规则,百度切片原点在中心点,不符合。 9 | 2. xyz切片大小为标准的256 * 256,大部分切片大小符合这个规则,类似cesium地形大小为64 * 64不符合。 10 | 11 | ## 三 支持范围 12 | 13 | 1 支持esri公网这种不需要带token的切片下载。 14 | 15 | 2 支持天地图,mapbox这种带token的切片下载,由于这类服务器对单token的请求数量和请求规则做了爬虫限制,需自备一个token列表,绕开数量限制和请求行为限制。 16 | 17 | 3 大部分明显为墨卡托的xyz格式的切片都可以下载。 18 | 19 | ## 四 使用说明 20 | 21 | ### 4.1 安装 22 | 23 | 源码形式: 24 | 25 | ```shell 26 | git clone git@github.com:FreeGIS/map-tile-downloader.git 27 | cd map-tile-downloader 28 | npm install 29 | npm link 30 | ``` 31 | 32 | npm安装命令行形式: 33 | 34 | ``` 35 | npm i map-tile-downloader -g 36 | ``` 37 | 38 | 验证安装: 39 | 40 | ``` 41 | freetile -h 42 | Usage: freetile [options] 43 | 44 | Options: 45 | -f, --config_file 底图下载配置文件 46 | -h, --help display help for command 47 | ``` 48 | 49 | ### 4.2 下载配置 50 | 51 | 工程目录config下有若干下载模板,配置参数说明如下: 52 | 53 | bound:下载切片的wgs84坐标系的地理范围。 54 | 55 | levels:下载切片的级别数组。 56 | 57 | parallel:下载请求的并发数。 58 | 59 | mapurl:下载切片服务xyz模板。 60 | 61 | tileformat:明确指定下载切片的格式,如png jpeg pbf webp等。 62 | 63 | downPath:下载切片本地存储目录。 64 | 65 | tokenInfo:可选,对需要指定token的服务在此设置,该设置有三个选项。 66 | 67 | ​ location:token位置,枚举型,枚举值为"url"与"headers"。该设置用于明确指定token是在url里申明还是 headers里申明,这需要根据具体服务明确。例如:天地图和mapbox都是url中加token,而cesium地形却是在headers里申明。 68 | 69 | ​ key:token值绑定的主键,例如天地图是xxxx?tk=xxxxx,那么key就配置为"tk"。 70 | 71 | ​ values:token值数组,多配置几个,用于随机获取token下载,避免请求数量和行为限制。 72 | 73 | ### 4.3 切片下载 74 | 75 | ``` 76 | freetile -f D:/xxx/xx/esri.json 77 | ``` 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /src/util/userAgent.js: -------------------------------------------------------------------------------- 1 | let hds=[ 2 | {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}, 3 | {'User-Agent':'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 Safari/535.11'}, 4 | {'User-Agent':'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)'}, 5 | {'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0'}, 6 | {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36'}, 7 | {'User-Agent':'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50'}, 8 | {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50'}, 9 | {'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0'}, 10 | {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'}, 11 | {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'}, 12 | {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'}, 13 | {'User-Agent':'Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11'}, 14 | {'User-Agent':'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11'} 15 | ]; 16 | 17 | const hdsLength=hds.length; 18 | 19 | function getRandomUserAgent(){ 20 | let _index=Math.round(Math.random()*(hdsLength-1)); 21 | return hds[_index]; 22 | } 23 | 24 | module.exports = getRandomUserAgent; -------------------------------------------------------------------------------- /src/util/progressbar/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 进度条实现。 3 | */ 4 | //const log = require('./log'); 5 | var log = require('single-line-log').stdout; 6 | const format = require('./format'); 7 | const clicolor = require('cli-color'); 8 | /** 9 | * 封装一个进度条工具。 10 | */ 11 | function ProgressBar(description, bar_length) { 12 | this.description = description || "PROGRESS"; 13 | this.length = bar_length.length || 28; 14 | 15 | // 刷新进度条图案,文字的方法 16 | this.render = function(opts) { 17 | var percentage = (opts.completed/opts.total).toFixed(4); 18 | var cell_num = Math.floor(percentage * this.length); 19 | // 拼接黑色条 20 | var cell = ''; 21 | for(var i = 0; i < cell_num; i++) { 22 | cell += '█'; 23 | } 24 | // 拼接灰色条 25 | var empty = ''; 26 | for(var i = 0; i < this.length - cell_num; i++) { 27 | empty += '░'; 28 | } 29 | 30 | var percent = (100*percentage).toFixed(2); 31 | /** 32 | * 使用cli-color进行包装美化。 33 | */ 34 | this.description = clicolor.blue.bold(this.description); 35 | cell = clicolor.green.bgBlack.bold(cell); 36 | opts.completed = clicolor.yellow.bold(opts.completed); 37 | opts.failed = clicolor.red.bold(opts.failed); 38 | 39 | 40 | opts.total = clicolor.blue.bold(opts.total); 41 | opts.status = percent==100.00?clicolor.green.bold(opts.status):clicolor.red.bold(opts.status); 42 | 43 | 44 | // 拼接最终文本 45 | var cmdtext = format("<{}:{}%> {}{} [ {}/{} 失败切片数量:{} {}]", [this.description, percent, 46 | cell, empty, opts.completed, opts.total, opts.failed, opts.status]); 47 | log(cmdtext); 48 | }; 49 | } 50 | 51 | 52 | /** 53 | * 模块导出。 54 | */ 55 | module.exports = ProgressBar; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | my/ 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | config/ 107 | -------------------------------------------------------------------------------- /src/util/freetile_status.js: -------------------------------------------------------------------------------- 1 | var ProgressBar = require('./progressbar/index'); 2 | 3 | function FreeTile_Status(xyzCount){ 4 | this.sucessCount=0;//成功总数 5 | this.errorTiles={};//错误切片明细 6 | this.errorCount=0; 7 | this.tileCount=xyzCount;//切片任务总数 8 | this.currentIndex=0; 9 | this.pb=new ProgressBar('下载进度', 100); 10 | } 11 | 12 | //设置切片任务总数 13 | FreeTile_Status.prototype.setTileCount=function(xyzCount){ 14 | this.tileCount=xyzCount; 15 | } 16 | //得到错误切片总数 17 | FreeTile_Status.prototype.getErrorTileCount=function(){ 18 | return Object.keys(this.errorTiles).length; 19 | } 20 | //得到错误切片的数组 21 | FreeTile_Status.prototype.getErrorTiles=function(){ 22 | let errotTiles=[]; 23 | let self=this; 24 | Object.keys(this.errorTiles).forEach(function(key) { 25 | errotTiles.push(self.errorTiles[key].tile); 26 | }); 27 | return errotTiles; 28 | } 29 | 30 | //新增一个 错误切片 31 | FreeTile_Status.prototype.addErrorTile=function(xyz){ 32 | let id=xyz.join("-"); 33 | //只有不存在该tile,加入统计 34 | if(!this.errorTiles[id]) 35 | { 36 | this.errorTiles[id]={ 37 | tile:xyz, 38 | err_num:1 39 | }; 40 | this.errorCount++; 41 | } 42 | //错误集合已存在该tile,则计数,累计5次,判定是废弃切片请求,直接移除 43 | else{ 44 | this.errorTiles[id].err_num++; 45 | if(this.errorTiles[id].err_num==5){ 46 | delete this.errorTiles[id]; 47 | this.currentIndex++; 48 | } 49 | } 50 | this.showStatus(); 51 | } 52 | 53 | //正确处理的切片 54 | FreeTile_Status.prototype.addSuccessTile=function(xyz){ 55 | const id=xyz.join("-"); 56 | delete this.errorTiles[id]; 57 | //成功总数加1 58 | this.sucessCount++; 59 | this.currentIndex++; 60 | this.showStatus(); 61 | } 62 | 63 | 64 | 65 | FreeTile_Status.prototype.showStatus=function(){ 66 | if(this.currentIndex 0) { 72 | await Promise.all(promises); 73 | promises = []; 74 | } 75 | //执行错误补充下载 76 | errorTileTask(); 77 | } 78 | 79 | async function errorTileTask() { 80 | //如果错误切片数量为0,结束递归下载 81 | if (freetile_status.getErrorTileCount() == 0) { 82 | return; 83 | } 84 | else { 85 | let promises = []; 86 | const xyzs = freetile_status.getErrorTiles(); 87 | for (let i = 0; i < xyzs.length; i++) { 88 | promises.push(getTile2Disk(xyzs[i])); 89 | //根据访问并发设置,并发请求 90 | if (promises.length == TileConfig.parallel) { 91 | await Promise.all(promises); 92 | promises = []; 93 | } 94 | } 95 | if (promises.length > 0) { 96 | await Promise.all(promises); 97 | promises = []; 98 | } 99 | errorTileTask(); 100 | } 101 | } 102 | 103 | 104 | 105 | //切片下载 106 | function getTile2Disk(xyz) { 107 | var p = new Promise(function (resolve, reject) { 108 | //存储到本地的目录 109 | const target = `${TileConfig.downPath}/${xyz[0]}/${xyz[1]}/${xyz[2]}.${TileConfig.tileformat}`; 110 | if (fs.existsSync(target)) { 111 | freetile_status.addSuccessTile(xyz); 112 | resolve('success'); 113 | return; 114 | } 115 | //在线切片url地址 116 | let source = getTileUrl(TileConfig.mapurl, xyz, TileConfig.tokenInfo); 117 | //递归创建目录 118 | createDirs(target); 119 | const userAgent = getRandomUserAgent(); 120 | //设置一些token什么的 121 | if (!TileConfig.tokenInfo) { 122 | //从远程服务器请求 切片,写入本地磁盘文件 123 | superagent.get(source) 124 | .responseType('blob') 125 | .set(userAgent).timeout({ 126 | response: 20000, 127 | deadline: 40000, 128 | }) 129 | .retry(0) 130 | .end(getTileCallback); 131 | } 132 | else { 133 | if (TileConfig.tokenInfo.location === "url") { 134 | const token_key = TileConfig.tokenInfo.key; 135 | const token_value = getRandomToken(TileConfig.tokenInfo.values); 136 | if (source.includes('?')) 137 | source = `${source}&${token_key}=${token_value}`; 138 | else 139 | source = `${source}?${token_key}=${token_value}`; 140 | //从远程服务器请求 切片,写入本地磁盘文件 141 | superagent.get(source) 142 | .responseType('blob') 143 | .set(userAgent).timeout({ 144 | response: 30000, 145 | deadline: 60000, 146 | }) 147 | .retry(3) 148 | .end(getTileCallback); 149 | } 150 | else if (TileConfig.tokenInfo.location === "headers") { 151 | const token_key = TileConfig.tokenInfo.key; 152 | const token_value = getRandomToken(TileConfig.tokenInfo.values); 153 | //从远程服务器请求 切片,写入本地磁盘文件 154 | superagent.get(source) 155 | .responseType('blob') 156 | .set(token_key, token_value) 157 | .set(userAgent).timeout({ 158 | response: 30000, 159 | deadline: 60000, 160 | }) 161 | .retry(3) 162 | .end(getTileCallback); 163 | } 164 | } 165 | function getTileCallback(err, res) { 166 | if (err) { 167 | console.log(xyz); 168 | freetile_status.addErrorTile(xyz); 169 | reject(err); 170 | } else { 171 | if (res.status == 200) { 172 | //写入磁盘 173 | fs.writeFileSync(target, res.body); 174 | freetile_status.addSuccessTile(xyz); 175 | resolve('success'); 176 | } 177 | } 178 | } 179 | 180 | }).then(undefined, (error) => { 181 | //错误不做额外处理 182 | }); 183 | return p; 184 | } 185 | 186 | 187 | 188 | module.exports = run; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------