aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-07-23 00:44:13 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2025-09-24 11:03:39 +0200
commitcb9cb0b83dc90aeee6380cdc4d2fb61d1426939c (patch)
tree20d6ce0f4896bd5caf7b9a231adece7f4795ee72 /main.c
parentb9537b1d1164b9f3fbe704512b1e324c2e37beb5 (diff)
downloadslcl-cb9cb0b83dc90aeee6380cdc4d2fb61d1426939c.tar.gz
Display thumbnails, if available
Diffstat (limited to 'main.c')
-rw-r--r--main.c60
1 files changed, 58 insertions, 2 deletions
diff --git a/main.c b/main.c
index d56927a..3702706 100644
--- a/main.c
+++ b/main.c
@@ -729,10 +729,14 @@ static int search(const struct http_payload *const p,
const struct user_args *const args = user;
const struct auth *const a = args->a;
const char *const username = p->cookie.field, *const root = auth_dir(a);
- struct page_search s = {0};
int (*f)(struct http_response *);
char *dir = NULL;
struct dynstr userd, d, res;
+ struct page_search s =
+ {
+ .username = username,
+ .adir = root
+ };
dynstr_init(&userd);
dynstr_init(&d);
@@ -1043,6 +1047,8 @@ static int getnode(const struct http_payload *const p,
.r = r,
.args = p->args,
.n_args = p->n_args,
+ .username = username,
+ .adir = adir,
.dir = dir.str,
.root = root.str,
.res = d.str,
@@ -2077,6 +2083,55 @@ end:
return ret;
}
+static int getthumbnail(const struct http_payload *const p,
+ struct http_response *const r, void *const user)
+{
+ int ret = -1;
+ const struct user_args *const ua = user;
+ const struct auth *const a = ua->a;
+ struct dynstr d, dir;
+
+ dynstr_init(&d);
+ dynstr_init(&dir);
+
+ if (auth_cookie(a, &p->cookie))
+ {
+ fprintf(stderr, "%s: auth_cookie failed\n", __func__);
+ ret = page_forbidden(r);
+ goto end;
+ }
+
+ const char *const adir = auth_dir(a);
+
+ if (!adir)
+ {
+ fprintf(stderr, "%s: auth_dir failed\n", __func__);
+ goto end;
+ }
+ else if (dynstr_append(&d, "%s%s", adir, p->resource))
+ {
+ fprintf(stderr, "%s: dynstr_append failed\n", __func__);
+ goto end;
+ }
+ else if (dynstr_dup(&dir, &d))
+ {
+ fprintf(stderr, "%s: dynstr_dup failed\n", __func__);
+ goto end;
+ }
+ else if (page_thumbnail(r, d.str))
+ {
+ fprintf(stderr, "%s: page_public failed\n", __func__);
+ goto end;
+ }
+
+ ret = 0;
+
+end:
+ dynstr_free(&d);
+ dynstr_free(&dir);
+ return ret;
+}
+
static void usage(char *const argv[])
{
fprintf(stderr, "%s [-F] [-t tmpdir] [-p port] dir\n", *argv);
@@ -2309,7 +2364,8 @@ static int add_urls(struct handler *const h, void *const user)
{.url = "/upload", .op = HTTP_OP_POST, .f = upload},
{.url = "/mkdir", .op = HTTP_OP_POST, .f = createdir},
{.url = "/confirm/rm", .op = HTTP_OP_POST, .f = confirm_rm},
- {.url = "/rm", .op = HTTP_OP_POST, .f = rm}
+ {.url = "/rm", .op = HTTP_OP_POST, .f = rm},
+ {.url = "/thumbnails/*", .op = HTTP_OP_GET, .f = getthumbnail}
};
for (size_t i = 0; i < sizeof urls / sizeof *urls; i++)