0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 08:21:09 +01:00

modules/media/thumbnail: Various fixes: use dynamic content; use diff endpoint; throw errors.

This commit is contained in:
Jason Volk 2018-02-27 01:42:25 -08:00
parent 34ad473bdc
commit 6f6234fd38

View file

@ -115,28 +115,35 @@ get__thumbnail_remote(client &client,
hostname hostname
}; };
const unique_buffer<mutable_buffer> in char buf[6_KiB];
{ window_buffer wb{buf};
512_KiB //TODO: XXX
};
char outbuf[3_KiB];
thread_local char uri[2_KiB]; thread_local char uri[2_KiB];
window_buffer wb{outbuf};
http::request http::request
{ {
wb, hostname, "GET", fmt::sprintf wb, hostname, "GET", fmt::sprintf
{ {
uri, "/_matrix/media/v1/thumbnail/%s/%s", hostname, mediaid uri, "/_matrix/media/r0/download/%s/%s", hostname, mediaid
} }
}; };
struct server::request::opts opts; const const_buffer out_head
opts.http_exceptions = false; {
wb.completed()
};
// Remaining space in buffer is used for received head
const mutable_buffer in_head
{
buf + size(out_head), sizeof(buf) - size(out_head)
};
// Null content buffer will cause dynamic allocation internally.
const mutable_buffer in_content{};
struct server::request::opts opts;
server::request remote_request server::request remote_request
{ {
remote, { wb.completed() }, { in }, &opts remote, { out_head }, { in_head, in_content }, &opts
}; };
if(remote_request.wait(seconds(5)) == ctx::future_status::timeout) //TODO: conf if(remote_request.wait(seconds(5)) == ctx::future_status::timeout) //TODO: conf
@ -150,12 +157,6 @@ get__thumbnail_remote(client &client,
remote_request.get() remote_request.get()
}; };
if(code != http::OK)
return resource::response
{
client, code
};
//TODO: cache add //TODO: cache add
char mime_type_buf[64]; char mime_type_buf[64];
@ -180,6 +181,6 @@ get__thumbnail_remote(client &client,
return resource::response return resource::response
{ {
client, remote_request.in.content, head.content_type client, remote_request.in.content, content_type
}; };
} }