Commit 2b8327e5 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

others integrations

parent 6b6689da
const express = require('express');
const app = express();
const dirTree = require('directory-tree');
const fs = require('fs');
const http = require('http');
const request = require('request');
//console.log(JSON.stringify(tree, null, 4));
function startHere() {
var download = function (uri, filename, callback) {
request.head(uri, function (err, res, body) {
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};
var tree = dirTree('/root/.config/transmission-daemon/torrents', { extensions: /\.torrent/ });
for (var i = 0; i < tree.children.length; i++) {
if (tree.children[i].type == 'file') {
var lastSegment = tree.children[i].path;
lastSegment = lastSegment.substring(lastSegment.lastIndexOf('/'));
console.log(lastSegment);
var newFileName = "/mnt1/stuff/Downloads/torrentWatch" + lastSegment.substring(0, lastSegment.lastIndexOf('.'));
console.log(newFileName);
download('http://192.168.5.3:3000/' + lastSegment, newFileName, function () {
console.log('done');
});
}
};
}
setInterval(startHere, 60000);
/* serves all the static files */
app.get(/^(.+)$/, function (req, res) {
console.log('static file request : ' + req.params);
//res.sendFile(__dirname + req.params[0]);
res.sendFile(__dirname + req.params[0]);
});
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Example app listening on port 3000!'))
\ No newline at end of file
This diff is collapsed.
...@@ -4,12 +4,20 @@ ...@@ -4,12 +4,20 @@
"description": "Easy and basic program for sharing commands and file - didactical purpose", "description": "Easy and basic program for sharing commands and file - didactical purpose",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "start": "node index.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git@git-ssh.mittelab.org:glavermi/ShareCommand.git" "url": "git@git-ssh.mittelab.org:glavermi/ShareCommand.git"
}, },
"author": "Giacomo Lavermicocca", "author": "Giacomo Lavermicocca",
"license": "ISC" "license": "ISC",
"dependencies": {
"directory-tree": "2.0.0",
"express": "4.16.2",
"request": "2.83.0"
},
"engines": {
"node": "9.2.1"
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment