-
Notifications
You must be signed in to change notification settings - Fork 3
/
beetwerk.js
106 lines (80 loc) · 2.55 KB
/
beetwerk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"use strict";
/*
TODO: check for required programs:
exiftool
youtube-dl (or don't provide the option!)
ffmpeg
*/
var fs = require("fs");
process.chdir(__dirname); // cd to this file's directory
var server = require("./server/server.js");
var other = require("./server/other.js");
var cp = require("child_process");
// create a default config
var home = process.env.HOME;
var config_path = home+"/.config/beetwerk/config.js";
if(!fs.existsSync(config_path))
{
other.mkdir(home+"/.config");
other.mkdir(home+"/.config/beetwerk");
other.copy("./config.sample.js", config_path);
console.log("Created the default config!");
}
// Load the config
var config;
try {config = require(config_path);} catch(e){}
// Check if it still has the default settings
if(config && config.tempdir == require("./config.sample").tempdir)
{
console.log("Please configure your beetwerk installation:");
console.log("\t"+config_path);
process.exit(1);
}
// Check if it has been loaded properly
try
{
config.port;
config.tempdir;
config.binary;
config.meta.album.required;
config.meta.album.optional;
config.meta.file.required;
config.meta.file.optional;
}
catch(e)
{
console.log("You fucked up the config, dude. Fix it and try again.");
console.log("\t"+config_path);
process.exit(1);
}
// In case an exception gets thrown, keep the server running
// and print an error message on the terminal. This probably
// happens, when the network connection goes down.
// Related bug: https://github.com/Bytewerk/beetwerk/issues/4
process.on("uncaughtException", function (e)
{
console.error("----------------------------------------------");
console.error(new Date());
console.error("Unhandled exception, did the network go down?");
console.error("This is probably related to this bug:")
console.error("=> http://tinyurl.com/bw-netcrash");
console.error("Please leave a comment there with the output below.");
console.error("");
console.error("Type: " + e.type);
console.error(e.stack);
console.error("----------------------------------------------");
});
server.run(config);
// get the default beets config path and add it to the beets config
cp.execFile(config.binary, ["config", "--default", "--path"], null, function(error,stdout,stderr)
{
config.beet_default_cfg = stdout.split("\n")[1];
if(!config.beet_default_cfg)
{
console.error("ERROR: Couldn't find beets default config!");
console.error("Verify that beets is installed and working and");
console.error("check your config.binary in the config file:");
console.error("\t"+config_path);
process.exit();
}
});