Skip to content

Add AWS support for downloads #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This is the top-most editorconfig
root = true

[*.js]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
7 changes: 7 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"env": {
"es6": true,
"node": true
},
"extends": ["airbnb-base", "prettier"]
}
12 changes: 12 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"parser": "babel",
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
}
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is the ES6 module loader, don't edit it, go to src/app.js
require = require("esm")(module/*, options*/)
module.exports = require("./src/app.js")
require = require('esm')(module /*, options*/);
module.exports = require('./src/app.js');
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "Maxime Baconnais",
"license": "MIT",
"dependencies": {
"aws-sdk": "^2.418.0",
"color": "^3.1.0",
"cors": "^2.8.4",
"debug": "^4.0.1",
Expand All @@ -26,5 +27,11 @@
"sharp": "^0.21.2",
"sqlite3": "^4.0.2",
"uniqid": "^5.0.3"
},
"devDependencies": {
"eslint": "^5.15.1",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-import": "^2.16.0"
}
}
43 changes: 27 additions & 16 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import debug from 'debug';
const D = debug('UnicornLoadBalancer');

// Welcome
D('Version: ' + config.version)
D('Version: ' + config.version);

// Init Express
const app = express();
Expand All @@ -24,13 +24,22 @@ app.use(cors());

// Body parsing
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(
bodyParser.urlencoded({
extended: true,
}),
);
app.use((err, _, res, next) => {
if (err instanceof SyntaxError && err.status >= 400 && err.status < 500 && err.message.indexOf('JSON'))
return (res.status(400).send({ error: { code: 'INVALID_BODY', message: 'Syntax error in the JSON body' } }));
next();
if (
err instanceof SyntaxError &&
err.status >= 400 &&
err.status < 500 &&
err.message.indexOf('JSON')
)
return res.status(400).send({
error: { code: 'INVALID_BODY', message: 'Syntax error in the JSON body' },
});
next();
});

// Init routes
Expand All @@ -40,25 +49,27 @@ D('Initializing API routes...');
Router(app);

// Load servers available in configuration
((Array.isArray(config.custom.servers.list)) ? config.custom.servers.list : []).map(e => ({
(Array.isArray(config.custom.servers.list) ? config.custom.servers.list : [])
.map((e) => ({
name: e,
url: ((e.substr(-1) === '/') ? e.substr(0, e.length - 1) : e),
url: e.substr(-1) === '/' ? e.substr(0, e.length - 1) : e,
sessions: [],
settings: {
maxSessions: 0,
maxDownloads: 0,
maxTranscodes: 0
}
})).forEach(e => {
maxSessions: 0,
maxDownloads: 0,
maxTranscodes: 0,
},
}))
.forEach((e) => {
ServersManager.update(e);
});
});

// Create HTTP server
const httpServer = app.listen(config.server.port);

// Forward websockets
httpServer.on('upgrade', (req, res) => {
Proxy.ws(req, res);
Proxy.ws(req, res);
});

// Debug
Expand Down
112 changes: 64 additions & 48 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,68 @@ import env from 'getenv';
env.disableErrors();

export default {
version: '2.0.0',
server: {
port: env.int('SERVER_PORT', 3001),
public: env.string('SERVER_PUBLIC', 'http://127.0.0.1:3001/'),
host: env.string('SERVER_HOST', '127.0.0.1')
},
plex: {
host: env.string('PLEX_HOST', '127.0.0.1'),
port: env.int('PLEX_PORT', 32400),
path: {
usr: env.string('PLEX_PATH_USR', '/usr/lib/plexmediaserver/'),
sessions: env.string('PLEX_PATH_SESSIONS', '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode/Sessions/')
}
},
database: {
mode: env.string('DATABASE_MODE', 'sqlite'),
sqlite: {
path: env.string('DATABASE_SQLITE_PATH', '/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db')
},
postgresql: {
host: env.string('DATABASE_POSTGRESQL_HOST', ''),
database: env.string('DATABASE_POSTGRESQL_DATABASE', ''),
user: env.string('DATABASE_POSTGRESQL_USER', ''),
password: env.string('DATABASE_POSTGRESQL_PASSWORD', ''),
port: env.int('DATABASE_POSTGRESQL_PORT', 5432)
}
},
redis: {
host: env('REDIS_HOST', undefined),
port: env.int('REDIS_PORT', 6379),
password: env.string('REDIS_PASSWORD', ''),
db: env.int('REDIS_DB', 0)
},
custom: {
scores: {
timeout: env.int('CUSTOM_SCORES_TIMEOUT', 10)
},
image: {
resizer: env.boolish('CUSTOM_IMAGE_RESIZER', false),
proxy: env.string('CUSTOM_IMAGE_PROXY', '')
},
download: {
forward: env.boolish('CUSTOM_DOWNLOAD_FORWARD', false)
},
servers: {
list: env.array('CUSTOM_SERVERS_LIST', 'string', [])
}
}
version: '2.0.0',
server: {
port: env.int('SERVER_PORT', 3001),
public: env.string('SERVER_PUBLIC', 'http://127.0.0.1:3001/'),
host: env.string('SERVER_HOST', '127.0.0.1'),
},
aws: {
s3: {
bucket: env.string('AWS_S3_BUCKET', ''),
mountPath: env.string('AWS_S3_MOUNTPOINT', ''),
},
cloudFront: {
distributionUrl: env.string('AWS_CF_URL', ''),
keypairParameterPath: env.string('AWS_CF_KEYPAIR_SSM_PATH', ''),
},
},
plex: {
host: env.string('PLEX_HOST', '127.0.0.1'),
port: env.int('PLEX_PORT', 32400),
path: {
usr: env.string('PLEX_PATH_USR', '/usr/lib/plexmediaserver/'),
sessions: env.string(
'PLEX_PATH_SESSIONS',
'/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache/Transcode/Sessions/',
),
},
},
database: {
mode: env.string('DATABASE_MODE', 'sqlite'),
sqlite: {
path: env.string(
'DATABASE_SQLITE_PATH',
'/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-in Support/Databases/com.plexapp.plugins.library.db',
),
},
postgresql: {
host: env.string('DATABASE_POSTGRESQL_HOST', ''),
database: env.string('DATABASE_POSTGRESQL_DATABASE', ''),
user: env.string('DATABASE_POSTGRESQL_USER', ''),
password: env.string('DATABASE_POSTGRESQL_PASSWORD', ''),
port: env.int('DATABASE_POSTGRESQL_PORT', 5432),
},
},
redis: {
host: env('REDIS_HOST', undefined),
port: env.int('REDIS_PORT', 6379),
password: env.string('REDIS_PASSWORD', ''),
db: env.int('REDIS_DB', 0),
},
custom: {
scores: {
timeout: env.int('CUSTOM_SCORES_TIMEOUT', 10),
},
image: {
resizer: env.boolish('CUSTOM_IMAGE_RESIZER', false),
proxy: env.string('CUSTOM_IMAGE_PROXY', ''),
},
download: {
forward: env.boolish('CUSTOM_DOWNLOAD_FORWARD', false),
},
servers: {
list: env.array('CUSTOM_SERVERS_LIST', 'string', []),
},
},
};
Loading