mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 23:40:57 +01:00
modules/media/thumbnail: Implement uncached width and height scale thumbnailing.
closes #40.
This commit is contained in:
parent
21ca583a2b
commit
d156965271
1 changed files with 42 additions and 18 deletions
|
@ -138,17 +138,16 @@ get__thumbnail_local(client &client,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send HTTP head to client
|
const unique_buffer<mutable_buffer> buf
|
||||||
const resource::response response
|
|
||||||
{
|
{
|
||||||
client, http::OK, content_type, file_size
|
file_size
|
||||||
};
|
};
|
||||||
|
|
||||||
size_t sent_size{0};
|
size_t copied(0);
|
||||||
const auto sink{[&client, &sent_size]
|
const auto sink{[&buf, &copied]
|
||||||
(const const_buffer &block)
|
(const const_buffer &block)
|
||||||
{
|
{
|
||||||
sent_size += client.write_all(block);
|
copied += copy(buf + copied, block);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
const size_t read_size
|
const size_t read_size
|
||||||
|
@ -156,20 +155,45 @@ get__thumbnail_local(client &client,
|
||||||
read_each_block(room, sink)
|
read_each_block(room, sink)
|
||||||
};
|
};
|
||||||
|
|
||||||
if(unlikely(read_size != file_size)) log::error
|
if(unlikely(read_size != file_size || file_size != copied))
|
||||||
|
throw ircd::error
|
||||||
|
{
|
||||||
|
"File %s/%s [%s] size mismatch: expected %zu got %zu copied %zu",
|
||||||
|
hostname,
|
||||||
|
mediaid,
|
||||||
|
string_view{room.room_id},
|
||||||
|
file_size,
|
||||||
|
read_size,
|
||||||
|
copied
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto width
|
||||||
{
|
{
|
||||||
media_log, "File %s/%s [%s] size mismatch: expected %zu got %zu",
|
request.query.get<size_t>("width", 0)
|
||||||
hostname,
|
|
||||||
mediaid,
|
|
||||||
string_view{room.room_id},
|
|
||||||
file_size,
|
|
||||||
read_size
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Have to kill client here after failing content length expectation.
|
const auto height
|
||||||
if(unlikely(read_size != file_size))
|
{
|
||||||
client.close(net::dc::RST, net::close_ignore);
|
request.query.get<size_t>("height", 0)
|
||||||
|
};
|
||||||
|
|
||||||
assert(read_size == sent_size);
|
if(!width || !height || width > 1536 || height > 1536) // TODO: confs..
|
||||||
return response;
|
return resource::response
|
||||||
|
{
|
||||||
|
client, buf, content_type
|
||||||
|
};
|
||||||
|
|
||||||
|
magick::thumbnail
|
||||||
|
{
|
||||||
|
buf, {width, height}, [&client, &content_type]
|
||||||
|
(const const_buffer &buf)
|
||||||
|
{
|
||||||
|
resource::response
|
||||||
|
{
|
||||||
|
client, buf, content_type
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue