atm3-command-uploadcdn
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -20,3 +20,3 @@ 'use strict'; | ||
var _uploadCdn = require('uploadCdn'); | ||
var _uploadCdn = require('./uploadCdn'); | ||
@@ -39,3 +39,3 @@ var _uploadCdn2 = _interopRequireDefault(_uploadCdn); | ||
distPath = '/2015/market/allanyu/life', | ||
filePath = options.file; | ||
filePath = options.file && _path2.default.resolve(options.file); | ||
@@ -46,4 +46,4 @@ if (!filePath && !distPath) { | ||
} | ||
fis.log.info("options path: ", options.path, ", file: ", options.file); | ||
(0, _uploadCdn2.default)(filePath, distPath, null, function (filesURL) { | ||
fis.log.info("options path: ", options.path, ", file: ", _path2.default.resolve(options.file)); | ||
(0, _uploadCdn2.default)(filePath, distPath, 'allanyu', function (filesURL) { | ||
fis.log.info("upload cdn completed: filesURL=", filesURL); | ||
@@ -50,0 +50,0 @@ }); |
'use strict'; | ||
var fs = require('fs'), | ||
qs = require('querystring'), | ||
http = require('http'), | ||
path = require('path'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var UPLOAD_HOST = 'up.cdn.qq.com', | ||
UPLOAD_PORT = '8600', | ||
UPLOAD_PATH = '/uploadserver/uploadfile.jsp'; | ||
module.exports = function (file_path, server_path, username, callback) { | ||
exports.default = function (file_path, server_path, username, callback) { | ||
var filesArray = []; | ||
@@ -20,6 +15,6 @@ | ||
var fileMapping = function fileMapping(path) { | ||
var files = fs.readdirSync(path); | ||
var files = _fs2.default.readdirSync(path); | ||
files.forEach(function (file) { | ||
var tempPath = path + '/' + file; | ||
var stats = fs.statSync(tempPath); | ||
var stats = _fs2.default.statSync(tempPath); | ||
if (stats.isDirectory()) { | ||
@@ -45,3 +40,3 @@ fileMapping(tempPath); | ||
var content = fs.readFileSync(file.apath); | ||
var content = _fs2.default.readFileSync(file.apath); | ||
@@ -57,4 +52,4 @@ var options = { | ||
}; | ||
var req = http.request(options, function (res) { | ||
log.debug('start uploading file: ' + file.apath + ', http options: ', options); | ||
var req = _http2.default.request(options, function (res) { | ||
res.setEncoding('utf-8'); | ||
@@ -66,2 +61,3 @@ res.on('data', function (chunk) { | ||
data = JSON.parse(data); | ||
log.debug('upload completed! result = ', data); | ||
if (data["ret_code"] == 200) { | ||
@@ -79,3 +75,3 @@ var basename_ext = file.name + '.' + file.type; | ||
res.on('error', function (err) { | ||
console.log(err.message); | ||
log.error('upload error happend! error = ', err.stack || err.message || err); | ||
}); | ||
@@ -85,2 +81,5 @@ }); | ||
req.end(content, 'binary'); | ||
req.on('error', function (err) { | ||
log.error('upload request error happened! error=', err); | ||
}); | ||
}; | ||
@@ -104,4 +103,4 @@ var upToServer = function upToServer() { | ||
query.filesize = file.size; | ||
query_str = qs.stringify(query); | ||
console.log(query_str); | ||
query_str = _querystring2.default.stringify(query); | ||
log.debug('query string for ' + file.rpath + ' >> ' + query_str); | ||
post(query_str, file); | ||
@@ -116,2 +115,28 @@ }); | ||
init(); | ||
}; | ||
}; | ||
var _fs = require('fs'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _querystring = require('querystring'); | ||
var _querystring2 = _interopRequireDefault(_querystring); | ||
var _http = require('http'); | ||
var _http2 = _interopRequireDefault(_http); | ||
var _path = require('path'); | ||
var _path2 = _interopRequireDefault(_path); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var UPLOAD_HOST = 'up.cdn.qq.com', | ||
UPLOAD_PORT = '8600', | ||
UPLOAD_PATH = '/uploadserver/uploadfile.jsp'; | ||
var log = global.fis.log; | ||
; |
{ | ||
"name": "atm3-command-uploadcdn", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "atm3 command upload files to cdn server", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import fs from 'fs' | ||
import path from 'path' | ||
import request from 'request' | ||
import uploadCdn from 'uploadCdn' | ||
import uploadCdn from './uploadCdn' | ||
@@ -19,3 +19,3 @@ export const name = 'uploadcdn'; | ||
distPath = '/2015/market/allanyu/life', | ||
filePath = options.file; | ||
filePath = options.file && path.resolve(options.file); | ||
@@ -26,4 +26,4 @@ if (!filePath && !distPath) { | ||
} | ||
fis.log.info("options path: ", options.path, ", file: ", options.file); | ||
uploadCdn(filePath, distPath, null, (filesURL) => { | ||
fis.log.info("options path: ", options.path, ", file: ", path.resolve(options.file)); | ||
uploadCdn(filePath, distPath, 'allanyu', (filesURL) => { | ||
fis.log.info("upload cdn completed: filesURL=", filesURL); | ||
@@ -30,0 +30,0 @@ }); |
@@ -0,12 +1,14 @@ | ||
import fs from 'fs' | ||
import qs from 'querystring' | ||
import http from 'http' | ||
import path from 'path' | ||
var fs =require('fs'), | ||
qs = require('querystring'), | ||
http = require('http'), | ||
path = require('path'); | ||
var UPLOAD_HOST = 'up.cdn.qq.com', | ||
const | ||
UPLOAD_HOST = 'up.cdn.qq.com', | ||
UPLOAD_PORT = '8600', | ||
UPLOAD_PATH = '/uploadserver/uploadfile.jsp'; | ||
module.exports = function(file_path, server_path, username, callback){ | ||
const log = global.fis.log; | ||
export default function (file_path, server_path, username, callback) { | ||
var filesArray = []; | ||
@@ -18,8 +20,8 @@ | ||
var fileMapping = function(path){ | ||
var fileMapping = function (path) { | ||
var files = fs.readdirSync(path); | ||
files.forEach(function(file){ | ||
files.forEach(function (file) { | ||
var tempPath = path + '/' + file; | ||
var stats = fs.statSync(tempPath); | ||
if(stats.isDirectory()){ | ||
if (stats.isDirectory()) { | ||
fileMapping(tempPath); | ||
@@ -40,3 +42,3 @@ } else { | ||
}; | ||
var post = function(querystring, file){ | ||
var post = function (querystring, file) { | ||
var path = UPLOAD_PATH + '?' + querystring, | ||
@@ -56,11 +58,12 @@ data = ''; | ||
}; | ||
var req = http.request(options, function(res){ | ||
log.debug(`start uploading file: ${file.apath}, http options: `, options); | ||
var req = http.request(options, function (res) { | ||
res.setEncoding('utf-8'); | ||
res.on('data', function(chunk){ | ||
res.on('data', function (chunk) { | ||
data += chunk; | ||
}); | ||
res.on('end', function(){ | ||
res.on('end', function () { | ||
data = JSON.parse(data); | ||
if(data["ret_code"] == 200){ | ||
log.debug(`upload completed! result = `, data); | ||
if (data["ret_code"] == 200) { | ||
var basename_ext = file.name + '.' + file.type; | ||
@@ -72,8 +75,8 @@ filesURL[basename_ext] = data["cdn_url"]; | ||
post_counter++; | ||
if(post_counter == filesArray.length){ | ||
if (post_counter == filesArray.length) { | ||
callback && callback(filesURL); | ||
} | ||
}); | ||
res.on('error', function(err){ | ||
console.log(err.message); | ||
res.on('error', function (err) { | ||
log.error(`upload error happend! error = `, err.stack || err.message || err); | ||
}); | ||
@@ -83,4 +86,7 @@ }); | ||
req.end(content, 'binary'); | ||
req.on('error', err => { | ||
log.error(`upload request error happened! error=`, err); | ||
}) | ||
}; | ||
var upToServer = function(){ | ||
var upToServer = function () { | ||
var totals = filesArray.length; | ||
@@ -95,3 +101,3 @@ var query = { | ||
}; | ||
filesArray.forEach(function(file){ | ||
filesArray.forEach(function (file) { | ||
var query_str = ''; | ||
@@ -104,7 +110,7 @@ | ||
query_str = qs.stringify(query); | ||
console.log(query_str); | ||
log.debug(`query string for ${file.rpath} >> ${query_str}`); | ||
post(query_str, file); | ||
}); | ||
}; | ||
var init = function(){ | ||
var init = function () { | ||
fileMapping(file_path); | ||
@@ -111,0 +117,0 @@ upToServer(); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14515
326