Commit a23841b1 authored by dns2utf8's avatar dns2utf8

Respect 64kB FrameSize and implement resize

parent e2247ebd
......@@ -250,7 +250,7 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for Ws {
actix::Handler::handle(self, message, ctx);
}
_invalid => {
ctx.text("\"invalid request\"".to_string());
ctx.text(format!("{{\"invalid request\":{:?}}}", _invalid));
}
}
},
......
......@@ -48,28 +48,34 @@ fn main() {
println!("binding to https://{}", bind_addr);
server::HttpServer::new(move || {
App::with_state((incrementor.clone(), hub.clone()))
.resource("/ws/", |r| r.f(|req| {
/*
*req.state()
.send(GetId)
.into_actor(&req.address())
.then(|id: Result<NewId, _>, act, ctx| {
let id = id.unwrap().0;
ws::start(&req.drop_state(), Ws { id })
})
//.map_err(Error::from)
// */
//*
let (incrementor, hub) = req.state();
ws::start(
&req.drop_state(),
Ws {
id: incrementor.lock().unwrap().increment(),
hub: hub.clone(),
is_pod: false,
},
) // */
}))
.resource("/ws/", |r| {
r
/*.with_config(|cfg| {
cfg.limit(1024*1024);
})*/
.f(|req| {
/*
*req.state()
.send(GetId)
.into_actor(&req.address())
.then(|id: Result<NewId, _>, act, ctx| {
let id = id.unwrap().0;
ws::start(&req.drop_state(), Ws { id })
})
//.map_err(Error::from)
// */
//*
let (incrementor, hub) = req.state();
ws::start(
&req.drop_state(),
Ws {
id: incrementor.lock().unwrap().increment(),
hub: hub.clone(),
is_pod: false,
},
) // */
})
})
.handler(
"/",
fs::StaticFiles::new("static/")
......
......@@ -8,7 +8,7 @@ setup_ws();
WebSocket.prototype.send_object = function(obj) {
const str = JSON.stringify(obj);
html_logger('> ' + str);
html_logger('> ' + str.substr(0, 256));
return this.send(str);
}
......@@ -60,8 +60,8 @@ function setup_ws() {
}
ws.onmessage = msg => {
log(msg.data.substr(0, 32));
html_logger('< ' + msg.data.substr(0, 128));
log(msg.data.substr(0, 42));
html_logger('< ' + msg.data.substr(0, 256));
const data = JSON.parse(msg.data);
if (typeof data.ClientResponse !== 'undefined') {
Gallery.message_handler(data.ClientResponse);
......
......@@ -51,6 +51,10 @@ function message_handler(message) {
// TODO send an error: ws.send_object()
console.error(["no candidate found for path", path])
} else {
if (!candidate.blob) {
console.error(['candidate missing blob', candidate]);
debugger;
}
ws.send_object({"PodRequest":{
"DeliverImage":{
"client_id": client_id,
......@@ -137,11 +141,49 @@ function normalized_title() {
function regenPreview() {
const preview = document.querySelector('#pod_preview div');
const event_to_src = (function(aImg, file_handler) {
const MAX_BLOB_LENGTH = 64*1024;
function try_thumb(target_size, original, file_handler) {
const img = new Image();
img.onload = function() {
console.log("resize to "+target_size);
const width = Math.min(target_size, img.naturalWidth);
const height = Math.min(target_size, img.naturalHeight);
console.log([width, height]);
const canvas = document.createElement("canvas")
, ctx = canvas.getContext("2d");
canvas.width = width;
canvas.height= height;
// draw the img into canvas
ctx.drawImage(this, 0, 0, width, height);
const blob = canvas.toDataURL("image/jpeg");
if (blob.length > MAX_BLOB_LENGTH) {
target_size /= 2;
try_thumb(target_size, original, file_handler);
console.log("retry");
} else {
aImg.src = blob;
// backup into RAM
file_handler.blob = blob;
console.log("hurray compressed");
}
};
img.src = original;
}
return function(e) {
aImg.src = e.target.result;
// backup into RAM
if (file_handler.blob === undefined) {
file_handler.blob = e.target.result;
const original = e.target.result;
if (original.length > MAX_BLOB_LENGTH) {
const target_size = 512;
try_thumb(target_size, original, file_handler);
} else {
console.log("no resize");
aImg.src = original;
// backup into RAM
file_handler.blob = original;
}
};
});
......
......@@ -15,6 +15,7 @@
#galleries ul li:active { background: rgba(255, 128, 128, 0.3); }
#galleries div { display: flex; flex-flow: row wrap; }
#galleries div div { display: flex; flex-flow: column nowrap; }
.selected { background: yellow; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment