/**
 * Created by geoffroy on 01/04/16.
 */

const {app, protocol} = require('electron');

const path     = require('path');

/* 
 *  local:// — File protocol registration
 * 
 *  This protocol allows to access the user document 
 *  directory where iolab data are stored
 */
protocol.registerFileProtocol('local',
    function(request, callback) {
        var url = request.url.substr('local'.length + 3);

        if (url.indexOf(app.getPath('documents').replace(new RegExp(/\\/, 'g'), '/') + '/IOLab-WorkFiles') < 0) {
            throw new Error('You are not authorized to access that resource!');
        }

        callback({path: path.normalize(url)});
    },
    function (error) { if (error) throw error; }
);

module.exports = {};