From ae982006602d6fe18aa30210cd10cc4d86b50f49 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 3 Oct 2024 23:52:11 +0000 Subject: [PATCH] og: support filekeys --- README.md | 4 ++-- copyparty/httpcli.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 43b145e7..fde61d6c 100644 --- a/README.md +++ b/README.md @@ -1159,8 +1159,6 @@ note that this disables hotlinking because the opengraph spec demands it; to sne you can also hotlink files regardless by appending `?raw` to the url -NOTE: because discord (and maybe others) strip query args such as `?raw` in opengraph tags, any links which require a filekey or dirkey will not work - if you want to entirely replace the copyparty response with your own jinja2 template, give the template filepath to `--og-tpl` or volflag `og_tpl` (all members of `HttpCli` are available through the `this` object) @@ -2087,6 +2085,8 @@ volflag `dky` disables the actual key-check, meaning anyone can see the contents volflag `dks` lets people enter subfolders as well, and also enables download-as-zip/tar +if you enable dirkeys, it is probably a good idea to enable filekeys too, otherwise it will be impossible to hotlink files from a folder which was accessed using a dirkey + dirkeys are generated based on another salt (`--dk-salt`) + filesystem-path and have a few limitations: * the key does not change if the contents of the folder is modified * if you need a new dirkey, either change the salt or rename the folder diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 75503abc..98a259a8 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -5535,6 +5535,8 @@ class HttpCli(object): fmt = vn.flags.get("og_th", "j") th_base = ujoin(url_base, quotep(thumb)) query = "th=%s&cache" % (fmt,) + if use_filekey: + query += "&k=" + self.uparam["k"] query = ub64enc(query.encode("utf-8")).decode("ascii") # discord looks at file extension, not content-type... query += "/th.jpg" if "j" in fmt else "/th.webp" @@ -5544,7 +5546,10 @@ class HttpCli(object): j2a["og_file"] = file if og_fn: og_fn_q = quotep(og_fn) - query = ub64enc(b"raw").decode("ascii") + query = "raw" + if use_filekey: + query += "&k=" + self.uparam["k"] + query = ub64enc(query.encode("utf-8")).decode("ascii") query += "/%s" % (og_fn_q,) j2a["og_url"] = ujoin(url_base, og_fn_q) j2a["og_raw"] = j2a["og_url"] + "/.uqe/" + query