-
-
Save jorgelbg/c56ce9816fd65fa74971b5ccbcfb6c73 to your computer and use it in GitHub Desktop.
nodejs-owncloud-uploader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.0.0", | |
"private": true, | |
"name": "owncloud-uploader", | |
"description": "OwnCloud uploader", | |
"repository": "https://github.com/jorgelbg/owncloud-uploader", | |
"license": "MIT", | |
"devDependencies": { | |
"bower": "^1.3.1", | |
"casperjs": "^1.1.1", | |
"http-server": "^0.6.1", | |
"karma": "^0.12.16", | |
"karma-chrome-launcher": "^0.1.4", | |
"karma-jasmine": "^0.1.5", | |
"phantomjs": "^1.9.19", | |
"protractor": "~1.0.0", | |
"shelljs": "^0.2.6", | |
"tmp": "0.0.23" | |
}, | |
"scripts": { | |
"postinstall": "bower install", | |
"prestart": "npm install", | |
"start": "http-server -a 0.0.0.0 -p 8000", | |
"pretest": "npm install", | |
"test": "node node_modules/karma/bin/karma start test/karma.conf.js", | |
"test-single-run": "node node_modules/karma/bin/karma start test/karma.conf.js --single-run", | |
"preupdate-webdriver": "npm install", | |
"update-webdriver": "webdriver-manager update", | |
"preprotractor": "npm run update-webdriver", | |
"protractor": "protractor test/protractor-conf.js", | |
"update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + cat('bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\"" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Copyright 2016 Jorge Luis Betanourt | |
* | |
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions | |
* are met: | |
* | |
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | |
* | |
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in | |
* the documentation and/or other materials provided with the distribution. | |
* | |
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived | |
* from this software without specific prior written permission. | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT | |
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
*/ | |
var fs = require('fs') | |
var args = require('system').args | |
var casper = require('casper').create({ | |
verbose: true, | |
pageSettings: { | |
webSecurityEnabled: false, | |
// resourceTimeout: 10000, | |
} | |
}); | |
const URL = 'https://correo.uci.cu/owncloud/'; | |
const USER = 'jlbetancourt'; | |
const PASSWORD = 'TestPassw0rd'; | |
if (args.length < 5) { | |
casper.echo("Usage: casperjs --ignore-ssl-errors=true script.js <dir>") | |
casper.exit(0) | |
} | |
BASEDIR = args[4] | |
if (BASEDIR[BASEDIR.length - 1] != '/') { | |
BASEDIR = BASEDIR + '/' | |
} | |
// wait 7 seconds before giving up | |
casper.options.waitTimeout = 10000000 | |
casper.onResourceTimeout = function(request) { | |
console.log('Response (#' + request.id + '): ' + JSON.stringify(request)); | |
}; | |
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X); Safari'); | |
casper.on('started', function () { | |
this.page.customHeaders = { 'Accept': '*/*' } | |
}); | |
casper.on('resource.error',function (request) { | |
this.echo('[res : id and url + error description] <-- ' + request.id + ' ' + request.url + ' ' + request.errorString); | |
}); | |
casper.start(URL, function() { | |
this.echo(this.getTitle()); | |
this.fill('form[name="login"]', { | |
user: USER, | |
password: PASSWORD | |
}, true); | |
}) | |
casper.then(function () { | |
this.echo(this.getTitle()); | |
// this.capture('pepe.png') | |
// check if are any notifications | |
var info = this.getElementInfo('#notification') | |
if (info.visible) { | |
this.echo("There is some error, probably your storage is full") | |
this.exit(-1) | |
} | |
}) | |
casper.then(function () { | |
var list = fs.list(BASEDIR) | |
for (var i = 0; i < list.length; i++) { | |
var filename = BASEDIR + list[i] | |
if (fs.isFile(filename)) { | |
this.echo(filename) | |
var info = this.getElementInfo('#notification') | |
if (info.visible) { | |
this.echo("There is some error, probably your storage is full") | |
this.exit(-1) | |
} | |
this.page.uploadFile('input[type="file"]', filename); | |
this.echo("Processing ..." + filename) | |
this.waitWhileVisible('button.stop.icon-close', function () { | |
// this.capture('pepe.png'); | |
this.echo('Done!'); | |
}) | |
} | |
} | |
}) | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment