0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-29 04:08:54 +02:00

modules/media: Consolidate media modules for easier linkages.

This commit is contained in:
Jason Volk 2018-04-12 14:44:30 -07:00
parent a08684c9e7
commit a8b143d6c2
6 changed files with 55 additions and 53 deletions

View file

@ -280,14 +280,15 @@ federation_module_LTLIBRARIES = \
media_moduledir = @moduledir@ media_moduledir = @moduledir@
media_media_download_la_SOURCES = media/download.cc media_media_media_la_SOURCES = \
media_media_upload_la_SOURCES = media/upload.cc media/download.cc \
media_media_thumbnail_la_SOURCES = media/thumbnail.cc media/upload.cc \
media/thumbnail.cc \
media/media.cc \
###
media_module_LTLIBRARIES = \ media_module_LTLIBRARIES = \
media/media_download.la \ media/media_media.la \
media/media_upload.la \
media/media_thumbnail.la \
### ###
############################################################################### ###############################################################################

View file

@ -10,12 +10,6 @@
#include "media.h" #include "media.h"
mapi::header
IRCD_MODULE
{
"Client 11.7 :Content repository (download)"
};
resource resource
download_resource download_resource
{ {
@ -73,13 +67,13 @@ get__download(client &client,
}; };
} }
resource::method static resource::method
method_get method_get
{ {
download_resource, "GET", get__download download_resource, "GET", get__download
}; };
resource::method static resource::method
method_get__legacy method_get__legacy
{ {
download_resource__legacy, "GET", get__download download_resource__legacy, "GET", get__download

37
modules/media/media.cc Normal file
View file

@ -0,0 +1,37 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#include "media.h"
mapi::header
IRCD_MODULE
{
"11.7 :Content respository"
};
m::room::id::buf
file_room_id(const string_view &server,
const string_view &file)
{
size_t len;
thread_local char buf[512];
len = strlcpy(buf, server);
len = strlcat(buf, "/"_sv);
len = strlcat(buf, file);
const sha256::buf hash
{
sha256{string_view{buf, len}}
};
return m::room::id::buf
{
b58encode(buf, hash), my_host()
};
}

View file

@ -10,22 +10,4 @@
using namespace ircd; using namespace ircd;
static m::room::id::buf m::room::id::buf file_room_id(const string_view &server, const string_view &file);
file_room_id(const string_view &server,
const string_view &file)
{
size_t len;
thread_local char buf[512];
len = strlcpy(buf, server);
len = strlcat(buf, "/"_sv);
len = strlcat(buf, file);
const sha256::buf hash
{
sha256{string_view{buf, len}}
};
return m::room::id::buf
{
b58encode(buf, hash), my_host()
};
}

View file

@ -16,18 +16,12 @@
#include "media.h" #include "media.h"
mapi::header
IRCD_MODULE
{
"Client 11.7.1.4 :Media thumbnails"
};
resource resource
thumbnail_resource__legacy thumbnail_resource__legacy
{ {
"/_matrix/media/v1/thumbnail/", "/_matrix/media/v1/thumbnail/",
{ {
"Media thumbnails (legacy version)", "(11.7.1.4) thumbnails (legacy version)",
resource::DIRECTORY, resource::DIRECTORY,
} }
}; };
@ -37,7 +31,7 @@ thumbnail_resource
{ {
"/_matrix/media/r0/thumbnail/", "/_matrix/media/r0/thumbnail/",
{ {
"Media thumbnails", "(11.7.1.4) thumbnails",
resource::DIRECTORY, resource::DIRECTORY,
} }
}; };
@ -105,13 +99,13 @@ get__thumbnail(client &client,
}; };
} }
resource::method static resource::method
method_get__legacy method_get__legacy
{ {
thumbnail_resource__legacy, "GET", get__thumbnail thumbnail_resource__legacy, "GET", get__thumbnail
}; };
resource::method static resource::method
method_get method_get
{ {
thumbnail_resource, "GET", get__thumbnail thumbnail_resource, "GET", get__thumbnail

View file

@ -10,12 +10,6 @@
#include "media.h" #include "media.h"
mapi::header
IRCD_MODULE
{
"Client 11.7 :Content repository (upload)"
};
resource resource
upload_resource__legacy upload_resource__legacy
{ {
@ -135,8 +129,8 @@ post__upload(client &client,
}; };
} }
struct resource::method::opts static const struct resource::method::opts
const method_post_opts method_post_opts
{ {
resource::method::REQUIRES_AUTH | resource::method::REQUIRES_AUTH |
resource::method::CONTENT_DISCRETION, resource::method::CONTENT_DISCRETION,
@ -144,13 +138,13 @@ const method_post_opts
8_MiB //TODO: conf; (this is the payload max option) 8_MiB //TODO: conf; (this is the payload max option)
}; };
resource::method static resource::method
method_post method_post
{ {
upload_resource, "POST", post__upload, method_post_opts upload_resource, "POST", post__upload, method_post_opts
}; };
resource::method static resource::method
method_post__legacy method_post__legacy
{ {
upload_resource__legacy, "POST", post__upload, method_post_opts upload_resource__legacy, "POST", post__upload, method_post_opts