Implement adding model by name in the webinterface like in the JavaFX
GUI
This commit is contained in:
parent
28e6313d41
commit
ccab1261dc
|
@ -8,6 +8,7 @@ import java.security.NoSuchAlgorithmException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -77,6 +78,12 @@ public class RecorderServlet extends AbstractCtbrecServlet {
|
||||||
response = "{\"status\": \"success\", \"msg\": \"Recording started\"}";
|
response = "{\"status\": \"success\", \"msg\": \"Recording started\"}";
|
||||||
resp.getWriter().write(response);
|
resp.getWriter().write(response);
|
||||||
break;
|
break;
|
||||||
|
case "startByName":
|
||||||
|
LOG.debug("Starting recording for model {}", request.model.getUrl());
|
||||||
|
startByName(request);
|
||||||
|
response = "{\"status\": \"success\", \"msg\": \"Recording started\"}";
|
||||||
|
resp.getWriter().write(response);
|
||||||
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
|
@ -223,6 +230,20 @@ public class RecorderServlet extends AbstractCtbrecServlet {
|
||||||
throw new IllegalArgumentException("No site found to record " + url);
|
throw new IllegalArgumentException("No site found to record " + url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startByName(Request request) throws InvalidKeyException, NoSuchAlgorithmException, IOException {
|
||||||
|
String[] input = request.model.getUrl().split(":");
|
||||||
|
String siteName = input[0];
|
||||||
|
String modelName = input[1];
|
||||||
|
for (Site site : sites) {
|
||||||
|
if (Objects.equals(siteName.toLowerCase(), site.getClass().getSimpleName().toLowerCase())) {
|
||||||
|
Model m = site.createModel(modelName);
|
||||||
|
recorder.startRecording(m);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalArgumentException("No site found to record " + request.model.getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
private static class Request {
|
private static class Request {
|
||||||
public String action;
|
public String action;
|
||||||
public Model model;
|
public Model model;
|
||||||
|
|
|
@ -77,13 +77,13 @@
|
||||||
<div id="alert-container"></div>
|
<div id="alert-container"></div>
|
||||||
|
|
||||||
<div class="tab-content" id="myTabContent">
|
<div class="tab-content" id="myTabContent">
|
||||||
<section id="models" class="tab-pane fade" role="tabpanel" aria-labelledby="models-tab">
|
<section id="models" class="tab-pane fade active show" role="tabpanel" aria-labelledby="models-tab">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-10 mx-auto">
|
<div class="col-lg-10 mx-auto">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="addModelByUrl">Add Model</label>
|
<label for="addModelByUrl">Add Model</label>
|
||||||
<input type="text" class="form-control" id="addModelByUrl" placeholder="URL"
|
<input type="text" class="form-control" id="addModelByUrl" placeholder="e.g. MyFreeCams:ModelName or an URL like https://chaturbate.com/modelname/"
|
||||||
onKeyUp="addModelKeyPressed(event)">
|
onKeyUp="addModelKeyPressed(event)">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -172,7 +172,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section id="configuration" class="tab-pane fade active show" role="tabpanel" aria-labelledby="configuration-tab">
|
<section id="configuration" class="tab-pane fade" role="tabpanel" aria-labelledby="configuration-tab">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<form data-bind="submit: saveConfig">
|
<form data-bind="submit: saveConfig">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -254,35 +254,41 @@
|
||||||
text: ko.observable('')
|
text: ko.observable('')
|
||||||
};
|
};
|
||||||
let hmac;
|
let hmac;
|
||||||
|
|
||||||
function addModelKeyPressed(e) {
|
function addModelKeyPressed(e) {
|
||||||
let charCode = (typeof e.which === "number") ? e.which : e.keyCode;
|
let charCode = (typeof e.which === "number") ? e.which : e.keyCode;
|
||||||
if(charCode === 13) {
|
let val = $('#addModelByUrl').val();
|
||||||
let url = $('#addModelByUrl').val();
|
if (charCode === 13) {
|
||||||
ctbrec.add(url, function() {
|
ctbrec.add(val, function() {
|
||||||
$('#addModelByUrl').val('');
|
$('#addModelByUrl').val('');
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
$('#addModelByUrl').autocomplete({
|
||||||
|
source: ["BongaCams:", "Cam4:", "Camsoda:", "Chaturbate:", "Fc2Live:", "Flirt4Free:", "LiveJasmin:", "MyFreeCams:", "Showup:", "Streamate:", "Stripchat:"]
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ctbrec = {
|
let ctbrec = {
|
||||||
add: function(modelUrl, onsuccess) {
|
add: function(input, onsuccess) {
|
||||||
try {
|
try {
|
||||||
let model = {
|
let model = {
|
||||||
type: null,
|
type: null,
|
||||||
name: '',
|
name: '',
|
||||||
url: modelUrl
|
url: input
|
||||||
};
|
};
|
||||||
|
|
||||||
if(console) console.log(model);
|
if(console) console.log(model);
|
||||||
let action = '{"action": "startByUrl", "model": ' + JSON.stringify(model) + '}';
|
let action = input.startsWith('http') ? 'startByUrl' : 'startByName';
|
||||||
|
let msg = '{"action": "' + action + '", "model": ' + JSON.stringify(model) + '}';
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type : 'POST',
|
type : 'POST',
|
||||||
url : '../rec',
|
url : '../rec',
|
||||||
dataType : 'json',
|
dataType : 'json',
|
||||||
async : true,
|
async : true,
|
||||||
timeout : 60000,
|
timeout : 60000,
|
||||||
headers : {'CTBREC-HMAC': CryptoJS.HmacSHA256(action, hmac)},
|
headers : {'CTBREC-HMAC': CryptoJS.HmacSHA256(msg, hmac)},
|
||||||
data : action
|
data : msg
|
||||||
})
|
})
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
if (data.status === 'success') {
|
if (data.status === 'success') {
|
||||||
|
|
Loading…
Reference in New Issue