Skip to content

cloudcmd/node-remedy

Repository files navigation

Remedy

Emitting middleware for file removing based on socket.io and remy.

Install

npm i remedy --save

Client

Could be loaded from url /remedy/remedy.js.

/* could be one argument: callback */
remedy('/remedy', function(remover) {
    const from = '/';
    const to = '/tmp';
    const names = [
        'bin'
    ];
    const progress = (value) => {
        console.log('progress:', value);
    };
    
    const end = () => {
        console.log('end');
        remover.removeListener('progress', progress);
        remover.removeListener('end', end);
    };
    
    const error = (data) => {
        const msg = data + '\n Continue?';
        const is = confirm(msg);
        
        if (is)
            return remover.continue();
        
        remover.abort();
    };
    
    remover(from, names);
    
    remover.on('progress', progress);
    remover.on('end', end);
    remover.on('error', error);
});

Server

const remedy = require('remedy');
const http = require('http');
const express = require('express');
const io = require('socket.io');
const app = express();
const port = 1337;
const server = http.createServer(app);
const socket = io.listen(server);

server.listen(port);

app.use(remedy({
    online: true,
    authCheck: function(socket, success) {
    }
});

remedy.listen(socket, {
    prefix: '/remedy',  /* default              */
    root: '/',          /* string or function   */
});

License

MIT