-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
288 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
node_modules | ||
env.sh | ||
public/javascripts/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,79 @@ | ||
/* API for running shell scripts */ | ||
|
||
const { spawn } = require('child_process') | ||
|
||
class API { | ||
addClients() {} | ||
removeClients() {} | ||
exec(script, args, callback) { | ||
const proc = spawn(script, args) | ||
|
||
let stdout = '' | ||
let stderr = '' | ||
|
||
proc.stdout.on('data', data => (stdout += String(data))) | ||
proc.stderr.on('data', data => (stderr += String(data))) | ||
|
||
proc.on('close', code => { | ||
if (code !== 0) return callback(stderr.trim()) | ||
return callback(null, stdout.trim()) | ||
}) | ||
} | ||
|
||
addClients(rpcPorts, transmissionPorts, callback) { | ||
let args = [] | ||
args = rpcPorts.reduce((acc, port) => acc.concat(['-p', port]), args) | ||
args = transmissionPorts.reduce((acc, port) => acc.concat(['-P', port]), args) | ||
|
||
this.exec(process.env.SCRIPT_CREATE_CLIENTS, args, callback) | ||
} | ||
|
||
removeClients(rpcPorts, callback) { | ||
const args = rpcPorts.reduce((acc, port) => acc.concat(['-p', port]), []) | ||
this.exec(process.env.SCRIPT_REMOVE_CLIENTS, args, callback) | ||
} | ||
|
||
startClients() {} | ||
stopClients() {} | ||
startClients(rpcPorts, callback) { | ||
const args = rpcPorts.reduce((acc, port) => acc.concat(['-p', port]), []) | ||
this.exec(process.env.SCRIPT_START_CLIENTS, args, callback) | ||
} | ||
|
||
addTorrents() {} | ||
createTorrent() {} | ||
removeTorrents() {} | ||
stopClients(rpcPorts, callback) { | ||
const args = rpcPorts.reduce((acc, port) => acc.concat(['-p', port]), []) | ||
this.exec(process.env.SCRIPT_STOP_CLIENTS, args, callback) | ||
} | ||
|
||
createTorrent(fileName, callback) { | ||
this.exec(process.env.SCRIPT_CREATE_TORRENT, [fileName], callback) | ||
} | ||
|
||
addTorrents(rpcPorts, torrents, callback) { | ||
let args = [] | ||
args = rpcPorts.reduce((acc, port) => acc.concat(['-p', port]), args) | ||
args = torrents.reduce((acc, port) => acc.concat(['-t', port]), args) | ||
|
||
this.exec(process.env.SCRIPT_ADD_TORRENTS, args, callback) | ||
} | ||
|
||
removeTorrents(rpcPorts, torrents, callback) { | ||
let args = [] | ||
args = rpcPorts.reduce((acc, port) => acc.concat(['-p', port]), args) | ||
args = torrents.reduce((acc, port) => acc.concat(['-t', port]), args) | ||
|
||
this.exec(process.env.SCRIPT_REMOVE_TORRENTS, args, callback) | ||
} | ||
} | ||
|
||
// const callback = (err, data) => { | ||
// if (err) return console.log('ERR!', err) | ||
// console.log(data) | ||
// } | ||
|
||
// const api = new API() | ||
// api.addClients([9091, 9092], [5111, 5222], callback) | ||
// api.removeClients([9091, 9092], callback) | ||
// api.startClients([9091, 9092], callback) | ||
// api.stopClients([9091, 9092], callback) | ||
// api.addTorrents([9091, 9092], ['torrent-1', 'torrent-2'], callback) | ||
// api.removeTorrents([9091, 9092], ['torrent-1', 'torrent-2'], callback) | ||
// api.createTorrent('foo', callback) | ||
|
||
module.exports = new API() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = | ||
"DROP TABLE IF EXISTS `clients`; \ | ||
CREATE TABLE `clients` ( \ | ||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, \ | ||
`name` varchar(255) COLLATE utf8mb4_unicode_520_ci NOT NULL, \ | ||
`rpc_port` bigint(20) unsigned NOT NULL, \ | ||
`transmission_port` bigint(20) unsigned NOT NULL, \ | ||
`active` tinyint(1) DEFAULT '0', \ | ||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, \ | ||
PRIMARY KEY (`id`), \ | ||
UNIQUE KEY `rcp_port` (`rpc_port`), \ | ||
UNIQUE KEY `transmission_port` (`transmission_port`) \ | ||
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = | ||
"DROP TABLE IF EXISTS `ports`; \ | ||
CREATE TABLE `ports` ( \ | ||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, \ | ||
`rpc_port` bigint(20) unsigned NOT NULL, \ | ||
`transmission_port` bigint(20) unsigned NOT NULL, \ | ||
`available` tinyint(1) DEFAULT '1', \ | ||
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, \ | ||
PRIMARY KEY (`id`) \ | ||
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#! /bin/bash | ||
|
||
# echo "$@" | ||
|
||
# sleep 3 | ||
cmd="ls . > /dev/null 2>&1" | ||
if eval "$cmd"; then | ||
echo "$(jq -n '{ error: null, data: {} }')" | ||
else | ||
echo "ERR" | ||
fi |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// eslint-disable-next-line no-extra-semi | ||
;(function($) { | ||
function request(url, type, data) { | ||
return $.post({ | ||
url, | ||
type, | ||
data, | ||
success: data => console.log(data), | ||
error: (xhr, status, text) => console.log(status, text) | ||
}) | ||
} | ||
|
||
function run() { | ||
// request('/api/v1/clients/add', 'POST', { | ||
// n: 2 | ||
// }) | ||
request('/api/v1/clients/remove', 'POST', { | ||
ports: [9091, 9092] | ||
}) | ||
} | ||
|
||
$(function() { | ||
run() | ||
}) | ||
})(jQuery) |
Oops, something went wrong.