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

others integrations

parent 6b6689da
Loading
Loading
Loading
Loading
+48 −0
Changes for index.js: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
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
+708 −1

File changed.

Preview size limit exceeded, changes collapsed.

+10 −2
Changes for package.json: 10 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -4,12 +4,20 @@
  "description": "Easy and basic program for sharing commands and file - didactical purpose",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
    "start": "node index.js"
  },
  "repository": {
    "type": "git",
    "url": "git@git-ssh.mittelab.org:glavermi/ShareCommand.git"
  },
  "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"
  }
}