Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion cute-files.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,50 @@
#!/usr/bin/env node

var spawn = require('child_process').spawn;
var bin = 'google-chrome';
var os = require('os');
var fs = require('fs');

var path = require('path');
var express = require('express');
var contentDisposition = require('content-disposition');
var pkg = require( path.join(__dirname, 'package.json') );

var scan = require('./scan');

var darwinBin = [
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
, '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'
, '/opt/homebrew-cask/Caskroom/google-chrome/stable-channel/Google Chrome.app/Contents/MacOS/Google Chrome'
, '/opt/homebrew-cask/Caskroom/google-chrome/latest/Google Chrome.app/Contents/MacOS/Google Chrome'
];
var linuxBin = [
'/usr/bin/google-chrome'
, '/usr/bin/chromium-browser'
, '/usr/bin/chromium'
];

if (os.platform() == 'darwin') {
bin = darwinBin.reduce(function (p, c) {
if (p)
return p;
return fs.existsSync(c) && c;
}, null);

if (!bin)
throw(new Error('Chrome or Canary were not found'));
}

if (os.platform() == 'linux') {
bin = linuxBin.reduce(function (p, c) {
if (p)
return p;
return fs.existsSync(c) && c;
}, null);

if (!bin)
throw(new Error('Chrome or Chromium were not found'));
}

// Parse command line options

Expand All @@ -19,6 +57,12 @@ program

var port = program.port || 3000;

var args = [
'--app=http://localhost:' + port
, '--disk-cache-size 0'
, '--no-proxy-server'
];


// Scan the directory in which the script was called. It will
// add the 'files/' prefix to all files and folders, so that
Expand Down Expand Up @@ -59,4 +103,14 @@ app.get('/scan', function(req,res){

app.listen(port);

console.log('Cute files is running on port ' + port);
console.log('Cute files is running on port ' + port);

if (process.env.HOME)
args.push('--user-data-dir=' + path.join(process.env.HOME, '.cute-files'));

if (fs.existsSync(bin))
spawn(bin, args)
.on('exit', process.exit.bind(process, 0))
.stderr.pipe(process.stderr);