mirror of
https://github.com/matrix-construct/construct
synced 2024-11-15 22:41:12 +01:00
modules/media: Convey a user_id through the download stack for the file room.
This commit is contained in:
parent
9af649f739
commit
e6a204263e
6 changed files with 35 additions and 10 deletions
|
@ -4589,6 +4589,7 @@ console_cmd__file__download(opt &out, const string_view &line)
|
|||
|
||||
using prototype = m::room::id::buf (const string_view &server,
|
||||
const string_view &file,
|
||||
const m::user::id &,
|
||||
const net::hostport &remote);
|
||||
|
||||
static m::import<prototype> download
|
||||
|
@ -4598,7 +4599,7 @@ console_cmd__file__download(opt &out, const string_view &line)
|
|||
|
||||
const m::room::id::buf room_id
|
||||
{
|
||||
download(server, file, remote)
|
||||
download(server, file, m::me.user_id, remote)
|
||||
};
|
||||
|
||||
out << room_id << std::endl;
|
||||
|
|
|
@ -57,9 +57,18 @@ get__download(client &client,
|
|||
request.parv[1]
|
||||
};
|
||||
|
||||
// Download doesn't require auth so if there is no user_id detected
|
||||
// then we download on behalf of @ircd.
|
||||
const m::user::id &user_id
|
||||
{
|
||||
request.user_id?
|
||||
m::user::id{request.user_id}:
|
||||
m::me.user_id
|
||||
};
|
||||
|
||||
const m::room::id::buf room_id
|
||||
{
|
||||
download(server, file)
|
||||
download(server, file, user_id)
|
||||
};
|
||||
|
||||
return get__download_local(client, request, server, file, room_id);
|
||||
|
|
|
@ -31,6 +31,7 @@ downloading_dock;
|
|||
m::room::id::buf
|
||||
download(const string_view &server,
|
||||
const string_view &mediaid,
|
||||
const m::user::id &user_id,
|
||||
const net::hostport &remote)
|
||||
{
|
||||
const m::room::id::buf room_id
|
||||
|
@ -38,13 +39,14 @@ download(const string_view &server,
|
|||
file_room_id(server, mediaid)
|
||||
};
|
||||
|
||||
download(server, mediaid, remote, room_id);
|
||||
download(server, mediaid, user_id, remote, room_id);
|
||||
return room_id;
|
||||
}
|
||||
|
||||
m::room
|
||||
download(const string_view &server,
|
||||
const string_view &mediaid,
|
||||
const m::user::id &user_id,
|
||||
const net::hostport &remote,
|
||||
const m::room::id &room_id)
|
||||
try
|
||||
|
@ -115,11 +117,11 @@ try
|
|||
room_id, &vmopts
|
||||
};
|
||||
|
||||
create(room, m::me.user_id, "file");
|
||||
create(room, user_id, "file");
|
||||
|
||||
const size_t written
|
||||
{
|
||||
write_file(room, content, content_type)
|
||||
write_file(room, user_id, content, content_type)
|
||||
};
|
||||
|
||||
return room;
|
||||
|
@ -197,17 +199,18 @@ download(const mutable_buffer &head_buf,
|
|||
|
||||
size_t
|
||||
write_file(const m::room &room,
|
||||
const m::user::id &user_id,
|
||||
const const_buffer &content,
|
||||
const string_view &content_type)
|
||||
{
|
||||
//TODO: TXN
|
||||
send(room, m::me.user_id, "ircd.file.stat", "size",
|
||||
send(room, user_id, "ircd.file.stat", "size",
|
||||
{
|
||||
{ "value", long(size(content)) }
|
||||
});
|
||||
|
||||
//TODO: TXN
|
||||
send(room, m::me.user_id, "ircd.file.stat", "type",
|
||||
send(room, user_id, "ircd.file.stat", "type",
|
||||
{
|
||||
{ "value", content_type }
|
||||
});
|
||||
|
|
|
@ -27,7 +27,8 @@ read_each_block(const m::room &,
|
|||
const std::function<void (const const_buffer &)> &);
|
||||
|
||||
extern "C" size_t
|
||||
write_file(const m::room &room,
|
||||
write_file(const m::room &,
|
||||
const m::user::id &,
|
||||
const const_buffer &content,
|
||||
const string_view &content_type);
|
||||
|
||||
|
@ -41,10 +42,12 @@ download(const mutable_buffer &head_buf,
|
|||
m::room
|
||||
download(const string_view &server,
|
||||
const string_view &mediaid,
|
||||
const m::user::id &user_id,
|
||||
const net::hostport &remote,
|
||||
const m::room::id &room_id);
|
||||
|
||||
extern "C" m::room::id::buf
|
||||
download(const string_view &server,
|
||||
const string_view &mediaid,
|
||||
const m::user::id &user_id,
|
||||
const net::hostport &remote = {});
|
||||
|
|
|
@ -69,9 +69,18 @@ get__thumbnail(client &client,
|
|||
request.parv[1]
|
||||
};
|
||||
|
||||
// Thumbnail doesn't require auth so if there is no user_id detected
|
||||
// then we download on behalf of @ircd.
|
||||
const m::user::id &user_id
|
||||
{
|
||||
request.user_id?
|
||||
m::user::id{request.user_id}:
|
||||
m::me.user_id
|
||||
};
|
||||
|
||||
const m::room::id::buf room_id
|
||||
{
|
||||
download(server, file)
|
||||
download(server, file, user_id)
|
||||
};
|
||||
|
||||
return get__thumbnail_local(client, request, server, file, room_id);
|
||||
|
|
|
@ -78,7 +78,7 @@ post__upload(client &client,
|
|||
|
||||
const size_t written
|
||||
{
|
||||
write_file(room, buf, content_type)
|
||||
write_file(room, request.user_id, buf, content_type)
|
||||
};
|
||||
|
||||
char uribuf[256];
|
||||
|
|
Loading…
Reference in a new issue