Add input field to add models by URL
This commit is contained in:
parent
2417ee0069
commit
1e5eff780c
|
@ -36,7 +36,7 @@ public class ModelJsonAdapter extends JsonAdapter<Model> {
|
||||||
String name = null;
|
String name = null;
|
||||||
String description = null;
|
String description = null;
|
||||||
String url = null;
|
String url = null;
|
||||||
String type = null;
|
Object type = null;
|
||||||
int streamUrlIndex = -1;
|
int streamUrlIndex = -1;
|
||||||
boolean suspended = false;
|
boolean suspended = false;
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ public class ModelJsonAdapter extends JsonAdapter<Model> {
|
||||||
url = reader.nextString();
|
url = reader.nextString();
|
||||||
model.setUrl(url);
|
model.setUrl(url);
|
||||||
} else if(key.equals("type")) {
|
} else if(key.equals("type")) {
|
||||||
type = reader.nextString();
|
type = reader.readJsonValue();
|
||||||
Class<?> modelClass = Class.forName(Optional.ofNullable(type).orElse(ChaturbateModel.class.getName()));
|
Class<?> modelClass = Class.forName(Optional.ofNullable(type).orElse(ChaturbateModel.class.getName()).toString());
|
||||||
model = (Model) modelClass.getDeclaredConstructor().newInstance();
|
model = (Model) modelClass.getDeclaredConstructor().newInstance();
|
||||||
} else if(key.equals("streamUrlIndex")) {
|
} else if(key.equals("streamUrlIndex")) {
|
||||||
streamUrlIndex = reader.nextInt();
|
streamUrlIndex = reader.nextInt();
|
||||||
|
|
|
@ -13,6 +13,7 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -70,6 +71,12 @@ public class RecorderServlet extends AbstractCtbrecServlet {
|
||||||
String response = "{\"status\": \"success\", \"msg\": \"Recording started\"}";
|
String response = "{\"status\": \"success\", \"msg\": \"Recording started\"}";
|
||||||
resp.getWriter().write(response);
|
resp.getWriter().write(response);
|
||||||
break;
|
break;
|
||||||
|
case "startByUrl":
|
||||||
|
LOG.debug("Starting recording for model {}", request.model.getUrl());
|
||||||
|
startByUrl(request);
|
||||||
|
response = "{\"status\": \"success\", \"msg\": \"Recording started\"}";
|
||||||
|
resp.getWriter().write(response);
|
||||||
|
break;
|
||||||
case "stop":
|
case "stop":
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
|
@ -174,8 +181,10 @@ public class RecorderServlet extends AbstractCtbrecServlet {
|
||||||
}
|
}
|
||||||
} catch(Throwable t) {
|
} catch(Throwable t) {
|
||||||
resp.setStatus(SC_INTERNAL_SERVER_ERROR);
|
resp.setStatus(SC_INTERNAL_SERVER_ERROR);
|
||||||
String response = "{\"status\": \"error\", \"msg\": \"An unexpected error occured\"}";
|
JSONObject response = new JSONObject();
|
||||||
resp.getWriter().write(response);
|
response.put("status", "error");
|
||||||
|
response.put("msg", t.getMessage());
|
||||||
|
resp.getWriter().write(response.toString());
|
||||||
LOG.error("Unexpected error", t);
|
LOG.error("Unexpected error", t);
|
||||||
if (json != null) {
|
if (json != null) {
|
||||||
LOG.debug("Request: {}", json);
|
LOG.debug("Request: {}", json);
|
||||||
|
@ -183,6 +192,16 @@ public class RecorderServlet extends AbstractCtbrecServlet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startByUrl(Request request) throws InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, IOException {
|
||||||
|
String url = request.model.getUrl();
|
||||||
|
for (Site site : sites) {
|
||||||
|
Model model = site.createModelFromUrl(url);
|
||||||
|
if (model != null) {
|
||||||
|
recorder.startRecording(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class Request {
|
private static class Request {
|
||||||
public String action;
|
public String action;
|
||||||
public Model model;
|
public Model model;
|
||||||
|
|
|
@ -76,8 +76,17 @@
|
||||||
<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="col-lg-10 mx-auto">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="addModelByUrl">Add Model</label>
|
||||||
|
<input type="text" class="form-control" id="addModelByUrl" placeholder="URL"
|
||||||
|
onKeyUp="addModelKeyPressed(event)">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-10 mx-auto">
|
<div class="col-lg-10 mx-auto">
|
||||||
<p class="lead"></p>
|
<p class="lead"></p>
|
||||||
|
@ -107,11 +116,11 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section id="recordings" class="tab-pane fade active show" role="tabpanel" aria-labelledby="recordings-tab">
|
<section id="recordings" class="tab-pane fade" role="tabpanel" aria-labelledby="recordings-tab">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-4 mx-auto">
|
<div class="col-lg-4 mx-auto">
|
||||||
Space left
|
Space left: <span data-bind="text: space.text()"></span>
|
||||||
<div class="progress">
|
<div class="progress">
|
||||||
<div class="progress-bar progress-bar-striped" role="progressbar" aria-valuemin="0"
|
<div class="progress-bar progress-bar-striped" role="progressbar" aria-valuemin="0"
|
||||||
data-bind="attr: {'aria-valuemax': space.total, 'aria-valuenow': space.free},
|
data-bind="attr: {'aria-valuemax': space.total, 'aria-valuenow': space.free},
|
||||||
|
@ -211,10 +220,54 @@
|
||||||
let space = {
|
let space = {
|
||||||
free: ko.observable(0),
|
free: ko.observable(0),
|
||||||
total: ko.observable(0),
|
total: ko.observable(0),
|
||||||
percent: ko.observable(0)
|
percent: ko.observable(0),
|
||||||
|
text: ko.observable('')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function addModelKeyPressed(e) {
|
||||||
|
let charCode = (typeof e.which === "number") ? e.which : e.keyCode;
|
||||||
|
if(charCode === 13) {
|
||||||
|
let url = $('#addModelByUrl').val();
|
||||||
|
ctbrec.add(url, function() {
|
||||||
|
$('#addModelByUrl').val('');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let ctbrec = {
|
let ctbrec = {
|
||||||
|
add: function(modelUrl, onsuccess) {
|
||||||
|
try {
|
||||||
|
let model = {
|
||||||
|
type: null,
|
||||||
|
name: '',
|
||||||
|
url: modelUrl
|
||||||
|
};
|
||||||
|
console.log(model);
|
||||||
|
$.ajax({
|
||||||
|
type : 'POST',
|
||||||
|
url : '/rec',
|
||||||
|
dataType : 'json',
|
||||||
|
async : true,
|
||||||
|
timeout : 60000,
|
||||||
|
data : '{"action": "startByUrl", "model": ' + JSON.stringify(model) + '}'
|
||||||
|
})
|
||||||
|
.done(function(data) {
|
||||||
|
if (data.status === 'success') {
|
||||||
|
onsuccess.call(data);
|
||||||
|
$.notify('Model added', 'info');
|
||||||
|
} else {
|
||||||
|
$.notify('Adding model failed', 'error');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function(jqXHR, textStatus, errorThrown) {
|
||||||
|
console.log(textStatus, errorThrown);
|
||||||
|
$.notify('Adding model failed', 'error');
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Unexpected error', e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
resume: function(model) {
|
resume: function(model) {
|
||||||
try {
|
try {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -618,6 +671,7 @@
|
||||||
space.total(data.spaceTotal);
|
space.total(data.spaceTotal);
|
||||||
space.free(data.spaceFree);
|
space.free(data.spaceFree);
|
||||||
space.percent( (data.spaceFree/data.spaceTotal*100).toFixed(2) );
|
space.percent( (data.spaceFree/data.spaceTotal*100).toFixed(2) );
|
||||||
|
space.text(calculateSize(data.spaceFree) + ' / ' + calculateSize(data.spaceTotal));
|
||||||
} else {
|
} else {
|
||||||
console.log('request failed', data);
|
console.log('request failed', data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue