diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index a6b93d2e..d6f3dcd0 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -228,7 +228,6 @@ class HttpCli(object): self.args = conn.args # mypy404 self.E: EnvParams = self.args.E self.asrv = conn.asrv # mypy404 - self.ico = conn.ico # mypy404 self.thumbcli = conn.hsrv.thumbcli self.u2fh = conn.u2fh # mypy404 self.pipes = conn.pipes # mypy404 @@ -534,7 +533,7 @@ class HttpCli(object): else: self.keepalive = False - ptn: Optional[Pattern[str]] = self.conn.lf_url # mypy404 + ptn = self.conn.lf_url self.do_log = not ptn or not ptn.search(self.req) if self.args.ihead and self.do_log: @@ -5285,7 +5284,7 @@ class HttpCli(object): # chrome cannot handle more than ~2000 unique SVGs # so url-param "raster" returns a png/webp instead # (useragent-sniffing kinshi due to caching proxies) - mime, ico = self.ico.get(txt, not small, "raster" in self.uparam) + mime, ico = self.conn.hsrv.ico.get(txt, not small, "raster" in self.uparam) lm = formatdate(self.E.t0) self.reply(ico, mime=mime, headers={"Last-Modified": lm}) diff --git a/copyparty/httpconn.py b/copyparty/httpconn.py index 3d4636dc..03d33199 100644 --- a/copyparty/httpconn.py +++ b/copyparty/httpconn.py @@ -21,10 +21,6 @@ from . import util as Util from .__init__ import TYPE_CHECKING, EnvParams from .authsrv import AuthSrv # typechk from .httpcli import HttpCli -from .ico import Ico -from .mtag import HAVE_FFMPEG -from .th_cli import ThumbCli -from .th_srv import HAVE_PIL, HAVE_VIPS from .u2idx import U2idx from .util import HMaccas, NetMap, shut_socket @@ -69,19 +65,15 @@ class HttpConn(object): self.bans: dict[str, int] = hsrv.bans self.aclose: dict[str, int] = hsrv.aclose - self.ico: Ico = Ico(self.args) # mypy404 - self.t0: float = time.time() # mypy404 self.freshen_pwd: float = 0.0 self.stopping = False self.nreq: int = -1 # mypy404 self.nbyte: int = 0 # mypy404 self.u2idx: Optional[U2idx] = None + self.lf_url: Optional[Pattern[str]] = self.args.lf_url self.log_func: "Util.RootLogger" = hsrv.log # mypy404 self.log_src: str = "httpconn" # mypy404 - self.lf_url: Optional[Pattern[str]] = ( - re.compile(self.args.lf_url) if self.args.lf_url else None - ) # mypy404 self.set_rproxy() def shutdown(self) -> None: diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index 7da35727..6d24b4f6 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -56,6 +56,7 @@ except SyntaxError: sys.exit(1) from .httpconn import HttpConn +from .ico import Ico from .metrics import Metrics from .mtag import HAVE_FFMPEG from .th_cli import ThumbCli @@ -137,6 +138,7 @@ class HttpSrv(object): self.aclose: dict[str, int] = {} self.thumbcli: Optional[ThumbCli] = None + self.ico: Ico = Ico(self.args) dli: dict[str, tuple[float, int, "VFS", str, str]] = {} # info dls: dict[str, tuple[float, int]] = {} # state diff --git a/copyparty/svchub.py b/copyparty/svchub.py index b3f409eb..bf2a3ebd 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -1145,7 +1145,7 @@ class SvcHub(object): vsa = [x.upper() for x in vsa if x] setattr(al, k + "_set", set(vsa)) - zs = "dav_ua1 sus_urls nonsus_urls ua_nodav ua_nodoc ua_nozip" + zs = "dav_ua1 lf_url sus_urls nonsus_urls ua_nodav ua_nodoc ua_nozip" for k in zs.split(" "): vs = getattr(al, k) if not vs or vs == "no": diff --git a/copyparty/th_cli.py b/copyparty/th_cli.py index 1a4155ac..3cb0e3b5 100644 --- a/copyparty/th_cli.py +++ b/copyparty/th_cli.py @@ -43,8 +43,8 @@ class ThumbCli(object): # defer args.th_ff_jpg, can change at runtime nonpil = next((x for x in self.args.th_dec if x in ("vips", "ff")), None) - self.can_webp = H_PIL_WEBP or nonpil - self.can_jxl = H_PIL_JXL or nonpil + self.can_webp = (H_PIL_WEBP or nonpil) and not self.args.th_no_webp + self.can_jxl = (H_PIL_JXL or nonpil) and not self.args.th_no_jxl def log(self, msg: str, c: Union[int, str] = 0) -> None: self.log_func("thumbcli", msg, c) @@ -85,23 +85,20 @@ class ThumbCli(object): if rem.startswith(".hist/th/") and rem.split(".")[-1] in IMG_EXTS: return os.path.join(ptop, rem) - if fmt[:1] in "jwx" and fmt != "wav": - sfmt = fmt[:1] + sfmt = fmt[:1] + if sfmt in "jwx" and fmt != "wav": if sfmt == "j" and self.args.th_no_jpg: sfmt = "w" if sfmt == "w": - if ( - self.args.th_no_webp - or not self.can_webp - or (self.args.th_ff_jpg and (not is_img or preferred == "ff")) + if not self.can_webp or ( + self.args.th_ff_jpg and (not is_img or preferred == "ff") ): sfmt = "j" - if sfmt == "x": - if self.args.th_no_jxl or not self.can_jxl: - sfmt = "w" + if sfmt == "x" and not self.can_jxl: + sfmt = "w" vf_crop = dbv.flags["crop"] vf_th3x = dbv.flags["th3x"] @@ -118,7 +115,7 @@ class ThumbCli(object): fmt = sfmt - elif fmt[:1] == "p" and not is_au and not is_vid: + elif sfmt == "p" and not is_au and not is_vid: t = "cannot thumbnail %r: png only allowed for waveforms" self.log(t % (rem,), 6) return None diff --git a/tests/util.py b/tests/util.py index 2d75c71d..50052254 100644 --- a/tests/util.py +++ b/tests/util.py @@ -149,7 +149,7 @@ class Cfg(Namespace): ex = "dav_inf dedup dotpart dotsrch hook_v no_dhash no_fastboot no_fpool no_htp no_rescan no_sendfile no_ses no_snap no_up_list no_voldump wram re_dhash see_dots plain_ip" ka.update(**{k: True for k in ex.split()}) - ex = "ah_cli ah_gen css_browser dbpath hist ipu js_browser js_other mime mimes no_forget no_hash no_idx nonsus_urls og_tpl og_ua ua_nodoc ua_nozip" + ex = "ah_cli ah_gen css_browser dbpath hist ipu js_browser js_other lf_url mime mimes no_forget no_hash no_idx nonsus_urls og_tpl og_ua ua_nodoc ua_nozip" ka.update(**{k: None for k in ex.split()}) ex = "gid uid" @@ -316,6 +316,7 @@ class VHttpSrv(object): self.g403 = Garda("") self.gurl = Garda("") + self.ico = Ico(args) self.thumbcli = None self.u2idx = None @@ -357,7 +358,6 @@ class VHttpConn(object): Ctor = VHttpSrvUp2k if use_up2k else VHttpSrv self.hsrv = Ctor(args, asrv, log) - self.ico = Ico(args) self.ipr = None self.ipa_nm = None self.ipar_nm = None