Bump remaining crates to latest
Browse files at this commitb743a9d15ce4a3c8a0ccefb104b1a6e637633b25Parent: 9fec6a0- chore
- bump remaining crates to latest
26 changed files +944 -847
- Cargo.lock +182 -149
- Cargo.toml +4 -4
- crates/in-client/Cargo.toml +8 -9
- crates/in-client/src/lib.rs +11 -12
- crates/in-core/Cargo.toml +1 -1
- crates/in-core/src/config.rs +1 -1
- crates/in-core/src/store/blobs.rs +1 -1
- crates/in-core/src/store/mod.rs +7 -5
- crates/in-core/src/store/reconcile.rs +2 -2
- crates/in-core/src/store/schema.rs +24 -12
- crates/in-core/src/store/secret.rs +4 -4
- crates/in-core/src/store/sniff.rs +4 -204
- crates/in-core/src/store/turso_store.rs +72 -38
- crates/in-core/tests/store.rs +7 -7
- crates/in-web/Cargo.toml +3 -3
- crates/in-web/src/drive.rs +47 -39
- crates/in-web/src/dropdown.rs +3 -3
- crates/in-web/src/files.rs +45 -42
- crates/in-web/src/layout.rs +83 -75
- crates/in-web/src/main.rs +3 -2
- crates/in-web/src/pages.rs +12 -10
- crates/in-web/src/server.rs +24 -11
- crates/in-web/src/settings.rs +169 -45
- crates/in-web/src/share.rs +71 -65
- crates/in-web/src/trash.rs +21 -18
- crates/in-web/tests/http.rs +135 -85
Cargo.lockmodified+182 -149
| @@ -18,6 +18,16 @@ dependencies = [ | |||
| 18 | "generic-array", | 18 | "generic-array", |
| 19 | ] | 19 | ] |
| 20 | 20 | ||
| 21 | +[[package]] | ||
| 22 | +name = "aead" | ||
| 23 | +version = "0.6.1" | ||
| 24 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 25 | +checksum = "1973cfbc1a2daf9cf550e74e1f088c28e7f7d8c1e1418fb6c9dc5184b7e84c99" | ||
| 26 | +dependencies = [ | ||
| 27 | + "crypto-common 0.2.2", | ||
| 28 | + "inout 0.2.2", | ||
| 29 | +] | ||
| 30 | + | ||
| 21 | [[package]] | 31 | [[package]] |
| 22 | name = "aegis" | 32 | name = "aegis" |
| 23 | version = "0.9.15" | 33 | version = "0.9.15" |
| @@ -35,7 +45,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 35 | checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" | 45 | checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" |
| 36 | dependencies = [ | 46 | dependencies = [ |
| 37 | "cfg-if", | 47 | "cfg-if", |
| 38 | - "cipher", | 48 | + "cipher 0.4.4", |
| 39 | "cpufeatures 0.2.17", | 49 | "cpufeatures 0.2.17", |
| 40 | ] | 50 | ] |
| 41 | 51 | ||
| @@ -45,9 +55,9 @@ version = "0.10.3" | |||
| 45 | source = "registry+https://github.com/rust-lang/crates.io-index" | 55 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 46 | checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" | 56 | checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" |
| 47 | dependencies = [ | 57 | dependencies = [ |
| 48 | - "aead", | 58 | + "aead 0.5.2", |
| 49 | "aes", | 59 | "aes", |
| 50 | - "cipher", | 60 | + "cipher 0.4.4", |
| 51 | "ctr", | 61 | "ctr", |
| 52 | "ghash", | 62 | "ghash", |
| 53 | "subtle", | 63 | "subtle", |
| @@ -308,6 +318,12 @@ dependencies = [ | |||
| 308 | "pkg-config", | 318 | "pkg-config", |
| 309 | ] | 319 | ] |
| 310 | 320 | ||
| 321 | +[[package]] | ||
| 322 | +name = "base16ct" | ||
| 323 | +version = "1.0.0" | ||
| 324 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 325 | +checksum = "fd307490d624467aa6f74b0eabb77633d1f758a7b25f12bceb0b22e08d9726f6" | ||
| 326 | + | ||
| 311 | [[package]] | 327 | [[package]] |
| 312 | name = "base64" | 328 | name = "base64" |
| 313 | version = "0.22.1" | 329 | version = "0.22.1" |
| @@ -577,17 +593,6 @@ version = "0.1.1" | |||
| 577 | source = "registry+https://github.com/rust-lang/crates.io-index" | 593 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 578 | checksum = "18758054972164c3264f7c8386f5fc6da6114cb46b619fd365d4e3b2dc3ae487" | 594 | checksum = "18758054972164c3264f7c8386f5fc6da6114cb46b619fd365d4e3b2dc3ae487" |
| 579 | 595 | ||
| 580 | -[[package]] | ||
| 581 | -name = "chacha20" | ||
| 582 | -version = "0.9.1" | ||
| 583 | -source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 584 | -checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" | ||
| 585 | -dependencies = [ | ||
| 586 | - "cfg-if", | ||
| 587 | - "cipher", | ||
| 588 | - "cpufeatures 0.2.17", | ||
| 589 | -] | ||
| 590 | - | ||
| 591 | [[package]] | 596 | [[package]] |
| 592 | name = "chacha20" | 597 | name = "chacha20" |
| 593 | version = "0.10.2" | 598 | version = "0.10.2" |
| @@ -595,21 +600,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 595 | checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" | 600 | checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" |
| 596 | dependencies = [ | 601 | dependencies = [ |
| 597 | "cfg-if", | 602 | "cfg-if", |
| 603 | + "cipher 0.5.2", | ||
| 598 | "cpufeatures 0.3.1", | 604 | "cpufeatures 0.3.1", |
| 599 | "rand_core 0.10.1", | 605 | "rand_core 0.10.1", |
| 600 | ] | 606 | ] |
| 601 | 607 | ||
| 602 | [[package]] | 608 | [[package]] |
| 603 | name = "chacha20poly1305" | 609 | name = "chacha20poly1305" |
| 604 | -version = "0.10.1" | 610 | +version = "0.11.0" |
| 605 | source = "registry+https://github.com/rust-lang/crates.io-index" | 611 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 606 | -checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" | 612 | +checksum = "9b89e1c441e926b9c82a8d023f6e1b7ae0adcfaa7d621814e4d60789bac751cb" |
| 607 | dependencies = [ | 613 | dependencies = [ |
| 608 | - "aead", | 614 | + "aead 0.6.1", |
| 609 | - "chacha20 0.9.1", | 615 | + "chacha20", |
| 610 | - "cipher", | 616 | + "cipher 0.5.2", |
| 611 | "poly1305", | 617 | "poly1305", |
| 612 | - "zeroize", | ||
| 613 | ] | 618 | ] |
| 614 | 619 | ||
| 615 | [[package]] | 620 | [[package]] |
| @@ -633,8 +638,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 633 | checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" | 638 | checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" |
| 634 | dependencies = [ | 639 | dependencies = [ |
| 635 | "crypto-common 0.1.7", | 640 | "crypto-common 0.1.7", |
| 636 | - "inout", | 641 | + "inout 0.1.4", |
| 637 | - "zeroize", | 642 | +] |
| 643 | + | ||
| 644 | +[[package]] | ||
| 645 | +name = "cipher" | ||
| 646 | +version = "0.5.2" | ||
| 647 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 648 | +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" | ||
| 649 | +dependencies = [ | ||
| 650 | + "block-buffer 0.12.1", | ||
| 651 | + "crypto-common 0.2.2", | ||
| 652 | + "inout 0.2.2", | ||
| 638 | ] | 653 | ] |
| 639 | 654 | ||
| 640 | [[package]] | 655 | [[package]] |
| @@ -745,12 +760,6 @@ dependencies = [ | |||
| 745 | "crossbeam-utils", | 760 | "crossbeam-utils", |
| 746 | ] | 761 | ] |
| 747 | 762 | ||
| 748 | -[[package]] | ||
| 749 | -name = "const-oid" | ||
| 750 | -version = "0.9.6" | ||
| 751 | -source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 752 | -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" | ||
| 753 | - | ||
| 754 | [[package]] | 763 | [[package]] |
| 755 | name = "const-oid" | 764 | name = "const-oid" |
| 756 | version = "0.10.2" | 765 | version = "0.10.2" |
| @@ -797,6 +806,12 @@ version = "1.0.0" | |||
| 797 | source = "registry+https://github.com/rust-lang/crates.io-index" | 806 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 798 | checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" | 807 | checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" |
| 799 | 808 | ||
| 809 | +[[package]] | ||
| 810 | +name = "cpubits" | ||
| 811 | +version = "0.1.1" | ||
| 812 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 813 | +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" | ||
| 814 | + | ||
| 800 | [[package]] | 815 | [[package]] |
| 801 | name = "cpufeatures" | 816 | name = "cpufeatures" |
| 802 | version = "0.2.17" | 817 | version = "0.2.17" |
| @@ -883,6 +898,20 @@ version = "0.2.4" | |||
| 883 | source = "registry+https://github.com/rust-lang/crates.io-index" | 898 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 884 | checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" | 899 | checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" |
| 885 | 900 | ||
| 901 | +[[package]] | ||
| 902 | +name = "crypto-bigint" | ||
| 903 | +version = "0.7.5" | ||
| 904 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 905 | +checksum = "1a52aa3fcda4e6302a9f48734f234d35d4721b96f8fe07d073f07ce9df4f0271" | ||
| 906 | +dependencies = [ | ||
| 907 | + "cpubits", | ||
| 908 | + "ctutils", | ||
| 909 | + "num-traits", | ||
| 910 | + "rand_core 0.10.1", | ||
| 911 | + "serdect", | ||
| 912 | + "zeroize", | ||
| 913 | +] | ||
| 914 | + | ||
| 886 | [[package]] | 915 | [[package]] |
| 887 | name = "crypto-common" | 916 | name = "crypto-common" |
| 888 | version = "0.1.7" | 917 | version = "0.1.7" |
| @@ -900,7 +929,19 @@ version = "0.2.2" | |||
| 900 | source = "registry+https://github.com/rust-lang/crates.io-index" | 929 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 901 | checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" | 930 | checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" |
| 902 | dependencies = [ | 931 | dependencies = [ |
| 932 | + "getrandom 0.4.3", | ||
| 903 | "hybrid-array", | 933 | "hybrid-array", |
| 934 | + "rand_core 0.10.1", | ||
| 935 | +] | ||
| 936 | + | ||
| 937 | +[[package]] | ||
| 938 | +name = "crypto-primes" | ||
| 939 | +version = "0.7.2" | ||
| 940 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 941 | +checksum = "3633a51a39c69ebbaa4feaa694bd83d241e4093901c84a0963b19d9bb3f0cf8f" | ||
| 942 | +dependencies = [ | ||
| 943 | + "crypto-bigint", | ||
| 944 | + "rand_core 0.10.1", | ||
| 904 | ] | 945 | ] |
| 905 | 946 | ||
| 906 | [[package]] | 947 | [[package]] |
| @@ -909,7 +950,7 @@ version = "0.9.2" | |||
| 909 | source = "registry+https://github.com/rust-lang/crates.io-index" | 950 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 910 | checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" | 951 | checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" |
| 911 | dependencies = [ | 952 | dependencies = [ |
| 912 | - "cipher", | 953 | + "cipher 0.4.4", |
| 913 | ] | 954 | ] |
| 914 | 955 | ||
| 915 | [[package]] | 956 | [[package]] |
| @@ -969,11 +1010,11 @@ checksum = "c286de4e81ea2590afc24d754e0f83810c566f50a1388fa75ebd57928c0d9745" | |||
| 969 | 1010 | ||
| 970 | [[package]] | 1011 | [[package]] |
| 971 | name = "der" | 1012 | name = "der" |
| 972 | -version = "0.7.10" | 1013 | +version = "0.8.2" |
| 973 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1014 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 974 | -checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" | 1015 | +checksum = "a878c850e9e421b20262e9b41f9c860e4785fa07541c266b62ff9d1ef998a80a" |
| 975 | dependencies = [ | 1016 | dependencies = [ |
| 976 | - "const-oid 0.9.6", | 1017 | + "const-oid", |
| 977 | "pem-rfc7468", | 1018 | "pem-rfc7468", |
| 978 | "zeroize", | 1019 | "zeroize", |
| 979 | ] | 1020 | ] |
| @@ -994,7 +1035,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 994 | checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | 1035 | checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" |
| 995 | dependencies = [ | 1036 | dependencies = [ |
| 996 | "block-buffer 0.10.4", | 1037 | "block-buffer 0.10.4", |
| 997 | - "const-oid 0.9.6", | ||
| 998 | "crypto-common 0.1.7", | 1038 | "crypto-common 0.1.7", |
| 999 | "subtle", | 1039 | "subtle", |
| 1000 | ] | 1040 | ] |
| @@ -1006,7 +1046,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 1006 | checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" | 1046 | checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" |
| 1007 | dependencies = [ | 1047 | dependencies = [ |
| 1008 | "block-buffer 0.12.1", | 1048 | "block-buffer 0.12.1", |
| 1009 | - "const-oid 0.10.2", | 1049 | + "const-oid", |
| 1010 | "crypto-common 0.2.2", | 1050 | "crypto-common 0.2.2", |
| 1011 | "ctutils", | 1051 | "ctutils", |
| 1012 | ] | 1052 | ] |
| @@ -1889,16 +1929,15 @@ dependencies = [ | |||
| 1889 | [[package]] | 1929 | [[package]] |
| 1890 | name = "im-client" | 1930 | name = "im-client" |
| 1891 | version = "0.1.0" | 1931 | version = "0.1.0" |
| 1892 | -source = "git+https://github.com/DizeyLab/im?rev=f7b2081#f7b208171820ca309b10043c6e86de12b81f3826" | 1932 | +source = "git+https://github.com/DizeyLab/im?rev=25140f3#25140f308a711d4090fa75bb29558a3f5335587c" |
| 1893 | dependencies = [ | 1933 | dependencies = [ |
| 1894 | - "base64 0.22.1", | 1934 | + "base64 0.23.1", |
| 1895 | "chacha20poly1305", | 1935 | "chacha20poly1305", |
| 1896 | "rand 0.10.2", | 1936 | "rand 0.10.2", |
| 1897 | "reqwest", | 1937 | "reqwest", |
| 1898 | "rsa", | 1938 | "rsa", |
| 1899 | "serde", | 1939 | "serde", |
| 1900 | "serde_json", | 1940 | "serde_json", |
| 1901 | - "sha2 0.10.9", | ||
| 1902 | "sha2 0.11.0", | 1941 | "sha2 0.11.0", |
| 1903 | "subtle", | 1942 | "subtle", |
| 1904 | "thiserror", | 1943 | "thiserror", |
| @@ -1939,16 +1978,15 @@ dependencies = [ | |||
| 1939 | name = "in-client" | 1978 | name = "in-client" |
| 1940 | version = "0.1.0" | 1979 | version = "0.1.0" |
| 1941 | dependencies = [ | 1980 | dependencies = [ |
| 1942 | - "base64 0.22.1", | 1981 | + "base64 0.23.1", |
| 1943 | "chacha20poly1305", | 1982 | "chacha20poly1305", |
| 1944 | "http", | 1983 | "http", |
| 1945 | "rand 0.10.2", | 1984 | "rand 0.10.2", |
| 1946 | - "rand_core 0.6.4", | 1985 | + "rand_core 0.10.1", |
| 1947 | "reqwest", | 1986 | "reqwest", |
| 1948 | "rsa", | 1987 | "rsa", |
| 1949 | "serde", | 1988 | "serde", |
| 1950 | "serde_json", | 1989 | "serde_json", |
| 1951 | - "sha2 0.10.9", | ||
| 1952 | "sha2 0.11.0", | 1990 | "sha2 0.11.0", |
| 1953 | "subtle", | 1991 | "subtle", |
| 1954 | "thiserror", | 1992 | "thiserror", |
| @@ -1963,7 +2001,7 @@ version = "0.1.0" | |||
| 1963 | dependencies = [ | 2001 | dependencies = [ |
| 1964 | "argon2", | 2002 | "argon2", |
| 1965 | "async-trait", | 2003 | "async-trait", |
| 1966 | - "base64 0.22.1", | 2004 | + "base64 0.23.1", |
| 1967 | "bytes", | 2005 | "bytes", |
| 1968 | "chacha20poly1305", | 2006 | "chacha20poly1305", |
| 1969 | "futures-core", | 2007 | "futures-core", |
| @@ -2005,7 +2043,7 @@ dependencies = [ | |||
| 2005 | "in-core", | 2043 | "in-core", |
| 2006 | "serde", | 2044 | "serde", |
| 2007 | "serde_json", | 2045 | "serde_json", |
| 2008 | - "sha2 0.10.9", | 2046 | + "sha2 0.11.0", |
| 2009 | "thiserror", | 2047 | "thiserror", |
| 2010 | "time", | 2048 | "time", |
| 2011 | "tokio", | 2049 | "tokio", |
| @@ -2032,6 +2070,15 @@ dependencies = [ | |||
| 2032 | "generic-array", | 2070 | "generic-array", |
| 2033 | ] | 2071 | ] |
| 2034 | 2072 | ||
| 2073 | +[[package]] | ||
| 2074 | +name = "inout" | ||
| 2075 | +version = "0.2.2" | ||
| 2076 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2077 | +checksum = "4250ce6452e92010fdf7268ccc5d14faa80bb12fc741938534c58f16804e03c7" | ||
| 2078 | +dependencies = [ | ||
| 2079 | + "hybrid-array", | ||
| 2080 | +] | ||
| 2081 | + | ||
| 2035 | [[package]] | 2082 | [[package]] |
| 2036 | name = "intrusive-collections" | 2083 | name = "intrusive-collections" |
| 2037 | version = "0.9.7" | 2084 | version = "0.9.7" |
| @@ -2190,9 +2237,6 @@ name = "lazy_static" | |||
| 2190 | version = "1.5.0" | 2237 | version = "1.5.0" |
| 2191 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2238 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2192 | checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" | 2239 | checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" |
| 2193 | -dependencies = [ | ||
| 2194 | - "spin 0.9.9", | ||
| 2195 | -] | ||
| 2196 | 2240 | ||
| 2197 | [[package]] | 2241 | [[package]] |
| 2198 | name = "lazycell" | 2242 | name = "lazycell" |
| @@ -2571,22 +2615,6 @@ dependencies = [ | |||
| 2571 | "num-traits", | 2615 | "num-traits", |
| 2572 | ] | 2616 | ] |
| 2573 | 2617 | ||
| 2574 | -[[package]] | ||
| 2575 | -name = "num-bigint-dig" | ||
| 2576 | -version = "0.8.6" | ||
| 2577 | -source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2578 | -checksum = "e661dda6640fad38e827a6d4a310ff4763082116fe217f279885c97f511bb0b7" | ||
| 2579 | -dependencies = [ | ||
| 2580 | - "lazy_static", | ||
| 2581 | - "libm", | ||
| 2582 | - "num-integer", | ||
| 2583 | - "num-iter", | ||
| 2584 | - "num-traits", | ||
| 2585 | - "rand 0.8.8", | ||
| 2586 | - "smallvec", | ||
| 2587 | - "zeroize", | ||
| 2588 | -] | ||
| 2589 | - | ||
| 2590 | [[package]] | 2618 | [[package]] |
| 2591 | name = "num-conv" | 2619 | name = "num-conv" |
| 2592 | version = "0.2.2" | 2620 | version = "0.2.2" |
| @@ -2602,16 +2630,6 @@ dependencies = [ | |||
| 2602 | "num-traits", | 2630 | "num-traits", |
| 2603 | ] | 2631 | ] |
| 2604 | 2632 | ||
| 2605 | -[[package]] | ||
| 2606 | -name = "num-iter" | ||
| 2607 | -version = "0.1.46" | ||
| 2608 | -source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 2609 | -checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" | ||
| 2610 | -dependencies = [ | ||
| 2611 | - "num-integer", | ||
| 2612 | - "num-traits", | ||
| 2613 | -] | ||
| 2614 | - | ||
| 2615 | [[package]] | 2633 | [[package]] |
| 2616 | name = "num-traits" | 2634 | name = "num-traits" |
| 2617 | version = "0.2.19" | 2635 | version = "0.2.19" |
| @@ -2619,7 +2637,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
| 2619 | checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" | 2637 | checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" |
| 2620 | dependencies = [ | 2638 | dependencies = [ |
| 2621 | "autocfg", | 2639 | "autocfg", |
| 2622 | - "libm", | ||
| 2623 | ] | 2640 | ] |
| 2624 | 2641 | ||
| 2625 | [[package]] | 2642 | [[package]] |
| @@ -2792,9 +2809,9 @@ checksum = "03351d0f1c066c114015408dc6a3e101f080fc03ef9d8d799aa58ec760cac5a6" | |||
| 2792 | 2809 | ||
| 2793 | [[package]] | 2810 | [[package]] |
| 2794 | name = "pem-rfc7468" | 2811 | name = "pem-rfc7468" |
| 2795 | -version = "0.7.0" | 2812 | +version = "1.0.0" |
| 2796 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2813 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2797 | -checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" | 2814 | +checksum = "a6305423e0e7738146434843d1694d621cce767262b2a86910beab705e4493d9" |
| 2798 | dependencies = [ | 2815 | dependencies = [ |
| 2799 | "base64ct", | 2816 | "base64ct", |
| 2800 | ] | 2817 | ] |
| @@ -2866,20 +2883,19 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" | |||
| 2866 | 2883 | ||
| 2867 | [[package]] | 2884 | [[package]] |
| 2868 | name = "pkcs1" | 2885 | name = "pkcs1" |
| 2869 | -version = "0.7.5" | 2886 | +version = "0.8.0-rc.4" |
| 2870 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2887 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2871 | -checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" | 2888 | +checksum = "986d2e952779af96ea048f160fd9194e1751b4faea78bcf3ceb456efe008088e" |
| 2872 | dependencies = [ | 2889 | dependencies = [ |
| 2873 | "der", | 2890 | "der", |
| 2874 | - "pkcs8", | ||
| 2875 | "spki", | 2891 | "spki", |
| 2876 | ] | 2892 | ] |
| 2877 | 2893 | ||
| 2878 | [[package]] | 2894 | [[package]] |
| 2879 | name = "pkcs8" | 2895 | name = "pkcs8" |
| 2880 | -version = "0.10.2" | 2896 | +version = "0.11.0" |
| 2881 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2897 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2882 | -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" | 2898 | +checksum = "451913da69c775a56034ea8d9003d27ee8948e12443eae7c038ba100a4f21cb7" |
| 2883 | dependencies = [ | 2899 | dependencies = [ |
| 2884 | "der", | 2900 | "der", |
| 2885 | "spki", | 2901 | "spki", |
| @@ -2920,13 +2936,12 @@ dependencies = [ | |||
| 2920 | 2936 | ||
| 2921 | [[package]] | 2937 | [[package]] |
| 2922 | name = "poly1305" | 2938 | name = "poly1305" |
| 2923 | -version = "0.8.0" | 2939 | +version = "0.9.1" |
| 2924 | source = "registry+https://github.com/rust-lang/crates.io-index" | 2940 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2925 | -checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" | 2941 | +checksum = "6e2d0073b297041425c7c3df6eb4792d598a15323fe63346852b092eca02904c" |
| 2926 | dependencies = [ | 2942 | dependencies = [ |
| 2927 | - "cpufeatures 0.2.17", | 2943 | + "cpufeatures 0.3.1", |
| 2928 | - "opaque-debug", | 2944 | + "universal-hash 0.6.1", |
| 2929 | - "universal-hash", | ||
| 2930 | ] | 2945 | ] |
| 2931 | 2946 | ||
| 2932 | [[package]] | 2947 | [[package]] |
| @@ -2938,7 +2953,7 @@ dependencies = [ | |||
| 2938 | "cfg-if", | 2953 | "cfg-if", |
| 2939 | "cpufeatures 0.2.17", | 2954 | "cpufeatures 0.2.17", |
| 2940 | "opaque-debug", | 2955 | "opaque-debug", |
| 2941 | - "universal-hash", | 2956 | + "universal-hash 0.5.1", |
| 2942 | ] | 2957 | ] |
| 2943 | 2958 | ||
| 2944 | [[package]] | 2959 | [[package]] |
| @@ -3167,7 +3182,7 @@ version = "0.10.2" | |||
| 3167 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3182 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3168 | checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" | 3183 | checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" |
| 3169 | dependencies = [ | 3184 | dependencies = [ |
| 3170 | - "chacha20 0.10.2", | 3185 | + "chacha20", |
| 3171 | "getrandom 0.4.3", | 3186 | "getrandom 0.4.3", |
| 3172 | "rand_core 0.10.1", | 3187 | "rand_core 0.10.1", |
| 3173 | ] | 3188 | ] |
| @@ -3389,21 +3404,19 @@ dependencies = [ | |||
| 3389 | 3404 | ||
| 3390 | [[package]] | 3405 | [[package]] |
| 3391 | name = "rsa" | 3406 | name = "rsa" |
| 3392 | -version = "0.9.10" | 3407 | +version = "0.10.0-rc.18" |
| 3393 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3408 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3394 | -checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" | 3409 | +checksum = "30b2aa4ba0d89f73d1e332df05be0eeab8840351c36ca5654341dfdb57bb3caf" |
| 3395 | dependencies = [ | 3410 | dependencies = [ |
| 3396 | - "const-oid 0.9.6", | 3411 | + "const-oid", |
| 3397 | - "digest 0.10.7", | 3412 | + "crypto-bigint", |
| 3398 | - "num-bigint-dig", | 3413 | + "crypto-primes", |
| 3399 | - "num-integer", | 3414 | + "digest 0.11.3", |
| 3400 | - "num-traits", | ||
| 3401 | "pkcs1", | 3415 | "pkcs1", |
| 3402 | "pkcs8", | 3416 | "pkcs8", |
| 3403 | - "rand_core 0.6.4", | 3417 | + "rand_core 0.10.1", |
| 3404 | "signature", | 3418 | "signature", |
| 3405 | "spki", | 3419 | "spki", |
| 3406 | - "subtle", | ||
| 3407 | "zeroize", | 3420 | "zeroize", |
| 3408 | ] | 3421 | ] |
| 3409 | 3422 | ||
| @@ -3779,6 +3792,16 @@ dependencies = [ | |||
| 3779 | "serde", | 3792 | "serde", |
| 3780 | ] | 3793 | ] |
| 3781 | 3794 | ||
| 3795 | +[[package]] | ||
| 3796 | +name = "serdect" | ||
| 3797 | +version = "0.4.3" | ||
| 3798 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 3799 | +checksum = "66cf8fedced2fcf12406bcb34223dffb92eaf34908ede12fed414c82b7f00b3e" | ||
| 3800 | +dependencies = [ | ||
| 3801 | + "base16ct", | ||
| 3802 | + "serde", | ||
| 3803 | +] | ||
| 3804 | + | ||
| 3782 | [[package]] | 3805 | [[package]] |
| 3783 | name = "sha1" | 3806 | name = "sha1" |
| 3784 | version = "0.10.7" | 3807 | version = "0.10.7" |
| @@ -3882,12 +3905,12 @@ dependencies = [ | |||
| 3882 | 3905 | ||
| 3883 | [[package]] | 3906 | [[package]] |
| 3884 | name = "signature" | 3907 | name = "signature" |
| 3885 | -version = "2.2.0" | 3908 | +version = "3.0.0" |
| 3886 | source = "registry+https://github.com/rust-lang/crates.io-index" | 3909 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3887 | -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" | 3910 | +checksum = "28d567dcbaf0049cb8ac2608a76cd95ff9e4412e1899d389ee400918ca7537f5" |
| 3888 | dependencies = [ | 3911 | dependencies = [ |
| 3889 | - "digest 0.10.7", | 3912 | + "digest 0.11.3", |
| 3890 | - "rand_core 0.6.4", | 3913 | + "rand_core 0.10.1", |
| 3891 | ] | 3914 | ] |
| 3892 | 3915 | ||
| 3893 | [[package]] | 3916 | [[package]] |
| @@ -3978,9 +4001,9 @@ checksum = "023a211cb3138dbc438680b32560ad89f699977624c9f8dbb95a47d5b4c07dd3" | |||
| 3978 | 4001 | ||
| 3979 | [[package]] | 4002 | [[package]] |
| 3980 | name = "spki" | 4003 | name = "spki" |
| 3981 | -version = "0.7.3" | 4004 | +version = "0.8.0" |
| 3982 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4005 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3983 | -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" | 4006 | +checksum = "1d9efca8738c78ee9484207732f728b1ef517bbb1833d6fc0879ca898a522f6f" |
| 3984 | dependencies = [ | 4007 | dependencies = [ |
| 3985 | "base64ct", | 4008 | "base64ct", |
| 3986 | "der", | 4009 | "der", |
| @@ -4453,14 +4476,13 @@ checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" | |||
| 4453 | 4476 | ||
| 4454 | [[package]] | 4477 | [[package]] |
| 4455 | name = "topcoat" | 4478 | name = "topcoat" |
| 4456 | -version = "0.6.2" | 4479 | +version = "0.8.0" |
| 4457 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4480 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4458 | -checksum = "050c11e7b0e146a2b1eb15855abd5fa03e2754eb880922f8b6cab5ec71cac5aa" | 4481 | +checksum = "f3c199295b1c52e0a9c88a2b0518f6bc7522503cd0bb06d9f4742c515ac4df0a" |
| 4459 | dependencies = [ | 4482 | dependencies = [ |
| 4460 | "futures-util", | 4483 | "futures-util", |
| 4461 | "inventory", | 4484 | "inventory", |
| 4462 | "serde", | 4485 | "serde", |
| 4463 | - "serde_urlencoded", | ||
| 4464 | "tokio", | 4486 | "tokio", |
| 4465 | "tokio-tungstenite", | 4487 | "tokio-tungstenite", |
| 4466 | "topcoat-asset", | 4488 | "topcoat-asset", |
| @@ -4481,9 +4503,9 @@ dependencies = [ | |||
| 4481 | 4503 | ||
| 4482 | [[package]] | 4504 | [[package]] |
| 4483 | name = "topcoat-asset" | 4505 | name = "topcoat-asset" |
| 4484 | -version = "0.6.2" | 4506 | +version = "0.8.0" |
| 4485 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4507 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4486 | -checksum = "a72e4ba8cb6a9d29613a25c2151e72d887b4a79b3f179b497734eed0e65ea702" | 4508 | +checksum = "fba199ae779d0409672929e7c32711ac35e87c9e39e0823d0b33b6293e3e0011" |
| 4487 | dependencies = [ | 4509 | dependencies = [ |
| 4488 | "http", | 4510 | "http", |
| 4489 | "memchr", | 4511 | "memchr", |
| @@ -4499,9 +4521,9 @@ dependencies = [ | |||
| 4499 | 4521 | ||
| 4500 | [[package]] | 4522 | [[package]] |
| 4501 | name = "topcoat-cookie" | 4523 | name = "topcoat-cookie" |
| 4502 | -version = "0.6.2" | 4524 | +version = "0.8.0" |
| 4503 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4525 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4504 | -checksum = "f68c83654c4bf075f667d39463cd38ef0be9fee057054454b06612efe16e7a37" | 4526 | +checksum = "3cb0bf2f95c1931d32d579389695e8cf221d114f9629a57fc005d7a0bb459c0d" |
| 4505 | dependencies = [ | 4527 | dependencies = [ |
| 4506 | "cookie", | 4528 | "cookie", |
| 4507 | "getrandom 0.2.17", | 4529 | "getrandom 0.2.17", |
| @@ -4514,9 +4536,9 @@ dependencies = [ | |||
| 4514 | 4536 | ||
| 4515 | [[package]] | 4537 | [[package]] |
| 4516 | name = "topcoat-core" | 4538 | name = "topcoat-core" |
| 4517 | -version = "0.6.2" | 4539 | +version = "0.8.0" |
| 4518 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4540 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4519 | -checksum = "42f94adaa301d7a4b949d650fa803323c00cc8ffa8bf1984511c1ec5d390b6c6" | 4541 | +checksum = "d88c5ed693dd383ba8a4112f5b665bdb7e979ada413a7b5f9ede6935fe18e8e6" |
| 4520 | dependencies = [ | 4542 | dependencies = [ |
| 4521 | "anyhow", | 4543 | "anyhow", |
| 4522 | "anymap3", | 4544 | "anymap3", |
| @@ -4530,9 +4552,9 @@ dependencies = [ | |||
| 4530 | 4552 | ||
| 4531 | [[package]] | 4553 | [[package]] |
| 4532 | name = "topcoat-core-grammar" | 4554 | name = "topcoat-core-grammar" |
| 4533 | -version = "0.6.2" | 4555 | +version = "0.8.0" |
| 4534 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4556 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4535 | -checksum = "0756aa9285794c155624494bc563d56859e35205313db883a89d7dabfa6d0393" | 4557 | +checksum = "ce257f5c2248b4d7bf1bbd76a0e71709221f06d690462a49aad5929732c42001" |
| 4536 | dependencies = [ | 4558 | dependencies = [ |
| 4537 | "proc-macro-crate", | 4559 | "proc-macro-crate", |
| 4538 | "proc-macro2", | 4560 | "proc-macro2", |
| @@ -4542,9 +4564,9 @@ dependencies = [ | |||
| 4542 | 4564 | ||
| 4543 | [[package]] | 4565 | [[package]] |
| 4544 | name = "topcoat-core-macro" | 4566 | name = "topcoat-core-macro" |
| 4545 | -version = "0.6.2" | 4567 | +version = "0.8.0" |
| 4546 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4568 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4547 | -checksum = "e4908dba6268c8592be73e9059cdefa053066e1b1bc879c1c9a5d8d3b6e97aad" | 4569 | +checksum = "5d239098a8c674f16120e7bfcba6f670865c807eec2a0e2648cb319d300fab39" |
| 4548 | dependencies = [ | 4570 | dependencies = [ |
| 4549 | "quote", | 4571 | "quote", |
| 4550 | "syn 2.0.119", | 4572 | "syn 2.0.119", |
| @@ -4553,9 +4575,9 @@ dependencies = [ | |||
| 4553 | 4575 | ||
| 4554 | [[package]] | 4576 | [[package]] |
| 4555 | name = "topcoat-font" | 4577 | name = "topcoat-font" |
| 4556 | -version = "0.6.2" | 4578 | +version = "0.8.0" |
| 4557 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4579 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4558 | -checksum = "e7b8308aff65f46bbe2f58371fc9823db596236bd0ea3c9d87de6534fd977e60" | 4580 | +checksum = "8ccc2da492bfdcf2d23d761b60338eb20ad178fd754ef19570abe6030663137d" |
| 4559 | dependencies = [ | 4581 | dependencies = [ |
| 4560 | "heck", | 4582 | "heck", |
| 4561 | "inventory", | 4583 | "inventory", |
| @@ -4570,9 +4592,9 @@ dependencies = [ | |||
| 4570 | 4592 | ||
| 4571 | [[package]] | 4593 | [[package]] |
| 4572 | name = "topcoat-font-grammar" | 4594 | name = "topcoat-font-grammar" |
| 4573 | -version = "0.6.2" | 4595 | +version = "0.8.0" |
| 4574 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4596 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4575 | -checksum = "5b7d68e226827fb7531d0dba69cb74fa7b82515f8428fd1a75f556f5a2bf87c1" | 4597 | +checksum = "6125e270bb16bf826a54e4b40b41484682b2b660af4803688887f64a9918745a" |
| 4576 | dependencies = [ | 4598 | dependencies = [ |
| 4577 | "proc-macro2", | 4599 | "proc-macro2", |
| 4578 | "quote", | 4600 | "quote", |
| @@ -4583,9 +4605,9 @@ dependencies = [ | |||
| 4583 | 4605 | ||
| 4584 | [[package]] | 4606 | [[package]] |
| 4585 | name = "topcoat-font-macro" | 4607 | name = "topcoat-font-macro" |
| 4586 | -version = "0.6.2" | 4608 | +version = "0.8.0" |
| 4587 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4609 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4588 | -checksum = "e655c430bcb380f879603ea750c6222ade2ff3ade33869d9eaa32e3fc49f5469" | 4610 | +checksum = "5f46d0a9c08e7bf774683c05add490824af80a844f410e6ffc9fdaf00c88d7be" |
| 4589 | dependencies = [ | 4611 | dependencies = [ |
| 4590 | "quote", | 4612 | "quote", |
| 4591 | "syn 2.0.119", | 4613 | "syn 2.0.119", |
| @@ -4594,9 +4616,9 @@ dependencies = [ | |||
| 4594 | 4616 | ||
| 4595 | [[package]] | 4617 | [[package]] |
| 4596 | name = "topcoat-mail" | 4618 | name = "topcoat-mail" |
| 4597 | -version = "0.6.2" | 4619 | +version = "0.8.0" |
| 4598 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4620 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4599 | -checksum = "959c9c32172ad3840f94c589a29bd143c072661c9abf2215a68fd76440ed2300" | 4621 | +checksum = "1b8fa0e1ad5a4f4419c50b783ac565426df5c30dfa3dc9ca9602c8cd1c3535a3" |
| 4600 | dependencies = [ | 4622 | dependencies = [ |
| 4601 | "lettre", | 4623 | "lettre", |
| 4602 | "thiserror", | 4624 | "thiserror", |
| @@ -4608,9 +4630,9 @@ dependencies = [ | |||
| 4608 | 4630 | ||
| 4609 | [[package]] | 4631 | [[package]] |
| 4610 | name = "topcoat-router" | 4632 | name = "topcoat-router" |
| 4611 | -version = "0.6.2" | 4633 | +version = "0.8.0" |
| 4612 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4634 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4613 | -checksum = "e062bd348df5647f6904f4f4045b3c92c08c4a8826196e8e91a51aade00b5764" | 4635 | +checksum = "9f452945373fac2b61a4050639681829e99afeea872faebc93ef0b03c4211335" |
| 4614 | dependencies = [ | 4636 | dependencies = [ |
| 4615 | "bytes", | 4637 | "bytes", |
| 4616 | "form_urlencoded", | 4638 | "form_urlencoded", |
| @@ -4626,6 +4648,7 @@ dependencies = [ | |||
| 4626 | "matchit", | 4648 | "matchit", |
| 4627 | "multer", | 4649 | "multer", |
| 4628 | "percent-encoding", | 4650 | "percent-encoding", |
| 4651 | + "pin-project-lite", | ||
| 4629 | "ref-cast", | 4652 | "ref-cast", |
| 4630 | "serde", | 4653 | "serde", |
| 4631 | "serde_json", | 4654 | "serde_json", |
| @@ -4640,9 +4663,9 @@ dependencies = [ | |||
| 4640 | 4663 | ||
| 4641 | [[package]] | 4664 | [[package]] |
| 4642 | name = "topcoat-router-grammar" | 4665 | name = "topcoat-router-grammar" |
| 4643 | -version = "0.6.2" | 4666 | +version = "0.8.0" |
| 4644 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4667 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4645 | -checksum = "c052423d2aa4039036f1ac5567d1e2dac48897602d34561b3024a87830e5bdce" | 4668 | +checksum = "188df45ec401d790e3dd84564580c5c436a456331a187bdbfb7441f8e48fa1ca" |
| 4646 | dependencies = [ | 4669 | dependencies = [ |
| 4647 | "heck", | 4670 | "heck", |
| 4648 | "proc-macro2", | 4671 | "proc-macro2", |
| @@ -4653,9 +4676,9 @@ dependencies = [ | |||
| 4653 | 4676 | ||
| 4654 | [[package]] | 4677 | [[package]] |
| 4655 | name = "topcoat-router-macro" | 4678 | name = "topcoat-router-macro" |
| 4656 | -version = "0.6.2" | 4679 | +version = "0.8.0" |
| 4657 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4680 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4658 | -checksum = "cea98692b786bab3adda35a60d71981f60b2a98c6e7105ac92e582b7c9ce9cab" | 4681 | +checksum = "ac6f9a61d3ecfe1252b861795070c4317aca6b816382919d9c941eccad2fe42d" |
| 4659 | dependencies = [ | 4682 | dependencies = [ |
| 4660 | "quote", | 4683 | "quote", |
| 4661 | "syn 2.0.119", | 4684 | "syn 2.0.119", |
| @@ -4664,9 +4687,9 @@ dependencies = [ | |||
| 4664 | 4687 | ||
| 4665 | [[package]] | 4688 | [[package]] |
| 4666 | name = "topcoat-runtime" | 4689 | name = "topcoat-runtime" |
| 4667 | -version = "0.6.2" | 4690 | +version = "0.8.0" |
| 4668 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4691 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4669 | -checksum = "5dea200c86ca554bab7410f09cae8790a8adcbfd8f306eb78db7092ca71f8aae" | 4692 | +checksum = "b75367a6fb32878f28bb1e42fe97385c9b14f1d3455b0bb69afb399260a8995a" |
| 4670 | dependencies = [ | 4693 | dependencies = [ |
| 4671 | "inventory", | 4694 | "inventory", |
| 4672 | "ref-cast", | 4695 | "ref-cast", |
| @@ -4676,14 +4699,13 @@ dependencies = [ | |||
| 4676 | "topcoat-core", | 4699 | "topcoat-core", |
| 4677 | "topcoat-router", | 4700 | "topcoat-router", |
| 4678 | "topcoat-view", | 4701 | "topcoat-view", |
| 4679 | - "uuid", | ||
| 4680 | ] | 4702 | ] |
| 4681 | 4703 | ||
| 4682 | [[package]] | 4704 | [[package]] |
| 4683 | name = "topcoat-runtime-grammar" | 4705 | name = "topcoat-runtime-grammar" |
| 4684 | -version = "0.6.2" | 4706 | +version = "0.8.0" |
| 4685 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4707 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4686 | -checksum = "87b73f7e4e10f49e006a71dd43e8ee629c76c08451acbc51faa7ec5b6952c53c" | 4708 | +checksum = "c19d5cf0ad59525a9fdd0a6ada36448833b39b85602736df16d32712f6c3a3c8" |
| 4687 | dependencies = [ | 4709 | dependencies = [ |
| 4688 | "proc-macro2", | 4710 | "proc-macro2", |
| 4689 | "quote", | 4711 | "quote", |
| @@ -4697,9 +4719,9 @@ dependencies = [ | |||
| 4697 | 4719 | ||
| 4698 | [[package]] | 4720 | [[package]] |
| 4699 | name = "topcoat-runtime-macro" | 4721 | name = "topcoat-runtime-macro" |
| 4700 | -version = "0.6.2" | 4722 | +version = "0.8.0" |
| 4701 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4723 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4702 | -checksum = "5dc3e4e245abcaea6af780437cae072e8f2157c9852ec5b3058a658c61b9e0bf" | 4724 | +checksum = "3504cd2966788c4cb6f417a9f73faf3ae2631c5aa415bc0d37d142ba597d5c42" |
| 4703 | dependencies = [ | 4725 | dependencies = [ |
| 4704 | "quote", | 4726 | "quote", |
| 4705 | "syn 2.0.119", | 4727 | "syn 2.0.119", |
| @@ -4708,9 +4730,9 @@ dependencies = [ | |||
| 4708 | 4730 | ||
| 4709 | [[package]] | 4731 | [[package]] |
| 4710 | name = "topcoat-session" | 4732 | name = "topcoat-session" |
| 4711 | -version = "0.6.2" | 4733 | +version = "0.8.0" |
| 4712 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4734 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4713 | -checksum = "e079e8c5a63987d7f929ab05a75922feab1fe390a9cfa2c101eb35829e67eac2" | 4735 | +checksum = "d432a276f3d7e4e0af0f9789ee0c919fbfbf8d2025d0dac7f8072a918521cf6d" |
| 4714 | dependencies = [ | 4736 | dependencies = [ |
| 4715 | "base64 0.22.1", | 4737 | "base64 0.22.1", |
| 4716 | "getrandom 0.4.3", | 4738 | "getrandom 0.4.3", |
| @@ -4725,25 +4747,26 @@ dependencies = [ | |||
| 4725 | 4747 | ||
| 4726 | [[package]] | 4748 | [[package]] |
| 4727 | name = "topcoat-view" | 4749 | name = "topcoat-view" |
| 4728 | -version = "0.6.2" | 4750 | +version = "0.8.0" |
| 4729 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4751 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4730 | -checksum = "5904449bd6f633759d187fa621ded68178b551428c297959fd53d8fb91f3e6f6" | 4752 | +checksum = "4acc959c83729cb4b967c2e7de8ee78a2fc3216cceb1be650ee9524fabd26baa" |
| 4731 | dependencies = [ | 4753 | dependencies = [ |
| 4754 | + "base64 0.22.1", | ||
| 4732 | "futures-core", | 4755 | "futures-core", |
| 4733 | "futures-util", | 4756 | "futures-util", |
| 4734 | "http", | 4757 | "http", |
| 4735 | - "itoa", | ||
| 4736 | "memchr", | 4758 | "memchr", |
| 4737 | "pin-project-lite", | 4759 | "pin-project-lite", |
| 4760 | + "siphasher", | ||
| 4738 | "smallvec", | 4761 | "smallvec", |
| 4739 | "topcoat-core", | 4762 | "topcoat-core", |
| 4740 | ] | 4763 | ] |
| 4741 | 4764 | ||
| 4742 | [[package]] | 4765 | [[package]] |
| 4743 | name = "topcoat-view-grammar" | 4766 | name = "topcoat-view-grammar" |
| 4744 | -version = "0.6.2" | 4767 | +version = "0.8.0" |
| 4745 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4768 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4746 | -checksum = "1bf4293156d7c5fa7960edc573b686eb27426dcd888bfbe9e532304178cdda24" | 4769 | +checksum = "fa71393a00dba3ce203d3236e24311851134721f5bfae6a17bfacd709a983660" |
| 4747 | dependencies = [ | 4770 | dependencies = [ |
| 4748 | "heck", | 4771 | "heck", |
| 4749 | "proc-macro2", | 4772 | "proc-macro2", |
| @@ -4755,9 +4778,9 @@ dependencies = [ | |||
| 4755 | 4778 | ||
| 4756 | [[package]] | 4779 | [[package]] |
| 4757 | name = "topcoat-view-macro" | 4780 | name = "topcoat-view-macro" |
| 4758 | -version = "0.6.2" | 4781 | +version = "0.8.0" |
| 4759 | source = "registry+https://github.com/rust-lang/crates.io-index" | 4782 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 4760 | -checksum = "58ab2b200eda4516abdb543f307006d83fedd3681b871d2042c17106c688f716" | 4783 | +checksum = "2a625be243364f6674204ba412700d9eed2a1c9168f7add3b1020be4825f0e49" |
| 4761 | dependencies = [ | 4784 | dependencies = [ |
| 4762 | "quote", | 4785 | "quote", |
| 4763 | "syn 2.0.119", | 4786 | "syn 2.0.119", |
| @@ -5194,11 +5217,11 @@ dependencies = [ | |||
| 5194 | 5217 | ||
| 5195 | [[package]] | 5218 | [[package]] |
| 5196 | name = "ulid" | 5219 | name = "ulid" |
| 5197 | -version = "1.2.1" | 5220 | +version = "3.0.0" |
| 5198 | source = "registry+https://github.com/rust-lang/crates.io-index" | 5221 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 5199 | -checksum = "470dbf6591da1b39d43c14523b2b469c86879a53e8b758c8e090a470fe7b1fbe" | 5222 | +checksum = "947dde63b6d514cc5e044edad4e0ca7261afd1099d16c83d942cb2b2f348689c" |
| 5200 | dependencies = [ | 5223 | dependencies = [ |
| 5201 | - "rand 0.9.5", | 5224 | + "rand 0.10.2", |
| 5202 | "web-time", | 5225 | "web-time", |
| 5203 | ] | 5226 | ] |
| 5204 | 5227 | ||
| @@ -5233,6 +5256,16 @@ dependencies = [ | |||
| 5233 | "subtle", | 5256 | "subtle", |
| 5234 | ] | 5257 | ] |
| 5235 | 5258 | ||
| 5259 | +[[package]] | ||
| 5260 | +name = "universal-hash" | ||
| 5261 | +version = "0.6.1" | ||
| 5262 | +source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 5263 | +checksum = "f4987bdc12753382e0bec4a65c50738ffaabc998b9cdd1f952fb5f39b0048a96" | ||
| 5264 | +dependencies = [ | ||
| 5265 | + "crypto-common 0.2.2", | ||
| 5266 | + "ctutils", | ||
| 5267 | +] | ||
| 5268 | + | ||
| 5236 | [[package]] | 5269 | [[package]] |
| 5237 | name = "untrusted" | 5270 | name = "untrusted" |
| 5238 | version = "0.9.0" | 5271 | version = "0.9.0" |
| @@ -5791,9 +5824,9 @@ dependencies = [ | |||
| 5791 | 5824 | ||
| 5792 | [[package]] | 5825 | [[package]] |
| 5793 | name = "zip" | 5826 | name = "zip" |
| 5794 | -version = "8.6.0" | 5827 | +version = "9.0.0-pre3" |
| 5795 | source = "registry+https://github.com/rust-lang/crates.io-index" | 5828 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 5796 | -checksum = "2d04a6b5381502aa6087c94c669499eb1602eb9c5e8198e534de571f7154809b" | 5829 | +checksum = "58e8082c6efe6dbccc7e8ea3ebf6afe46a04847f2e0bcf772c8aebc933dd2ccf" |
| 5797 | dependencies = [ | 5830 | dependencies = [ |
| 5798 | "crc32fast", | 5831 | "crc32fast", |
| 5799 | "flate2", | 5832 | "flate2", |
Cargo.tomlmodified+4 -4
| @@ -16,11 +16,11 @@ in-client = { path = "crates/in-client" } | |||
| 16 | # pair the OIDC side already holds. The OIDC half stays gated off — this | 16 | # pair the OIDC side already holds. The OIDC half stays gated off — this |
| 17 | # app's own `in-client` fork keeps the auth routes, and two route sets in | 17 | # app's own `in-client` fork keeps the auth routes, and two route sets in |
| 18 | # one binary collide. | 18 | # one binary collide. |
| 19 | -im-client = { git = "https://github.com/DizeyLab/im", rev = "f7b2081", default-features = false } | 19 | +im-client = { git = "https://github.com/DizeyLab/im", rev = "25140f3", default-features = false } |
| 20 | serde = { version = "1.0.229", features = ["derive"] } | 20 | serde = { version = "1.0.229", features = ["derive"] } |
| 21 | serde_json = "1.0.151" | 21 | serde_json = "1.0.151" |
| 22 | thiserror = "2.0.20" | 22 | thiserror = "2.0.20" |
| 23 | -ulid = "1" | 23 | +ulid = "3" |
| 24 | time = { version = "0.3.55", features = ["serde", "formatting", "parsing", "macros"] } | 24 | time = { version = "0.3.55", features = ["serde", "formatting", "parsing", "macros"] } |
| 25 | tokio = { version = "1.53.1", features = ["full"] } | 25 | tokio = { version = "1.53.1", features = ["full"] } |
| 26 | turso = "=0.8.0-pre.10" | 26 | turso = "=0.8.0-pre.10" |
| @@ -28,8 +28,8 @@ rand = "0.10.2" | |||
| 28 | sha2 = "0.11.0" | 28 | sha2 = "0.11.0" |
| 29 | subtle = "2.6.1" | 29 | subtle = "2.6.1" |
| 30 | argon2 = "0.6.0" | 30 | argon2 = "0.6.0" |
| 31 | -chacha20poly1305 = "0.10.1" | 31 | +chacha20poly1305 = "0.11.0" |
| 32 | -base64 = "0.22.1" | 32 | +base64 = "0.23.1" |
| 33 | toml = "1" | 33 | toml = "1" |
| 34 | async-trait = "0.1.92" | 34 | async-trait = "0.1.92" |
| 35 | object_store = { version = "=0.14.1", default-features = false, features = ["aws"] } | 35 | object_store = { version = "=0.14.1", default-features = false, features = ["aws"] } |
crates/in-client/Cargo.tomlmodified+8 -9
| @@ -7,7 +7,7 @@ repository.workspace = true | |||
| 7 | description = "Drop-in OIDC client for topcoat apps authenticating against im" | 7 | description = "Drop-in OIDC client for topcoat apps authenticating against im" |
| 8 | 8 | ||
| 9 | [dependencies] | 9 | [dependencies] |
| 10 | -topcoat = { version = "0.6.2", default-features = false, features = [ | 10 | +topcoat = { version = "0.8.0", default-features = false, features = [ |
| 11 | "router", | 11 | "router", |
| 12 | "cookie", | 12 | "cookie", |
| 13 | ] } | 13 | ] } |
| @@ -21,10 +21,9 @@ rand.workspace = true | |||
| 21 | sha2.workspace = true | 21 | sha2.workspace = true |
| 22 | subtle.workspace = true | 22 | subtle.workspace = true |
| 23 | chacha20poly1305.workspace = true | 23 | chacha20poly1305.workspace = true |
| 24 | -# rsa 0.9 verifies through the digest 0.10 traits, so its hasher comes from | 24 | +# rsa 0.10 verifies through the digest 0.11 traits, so its hasher is the |
| 25 | -# the sha2 0.10 line; the workspace sha2 0.11 stays for PKCE. | 25 | +# workspace sha2 0.11 that PKCE already uses. |
| 26 | -sha2-for-rsa = { package = "sha2", version = "0.10", features = ["oid"] } | 26 | +rsa = "0.10.0-rc.18" |
| 27 | -rsa = "0.9.10" | ||
| 28 | reqwest = { version = "0.13.5", default-features = false, features = [ | 27 | reqwest = { version = "0.13.5", default-features = false, features = [ |
| 29 | "rustls", | 28 | "rustls", |
| 30 | "json", | 29 | "json", |
| @@ -36,7 +35,7 @@ reqwest = { version = "0.13.5", default-features = false, features = [ | |||
| 36 | test-seam = [] | 35 | test-seam = [] |
| 37 | 36 | ||
| 38 | [dev-dependencies] | 37 | [dev-dependencies] |
| 39 | -topcoat = { version = "0.6.2", default-features = false, features = [ | 38 | +topcoat = { version = "0.8.0", default-features = false, features = [ |
| 40 | "router", | 39 | "router", |
| 41 | "cookie", | 40 | "cookie", |
| 42 | "view", | 41 | "view", |
| @@ -44,9 +43,9 @@ topcoat = { version = "0.6.2", default-features = false, features = [ | |||
| 44 | "discover", | 43 | "discover", |
| 45 | ] } | 44 | ] } |
| 46 | http = "1.5" | 45 | http = "1.5" |
| 47 | -# Tests generate their own RSA keys, and rsa 0.9's RNG is the rand_core 0.6 | 46 | +# Tests generate their own RSA keys, and rsa 0.10's RNG is the rand_core 0.10 |
| 48 | -# line. | 47 | +# line that the workspace rand 0.10 provides. |
| 49 | -rand_core06 = { package = "rand_core", version = "0.6.4", features = ["getrandom"] } | 48 | +rand_core010 = { package = "rand_core", version = "0.10.1" } |
| 50 | 49 | ||
| 51 | [[example]] | 50 | [[example]] |
| 52 | name = "mint" | 51 | name = "mint" |
crates/in-client/src/lib.rsmodified+11 -12
| @@ -371,7 +371,7 @@ fn seal(key: &[u8; 32], plaintext: &[u8]) -> String { | |||
| 371 | let mut nonce_bytes = [0u8; 24]; | 371 | let mut nonce_bytes = [0u8; 24]; |
| 372 | rand::rng().fill_bytes(&mut nonce_bytes); | 372 | rand::rng().fill_bytes(&mut nonce_bytes); |
| 373 | let ciphertext = cipher | 373 | let ciphertext = cipher |
| 374 | - .encrypt(XNonce::from_slice(&nonce_bytes), plaintext) | 374 | + .encrypt(&XNonce::from(nonce_bytes), plaintext) |
| 375 | .expect("XChaCha20-Poly1305 cannot fail on a payload this small"); | 375 | .expect("XChaCha20-Poly1305 cannot fail on a payload this small"); |
| 376 | let mut payload = nonce_bytes.to_vec(); | 376 | let mut payload = nonce_bytes.to_vec(); |
| 377 | payload.extend_from_slice(&ciphertext); | 377 | payload.extend_from_slice(&ciphertext); |
| @@ -385,9 +385,8 @@ fn open(key: &[u8; 32], sealed: &str) -> Option<Vec<u8>> { | |||
| 385 | } | 385 | } |
| 386 | let (nonce_bytes, ciphertext) = payload.split_at(24); | 386 | let (nonce_bytes, ciphertext) = payload.split_at(24); |
| 387 | let cipher = XChaCha20Poly1305::new(key.into()); | 387 | let cipher = XChaCha20Poly1305::new(key.into()); |
| 388 | - cipher | 388 | + let nonce: &XNonce = nonce_bytes.try_into().ok()?; |
| 389 | - .decrypt(XNonce::from_slice(nonce_bytes), ciphertext) | 389 | + cipher.decrypt(nonce, ciphertext).ok() |
| 390 | - .ok() | ||
| 391 | } | 390 | } |
| 392 | 391 | ||
| 393 | fn seal_json<T: Serialize>(key: &[u8; 32], value: &T) -> String { | 392 | fn seal_json<T: Serialize>(key: &[u8; 32], value: &T) -> String { |
| @@ -754,7 +753,7 @@ fn verify_claims( | |||
| 754 | .map_err(|e| Error::Token(e.to_string()))?; | 753 | .map_err(|e| Error::Token(e.to_string()))?; |
| 755 | let signature = rsa::pkcs1v15::Signature::try_from(signature_bytes.as_slice()) | 754 | let signature = rsa::pkcs1v15::Signature::try_from(signature_bytes.as_slice()) |
| 756 | .map_err(|e| Error::Token(e.to_string()))?; | 755 | .map_err(|e| Error::Token(e.to_string()))?; |
| 757 | - let verifying = rsa::pkcs1v15::VerifyingKey::<sha2_for_rsa::Sha256>::new(key.clone()); | 756 | + let verifying = rsa::pkcs1v15::VerifyingKey::<sha2::Sha256>::new(key.clone()); |
| 758 | verifying | 757 | verifying |
| 759 | .verify(format!("{}.{}", parts[0], parts[1]).as_bytes(), &signature) | 758 | .verify(format!("{}.{}", parts[0], parts[1]).as_bytes(), &signature) |
| 760 | .map_err(|_| Error::Token("bad signature".into()))?; | 759 | .map_err(|_| Error::Token("bad signature".into()))?; |
| @@ -815,8 +814,8 @@ async fn refetch_jwks(state: &InClient) -> Result<()> { | |||
| 815 | continue; | 814 | continue; |
| 816 | }; | 815 | }; |
| 817 | let key = rsa::RsaPublicKey::new( | 816 | let key = rsa::RsaPublicKey::new( |
| 818 | - rsa::BigUint::from_bytes_be(&n), | 817 | + rsa::BoxedUint::from_be_slice_vartime(&n), |
| 819 | - rsa::BigUint::from_bytes_be(&e), | 818 | + rsa::BoxedUint::from_be_slice_vartime(&e), |
| 820 | ) | 819 | ) |
| 821 | .map_err(|err| Error::Token(format!("bad jwk {kid}: {err}")))?; | 820 | .map_err(|err| Error::Token(format!("bad jwk {kid}: {err}")))?; |
| 822 | keys.push((kid.to_string(), key)); | 821 | keys.push((kid.to_string(), key)); |
| @@ -838,8 +837,8 @@ mod tests { | |||
| 838 | 837 | ||
| 839 | fn keypair() -> (rsa::RsaPrivateKey, rsa::RsaPublicKey) { | 838 | fn keypair() -> (rsa::RsaPrivateKey, rsa::RsaPublicKey) { |
| 840 | // 2048-bit generation is slow for a unit test; 1024 is the smallest | 839 | // 2048-bit generation is slow for a unit test; 1024 is the smallest |
| 841 | - // rsa 0.9 accepts and the signature math under test is identical. | 840 | + // rsa accepts and the signature math under test is identical. |
| 842 | - let private = rsa::RsaPrivateKey::new(&mut rand_core06::OsRng, 1024).unwrap(); | 841 | + let private = rsa::RsaPrivateKey::new(&mut rand::rng(), 1024).unwrap(); |
| 843 | let public = private.to_public_key(); | 842 | let public = private.to_public_key(); |
| 844 | (private, public) | 843 | (private, public) |
| 845 | } | 844 | } |
| @@ -849,7 +848,7 @@ mod tests { | |||
| 849 | let mut out = b64url.encode(header.to_string()); | 848 | let mut out = b64url.encode(header.to_string()); |
| 850 | out.push('.'); | 849 | out.push('.'); |
| 851 | out.push_str(&b64url.encode(claims.to_string())); | 850 | out.push_str(&b64url.encode(claims.to_string())); |
| 852 | - let signing = rsa::pkcs1v15::SigningKey::<sha2_for_rsa::Sha256>::new(key.clone()); | 851 | + let signing = rsa::pkcs1v15::SigningKey::<sha2::Sha256>::new(key.clone()); |
| 853 | let signature = signing.sign(out.as_bytes()); | 852 | let signature = signing.sign(out.as_bytes()); |
| 854 | format!("{}.{}", out, b64url.encode(signature.to_bytes())) | 853 | format!("{}.{}", out, b64url.encode(signature.to_bytes())) |
| 855 | } | 854 | } |
| @@ -1238,8 +1237,8 @@ mod tests { | |||
| 1238 | serde_json::json!({ | 1237 | serde_json::json!({ |
| 1239 | "kty": "RSA", | 1238 | "kty": "RSA", |
| 1240 | "kid": kid, | 1239 | "kid": kid, |
| 1241 | - "n": b64url.encode(public.n().to_bytes_be()), | 1240 | + "n": b64url.encode(public.n().to_be_bytes()), |
| 1242 | - "e": b64url.encode(public.e().to_bytes_be()), | 1241 | + "e": b64url.encode(public.e().to_be_bytes()), |
| 1243 | }) | 1242 | }) |
| 1244 | } | 1243 | } |
| 1245 | 1244 | ||
crates/in-core/Cargo.tomlmodified+1 -1
| @@ -61,4 +61,4 @@ tempfile = "3" | |||
| 61 | s3s = "=0.15.0" | 61 | s3s = "=0.15.0" |
| 62 | s3s-fs = "=0.15.0" | 62 | s3s-fs = "=0.15.0" |
| 63 | hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] } | 63 | hyper-util = { version = "0.1", features = ["tokio", "server-auto", "http1"] } |
| 64 | -zip = { version = "8.6.0", default-features = false, features = ["deflate"] } | 64 | +zip = { version = "9.0.0-pre3", default-features = false, features = ["deflate"] } |
crates/in-core/src/config.rsmodified+1 -1
| @@ -737,7 +737,7 @@ mod tests { | |||
| 737 | 737 | ||
| 738 | impl Scratch { | 738 | impl Scratch { |
| 739 | fn new() -> Self { | 739 | fn new() -> Self { |
| 740 | - let dir = std::env::temp_dir().join(format!("in-config-test-{}", Ulid::new())); | 740 | + let dir = std::env::temp_dir().join(format!("in-config-test-{}", Ulid::generate())); |
| 741 | std::fs::create_dir_all(dir.join("config")).unwrap(); | 741 | std::fs::create_dir_all(dir.join("config")).unwrap(); |
| 742 | Self { dir } | 742 | Self { dir } |
| 743 | } | 743 | } |
crates/in-core/src/store/blobs.rsmodified+1 -1
| @@ -145,7 +145,7 @@ impl Blobs for LocalBlobs { | |||
| 145 | // Temp name in the destination's own directory, then a rename: a | 145 | // Temp name in the destination's own directory, then a rename: a |
| 146 | // reader of the key never sees a prefix, and a crash leaves a | 146 | // reader of the key never sees a prefix, and a crash leaves a |
| 147 | // `.tmp` for the boot sweep rather than a half blob at the key. | 147 | // `.tmp` for the boot sweep rather than a half blob at the key. |
| 148 | - let tmp = path.with_extension(format!("{}.tmp", Ulid::new())); | 148 | + let tmp = path.with_extension(format!("{}.tmp", Ulid::generate())); |
| 149 | let mut file = std::fs::File::create(&tmp)?; | 149 | let mut file = std::fs::File::create(&tmp)?; |
| 150 | file.write_all(bytes)?; | 150 | file.write_all(bytes)?; |
| 151 | file.flush()?; | 151 | file.flush()?; |
crates/in-core/src/store/mod.rsmodified+7 -5
| @@ -15,6 +15,8 @@ use time::OffsetDateTime; | |||
| 15 | #[cfg(feature = "server")] | 15 | #[cfg(feature = "server")] |
| 16 | pub mod blobs; | 16 | pub mod blobs; |
| 17 | #[cfg(feature = "server")] | 17 | #[cfg(feature = "server")] |
| 18 | +pub mod r2; | ||
| 19 | +#[cfg(feature = "server")] | ||
| 18 | pub mod reconcile; | 20 | pub mod reconcile; |
| 19 | #[cfg(feature = "server")] | 21 | #[cfg(feature = "server")] |
| 20 | pub mod schema; | 22 | pub mod schema; |
| @@ -24,8 +26,6 @@ pub mod secret; | |||
| 24 | pub mod sniff; | 26 | pub mod sniff; |
| 25 | #[cfg(feature = "server")] | 27 | #[cfg(feature = "server")] |
| 26 | pub mod turso_store; | 28 | pub mod turso_store; |
| 27 | -#[cfg(feature = "server")] | ||
| 28 | -pub mod r2; | ||
| 29 | 29 | ||
| 30 | #[cfg(feature = "server")] | 30 | #[cfg(feature = "server")] |
| 31 | pub use reconcile::{ReconcileOptions, reconcile}; | 31 | pub use reconcile::{ReconcileOptions, reconcile}; |
| @@ -427,7 +427,6 @@ pub trait Store: 'static + Send + Sync { | |||
| 427 | 427 | ||
| 428 | /// Writes the person's display preferences — `theme` ('light'/'dark'), | 428 | /// Writes the person's display preferences — `theme` ('light'/'dark'), |
| 429 | /// `language` ('en'/'tr') and `ui` ('ledger'/'instrument') — read by | 429 | /// `language` ('en'/'tr') and `ui` ('ledger'/'instrument') — read by |
| 430 | - | ||
| 431 | /// `root_layout` into `data-theme`, `<html lang>` and `data-ui`. A value | 430 | /// `root_layout` into `data-theme`, `<html lang>` and `data-ui`. A value |
| 432 | /// no preferences form offers is refused with [`StoreError::Corrupt`] — | 431 | /// no preferences form offers is refused with [`StoreError::Corrupt`] — |
| 433 | /// the same refusal a bad enum read from the row gets, because a bad | 432 | /// the same refusal a bad enum read from the row gets, because a bad |
| @@ -489,8 +488,11 @@ pub trait Store: 'static + Send + Sync { | |||
| 489 | 488 | ||
| 490 | /// The bytes themselves, by the service's own handle. `None` when there | 489 | /// The bytes themselves, by the service's own handle. `None` when there |
| 491 | /// is no such row, or its file went missing. | 490 | /// is no such row, or its file went missing. |
| 492 | - async fn service_file_bytes(&self, owner_id: &str, external_id: &str) | 491 | + async fn service_file_bytes( |
| 493 | - -> Result<Option<Vec<u8>>>; | 492 | + &self, |
| 493 | + owner_id: &str, | ||
| 494 | + external_id: &str, | ||
| 495 | + ) -> Result<Option<Vec<u8>>>; | ||
| 494 | 496 | ||
| 495 | /// Takes a service file away for good — the row, its bytes, and the | 497 | /// Takes a service file away for good — the row, its bytes, and the |
| 496 | /// usage they carried. No trash: a machine client's delete is a delete. | 498 | /// usage they carried. No trash: a machine client's delete is a delete. |
crates/in-core/src/store/reconcile.rsmodified+2 -2
| @@ -125,8 +125,8 @@ pub async fn reconcile( | |||
| 125 | // Best-effort undo so the live file is not gone. If this also fails, | 125 | // Best-effort undo so the live file is not gone. If this also fails, |
| 126 | // the caller has both the backup and the rebuilt file to recover from. | 126 | // the caller has both the backup and the rebuilt file to recover from. |
| 127 | let _ = std::fs::rename(&backup_path, path); | 127 | let _ = std::fs::rename(&backup_path, path); |
| 128 | - let _ = rename_sibling(&backup_path, path, "-wal"); | 128 | + rename_sibling(&backup_path, path, "-wal"); |
| 129 | - let _ = rename_sibling(&backup_path, path, "-shm"); | 129 | + rename_sibling(&backup_path, path, "-shm"); |
| 130 | return Err(StoreError::Backend(format!( | 130 | return Err(StoreError::Backend(format!( |
| 131 | "failed to move rebuilt database into place {}: {}", | 131 | "failed to move rebuilt database into place {}: {}", |
| 132 | rebuilt_path, e | 132 | rebuilt_path, e |
crates/in-core/src/store/schema.rsmodified+24 -12
| @@ -52,11 +52,14 @@ pub async fn fingerprint(conn: &Connection) -> Result<String> { | |||
| 52 | .map_err(|e| StoreError::Backend(e.to_string()))?; | 52 | .map_err(|e| StoreError::Backend(e.to_string()))?; |
| 53 | 53 | ||
| 54 | let mut out = String::new(); | 54 | let mut out = String::new(); |
| 55 | - while let Some(row) = rows.next().await.map_err(|e| StoreError::Backend(e.to_string()))? { | 55 | + while let Some(row) = rows |
| 56 | + .next() | ||
| 57 | + .await | ||
| 58 | + .map_err(|e| StoreError::Backend(e.to_string()))? | ||
| 59 | + { | ||
| 56 | let t: String = row.get(0).map_err(|e| StoreError::Backend(e.to_string()))?; | 60 | let t: String = row.get(0).map_err(|e| StoreError::Backend(e.to_string()))?; |
| 57 | let name: String = row.get(1).map_err(|e| StoreError::Backend(e.to_string()))?; | 61 | let name: String = row.get(1).map_err(|e| StoreError::Backend(e.to_string()))?; |
| 58 | - let sql: Option<String> = | 62 | + let sql: Option<String> = row.get(2).map_err(|e| StoreError::Backend(e.to_string()))?; |
| 59 | - row.get(2).map_err(|e| StoreError::Backend(e.to_string()))?; | ||
| 60 | out.push_str(&t); | 63 | out.push_str(&t); |
| 61 | out.push('|'); | 64 | out.push('|'); |
| 62 | out.push_str(&name); | 65 | out.push_str(&name); |
| @@ -75,7 +78,9 @@ pub async fn declared_fingerprint() -> Result<String> { | |||
| 75 | .build() | 78 | .build() |
| 76 | .await | 79 | .await |
| 77 | .map_err(|e| StoreError::Backend(e.to_string()))?; | 80 | .map_err(|e| StoreError::Backend(e.to_string()))?; |
| 78 | - let conn = db.connect().map_err(|e| StoreError::Backend(e.to_string()))?; | 81 | + let conn = db |
| 82 | + .connect() | ||
| 83 | + .map_err(|e| StoreError::Backend(e.to_string()))?; | ||
| 79 | conn.execute_batch(&schema_sql()) | 84 | conn.execute_batch(&schema_sql()) |
| 80 | .await | 85 | .await |
| 81 | .map_err(|e| StoreError::Backend(e.to_string()))?; | 86 | .map_err(|e| StoreError::Backend(e.to_string()))?; |
| @@ -115,14 +120,20 @@ pub(crate) fn diff_report(old: &str, new: &str) -> String { | |||
| 115 | let mut changed = Vec::new(); | 120 | let mut changed = Vec::new(); |
| 116 | 121 | ||
| 117 | for old_obj in &old_objs { | 122 | for old_obj in &old_objs { |
| 118 | - match new_objs.iter().find(|n| n.kind == old_obj.kind && n.name == old_obj.name) { | 123 | + match new_objs |
| 124 | + .iter() | ||
| 125 | + .find(|n| n.kind == old_obj.kind && n.name == old_obj.name) | ||
| 126 | + { | ||
| 119 | Some(new_obj) if new_obj.sql != old_obj.sql => changed.push((old_obj, new_obj)), | 127 | Some(new_obj) if new_obj.sql != old_obj.sql => changed.push((old_obj, new_obj)), |
| 120 | Some(_) => {} | 128 | Some(_) => {} |
| 121 | None => missing.push(old_obj), | 129 | None => missing.push(old_obj), |
| 122 | } | 130 | } |
| 123 | } | 131 | } |
| 124 | for new_obj in &new_objs { | 132 | for new_obj in &new_objs { |
| 125 | - if !old_objs.iter().any(|o| o.kind == new_obj.kind && o.name == new_obj.name) { | 133 | + if !old_objs |
| 134 | + .iter() | ||
| 135 | + .any(|o| o.kind == new_obj.kind && o.name == new_obj.name) | ||
| 136 | + { | ||
| 126 | extra.push(new_obj); | 137 | extra.push(new_obj); |
| 127 | } | 138 | } |
| 128 | } | 139 | } |
| @@ -204,10 +215,10 @@ fn extract_column_names(sql: &str) -> Vec<String> { | |||
| 204 | _ => current.push(ch), | 215 | _ => current.push(ch), |
| 205 | } | 216 | } |
| 206 | } | 217 | } |
| 207 | - if !current.is_empty() { | 218 | + if !current.is_empty() |
| 208 | - if let Some(col) = first_identifier(¤t) { | 219 | + && let Some(col) = first_identifier(¤t) |
| 209 | - cols.push(col); | 220 | + { |
| 210 | - } | 221 | + cols.push(col); |
| 211 | } | 222 | } |
| 212 | cols | 223 | cols |
| 213 | } | 224 | } |
| @@ -263,7 +274,7 @@ fn normalize_schema(sql: &str) -> String { | |||
| 263 | 274 | ||
| 264 | if ch == '-' && chars.peek() == Some(&'-') { | 275 | if ch == '-' && chars.peek() == Some(&'-') { |
| 265 | chars.next(); | 276 | chars.next(); |
| 266 | - while let Some(c) = chars.next() { | 277 | + for c in chars.by_ref() { |
| 267 | if c == '\n' { | 278 | if c == '\n' { |
| 268 | break; | 279 | break; |
| 269 | } | 280 | } |
| @@ -364,7 +375,8 @@ mod tests { | |||
| 364 | fn if_not_exists_does_not_corrupt_identifiers() { | 375 | fn if_not_exists_does_not_corrupt_identifiers() { |
| 365 | // The stripper looks for whole tokens; words that merely appear | 376 | // The stripper looks for whole tokens; words that merely appear |
| 366 | // inside identifiers or string literals must stay put. | 377 | // inside identifiers or string literals must stay put. |
| 367 | - let a = "CREATE TABLE IF NOT EXISTS notification (if_not_exists TEXT DEFAULT 'IF NOT EXISTS');"; | 378 | + let a = |
| 379 | + "CREATE TABLE IF NOT EXISTS notification (if_not_exists TEXT DEFAULT 'IF NOT EXISTS');"; | ||
| 368 | let b = "CREATE TABLE notification (if_not_exists TEXT DEFAULT 'IF NOT EXISTS');"; | 380 | let b = "CREATE TABLE notification (if_not_exists TEXT DEFAULT 'IF NOT EXISTS');"; |
| 369 | assert_eq!(normalize_schema(a), normalize_schema(b)); | 381 | assert_eq!(normalize_schema(a), normalize_schema(b)); |
| 370 | } | 382 | } |
crates/in-core/src/store/secret.rsmodified+4 -4
| @@ -26,8 +26,8 @@ | |||
| 26 | use std::io; | 26 | use std::io; |
| 27 | use std::path::Path; | 27 | use std::path::Path; |
| 28 | 28 | ||
| 29 | -use base64::Engine; | ||
| 30 | use base64::engine::general_purpose::STANDARD as base64; | 29 | use base64::engine::general_purpose::STANDARD as base64; |
| 30 | +use base64::Engine; | ||
| 31 | use chacha20poly1305::aead::Aead; | 31 | use chacha20poly1305::aead::Aead; |
| 32 | use chacha20poly1305::{KeyInit, XChaCha20Poly1305, XNonce}; | 32 | use chacha20poly1305::{KeyInit, XChaCha20Poly1305, XNonce}; |
| 33 | use rand::Rng; | 33 | use rand::Rng; |
| @@ -57,9 +57,9 @@ pub fn seal(key: &Key, plaintext: &str) -> String { | |||
| 57 | let cipher = XChaCha20Poly1305::new(key.into()); | 57 | let cipher = XChaCha20Poly1305::new(key.into()); |
| 58 | let mut nonce_bytes = [0u8; NONCE_BYTES]; | 58 | let mut nonce_bytes = [0u8; NONCE_BYTES]; |
| 59 | rand::rng().fill_bytes(&mut nonce_bytes); | 59 | rand::rng().fill_bytes(&mut nonce_bytes); |
| 60 | - let nonce = XNonce::from_slice(&nonce_bytes); | 60 | + let nonce = XNonce::from(nonce_bytes); |
| 61 | let ciphertext = cipher | 61 | let ciphertext = cipher |
| 62 | - .encrypt(nonce, plaintext.as_bytes()) | 62 | + .encrypt(&nonce, plaintext.as_bytes()) |
| 63 | .expect("XChaCha20-Poly1305 cannot fail to encrypt a plaintext this small"); | 63 | .expect("XChaCha20-Poly1305 cannot fail to encrypt a plaintext this small"); |
| 64 | let mut payload = Vec::with_capacity(NONCE_BYTES + ciphertext.len()); | 64 | let mut payload = Vec::with_capacity(NONCE_BYTES + ciphertext.len()); |
| 65 | payload.extend_from_slice(&nonce_bytes); | 65 | payload.extend_from_slice(&nonce_bytes); |
| @@ -80,7 +80,7 @@ pub fn open(key: &Key, sealed: &str) -> Option<String> { | |||
| 80 | } | 80 | } |
| 81 | let (nonce_bytes, ciphertext) = payload.split_at(NONCE_BYTES); | 81 | let (nonce_bytes, ciphertext) = payload.split_at(NONCE_BYTES); |
| 82 | let cipher = XChaCha20Poly1305::new(key.into()); | 82 | let cipher = XChaCha20Poly1305::new(key.into()); |
| 83 | - let nonce = XNonce::from_slice(nonce_bytes); | 83 | + let nonce: &XNonce = nonce_bytes.try_into().ok()?; |
| 84 | let plaintext = cipher.decrypt(nonce, ciphertext).ok()?; | 84 | let plaintext = cipher.decrypt(nonce, ciphertext).ok()?; |
| 85 | String::from_utf8(plaintext).ok() | 85 | String::from_utf8(plaintext).ok() |
| 86 | } | 86 | } |
crates/in-core/src/store/sniff.rsmodified+4 -204
| @@ -3,38 +3,9 @@ | |||
| 3 | //! | 3 | //! |
| 4 | //! Pure `bytes -> mime`, with no I/O and nothing browser-shaped in it, living | 4 | //! Pure `bytes -> mime`, with no I/O and nothing browser-shaped in it, living |
| 5 | //! behind the same `server` gate as the store it serves. The upload path | 5 | //! behind the same `server` gate as the store it serves. The upload path |
| 6 | -//! sniffs a file once when it arrives; [`TursoStore::open`] additionally runs | 6 | +//! sniffs a file once when it arrives, and the store cannot reach the web |
| 7 | -//! [`refine`] over rows whose stored type is one of the [`GENERIC_MIME_TYPES`] | 7 | +//! crate, so this one definition serves every caller — a second sniffer |
| 8 | -//! buckets, so attachments written before the sniffer could name OOXML files | 8 | +//! would drift. |
| 9 | -//! come out of the next restart carrying their real type. One definition | ||
| 10 | -//! serves both callers: the store cannot reach the web crate, and a second | ||
| 11 | -//! sniffer would drift. | ||
| 12 | - | ||
| 13 | -/// The mime types the upload path can store that name nothing: a zip that is | ||
| 14 | -/// not an office document, bytes no magic matched, and an OLE container with | ||
| 15 | -/// no stream name to narrow it. The boot pass reads only rows wearing one of | ||
| 16 | -/// these; `text/plain` is deliberately absent — no window of a text file can | ||
| 17 | -/// ever refine it, so sweeping it would read every text blob on every boot | ||
| 18 | -/// for a guaranteed no-op. | ||
| 19 | -pub const GENERIC_MIME_TYPES: &[&str] = &[ | ||
| 20 | - "application/zip", | ||
| 21 | - "application/octet-stream", | ||
| 22 | - "application/x-ole-storage", | ||
| 23 | -]; | ||
| 24 | - | ||
| 25 | -/// Head bytes read per generic row: every prefix-magic format this sniffer | ||
| 26 | -/// knows decides from the first bytes, an OpenDocument file's `mimetype` | ||
| 27 | -/// entry is required to be the first thing in the file, and an OLE | ||
| 28 | -/// container's directory sectors precede its stream data. | ||
| 29 | -pub const HEAD_WINDOW: i64 = 64 * 1024; | ||
| 30 | -/// Tail bytes read per generic row. A zip ends with its end-of-central- | ||
| 31 | -/// directory record, which — comment included — can sit at most | ||
| 32 | -/// 22 + 65535 bytes from the end of the file, so a tail this wide can never | ||
| 33 | -/// miss it, and it usually holds much of the central directory besides. | ||
| 34 | -pub const TAIL_WINDOW: i64 = 128 * 1024; | ||
| 35 | -/// A central directory larger than this — tens of thousands of entries — is | ||
| 36 | -/// left unread and the row left exactly as stored. | ||
| 37 | -pub const DIRECTORY_CAP: i64 = 4 * 1024 * 1024; | ||
| 38 | 9 | ||
| 39 | pub fn sniff(bytes: &[u8]) -> &'static str { | 10 | pub fn sniff(bytes: &[u8]) -> &'static str { |
| 40 | if bytes.starts_with(&[0x89, 0x50, 0x4E, 0x47]) { | 11 | if bytes.starts_with(&[0x89, 0x50, 0x4E, 0x47]) { |
| @@ -261,9 +232,7 @@ fn ebml_element(bytes: &[u8], at: usize, end: usize) -> Option<(u32, u64, usize, | |||
| 261 | return None; | 232 | return None; |
| 262 | } | 233 | } |
| 263 | let start = at + id_width + size_width; | 234 | let start = at + id_width + size_width; |
| 264 | - let stop = start | 235 | + let stop = start.checked_add(usize::try_from(size).ok()?)?.min(end); |
| 265 | - .checked_add(usize::try_from(size).ok()?)? | ||
| 266 | - .min(end); | ||
| 267 | Some((id, size, start, stop)) | 236 | Some((id, size, start, stop)) |
| 268 | } | 237 | } |
| 269 | 238 | ||
| @@ -303,97 +272,6 @@ fn contains(haystack: &[u8], needle: &[u8]) -> bool { | |||
| 303 | .any(|window| window == needle) | 272 | .any(|window| window == needle) |
| 304 | } | 273 | } |
| 305 | 274 | ||
| 306 | -/// The office mime declared by the zip entry names in `bytes` — the central | ||
| 307 | -/// directory's vocabulary, where every entry a file holds is listed. An | ||
| 308 | -/// OpenDocument file is deliberately absent: its marker is the *content* of | ||
| 309 | -/// the `mimetype` entry the format requires be stored first, not an entry | ||
| 310 | -/// name, so it is decided from the head window and could never be found here. | ||
| 311 | -pub(crate) fn office_entry_mime(bytes: &[u8]) -> Option<&'static str> { | ||
| 312 | - if contains(bytes, b"xl/workbook.xml") { | ||
| 313 | - Some("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") | ||
| 314 | - } else if contains(bytes, b"ppt/presentation.xml") { | ||
| 315 | - Some("application/vnd.openxmlformats-officedocument.presentationml.presentation") | ||
| 316 | - } else { | ||
| 317 | - None | ||
| 318 | - } | ||
| 319 | -} | ||
| 320 | - | ||
| 321 | -/// What one generic row's byte windows decided. | ||
| 322 | -#[derive(Debug)] | ||
| 323 | -pub(crate) enum Verdict { | ||
| 324 | - /// Nothing left to read. `Some` is a candidate more specific than the | ||
| 325 | - /// stored bucket (subject to [`refinement`]), `None` means the windows | ||
| 326 | - /// could not improve on what is stored — and, for a zip, never will: | ||
| 327 | - /// whatever the central directory says, the search already covered it. | ||
| 328 | - Settle(Option<&'static str>), | ||
| 329 | - /// A zip whose windows name no office part. `offset`/`size` locate the | ||
| 330 | - /// central directory as the end record states them; reading it is the | ||
| 331 | - /// last word, because every entry name the file has is listed there. | ||
| 332 | - ReadDirectory { offset: u64, size: u64 }, | ||
| 333 | -} | ||
| 334 | - | ||
| 335 | -/// Decides a generic row from its head and tail windows alone. When the | ||
| 336 | -/// windows themselves hold a verdict it settles; only a zip with no office | ||
| 337 | -/// marker in either window asks for the central directory. | ||
| 338 | -pub(crate) fn refine(stored: &str, head: &[u8], tail: &[u8]) -> Verdict { | ||
| 339 | - let mut windows = Vec::with_capacity(head.len() + tail.len()); | ||
| 340 | - windows.extend_from_slice(head); | ||
| 341 | - windows.extend_from_slice(tail); | ||
| 342 | - match sniff(&windows) { | ||
| 343 | - "application/zip" => match end_of_central_directory(tail) { | ||
| 344 | - Some((offset, size)) => Verdict::ReadDirectory { offset, size }, | ||
| 345 | - None => Verdict::Settle(None), | ||
| 346 | - }, | ||
| 347 | - candidate => Verdict::Settle(refinement(stored, Some(candidate))), | ||
| 348 | - } | ||
| 349 | -} | ||
| 350 | - | ||
| 351 | -/// Whether `candidate` may replace `stored`: something specific, something | ||
| 352 | -/// other than what is stored, and never `text/plain` — a window cannot prove | ||
| 353 | -/// a whole blob is UTF-8, so a text verdict out of windows is unverifiable, | ||
| 354 | -/// and a text row would gain nothing from the sweep anyway. Everything else | ||
| 355 | -/// the sniffer names is either a prefix-magic fact (true of the whole blob | ||
| 356 | -/// when true of its head) or an office marker, both safe to act on. | ||
| 357 | -pub(crate) fn refinement(stored: &str, candidate: Option<&'static str>) -> Option<&'static str> { | ||
| 358 | - let candidate = candidate?; | ||
| 359 | - if candidate == stored | ||
| 360 | - || candidate == "text/plain" | ||
| 361 | - || GENERIC_MIME_TYPES.contains(&candidate) | ||
| 362 | - { | ||
| 363 | - return None; | ||
| 364 | - } | ||
| 365 | - Some(candidate) | ||
| 366 | -} | ||
| 367 | - | ||
| 368 | -/// The end-of-central-directory record every zip ends with: `PK\x05\x06`, | ||
| 369 | -/// then the directory's size (12..16) and offset (16..20), then a comment | ||
| 370 | -/// whose declared length must land exactly at the end of the bytes. Scanning | ||
| 371 | -/// from the end, the first signature satisfying that anchor is the record. | ||
| 372 | -/// `None` when there is none to trust: no record at all, or a zip64 one — | ||
| 373 | -/// the `u32::MAX` sentinels say the real numbers live in a zip64 locator | ||
| 374 | -/// this pass declines to parse, and a row it declines stays as stored. | ||
| 375 | -pub(crate) fn end_of_central_directory(tail: &[u8]) -> Option<(u64, u64)> { | ||
| 376 | - if tail.len() < 22 { | ||
| 377 | - return None; | ||
| 378 | - } | ||
| 379 | - for i in (0..=tail.len() - 22).rev() { | ||
| 380 | - if &tail[i..i + 4] != b"PK\x05\x06" { | ||
| 381 | - continue; | ||
| 382 | - } | ||
| 383 | - let comment = u16::from_le_bytes([tail[i + 20], tail[i + 21]]) as usize; | ||
| 384 | - if i + 22 + comment != tail.len() { | ||
| 385 | - continue; | ||
| 386 | - } | ||
| 387 | - let size = u32::from_le_bytes(tail[i + 12..i + 16].try_into().ok()?) as u64; | ||
| 388 | - let offset = u32::from_le_bytes(tail[i + 16..i + 20].try_into().ok()?) as u64; | ||
| 389 | - if offset == u32::MAX as u64 || size == u32::MAX as u64 { | ||
| 390 | - return None; | ||
| 391 | - } | ||
| 392 | - return Some((offset, size)); | ||
| 393 | - } | ||
| 394 | - None | ||
| 395 | -} | ||
| 396 | - | ||
| 397 | #[cfg(test)] | 275 | #[cfg(test)] |
| 398 | mod tests { | 276 | mod tests { |
| 399 | use super::*; | 277 | use super::*; |
| @@ -463,83 +341,6 @@ mod tests { | |||
| 463 | assert_eq!(sniff(&zip_with(&["notes.txt"])), "application/zip"); | 341 | assert_eq!(sniff(&zip_with(&["notes.txt"])), "application/zip"); |
| 464 | } | 342 | } |
| 465 | 343 | ||
| 466 | - #[test] | ||
| 467 | - fn a_workbook_declared_only_in_its_central_directory_is_found_by_the_directory_search() { | ||
| 468 | - let bytes = zip_with(&["ppt/presentation.xml", "ppt/slides/slide1.xml"]); | ||
| 469 | - let head = &bytes[..bytes.len() / 2]; | ||
| 470 | - // Both windows of a cut in half hold the marker, so the windows alone | ||
| 471 | - // settle a small file. | ||
| 472 | - assert!(contains(head, b"ppt/presentation.xml")); | ||
| 473 | - match refine("application/zip", head, &bytes[bytes.len() / 2..]) { | ||
| 474 | - Verdict::Settle(Some( | ||
| 475 | - "application/vnd.openxmlformats-officedocument.presentationml.presentation", | ||
| 476 | - )) => {} | ||
| 477 | - other => panic!("expected a settled presentation, got {other:?}"), | ||
| 478 | - } | ||
| 479 | - // The real end record survives its move into the synthetic tail. | ||
| 480 | - let (offset, size) = end_of_central_directory(&bytes).expect("a real zip has an EOCD"); | ||
| 481 | - let directory = &bytes[offset as usize..(offset + size) as usize]; | ||
| 482 | - assert_eq!( | ||
| 483 | - office_entry_mime(directory), | ||
| 484 | - Some("application/vnd.openxmlformats-officedocument.presentationml.presentation") | ||
| 485 | - ); | ||
| 486 | - } | ||
| 487 | - | ||
| 488 | - #[test] | ||
| 489 | - fn an_eocd_is_found_by_its_anchor_and_declined_when_zip64_or_absent() { | ||
| 490 | - // A hand-built record: signature, the two disk fields, two entry | ||
| 491 | - // counts, size, offset, a one-byte comment. | ||
| 492 | - let mut tail = Vec::new(); | ||
| 493 | - tail.extend_from_slice(b"PK\x05\x06"); | ||
| 494 | - tail.extend_from_slice(&[0, 0, 0, 0]); // disk numbers | ||
| 495 | - tail.extend_from_slice(&[1, 0, 1, 0]); // entry counts | ||
| 496 | - tail.extend_from_slice(&0x1122_3344u32.to_le_bytes()); // size | ||
| 497 | - tail.extend_from_slice(&0x5566_7788u32.to_le_bytes()); // offset | ||
| 498 | - tail.extend_from_slice(&1u16.to_le_bytes()); // comment length | ||
| 499 | - tail.push(b'!'); | ||
| 500 | - assert_eq!( | ||
| 501 | - end_of_central_directory(&tail), | ||
| 502 | - Some((0x5566_7788, 0x1122_3344)) | ||
| 503 | - ); | ||
| 504 | - // A lie about the comment length leaves the record unanchored. | ||
| 505 | - let mut drifting = tail.clone(); | ||
| 506 | - *drifting.last_mut().unwrap() = b'?'; | ||
| 507 | - drifting.push(b'!'); | ||
| 508 | - assert_eq!(end_of_central_directory(&drifting), None); | ||
| 509 | - // zip64 sentinels are declined rather than mis-read. | ||
| 510 | - let mut zip64 = tail.clone(); | ||
| 511 | - zip64[16..20].copy_from_slice(&u32::MAX.to_le_bytes()); | ||
| 512 | - assert_eq!(end_of_central_directory(&zip64), None); | ||
| 513 | - // No record, no verdict. | ||
| 514 | - assert_eq!(end_of_central_directory(b"PK\x03\x04 not a tail"), None); | ||
| 515 | - assert_eq!(end_of_central_directory(&[]), None); | ||
| 516 | - } | ||
| 517 | - | ||
| 518 | - #[test] | ||
| 519 | - fn a_refinement_must_be_specific_different_and_never_text() { | ||
| 520 | - assert_eq!(refinement("application/zip", Some("image/png")), Some("image/png")); | ||
| 521 | - assert_eq!(refinement("image/png", Some("image/png")), None, "no rewrite of the same value"); | ||
| 522 | - assert_eq!(refinement("application/zip", Some("text/plain")), None, "windows cannot prove text"); | ||
| 523 | - assert_eq!(refinement("application/zip", Some("application/zip")), None, "never narrowed"); | ||
| 524 | - assert_eq!(refinement("application/zip", Some("application/octet-stream")), None); | ||
| 525 | - assert_eq!(refinement("application/zip", None), None); | ||
| 526 | - } | ||
| 527 | - | ||
| 528 | - #[test] | ||
| 529 | - fn an_opendocument_file_is_decided_from_the_head_window_alone() { | ||
| 530 | - // The format requires the `mimetype` entry first, stored | ||
| 531 | - // uncompressed: its marker is the first thing in the file. | ||
| 532 | - let head = b"PK\x03\x04\x08\x00\x00\x00mimetypeapplication/vnd.oasis.opendocument.spreadsheet"; | ||
| 533 | - match refine("application/zip", head, b"") { | ||
| 534 | - Verdict::Settle(Some( | ||
| 535 | - "application/vnd.oasis.opendocument.spreadsheet", | ||
| 536 | - )) => {} | ||
| 537 | - other => panic!("expected a settled spreadsheet, got {other:?}"), | ||
| 538 | - } | ||
| 539 | - // And the directory search, which reads entry names only, never | ||
| 540 | - // claims one — the marker is entry content, not an entry name. | ||
| 541 | - assert_eq!(office_entry_mime(head), None); | ||
| 542 | - } | ||
| 543 | fn matroska(tracks: &[(&str, u64)]) -> Vec<u8> { | 344 | fn matroska(tracks: &[(&str, u64)]) -> Vec<u8> { |
| 544 | let entries: Vec<u8> = tracks | 345 | let entries: Vec<u8> = tracks |
| 545 | .iter() | 346 | .iter() |
| @@ -588,5 +389,4 @@ mod tests { | |||
| 588 | fn an_unparseable_matroska_keeps_its_old_name() { | 389 | fn an_unparseable_matroska_keeps_its_old_name() { |
| 589 | assert_eq!(sniff(&[0x1A, 0x45, 0xDF, 0xA3, 0x00, 0x00]), "video/webm"); | 390 | assert_eq!(sniff(&[0x1A, 0x45, 0xDF, 0xA3, 0x00, 0x00]), "video/webm"); |
| 590 | } | 391 | } |
| 591 | - | ||
| 592 | } | 392 | } |
crates/in-core/src/store/turso_store.rsmodified+72 -38
| @@ -696,7 +696,7 @@ pub fn hash_link_password(password: &str) -> Result<String> { | |||
| 696 | /// hash answers false — a gate that could panic would be a gate an attacker | 696 | /// hash answers false — a gate that could panic would be a gate an attacker |
| 697 | /// could aim. | 697 | /// could aim. |
| 698 | pub fn link_password_matches(phc: &str, candidate: &str) -> bool { | 698 | pub fn link_password_matches(phc: &str, candidate: &str) -> bool { |
| 699 | - use argon2::password_hash::{phc::PasswordHash, PasswordVerifier}; | 699 | + use argon2::password_hash::{PasswordVerifier, phc::PasswordHash}; |
| 700 | match PasswordHash::new(phc) { | 700 | match PasswordHash::new(phc) { |
| 701 | Ok(parsed) => link_argon2() | 701 | Ok(parsed) => link_argon2() |
| 702 | .verify_password(candidate.as_bytes(), &parsed) | 702 | .verify_password(candidate.as_bytes(), &parsed) |
| @@ -831,7 +831,7 @@ fn default_storage(database: &str) -> std::path::PathBuf { | |||
| 831 | /// goes in after, and a failed row write unlinks this file best-effort. | 831 | /// goes in after, and a failed row write unlinks this file best-effort. |
| 832 | fn write_file_atomic(path: &std::path::Path, bytes: &[u8]) -> std::io::Result<()> { | 832 | fn write_file_atomic(path: &std::path::Path, bytes: &[u8]) -> std::io::Result<()> { |
| 833 | use std::io::Write as _; | 833 | use std::io::Write as _; |
| 834 | - let tmp = path.with_extension(format!("{}.tmp", Ulid::new())); | 834 | + let tmp = path.with_extension(format!("{}.tmp", Ulid::generate())); |
| 835 | let mut file = std::fs::File::create(&tmp)?; | 835 | let mut file = std::fs::File::create(&tmp)?; |
| 836 | file.write_all(bytes)?; | 836 | file.write_all(bytes)?; |
| 837 | file.flush()?; | 837 | file.flush()?; |
| @@ -1163,7 +1163,7 @@ impl Store for TursoStore { | |||
| 1163 | // because a deployment with no admin is a deployment nobody can | 1163 | // because a deployment with no admin is a deployment nobody can |
| 1164 | // administer. | 1164 | // administer. |
| 1165 | let admin = admin.unwrap_or(n == 0); | 1165 | let admin = admin.unwrap_or(n == 0); |
| 1166 | - let id = Ulid::new().to_string(); | 1166 | + let id = Ulid::generate().to_string(); |
| 1167 | let now = now_text()?; | 1167 | let now = now_text()?; |
| 1168 | tx.execute( | 1168 | tx.execute( |
| 1169 | "INSERT INTO user (id, oidc_sub, email, display_name, admin, disabled, \ | 1169 | "INSERT INTO user (id, oidc_sub, email, display_name, admin, disabled, \ |
| @@ -1282,7 +1282,7 @@ impl Store for TursoStore { | |||
| 1282 | .map_err(backend)?; | 1282 | .map_err(backend)?; |
| 1283 | check_live_parent(&tx, owner_id, parent_id).await?; | 1283 | check_live_parent(&tx, owner_id, parent_id).await?; |
| 1284 | let name = free_folder_name(&tx, owner_id, parent_id, &name, None).await?; | 1284 | let name = free_folder_name(&tx, owner_id, parent_id, &name, None).await?; |
| 1285 | - let id = Ulid::new().to_string(); | 1285 | + let id = Ulid::generate().to_string(); |
| 1286 | let now = now_text()?; | 1286 | let now = now_text()?; |
| 1287 | tx.execute( | 1287 | tx.execute( |
| 1288 | "INSERT INTO folder (id, owner_id, parent_id, name, created_at, deleted_at) \ | 1288 | "INSERT INTO folder (id, owner_id, parent_id, name, created_at, deleted_at) \ |
| @@ -1534,7 +1534,7 @@ impl Store for TursoStore { | |||
| 1534 | // The bytes land first, then the row says they are there: a crash | 1534 | // The bytes land first, then the row says they are there: a crash |
| 1535 | // in between leaves an orphan blob the boot sweep deletes, never a | 1535 | // in between leaves an orphan blob the boot sweep deletes, never a |
| 1536 | // row pointing at nothing. | 1536 | // row pointing at nothing. |
| 1537 | - let id = Ulid::new().to_string(); | 1537 | + let id = Ulid::generate().to_string(); |
| 1538 | let file_key = format!("files/{id}"); | 1538 | let file_key = format!("files/{id}"); |
| 1539 | let thumb_key = format!("thumbs/{id}"); | 1539 | let thumb_key = format!("thumbs/{id}"); |
| 1540 | self.blobs | 1540 | self.blobs |
| @@ -1984,10 +1984,7 @@ impl Store for TursoStore { | |||
| 1984 | // boot sweep collects. | 1984 | // boot sweep collects. |
| 1985 | let _ = self | 1985 | let _ = self |
| 1986 | .blobs | 1986 | .blobs |
| 1987 | - .delete(&[ | 1987 | + .delete(&[&format!("files/{id}"), &format!("thumbs/{id}")]) |
| 1988 | - &format!("files/{id}"), | ||
| 1989 | - &format!("thumbs/{id}"), | ||
| 1990 | - ]) | ||
| 1991 | .await; | 1988 | .await; |
| 1992 | self.announce([Topic::Library(owner.clone()), Topic::Trash(owner)]); | 1989 | self.announce([Topic::Library(owner.clone()), Topic::Trash(owner)]); |
| 1993 | Ok(true) | 1990 | Ok(true) |
| @@ -2057,10 +2054,7 @@ impl Store for TursoStore { | |||
| 2057 | for file_id in &deleted_files { | 2054 | for file_id in &deleted_files { |
| 2058 | let _ = self | 2055 | let _ = self |
| 2059 | .blobs | 2056 | .blobs |
| 2060 | - .delete(&[ | 2057 | + .delete(&[&format!("files/{file_id}"), &format!("thumbs/{file_id}")]) |
| 2061 | - &format!("files/{file_id}"), | ||
| 2062 | - &format!("thumbs/{file_id}"), | ||
| 2063 | - ]) | ||
| 2064 | .await; | 2058 | .await; |
| 2065 | } | 2059 | } |
| 2066 | let purged = (deleted_files.len() + deleted_folders.len()) as u64; | 2060 | let purged = (deleted_files.len() + deleted_folders.len()) as u64; |
| @@ -2129,7 +2123,7 @@ impl Store for TursoStore { | |||
| 2129 | } | 2123 | } |
| 2130 | let token = new_token(); | 2124 | let token = new_token(); |
| 2131 | let token_hash = hash_share_token(&token); | 2125 | let token_hash = hash_share_token(&token); |
| 2132 | - let id = Ulid::new().to_string(); | 2126 | + let id = Ulid::generate().to_string(); |
| 2133 | let now = now_text()?; | 2127 | let now = now_text()?; |
| 2134 | let expires = expires_at.map(stamp).transpose()?; | 2128 | let expires = expires_at.map(stamp).transpose()?; |
| 2135 | let conn = self.conn.lock().await; | 2129 | let conn = self.conn.lock().await; |
| @@ -2507,7 +2501,7 @@ impl Store for TursoStore { | |||
| 2507 | check_live_parent_on(&conn, owner_id, folder_id).await?; | 2501 | check_live_parent_on(&conn, owner_id, folder_id).await?; |
| 2508 | let (quota, used) = check_quota(&conn, owner_id).await?; | 2502 | let (quota, used) = check_quota(&conn, owner_id).await?; |
| 2509 | fit_quota(quota, used, size_bytes)?; | 2503 | fit_quota(quota, used, size_bytes)?; |
| 2510 | - let id = Ulid::new().to_string(); | 2504 | + let id = Ulid::generate().to_string(); |
| 2511 | let now = OffsetDateTime::now_utc(); | 2505 | let now = OffsetDateTime::now_utc(); |
| 2512 | let created = stamp(now)?; | 2506 | let created = stamp(now)?; |
| 2513 | let expires = stamp(now + time::Duration::hours(UPLOAD_TTL_HOURS as i64))?; | 2507 | let expires = stamp(now + time::Duration::hours(UPLOAD_TTL_HOURS as i64))?; |
| @@ -2570,11 +2564,11 @@ impl Store for TursoStore { | |||
| 2570 | if bytes.len() as u64 != expected_chunk_len(session.size_bytes, index) { | 2564 | if bytes.len() as u64 != expected_chunk_len(session.size_bytes, index) { |
| 2571 | return Err(StoreError::BadChunk); | 2565 | return Err(StoreError::BadChunk); |
| 2572 | } | 2566 | } |
| 2573 | - let dir = session_dir(&self.storage, &id); | 2567 | + let dir = session_dir(&self.storage, id); |
| 2574 | std::fs::create_dir_all(&dir).map_err(|e| StoreError::Backend(e.to_string()))?; | 2568 | std::fs::create_dir_all(&dir).map_err(|e| StoreError::Backend(e.to_string()))?; |
| 2575 | - write_file_atomic(&chunk_path(&self.storage, &id, index), bytes) | 2569 | + write_file_atomic(&chunk_path(&self.storage, id, index), bytes) |
| 2576 | .map_err(|e| StoreError::Backend(e.to_string()))?; | 2570 | .map_err(|e| StoreError::Backend(e.to_string()))?; |
| 2577 | - let received = staged_received(&self.storage, &id); | 2571 | + let received = staged_received(&self.storage, id); |
| 2578 | let conn = self.conn.lock().await; | 2572 | let conn = self.conn.lock().await; |
| 2579 | conn.execute( | 2573 | conn.execute( |
| 2580 | "UPDATE upload_session SET received_bytes = ?1 WHERE id = ?2", | 2574 | "UPDATE upload_session SET received_bytes = ?1 WHERE id = ?2", |
| @@ -2617,7 +2611,7 @@ impl Store for TursoStore { | |||
| 2617 | // still staged for another attempt. | 2611 | // still staged for another attempt. |
| 2618 | let count = chunk_count(session.size_bytes); | 2612 | let count = chunk_count(session.size_bytes); |
| 2619 | for index in 0..count { | 2613 | for index in 0..count { |
| 2620 | - let len = std::fs::metadata(chunk_path(&self.storage, &id, index)) | 2614 | + let len = std::fs::metadata(chunk_path(&self.storage, id, index)) |
| 2621 | .map(|m| m.len()) | 2615 | .map(|m| m.len()) |
| 2622 | .unwrap_or(u64::MAX); | 2616 | .unwrap_or(u64::MAX); |
| 2623 | if len != expected_chunk_len(session.size_bytes, index) { | 2617 | if len != expected_chunk_len(session.size_bytes, index) { |
| @@ -2627,18 +2621,19 @@ impl Store for TursoStore { | |||
| 2627 | // Assemble through a temp name in the files directory: a crash | 2621 | // Assemble through a temp name in the files directory: a crash |
| 2628 | // mid-assemble leaves a temp the sweep deletes, never a half file | 2622 | // mid-assemble leaves a temp the sweep deletes, never a half file |
| 2629 | // wearing a real name. | 2623 | // wearing a real name. |
| 2630 | - let file_id = Ulid::new().to_string(); | 2624 | + let file_id = Ulid::generate().to_string(); |
| 2631 | // Staged in the files directory under a temp name: the sniffer and | 2625 | // Staged in the files directory under a temp name: the sniffer and |
| 2632 | // the thumbnailer need a real local file, and the adopt that places | 2626 | // the thumbnailer need a real local file, and the adopt that places |
| 2633 | // the assembled bytes is a same-tree rename away. | 2627 | // the assembled bytes is a same-tree rename away. |
| 2634 | - let tmp = file_path(&self.storage, &file_id).with_extension(format!("{}.tmp", Ulid::new())); | 2628 | + let tmp = |
| 2629 | + file_path(&self.storage, &file_id).with_extension(format!("{}.tmp", Ulid::generate())); | ||
| 2635 | { | 2630 | { |
| 2636 | use std::io::Write as _; | 2631 | use std::io::Write as _; |
| 2637 | let mut out = | 2632 | let mut out = |
| 2638 | std::fs::File::create(&tmp).map_err(|e| StoreError::Backend(e.to_string()))?; | 2633 | std::fs::File::create(&tmp).map_err(|e| StoreError::Backend(e.to_string()))?; |
| 2639 | let mut total = 0u64; | 2634 | let mut total = 0u64; |
| 2640 | for index in 0..count { | 2635 | for index in 0..count { |
| 2641 | - let mut chunk = std::fs::File::open(chunk_path(&self.storage, &id, index)) | 2636 | + let mut chunk = std::fs::File::open(chunk_path(&self.storage, id, index)) |
| 2642 | .map_err(|e| StoreError::Backend(e.to_string()))?; | 2637 | .map_err(|e| StoreError::Backend(e.to_string()))?; |
| 2643 | total += std::io::copy(&mut chunk, &mut out) | 2638 | total += std::io::copy(&mut chunk, &mut out) |
| 2644 | .map_err(|e| StoreError::Backend(e.to_string()))?; | 2639 | .map_err(|e| StoreError::Backend(e.to_string()))?; |
| @@ -2775,10 +2770,7 @@ impl Store for TursoStore { | |||
| 2775 | // is what failed. | 2770 | // is what failed. |
| 2776 | let _ = self | 2771 | let _ = self |
| 2777 | .blobs | 2772 | .blobs |
| 2778 | - .delete(&[ | 2773 | + .delete(&[&format!("files/{file_id}"), &format!("thumbs/{file_id}")]) |
| 2779 | - &format!("files/{file_id}"), | ||
| 2780 | - &format!("thumbs/{file_id}"), | ||
| 2781 | - ]) | ||
| 2782 | .await; | 2774 | .await; |
| 2783 | return Err(backend(e)); | 2775 | return Err(backend(e)); |
| 2784 | } | 2776 | } |
| @@ -2805,7 +2797,7 @@ impl Store for TursoStore { | |||
| 2805 | drop(rows); | 2797 | drop(rows); |
| 2806 | tx.commit().await.map_err(backend)?; | 2798 | tx.commit().await.map_err(backend)?; |
| 2807 | // After the commit: the chunks served their purpose. | 2799 | // After the commit: the chunks served their purpose. |
| 2808 | - let _ = std::fs::remove_dir_all(session_dir(&self.storage, &id)); | 2800 | + let _ = std::fs::remove_dir_all(session_dir(&self.storage, id)); |
| 2809 | self.announce([Topic::Library(session.owner_id)]); | 2801 | self.announce([Topic::Library(session.owner_id)]); |
| 2810 | Ok(file) | 2802 | Ok(file) |
| 2811 | } | 2803 | } |
| @@ -2819,7 +2811,7 @@ impl Store for TursoStore { | |||
| 2819 | .await | 2811 | .await |
| 2820 | .map_err(backend)?; | 2812 | .map_err(backend)?; |
| 2821 | drop(conn); | 2813 | drop(conn); |
| 2822 | - let _ = std::fs::remove_dir_all(session_dir(&self.storage, &id)); | 2814 | + let _ = std::fs::remove_dir_all(session_dir(&self.storage, id)); |
| 2823 | Ok(()) | 2815 | Ok(()) |
| 2824 | } | 2816 | } |
| 2825 | 2817 | ||
| @@ -2848,7 +2840,7 @@ impl Store for TursoStore { | |||
| 2848 | } | 2840 | } |
| 2849 | drop(conn); | 2841 | drop(conn); |
| 2850 | for id in &ids { | 2842 | for id in &ids { |
| 2851 | - let _ = std::fs::remove_dir_all(session_dir(&self.storage, &id)); | 2843 | + let _ = std::fs::remove_dir_all(session_dir(&self.storage, id)); |
| 2852 | } | 2844 | } |
| 2853 | Ok(ids.len() as u64) | 2845 | Ok(ids.len() as u64) |
| 2854 | } | 2846 | } |
| @@ -2928,7 +2920,7 @@ impl Store for TursoStore { | |||
| 2928 | // service's bytes. | 2920 | // service's bytes. |
| 2929 | Some(row) => (user_from(&row)?.id, false), | 2921 | Some(row) => (user_from(&row)?.id, false), |
| 2930 | None => { | 2922 | None => { |
| 2931 | - let id = Ulid::new().to_string(); | 2923 | + let id = Ulid::generate().to_string(); |
| 2932 | tx.execute( | 2924 | tx.execute( |
| 2933 | "INSERT INTO user (id, oidc_sub, email, display_name, admin, disabled, \ | 2925 | "INSERT INTO user (id, oidc_sub, email, display_name, admin, disabled, \ |
| 2934 | quota_bytes, used_bytes, ui, theme, language, created_at, last_seen_at, \ | 2926 | quota_bytes, used_bytes, ui, theme, language, created_at, last_seen_at, \ |
| @@ -2951,7 +2943,13 @@ impl Store for TursoStore { | |||
| 2951 | tx.execute( | 2943 | tx.execute( |
| 2952 | "INSERT INTO service_key (token_hash, name, service, user_id, created_at) \ | 2944 | "INSERT INTO service_key (token_hash, name, service, user_id, created_at) \ |
| 2953 | VALUES (?1, ?2, ?3, ?4, ?5)", | 2945 | VALUES (?1, ?2, ?3, ?4, ?5)", |
| 2954 | - params![hash_share_token(&token), name, service, user_id.clone(), now_text()?], | 2946 | + params![ |
| 2947 | + hash_share_token(&token), | ||
| 2948 | + name, | ||
| 2949 | + service, | ||
| 2950 | + user_id.clone(), | ||
| 2951 | + now_text()? | ||
| 2952 | + ], | ||
| 2955 | ) | 2953 | ) |
| 2956 | .await | 2954 | .await |
| 2957 | .map_err(backend)?; | 2955 | .map_err(backend)?; |
| @@ -3053,7 +3051,10 @@ impl Store for TursoStore { | |||
| 3053 | .await | 3051 | .await |
| 3054 | .map_err(backend)?; | 3052 | .map_err(backend)?; |
| 3055 | let replaced = match rows.next().await.map_err(backend)? { | 3053 | let replaced = match rows.next().await.map_err(backend)? { |
| 3056 | - Some(row) => Some((text(&row, 0)?, row.get::<i64>(1).map_err(backend)?.max(0) as u64)), | 3054 | + Some(row) => Some(( |
| 3055 | + text(&row, 0)?, | ||
| 3056 | + row.get::<i64>(1).map_err(backend)?.max(0) as u64, | ||
| 3057 | + )), | ||
| 3057 | None => None, | 3058 | None => None, |
| 3058 | }; | 3059 | }; |
| 3059 | drop(rows); | 3060 | drop(rows); |
| @@ -3085,7 +3086,7 @@ impl Store for TursoStore { | |||
| 3085 | Ok(id) | 3086 | Ok(id) |
| 3086 | } | 3087 | } |
| 3087 | None => { | 3088 | None => { |
| 3088 | - let id = Ulid::new().to_string(); | 3089 | + let id = Ulid::generate().to_string(); |
| 3089 | let file_key = format!("files/{id}"); | 3090 | let file_key = format!("files/{id}"); |
| 3090 | self.blobs | 3091 | self.blobs |
| 3091 | .put(&file_key, bytes) | 3092 | .put(&file_key, bytes) |
| @@ -3123,7 +3124,8 @@ impl Store for TursoStore { | |||
| 3123 | } | 3124 | } |
| 3124 | 3125 | ||
| 3125 | async fn service_file(&self, owner_id: &str, external_id: &str) -> Result<Option<File>> { | 3126 | async fn service_file(&self, owner_id: &str, external_id: &str) -> Result<Option<File>> { |
| 3126 | - let sql = format!("SELECT {FILE_COLUMNS} FROM file WHERE owner_id = ?1 AND external_id = ?2"); | 3127 | + let sql = |
| 3128 | + format!("SELECT {FILE_COLUMNS} FROM file WHERE owner_id = ?1 AND external_id = ?2"); | ||
| 3127 | match self.one_row(&sql, params![owner_id, external_id]).await? { | 3129 | match self.one_row(&sql, params![owner_id, external_id]).await? { |
| 3128 | Some(row) => Ok(Some(file_from(&row)?)), | 3130 | Some(row) => Ok(Some(file_from(&row)?)), |
| 3129 | None => Ok(None), | 3131 | None => Ok(None), |
| @@ -3981,7 +3983,15 @@ mod tests { | |||
| 3981 | let store = TursoStore::open(dir.path().join("in.db").to_str().unwrap(), Some(&storage)) | 3983 | let store = TursoStore::open(dir.path().join("in.db").to_str().unwrap(), Some(&storage)) |
| 3982 | .await | 3984 | .await |
| 3983 | .unwrap(); | 3985 | .unwrap(); |
| 3984 | - let user = store.provision_user("sub-alice", "alice@example.com", "Alice", None, 0, 1024 * 1024 * 1024) | 3986 | + let user = store |
| 3987 | + .provision_user( | ||
| 3988 | + "sub-alice", | ||
| 3989 | + "alice@example.com", | ||
| 3990 | + "Alice", | ||
| 3991 | + None, | ||
| 3992 | + 0, | ||
| 3993 | + 1024 * 1024 * 1024, | ||
| 3994 | + ) | ||
| 3985 | .await | 3995 | .await |
| 3986 | .unwrap(); | 3996 | .unwrap(); |
| 3987 | 3997 | ||
| @@ -4078,7 +4088,15 @@ mod tests { | |||
| 4078 | let store = TursoStore::open(dir.path().join("in.db").to_str().unwrap(), Some(&storage)) | 4088 | let store = TursoStore::open(dir.path().join("in.db").to_str().unwrap(), Some(&storage)) |
| 4079 | .await | 4089 | .await |
| 4080 | .unwrap(); | 4090 | .unwrap(); |
| 4081 | - let user = store.provision_user("sub-alice", "alice@example.com", "Alice", None, 0, 1024 * 1024 * 1024) | 4091 | + let user = store |
| 4092 | + .provision_user( | ||
| 4093 | + "sub-alice", | ||
| 4094 | + "alice@example.com", | ||
| 4095 | + "Alice", | ||
| 4096 | + None, | ||
| 4097 | + 0, | ||
| 4098 | + 1024 * 1024 * 1024, | ||
| 4099 | + ) | ||
| 4082 | .await | 4100 | .await |
| 4083 | .unwrap(); | 4101 | .unwrap(); |
| 4084 | let file = store | 4102 | let file = store |
| @@ -4114,7 +4132,15 @@ mod tests { | |||
| 4114 | let store = TursoStore::open(dir.path().join("in.db").to_str().unwrap(), Some(&storage)) | 4132 | let store = TursoStore::open(dir.path().join("in.db").to_str().unwrap(), Some(&storage)) |
| 4115 | .await | 4133 | .await |
| 4116 | .unwrap(); | 4134 | .unwrap(); |
| 4117 | - let user = store.provision_user("sub-alice", "alice@example.com", "Alice", None, 0, 1024 * 1024 * 1024) | 4135 | + let user = store |
| 4136 | + .provision_user( | ||
| 4137 | + "sub-alice", | ||
| 4138 | + "alice@example.com", | ||
| 4139 | + "Alice", | ||
| 4140 | + None, | ||
| 4141 | + 0, | ||
| 4142 | + 1024 * 1024 * 1024, | ||
| 4143 | + ) | ||
| 4118 | .await | 4144 | .await |
| 4119 | .unwrap(); | 4145 | .unwrap(); |
| 4120 | let root = store.create_folder(&user.id, None, "root").await.unwrap(); | 4146 | let root = store.create_folder(&user.id, None, "root").await.unwrap(); |
| @@ -4179,7 +4205,15 @@ mod tests { | |||
| 4179 | let store = TursoStore::open(dir.path().join("in.db").to_str().unwrap(), Some(&storage)) | 4205 | let store = TursoStore::open(dir.path().join("in.db").to_str().unwrap(), Some(&storage)) |
| 4180 | .await | 4206 | .await |
| 4181 | .unwrap(); | 4207 | .unwrap(); |
| 4182 | - let user = store.provision_user("sub-alice", "alice@example.com", "Alice", None, 0, 1024 * 1024 * 1024) | 4208 | + let user = store |
| 4209 | + .provision_user( | ||
| 4210 | + "sub-alice", | ||
| 4211 | + "alice@example.com", | ||
| 4212 | + "Alice", | ||
| 4213 | + None, | ||
| 4214 | + 0, | ||
| 4215 | + 1024 * 1024 * 1024, | ||
| 4216 | + ) | ||
| 4183 | .await | 4217 | .await |
| 4184 | .unwrap(); | 4218 | .unwrap(); |
| 4185 | let session = store | 4219 | let session = store |
crates/in-core/tests/store.rsmodified+7 -7
| @@ -24,7 +24,7 @@ struct Scratch { | |||
| 24 | 24 | ||
| 25 | impl Scratch { | 25 | impl Scratch { |
| 26 | async fn open() -> Self { | 26 | async fn open() -> Self { |
| 27 | - let dir = std::env::temp_dir().join(format!("in-test-{}", Ulid::new())); | 27 | + let dir = std::env::temp_dir().join(format!("in-test-{}", Ulid::generate())); |
| 28 | std::fs::create_dir_all(&dir).unwrap(); | 28 | std::fs::create_dir_all(&dir).unwrap(); |
| 29 | let db = dir.join("in.db"); | 29 | let db = dir.join("in.db"); |
| 30 | let storage = dir.join("storage"); | 30 | let storage = dir.join("storage"); |
| @@ -96,7 +96,7 @@ fn png_bytes() -> Vec<u8> { | |||
| 96 | 96 | ||
| 97 | #[tokio::test] | 97 | #[tokio::test] |
| 98 | async fn the_schema_is_created_once_and_survives_reopen() { | 98 | async fn the_schema_is_created_once_and_survives_reopen() { |
| 99 | - let dir = std::env::temp_dir().join(format!("in-test-{}", Ulid::new())); | 99 | + let dir = std::env::temp_dir().join(format!("in-test-{}", Ulid::generate())); |
| 100 | std::fs::create_dir_all(&dir).unwrap(); | 100 | std::fs::create_dir_all(&dir).unwrap(); |
| 101 | let path = dir.join("in.db").to_string_lossy().into_owned(); | 101 | let path = dir.join("in.db").to_string_lossy().into_owned(); |
| 102 | 102 | ||
| @@ -358,7 +358,7 @@ fn make_test_mp4() -> Option<Vec<u8>> { | |||
| 358 | if !in_core::thumbs::ffmpeg_available() { | 358 | if !in_core::thumbs::ffmpeg_available() { |
| 359 | return None; | 359 | return None; |
| 360 | } | 360 | } |
| 361 | - let path = std::env::temp_dir().join(format!("in-test-upload-{}.mp4", Ulid::new())); | 361 | + let path = std::env::temp_dir().join(format!("in-test-upload-{}.mp4", Ulid::generate())); |
| 362 | let rendered = std::process::Command::new("ffmpeg") | 362 | let rendered = std::process::Command::new("ffmpeg") |
| 363 | .args([ | 363 | .args([ |
| 364 | "-v", | 364 | "-v", |
| @@ -843,7 +843,7 @@ async fn a_pre_password_link_reconciles_to_no_password_and_a_new_one_survives_re | |||
| 843 | // it onto the declared schema: the link row is carried across and wears | 843 | // it onto the declared schema: the link row is carried across and wears |
| 844 | // NULL, opening like it always did, and a password minted after the | 844 | // NULL, opening like it always did, and a password minted after the |
| 845 | // rebuild survives the next boot whole. | 845 | // rebuild survives the next boot whole. |
| 846 | - let dir = std::env::temp_dir().join(format!("in-test-{}", Ulid::new())); | 846 | + let dir = std::env::temp_dir().join(format!("in-test-{}", Ulid::generate())); |
| 847 | std::fs::create_dir_all(&dir).unwrap(); | 847 | std::fs::create_dir_all(&dir).unwrap(); |
| 848 | let path = dir.join("in.db").to_string_lossy().into_owned(); | 848 | let path = dir.join("in.db").to_string_lossy().into_owned(); |
| 849 | { | 849 | { |
| @@ -1627,7 +1627,7 @@ async fn a_second_migration_database_gains_the_preference_columns_on_open() { | |||
| 1627 | // column. Opening it with the current code reconciles it onto the | 1627 | // column. Opening it with the current code reconciles it onto the |
| 1628 | // declared schema: its interface choice is carried across, and the two | 1628 | // declared schema: its interface choice is carried across, and the two |
| 1629 | // new preferences arrive wearing their defaults. | 1629 | // new preferences arrive wearing their defaults. |
| 1630 | - let dir = std::env::temp_dir().join(format!("in-test-{}", Ulid::new())); | 1630 | + let dir = std::env::temp_dir().join(format!("in-test-{}", Ulid::generate())); |
| 1631 | std::fs::create_dir_all(&dir).unwrap(); | 1631 | std::fs::create_dir_all(&dir).unwrap(); |
| 1632 | let path = dir.join("in.db").to_string_lossy().into_owned(); | 1632 | let path = dir.join("in.db").to_string_lossy().into_owned(); |
| 1633 | { | 1633 | { |
| @@ -1855,7 +1855,7 @@ use in_core::store::r2::R2Blobs; | |||
| 1855 | /// buckets on CreateBucket, which an object-store client never calls, so | 1855 | /// buckets on CreateBucket, which an object-store client never calls, so |
| 1856 | /// the directory is the bucket. | 1856 | /// the directory is the bucket. |
| 1857 | async fn s3_server() -> (String, PathBuf) { | 1857 | async fn s3_server() -> (String, PathBuf) { |
| 1858 | - let root = std::env::temp_dir().join(format!("in-r2-server-{}", Ulid::new())); | 1858 | + let root = std::env::temp_dir().join(format!("in-r2-server-{}", Ulid::generate())); |
| 1859 | std::fs::create_dir_all(root.join("in-test")).unwrap(); | 1859 | std::fs::create_dir_all(root.join("in-test")).unwrap(); |
| 1860 | // The object-store client signs every request; without an auth provider | 1860 | // The object-store client signs every request; without an auth provider |
| 1861 | // the server would answer 501 to all of them. The credentials here are | 1861 | // the server would answer 501 to all of them. The credentials here are |
| @@ -1901,7 +1901,7 @@ impl R2Scratch { | |||
| 1901 | let blobs = Arc::new( | 1901 | let blobs = Arc::new( |
| 1902 | R2Blobs::open(&endpoint, "in-test", "test-key", "test-secret", true).unwrap(), | 1902 | R2Blobs::open(&endpoint, "in-test", "test-key", "test-secret", true).unwrap(), |
| 1903 | ); | 1903 | ); |
| 1904 | - let dir = std::env::temp_dir().join(format!("in-r2-{}", Ulid::new())); | 1904 | + let dir = std::env::temp_dir().join(format!("in-r2-{}", Ulid::generate())); |
| 1905 | std::fs::create_dir_all(&dir).unwrap(); | 1905 | std::fs::create_dir_all(&dir).unwrap(); |
| 1906 | let db = dir.join("in.db"); | 1906 | let db = dir.join("in.db"); |
| 1907 | let storage = dir.join("storage"); | 1907 | let storage = dir.join("storage"); |
crates/in-web/Cargo.tomlmodified+3 -3
| @@ -7,7 +7,7 @@ repository.workspace = true | |||
| 7 | description = "in web app: topcoat UI, routes and the server" | 7 | description = "in web app: topcoat UI, routes and the server" |
| 8 | 8 | ||
| 9 | [dependencies] | 9 | [dependencies] |
| 10 | -topcoat = { version = "0.6.2", default-features = false, features = [ | 10 | +topcoat = { version = "0.8.0", default-features = false, features = [ |
| 11 | "router", | 11 | "router", |
| 12 | "view", | 12 | "view", |
| 13 | "runtime", | 13 | "runtime", |
| @@ -39,12 +39,12 @@ http-body = "1" | |||
| 39 | # Hashes the compiled stylesheet against the bundle's bytes at boot, so a | 39 | # Hashes the compiled stylesheet against the bundle's bytes at boot, so a |
| 40 | # bundle from another generation refuses the boot instead of serving under | 40 | # bundle from another generation refuses the boot instead of serving under |
| 41 | # this binary (see `server.rs`'s `stylesheet_guard`). | 41 | # this binary (see `server.rs`'s `stylesheet_guard`). |
| 42 | -sha2 = "0.10" | 42 | +sha2 = "0.11" |
| 43 | ulid = { workspace = true } | 43 | ulid = { workspace = true } |
| 44 | 44 | ||
| 45 | [build-dependencies] | 45 | [build-dependencies] |
| 46 | grass = "0.13" | 46 | grass = "0.13" |
| 47 | -sha2 = "0.10" | 47 | +sha2 = "0.11" |
| 48 | 48 | ||
| 49 | [dev-dependencies] | 49 | [dev-dependencies] |
| 50 | http = "1.5" | 50 | http = "1.5" |
crates/in-web/src/drive.rsmodified+47 -39
| @@ -23,7 +23,7 @@ use topcoat::Result; | |||
| 23 | use topcoat::context::Cx; | 23 | use topcoat::context::Cx; |
| 24 | use topcoat::router::content::{Form, Json}; | 24 | use topcoat::router::content::{Form, Json}; |
| 25 | use topcoat::router::error::not_found; | 25 | use topcoat::router::error::not_found; |
| 26 | -use topcoat::view::view; | 26 | +use topcoat::view::{View, ViewExt, view}; |
| 27 | 27 | ||
| 28 | use crate::i18n::{Key, lang, t}; | 28 | use crate::i18n::{Key, lang, t}; |
| 29 | use crate::layout::{NavPage, topbar}; | 29 | use crate::layout::{NavPage, topbar}; |
| @@ -148,13 +148,13 @@ async fn folder_tree(store: &dyn Store, user_id: &str) -> Vec<(String, String)> | |||
| 148 | /// names cannot collide (the store postfixes them), so the display path | 148 | /// names cannot collide (the store postfixes them), so the display path |
| 149 | /// identifies a subtree exactly. A pair naming nothing owned and live opens | 149 | /// identifies a subtree exactly. A pair naming nothing owned and live opens |
| 150 | /// nothing. | 150 | /// nothing. |
| 151 | -async fn move_modal( | 151 | +async fn move_modal<'a>( |
| 152 | - cx: &Cx, | 152 | + cx: &'a Cx, |
| 153 | kind_raw: &str, | 153 | kind_raw: &str, |
| 154 | target_id: &str, | 154 | target_id: &str, |
| 155 | close_href: &str, | 155 | close_href: &str, |
| 156 | destinations: &[(String, String)], | 156 | destinations: &[(String, String)], |
| 157 | -) -> Result<Option<topcoat::view::View>> { | 157 | +) -> Result<Option<impl View + 'a>> { |
| 158 | let user = match require_user(cx).await { | 158 | let user = match require_user(cx).await { |
| 159 | Ok(user) => user, | 159 | Ok(user) => user, |
| 160 | Err(_) => return Ok(None), | 160 | Err(_) => return Ok(None), |
| @@ -207,7 +207,12 @@ async fn move_modal( | |||
| 207 | _ => return Ok(None), | 207 | _ => return Ok(None), |
| 208 | }; | 208 | }; |
| 209 | let subtree = own_path.map(|path| format!("{path} / ")); | 209 | let subtree = own_path.map(|path| format!("{path} / ")); |
| 210 | - let rows: Vec<&(String, String)> = destinations | 210 | + let close_href = close_href.to_string(); |
| 211 | + let target_id = target_id.to_string(); | ||
| 212 | + let field = field.to_string(); | ||
| 213 | + let action = action.to_string(); | ||
| 214 | + let kind_raw = kind_raw.to_string(); | ||
| 215 | + let rows: Vec<(String, String)> = destinations | ||
| 211 | .iter() | 216 | .iter() |
| 212 | .filter(|dest| match &subtree { | 217 | .filter(|dest| match &subtree { |
| 213 | Some(prefix) => { | 218 | Some(prefix) => { |
| @@ -215,6 +220,7 @@ async fn move_modal( | |||
| 215 | } | 220 | } |
| 216 | None => true, | 221 | None => true, |
| 217 | }) | 222 | }) |
| 223 | + .cloned() | ||
| 218 | .collect(); | 224 | .collect(); |
| 219 | Ok(Some(view! { | 225 | Ok(Some(view! { |
| 220 | cx => | 226 | cx => |
| @@ -226,7 +232,7 @@ async fn move_modal( | |||
| 226 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | 232 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> |
| 227 | } | 233 | } |
| 228 | if let Some(file) = file.as_ref() { | 234 | if let Some(file) = file.as_ref() { |
| 229 | - (crate::files::entry_chip(cx, file).await?) | 235 | + (topcoat::view::Child::new(crate::files::entry_chip(cx, file).await?)) |
| 230 | } | 236 | } |
| 231 | (format!("{} “{}”", t(language, Key::Move), name.clone())) | 237 | (format!("{} “{}”", t(language, Key::Move), name.clone())) |
| 232 | </h2> | 238 | </h2> |
| @@ -234,18 +240,18 @@ async fn move_modal( | |||
| 234 | <a class="quiet" href=(close_href.to_string()) aria-label=(t(language, Key::Close))>(t(language, Key::Close))</a> | 240 | <a class="quiet" href=(close_href.to_string()) aria-label=(t(language, Key::Close))>(t(language, Key::Close))</a> |
| 235 | </div> | 241 | </div> |
| 236 | <div class="move-list"> | 242 | <div class="move-list"> |
| 237 | - <form class="move-dest" method="post" action=(action)> | 243 | + <form class="move-dest" method="post" action=(action.clone())> |
| 238 | - <input type="hidden" name="id" value=(target_id.to_string())> | 244 | + <input type="hidden" name="id" value=(target_id.clone())> |
| 239 | - <input type="hidden" name=(field) value=""> | 245 | + <input type="hidden" name=(field.clone()) value=""> |
| 240 | <button class="move-pick" type="submit"> | 246 | <button class="move-pick" type="submit"> |
| 241 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | 247 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> |
| 242 | (t(language, Key::Drive)) | 248 | (t(language, Key::Drive)) |
| 243 | </button> | 249 | </button> |
| 244 | </form> | 250 | </form> |
| 245 | for dest in rows { | 251 | for dest in rows { |
| 246 | - <form class="move-dest" method="post" action=(action)> | 252 | + <form class="move-dest" method="post" action=(action.clone())> |
| 247 | - <input type="hidden" name="id" value=(target_id.to_string())> | 253 | + <input type="hidden" name="id" value=(target_id.clone())> |
| 248 | - <input type="hidden" name=(field) value=(dest.0.clone())> | 254 | + <input type="hidden" name=(field.clone()) value=(dest.0.clone())> |
| 249 | <button class="move-pick" type="submit"> | 255 | <button class="move-pick" type="submit"> |
| 250 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | 256 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> |
| 251 | (dest.1.clone()) | 257 | (dest.1.clone()) |
| @@ -255,7 +261,7 @@ async fn move_modal( | |||
| 255 | </div> | 261 | </div> |
| 256 | </div> | 262 | </div> |
| 257 | </div> | 263 | </div> |
| 258 | - }?)) | 264 | + }.boxed())) |
| 259 | } | 265 | } |
| 260 | 266 | ||
| 261 | pub(crate) fn human_size(bytes: u64) -> String { | 267 | pub(crate) fn human_size(bytes: u64) -> String { |
| @@ -415,16 +421,17 @@ fn sort_files(files: &mut [in_core::store::File], key: SortKey, dir: SortDir) { | |||
| 415 | 421 | ||
| 416 | /// `GET /drive?folder=<id>`: one directory. | 422 | /// `GET /drive?folder=<id>`: one directory. |
| 417 | #[page("/drive")] | 423 | #[page("/drive")] |
| 418 | -async fn drive(cx: &Cx) -> Result { | 424 | +async fn drive(cx: &Cx) -> Result<impl View> { |
| 419 | let user = match require_user(cx).await { | 425 | let user = match require_user(cx).await { |
| 420 | Ok(user) => user, | 426 | Ok(user) => user, |
| 421 | Err(_) => { | 427 | Err(_) => { |
| 422 | let location = (header::LOCATION, HeaderValue::from_static("/")); | 428 | let location = (header::LOCATION, HeaderValue::from_static("/")); |
| 423 | - return view! { | 429 | + return Ok(view! { |
| 424 | cx => | 430 | cx => |
| 425 | (StatusCode::SEE_OTHER) | 431 | (StatusCode::SEE_OTHER) |
| 426 | (location) | 432 | (location) |
| 427 | - }; | 433 | + } |
| 434 | + .boxed()); | ||
| 428 | } | 435 | } |
| 429 | }; | 436 | }; |
| 430 | let language = lang(cx).await; | 437 | let language = lang(cx).await; |
| @@ -577,9 +584,9 @@ async fn drive(cx: &Cx) -> Result { | |||
| 577 | created.clone() | 584 | created.clone() |
| 578 | }; | 585 | }; |
| 579 | 586 | ||
| 580 | - view! { | 587 | + Ok(view! { |
| 581 | cx => | 588 | cx => |
| 582 | - (topbar(cx, NavPage::Drive, &user, language).await?) | 589 | + (topcoat::view::Child::new(topbar(cx, NavPage::Drive, &user, language).await?)) |
| 583 | <main class="settings-stage stage-wide"> | 590 | <main class="settings-stage stage-wide"> |
| 584 | <h1 class="settings-title">(t(language, Key::Drive))</h1> | 591 | <h1 class="settings-title">(t(language, Key::Drive))</h1> |
| 585 | <div class="filterbar drive-bar"> | 592 | <div class="filterbar drive-bar"> |
| @@ -730,7 +737,7 @@ async fn drive(cx: &Cx) -> Result { | |||
| 730 | for file in &hits.files { | 737 | for file in &hits.files { |
| 731 | <div class="drive-row"> | 738 | <div class="drive-row"> |
| 732 | <a class="drive-open" href=(format!("/view/{}", file.id))> | 739 | <a class="drive-open" href=(format!("/view/{}", file.id))> |
| 733 | - (crate::files::entry_chip(cx, file).await?) | 740 | + (topcoat::view::Child::new(crate::files::entry_chip(cx, file).await?)) |
| 734 | <span class="dep-name-cell"> | 741 | <span class="dep-name-cell"> |
| 735 | <span class="dep-title">(file.name.clone())</span> | 742 | <span class="dep-title">(file.name.clone())</span> |
| 736 | if shared.contains(&(ShareKind::File, file.id.clone())) { | 743 | if shared.contains(&(ShareKind::File, file.id.clone())) { |
| @@ -795,11 +802,11 @@ async fn drive(cx: &Cx) -> Result { | |||
| 795 | <summary class="quiet entry-options-trigger" aria-label=(t(language, Key::Options))>"⋯"</summary> | 802 | <summary class="quiet entry-options-trigger" aria-label=(t(language, Key::Options))>"⋯"</summary> |
| 796 | <div class="user-menu-panel"> | 803 | <div class="user-menu-panel"> |
| 797 | <a class="user-menu-item" | 804 | <a class="user-menu-item" |
| 798 | - href=(format!("{here}{edit_sep}edit={}", folder.id))>(t(language, Key::Rename))</a> | 805 | + href=(format!("{}{edit_sep}edit={}", here.clone(), folder.id))>(t(language, Key::Rename))</a> |
| 799 | <a class="user-menu-item" | 806 | <a class="user-menu-item" |
| 800 | - href=(format!("{here}{edit_sep}share=folder:{}", folder.id))>(t(language, Key::Share))</a> | 807 | + href=(format!("{}{edit_sep}share=folder:{}", here.clone(), folder.id))>(t(language, Key::Share))</a> |
| 801 | <a class="user-menu-item" | 808 | <a class="user-menu-item" |
| 802 | - href=(format!("{here}{edit_sep}move=folder:{}", folder.id))>(t(language, Key::Move))</a> | 809 | + href=(format!("{}{edit_sep}move=folder:{}", here.clone(), folder.id))>(t(language, Key::Move))</a> |
| 803 | <form class="user-menu-item-form" method="post" action="/api/folder/delete"> | 810 | <form class="user-menu-item-form" method="post" action="/api/folder/delete"> |
| 804 | <input type="hidden" name="id" value=(folder.id.clone())> | 811 | <input type="hidden" name="id" value=(folder.id.clone())> |
| 805 | <button class="user-menu-item quiet quiet-danger" type="submit">(t(language, Key::Delete))</button> | 812 | <button class="user-menu-item quiet quiet-danger" type="submit">(t(language, Key::Delete))</button> |
| @@ -812,7 +819,7 @@ async fn drive(cx: &Cx) -> Result { | |||
| 812 | for file in listing.files.iter() { | 819 | for file in listing.files.iter() { |
| 813 | <div class="drive-row"> | 820 | <div class="drive-row"> |
| 814 | if edit_id.as_deref() == Some(file.id.as_str()) { | 821 | if edit_id.as_deref() == Some(file.id.as_str()) { |
| 815 | - (crate::files::entry_chip(cx, file).await?) | 822 | + (topcoat::view::Child::new(crate::files::entry_chip(cx, file).await?)) |
| 816 | <form class="dep-edit-form" method="post" action="/api/file/rename"> | 823 | <form class="dep-edit-form" method="post" action="/api/file/rename"> |
| 817 | <input type="hidden" name="id" value=(file.id.clone())> | 824 | <input type="hidden" name="id" value=(file.id.clone())> |
| 818 | <input class="field-input" type="text" name="name" maxlength="255" | 825 | <input class="field-input" type="text" name="name" maxlength="255" |
| @@ -824,7 +831,7 @@ async fn drive(cx: &Cx) -> Result { | |||
| 824 | </form> | 831 | </form> |
| 825 | } else { | 832 | } else { |
| 826 | <a class="drive-open" href=(format!("/view/{}", file.id))> | 833 | <a class="drive-open" href=(format!("/view/{}", file.id))> |
| 827 | - (crate::files::entry_chip(cx, file).await?) | 834 | + (topcoat::view::Child::new(crate::files::entry_chip(cx, file).await?)) |
| 828 | <span class="dep-name-cell"> | 835 | <span class="dep-name-cell"> |
| 829 | <span class="dep-title">(file.name.clone())</span> | 836 | <span class="dep-title">(file.name.clone())</span> |
| 830 | if shared.contains(&(ShareKind::File, file.id.clone())) { | 837 | if shared.contains(&(ShareKind::File, file.id.clone())) { |
| @@ -839,16 +846,16 @@ async fn drive(cx: &Cx) -> Result { | |||
| 839 | <summary class="quiet entry-options-trigger" aria-label=(t(language, Key::Options))>"⋯"</summary> | 846 | <summary class="quiet entry-options-trigger" aria-label=(t(language, Key::Options))>"⋯"</summary> |
| 840 | <div class="user-menu-panel"> | 847 | <div class="user-menu-panel"> |
| 841 | <a class="user-menu-item" | 848 | <a class="user-menu-item" |
| 842 | - href=(format!("{here}{edit_sep}edit={}", file.id))>(t(language, Key::Rename))</a> | 849 | + href=(format!("{}{edit_sep}edit={}", here.clone(), file.id))>(t(language, Key::Rename))</a> |
| 843 | <a class="user-menu-item" | 850 | <a class="user-menu-item" |
| 844 | - href=(format!("{here}{edit_sep}share=file:{}", file.id))>(t(language, Key::Share))</a> | 851 | + href=(format!("{}{edit_sep}share=file:{}", here.clone(), file.id))>(t(language, Key::Share))</a> |
| 845 | // The `download` attribute keeps the | 852 | // The `download` attribute keeps the |
| 846 | // soft-nav handler off the click, so the | 853 | // soft-nav handler off the click, so the |
| 847 | // bytes land as a file, not a page swap. | 854 | // bytes land as a file, not a page swap. |
| 848 | <a class="user-menu-item" | 855 | <a class="user-menu-item" |
| 849 | href=(format!("/file/{}?dl=1", file.id)) download="">(t(language, Key::Download))</a> | 856 | href=(format!("/file/{}?dl=1", file.id)) download="">(t(language, Key::Download))</a> |
| 850 | <a class="user-menu-item" | 857 | <a class="user-menu-item" |
| 851 | - href=(format!("{here}{edit_sep}move=file:{}", file.id))>(t(language, Key::Move))</a> | 858 | + href=(format!("{}{edit_sep}move=file:{}", here.clone(), file.id))>(t(language, Key::Move))</a> |
| 852 | <form class="user-menu-item-form" method="post" action="/api/file/delete"> | 859 | <form class="user-menu-item-form" method="post" action="/api/file/delete"> |
| 853 | <input type="hidden" name="id" value=(file.id.clone())> | 860 | <input type="hidden" name="id" value=(file.id.clone())> |
| 854 | <button class="user-menu-item quiet quiet-danger" type="submit">(t(language, Key::Delete))</button> | 861 | <button class="user-menu-item quiet quiet-danger" type="submit">(t(language, Key::Delete))</button> |
| @@ -864,21 +871,21 @@ async fn drive(cx: &Cx) -> Result { | |||
| 864 | } | 871 | } |
| 865 | </main> | 872 | </main> |
| 866 | if let Some(dialog) = move_dialog { | 873 | if let Some(dialog) = move_dialog { |
| 867 | - (dialog) | 874 | + (topcoat::view::Child::new(dialog)) |
| 868 | } | 875 | } |
| 869 | if let Some(dialog) = share_dialog { | 876 | if let Some(dialog) = share_dialog { |
| 870 | - (dialog) | 877 | + (topcoat::view::Child::new(dialog)) |
| 871 | } | 878 | } |
| 872 | - (crate::dropdown::dropdown_script(cx).await?) | 879 | + (topcoat::view::Child::new(crate::dropdown::dropdown_script(cx).await?)) |
| 873 | - (upload_script(cx).await?) | 880 | + (topcoat::view::Child::new(upload_script(cx).await?)) |
| 874 | - (options_menu_script(cx).await?) | 881 | + (topcoat::view::Child::new(options_menu_script(cx).await?)) |
| 875 | - } | 882 | + }.boxed()) |
| 876 | } | 883 | } |
| 877 | 884 | ||
| 878 | /// `GET /search`: the old address — a 303 to the drive's search box, keeping | 885 | /// `GET /search`: the old address — a 303 to the drive's search box, keeping |
| 879 | /// the query so old links land on their results. Nothing renders here. | 886 | /// the query so old links land on their results. Nothing renders here. |
| 880 | #[page("/search")] | 887 | #[page("/search")] |
| 881 | -async fn search_redirect(cx: &Cx) -> Result { | 888 | +async fn search_redirect(cx: &Cx) -> Result<impl View> { |
| 882 | let target = match query_value(uri(cx).query().unwrap_or(""), "q") { | 889 | let target = match query_value(uri(cx).query().unwrap_or(""), "q") { |
| 883 | Some(raw) if !raw.trim().is_empty() => format!("/drive?q={raw}"), | 890 | Some(raw) if !raw.trim().is_empty() => format!("/drive?q={raw}"), |
| 884 | _ => "/drive".to_string(), | 891 | _ => "/drive".to_string(), |
| @@ -887,11 +894,12 @@ async fn search_redirect(cx: &Cx) -> Result { | |||
| 887 | header::LOCATION, | 894 | header::LOCATION, |
| 888 | HeaderValue::from_str(&target).unwrap_or(HeaderValue::from_static("/drive")), | 895 | HeaderValue::from_str(&target).unwrap_or(HeaderValue::from_static("/drive")), |
| 889 | ); | 896 | ); |
| 890 | - view! { | 897 | + Ok(view! { |
| 891 | cx => | 898 | cx => |
| 892 | (StatusCode::SEE_OTHER) | 899 | (StatusCode::SEE_OTHER) |
| 893 | (location) | 900 | (location) |
| 894 | } | 901 | } |
| 902 | + .boxed()) | ||
| 895 | } | 903 | } |
| 896 | 904 | ||
| 897 | /// The value of one query pair, if present. A hand-edited query names | 905 | /// The value of one query pair, if present. A hand-edited query names |
| @@ -948,7 +956,7 @@ fn query_value(query: &str, key: &str) -> Option<String> { | |||
| 948 | /// The Rust `\`-continuations strip newlines, so the emitted script is one | 956 | /// The Rust `\`-continuations strip newlines, so the emitted script is one |
| 949 | /// long line: only `/* */` comments survive inside it — a `//` would eat | 957 | /// long line: only `/* */` comments survive inside it — a `//` would eat |
| 950 | /// the rest of the script and kill every handler silently. | 958 | /// the rest of the script and kill every handler silently. |
| 951 | -async fn upload_script(cx: &Cx) -> Result { | 959 | +async fn upload_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 952 | use topcoat::view::Unescaped; | 960 | use topcoat::view::Unescaped; |
| 953 | const JS: &str = "\ | 961 | const JS: &str = "\ |
| 954 | (function () { \ | 962 | (function () { \ |
| @@ -1366,7 +1374,7 @@ async fn upload_script(cx: &Cx) -> Result { | |||
| 1366 | }); \ | 1374 | }); \ |
| 1367 | })(); \ | 1375 | })(); \ |
| 1368 | })();"; | 1376 | })();"; |
| 1369 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 1377 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 1370 | } | 1378 | } |
| 1371 | 1379 | ||
| 1372 | /// The row Options menus' client half: a `<details class="entry-options">` | 1380 | /// The row Options menus' client half: a `<details class="entry-options">` |
| @@ -1392,7 +1400,7 @@ async fn upload_script(cx: &Cx) -> Result { | |||
| 1392 | /// | 1400 | /// |
| 1393 | /// The Rust `\`-continuations strip newlines, so the emitted script is one | 1401 | /// The Rust `\`-continuations strip newlines, so the emitted script is one |
| 1394 | /// long line: only `/* */` comments survive inside it. | 1402 | /// long line: only `/* */` comments survive inside it. |
| 1395 | -async fn options_menu_script(cx: &Cx) -> Result { | 1403 | +async fn options_menu_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 1396 | use topcoat::view::Unescaped; | 1404 | use topcoat::view::Unescaped; |
| 1397 | const JS: &str = "\ | 1405 | const JS: &str = "\ |
| 1398 | (function () { \ | 1406 | (function () { \ |
| @@ -1449,7 +1457,7 @@ async fn options_menu_script(cx: &Cx) -> Result { | |||
| 1449 | closeOthers(null); \ | 1457 | closeOthers(null); \ |
| 1450 | }, true); \ | 1458 | }, true); \ |
| 1451 | })();"; | 1459 | })();"; |
| 1452 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 1460 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 1453 | } | 1461 | } |
| 1454 | 1462 | ||
| 1455 | #[derive(serde::Deserialize)] | 1463 | #[derive(serde::Deserialize)] |
crates/in-web/src/dropdown.rsmodified+3 -3
| @@ -40,7 +40,7 @@ | |||
| 40 | 40 | ||
| 41 | use topcoat::Result; | 41 | use topcoat::Result; |
| 42 | use topcoat::context::Cx; | 42 | use topcoat::context::Cx; |
| 43 | -use topcoat::view::{Unescaped, view}; | 43 | +use topcoat::view::{Unescaped, View, ViewExt, view}; |
| 44 | 44 | ||
| 45 | /// Emitted once per page that renders a `<select>`; the enhancement is | 45 | /// Emitted once per page that renders a `<select>`; the enhancement is |
| 46 | /// per-element and idempotent (`data-dd-done`), re-run on `in:wire` so | 46 | /// per-element and idempotent (`data-dd-done`), re-run on `in:wire` so |
| @@ -66,7 +66,7 @@ use topcoat::view::{Unescaped, view}; | |||
| 66 | /// `place` caps the open panel's width at `innerWidth − 8`, shaving off the | 66 | /// `place` caps the open panel's width at `innerWidth − 8`, shaving off the |
| 67 | /// padding and borders a `max-width` does not cover, or its right edge would | 67 | /// padding and borders a `max-width` does not cover, or its right edge would |
| 68 | /// clip on a 320px phone no matter where the left clamp puts it. | 68 | /// clip on a 320px phone no matter where the left clamp puts it. |
| 69 | -pub async fn dropdown_script(cx: &Cx) -> Result { | 69 | +pub async fn dropdown_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 70 | const JS: &str = "\ | 70 | const JS: &str = "\ |
| 71 | (function () {\ | 71 | (function () {\ |
| 72 | if (window.__inDd) { return; }\ | 72 | if (window.__inDd) { return; }\ |
| @@ -309,5 +309,5 @@ pub async fn dropdown_script(cx: &Cx) -> Result { | |||
| 309 | enhanceAll();\ | 309 | enhanceAll();\ |
| 310 | document.addEventListener('in:wire', enhanceAll);\ | 310 | document.addEventListener('in:wire', enhanceAll);\ |
| 311 | })();"; | 311 | })();"; |
| 312 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 312 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 313 | } | 313 | } |
crates/in-web/src/files.rsmodified+45 -42
| @@ -23,7 +23,7 @@ use topcoat::router::request::headers as request_headers; | |||
| 23 | use topcoat::router::{ | 23 | use topcoat::router::{ |
| 24 | HeaderMap, HeaderName, HeaderValue, StatusCode, header, page, path_param, query_params, route, | 24 | HeaderMap, HeaderName, HeaderValue, StatusCode, header, page, path_param, query_params, route, |
| 25 | }; | 25 | }; |
| 26 | -use topcoat::view::view; | 26 | +use topcoat::view::{ViewExt, BoxView, View, view}; |
| 27 | 27 | ||
| 28 | use crate::i18n::{Key, lang, t}; | 28 | use crate::i18n::{Key, lang, t}; |
| 29 | use crate::layout::{NavPage, topbar}; | 29 | use crate::layout::{NavPage, topbar}; |
| @@ -282,10 +282,10 @@ async fn download(cx: &Cx) -> topcoat::Result<(StatusCode, HeaderMap, topcoat::r | |||
| 282 | // bytes. A resumed download counts once, on its first chunk; later | 282 | // bytes. A resumed download counts once, on its first chunk; later |
| 283 | // chunks are the same download going on. | 283 | // chunks are the same download going on. |
| 284 | let counts = forced | 284 | let counts = forced |
| 285 | - && match range.and_then(|range| parse_range(range, file.size_bytes)) { | 285 | + && matches!( |
| 286 | - Some(Ok((0, _))) | None => true, | 286 | + range.and_then(|range| parse_range(range, file.size_bytes)), |
| 287 | - _ => false, | 287 | + Some(Ok((0, _))) | None |
| 288 | - }; | 288 | + ); |
| 289 | // One answer for every browser: the stored bytes under the stored mime. | 289 | // One answer for every browser: the stored bytes under the stored mime. |
| 290 | // Where a browser cannot demux them, the house player says so in the | 290 | // Where a browser cannot demux them, the house player says so in the |
| 291 | // page — and `?dl=1` still serves the original, byte for byte. | 291 | // page — and `?dl=1` still serves the original, byte for byte. |
| @@ -434,20 +434,23 @@ pub(crate) fn viewer_kind(mime: &str) -> Option<ViewerKind> { | |||
| 434 | /// mime-class glyph. The glyphs are decorative — the file's name beside | 434 | /// mime-class glyph. The glyphs are decorative — the file's name beside |
| 435 | /// them carries the meaning — so they hide from assistive technology. | 435 | /// them carries the meaning — so they hide from assistive technology. |
| 436 | /// | 436 | /// |
| 437 | -/// Lists embed this beside the name: `(crate::files::entry_chip(cx, | 437 | +/// Lists embed this beside the name: `(topcoat::view::Child::new(crate::files::entry_chip(cx, |
| 438 | -/// file).await?)`. | 438 | +/// file).await?))`. |
| 439 | -pub(crate) async fn entry_chip(cx: &Cx, file: &File) -> Result { | 439 | +pub(crate) async fn entry_chip<'a>(cx: &'a Cx, file: &File) -> Result<BoxView<'a>> { |
| 440 | - if file.thumb_state == ThumbState::Ready { | 440 | + let id = file.id.clone(); |
| 441 | - return view! { | 441 | + let mime = file.mime.clone(); |
| 442 | + let ready = file.thumb_state == ThumbState::Ready; | ||
| 443 | + if ready { | ||
| 444 | + return Ok(view! { | ||
| 442 | cx => | 445 | cx => |
| 443 | - <img class="file-chip" src=(format!("/thumb/{}", file.id)) alt=""> | 446 | + <img class="file-chip" src=(format!("/thumb/{id}")) alt=""> |
| 444 | - }; | 447 | + }.boxed()); |
| 445 | } | 448 | } |
| 446 | - let (class, glyph) = chip_mark(&file.mime); | 449 | + let (class, glyph) = chip_mark(&mime); |
| 447 | - view! { | 450 | + Ok(view! { |
| 448 | cx => | 451 | cx => |
| 449 | <span class=(format!("file-chip file-chip-{class}")) aria-hidden="true">(glyph)</span> | 452 | <span class=(format!("file-chip file-chip-{class}")) aria-hidden="true">(glyph)</span> |
| 450 | - } | 453 | + }.boxed()) |
| 451 | } | 454 | } |
| 452 | 455 | ||
| 453 | /// The chip's modifier class and its glyph, by stored mime: one distinct | 456 | /// The chip's modifier class and its glyph, by stored mime: one distinct |
| @@ -497,18 +500,18 @@ fn is_archive_mime(mime: &str) -> bool { | |||
| 497 | /// wherever it was opened from, back to the trash; anything else back to | 500 | /// wherever it was opened from, back to the trash; anything else back to |
| 498 | /// the drive. | 501 | /// the drive. |
| 499 | #[page("/view/{id}")] | 502 | #[page("/view/{id}")] |
| 500 | -async fn view_file(cx: &Cx) -> Result { | 503 | +async fn view_file(cx: &Cx) -> Result<impl View> { |
| 501 | let id: &str = path_param::<Id>(cx); | 504 | let id: &str = path_param::<Id>(cx); |
| 502 | 505 | ||
| 503 | let user = match require_user(cx).await { | 506 | let user = match require_user(cx).await { |
| 504 | Ok(user) => user, | 507 | Ok(user) => user, |
| 505 | Err(_) => { | 508 | Err(_) => { |
| 506 | let location = (header::LOCATION, HeaderValue::from_static("/")); | 509 | let location = (header::LOCATION, HeaderValue::from_static("/")); |
| 507 | - return view! { | 510 | + return Ok(view! { |
| 508 | cx => | 511 | cx => |
| 509 | (StatusCode::SEE_OTHER) | 512 | (StatusCode::SEE_OTHER) |
| 510 | (location) | 513 | (location) |
| 511 | - }; | 514 | + }.boxed()); |
| 512 | } | 515 | } |
| 513 | }; | 516 | }; |
| 514 | let language = lang(cx).await; | 517 | let language = lang(cx).await; |
| @@ -544,9 +547,9 @@ async fn view_file(cx: &Cx) -> Result { | |||
| 544 | crate::settings::human_bytes(file.size_bytes) | 547 | crate::settings::human_bytes(file.size_bytes) |
| 545 | ); | 548 | ); |
| 546 | let uploaded = file.created_at.date().to_string(); | 549 | let uploaded = file.created_at.date().to_string(); |
| 547 | - view! { | 550 | + Ok(view! { |
| 548 | cx => | 551 | cx => |
| 549 | - (topbar(cx, NavPage::Drive, &user, language).await?) | 552 | + (topcoat::view::Child::new(topbar(cx, NavPage::Drive, &user, language).await?)) |
| 550 | <main class="settings-stage stage-wide"> | 553 | <main class="settings-stage stage-wide"> |
| 551 | <div class="viewer-head"> | 554 | <div class="viewer-head"> |
| 552 | <a class="quiet" href=(back_href)>(t(language, back_key))</a> | 555 | <a class="quiet" href=(back_href)>(t(language, back_key))</a> |
| @@ -555,7 +558,7 @@ async fn view_file(cx: &Cx) -> Result { | |||
| 555 | <a class="primary" href=(download_href) download="">(t(language, Key::Download))</a> | 558 | <a class="primary" href=(download_href) download="">(t(language, Key::Download))</a> |
| 556 | } | 559 | } |
| 557 | </div> | 560 | </div> |
| 558 | - <h1 class="settings-title viewer-title">(entry_chip(cx, &file).await?) (file.name.clone())</h1> | 561 | + <h1 class="settings-title viewer-title">(topcoat::view::Child::new(entry_chip(cx, &file).await?)) (file.name.clone())</h1> |
| 559 | <p class="field-note">(meta)</p> | 562 | <p class="field-note">(meta)</p> |
| 560 | <div class="viewer-stage"> | 563 | <div class="viewer-stage"> |
| 561 | // Media previews for every reader; documents only under the | 564 | // Media previews for every reader; documents only under the |
| @@ -563,8 +566,8 @@ async fn view_file(cx: &Cx) -> Result { | |||
| 563 | if matches!(viewer_kind(&file.mime), Some(ViewerKind::Image | ViewerKind::Video | ViewerKind::Audio)) || may_download { | 566 | if matches!(viewer_kind(&file.mime), Some(ViewerKind::Image | ViewerKind::Video | ViewerKind::Audio)) || may_download { |
| 564 | match viewer_kind(&file.mime) { | 567 | match viewer_kind(&file.mime) { |
| 565 | Some(ViewerKind::Image) => <img class="viewer-media" src=(src.clone()) alt=(file.name.clone()) draggable="false">, | 568 | Some(ViewerKind::Image) => <img class="viewer-media" src=(src.clone()) alt=(file.name.clone()) draggable="false">, |
| 566 | - Some(ViewerKind::Video) => (media_player(cx, language, file.name.clone(), src.clone(), true).await?), | 569 | + Some(ViewerKind::Video) => (topcoat::view::Child::new(media_player(cx, language, file.name.clone(), src.clone(), true).await?)), |
| 567 | - Some(ViewerKind::Audio) => (media_player(cx, language, file.name.clone(), src.clone(), false).await?), | 570 | + Some(ViewerKind::Audio) => (topcoat::view::Child::new(media_player(cx, language, file.name.clone(), src.clone(), false).await?)), |
| 568 | Some(ViewerKind::Pdf) => <object class="viewer-media viewer-pdf" data=(src.clone()) type="application/pdf"> | 571 | Some(ViewerKind::Pdf) => <object class="viewer-media viewer-pdf" data=(src.clone()) type="application/pdf"> |
| 569 | <p class="field-note">(t(language, Key::PreviewUnavailable))</p> | 572 | <p class="field-note">(t(language, Key::PreviewUnavailable))</p> |
| 570 | </object>, | 573 | </object>, |
| @@ -599,9 +602,9 @@ async fn view_file(cx: &Cx) -> Result { | |||
| 599 | </div> | 602 | </div> |
| 600 | </section> | 603 | </section> |
| 601 | </main> | 604 | </main> |
| 602 | - (media_player_script(cx).await?) | 605 | + (topcoat::view::Child::new(media_player_script(cx).await?)) |
| 603 | - (viewer_guard_script(cx).await?) | 606 | + (topcoat::view::Child::new(viewer_guard_script(cx).await?)) |
| 604 | - } | 607 | + }.boxed()) |
| 605 | } | 608 | } |
| 606 | 609 | ||
| 607 | /// The house player for one inline media element, shared verbatim by the | 610 | /// The house player for one inline media element, shared verbatim by the |
| @@ -610,39 +613,39 @@ async fn view_file(cx: &Cx) -> Result { | |||
| 610 | /// `<video>`/`<audio>` and the bar that drives it, wired by | 613 | /// `<video>`/`<audio>` and the bar that drives it, wired by |
| 611 | /// [`media_player_script`]. `video` picks the stacked video layout — | 614 | /// [`media_player_script`]. `video` picks the stacked video layout — |
| 612 | /// picture with the bar beneath — over the audio bar. | 615 | /// picture with the bar beneath — over the audio bar. |
| 613 | -pub(crate) async fn media_player( | 616 | +pub(crate) async fn media_player<'a>( |
| 614 | - cx: &Cx, | 617 | + cx: &'a Cx, |
| 615 | language: crate::i18n::Lang, | 618 | language: crate::i18n::Lang, |
| 616 | name: String, | 619 | name: String, |
| 617 | src: String, | 620 | src: String, |
| 618 | video: bool, | 621 | video: bool, |
| 619 | -) -> Result { | 622 | +) -> Result<impl View + 'a> { |
| 620 | if video { | 623 | if video { |
| 621 | - view! { | 624 | + Ok(view! { |
| 622 | cx => | 625 | cx => |
| 623 | <div class="media-player media-player-video"> | 626 | <div class="media-player media-player-video"> |
| 624 | <video class="media-el viewer-video" src=(src) preload="metadata"></video> | 627 | <video class="media-el viewer-video" src=(src) preload="metadata"></video> |
| 625 | <p class="media-error" hidden="">(t(language, Key::MediaWontPlay))</p> | 628 | <p class="media-error" hidden="">(t(language, Key::MediaWontPlay))</p> |
| 626 | - <div class="media-controls">(media_controls(cx, language, name, true).await?)</div> | 629 | + <div class="media-controls">(topcoat::view::Child::new(media_controls(cx, language, name, true).await?))</div> |
| 627 | </div> | 630 | </div> |
| 628 | - } | 631 | + }.boxed()) |
| 629 | } else { | 632 | } else { |
| 630 | - view! { | 633 | + Ok(view! { |
| 631 | cx => | 634 | cx => |
| 632 | <div class="media-player"> | 635 | <div class="media-player"> |
| 633 | - (media_controls(cx, language, name, false).await?) | 636 | + (topcoat::view::Child::new(media_controls(cx, language, name, false).await?)) |
| 634 | <audio class="media-el" src=(src) preload="metadata"></audio> | 637 | <audio class="media-el" src=(src) preload="metadata"></audio> |
| 635 | <p class="media-error" hidden="">(t(language, Key::MediaWontPlay))</p> | 638 | <p class="media-error" hidden="">(t(language, Key::MediaWontPlay))</p> |
| 636 | </div> | 639 | </div> |
| 637 | - } | 640 | + }.boxed()) |
| 638 | } | 641 | } |
| 639 | } | 642 | } |
| 640 | 643 | ||
| 641 | /// The one controls bar both media players draw: play toggle, clock, seek, | 644 | /// The one controls bar both media players draw: play toggle, clock, seek, |
| 642 | /// volume (mute + level), a speed cycle, and fullscreen on video. The script | 645 | /// volume (mute + level), a speed cycle, and fullscreen on video. The script |
| 643 | /// below wires it by class, so the bar stays markup-only. | 646 | /// below wires it by class, so the bar stays markup-only. |
| 644 | -async fn media_controls(cx: &Cx, language: crate::i18n::Lang, name: String, video: bool) -> Result { | 647 | +async fn media_controls<'a>(cx: &'a Cx, language: crate::i18n::Lang, name: String, video: bool) -> Result<impl View + 'a> { |
| 645 | - view! { | 648 | + Ok(view! { |
| 646 | cx => | 649 | cx => |
| 647 | <button type="button" class="media-play" aria-label=(t(language, Key::Play)) | 650 | <button type="button" class="media-play" aria-label=(t(language, Key::Play)) |
| 648 | data-play=(t(language, Key::Play)) data-pause=(t(language, Key::Pause))> | 651 | data-play=(t(language, Key::Play)) data-pause=(t(language, Key::Pause))> |
| @@ -664,7 +667,7 @@ async fn media_controls(cx: &Cx, language: crate::i18n::Lang, name: String, vide | |||
| 664 | <svg class="glyph" width="13" height="13" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="M6 2H2v4M10 2h4v4M14 10v4h-4M2 10v4h4"></path></svg> | 667 | <svg class="glyph" width="13" height="13" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="M6 2H2v4M10 2h4v4M14 10v4h-4M2 10v4h4"></path></svg> |
| 665 | </button> | 668 | </button> |
| 666 | } | 669 | } |
| 667 | - } | 670 | + }.boxed()) |
| 668 | } | 671 | } |
| 669 | 672 | ||
| 670 | /// The house media player: play toggle, clock, seek bar — and a fullscreen | 673 | /// The house media player: play toggle, clock, seek bar — and a fullscreen |
| @@ -680,7 +683,7 @@ async fn media_controls(cx: &Cx, language: crate::i18n::Lang, name: String, vide | |||
| 680 | /// that demuxes the container but carries no decoder for its tracks never | 683 | /// that demuxes the container but carries no decoder for its tracks never |
| 681 | /// errors, it just never gains even metadata, and five seconds of that is | 684 | /// errors, it just never gains even metadata, and five seconds of that is |
| 682 | /// named dead too. | 685 | /// named dead too. |
| 683 | -pub(crate) async fn media_player_script(cx: &Cx) -> Result { | 686 | +pub(crate) async fn media_player_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 684 | use topcoat::view::Unescaped; | 687 | use topcoat::view::Unescaped; |
| 685 | const JS: &str = "\ | 688 | const JS: &str = "\ |
| 686 | (function () { \ | 689 | (function () { \ |
| @@ -771,7 +774,7 @@ pub(crate) async fn media_player_script(cx: &Cx) -> Result { | |||
| 771 | wireAll(); \ | 774 | wireAll(); \ |
| 772 | document.addEventListener('in:wire', wireAll); \ | 775 | document.addEventListener('in:wire', wireAll); \ |
| 773 | })();"; | 776 | })();"; |
| 774 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 777 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 775 | } | 778 | } |
| 776 | 779 | ||
| 777 | /// The preview's save-path cleanup: the house media player carries no | 780 | /// The preview's save-path cleanup: the house media player carries no |
| @@ -779,7 +782,7 @@ pub(crate) async fn media_player_script(cx: &Cx) -> Result { | |||
| 779 | /// context menu over the stage, so "save as" never opens on a preview. | 782 | /// context menu over the stage, so "save as" never opens on a preview. |
| 780 | /// A page's bytes on the wire can always be captured — this keeps the | 783 | /// A page's bytes on the wire can always be captured — this keeps the |
| 781 | /// surface from offering it, which is what a view-only grant promises. | 784 | /// surface from offering it, which is what a view-only grant promises. |
| 782 | -async fn viewer_guard_script(cx: &Cx) -> Result { | 785 | +async fn viewer_guard_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 783 | use topcoat::view::Unescaped; | 786 | use topcoat::view::Unescaped; |
| 784 | const JS: &str = "\ | 787 | const JS: &str = "\ |
| 785 | (function () { \ | 788 | (function () { \ |
| @@ -789,7 +792,7 @@ async fn viewer_guard_script(cx: &Cx) -> Result { | |||
| 789 | if (e.target && e.target.closest && e.target.closest('.viewer-stage')) { e.preventDefault(); } \ | 792 | if (e.target && e.target.closest && e.target.closest('.viewer-stage')) { e.preventDefault(); } \ |
| 790 | }); \ | 793 | }); \ |
| 791 | })();"; | 794 | })();"; |
| 792 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 795 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 793 | } | 796 | } |
| 794 | 797 | ||
| 795 | /// Takes the files the drive's upload form carries — one per `file` part, | 798 | /// Takes the files the drive's upload form carries — one per `file` part, |
crates/in-web/src/layout.rsmodified+83 -75
| @@ -15,7 +15,7 @@ use topcoat::{ | |||
| 15 | error::{NotFoundError, not_found}, | 15 | error::{NotFoundError, not_found}, |
| 16 | layout, page, | 16 | layout, page, |
| 17 | }, | 17 | }, |
| 18 | - view::{Unescaped, view}, | 18 | + view::{Unescaped, View, ViewExt, error_boundary, view}, |
| 19 | }; | 19 | }; |
| 20 | 20 | ||
| 21 | use in_core::store::User; | 21 | use in_core::store::User; |
| @@ -46,8 +46,8 @@ const FAVICON: &str = "data:image/svg+xml,\ | |||
| 46 | /// The mark carries the chrome, where the name is already known and the room | 46 | /// The mark carries the chrome, where the name is already known and the room |
| 47 | /// is 44px; the word carries the front door, where a stranger arrives and | 47 | /// is 44px; the word carries the front door, where a stranger arrives and |
| 48 | /// nothing else has said it yet. | 48 | /// nothing else has said it yet. |
| 49 | -pub(crate) async fn mark(cx: &Cx) -> Result { | 49 | +pub(crate) async fn mark<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 50 | - view! { | 50 | + Ok(view! { |
| 51 | cx => | 51 | cx => |
| 52 | <a class="wordmark" href="/" aria-label="in"> | 52 | <a class="wordmark" href="/" aria-label="in"> |
| 53 | <svg class="wordmark-mark" width="24" height="24" viewBox="0 0 24 24" | 53 | <svg class="wordmark-mark" width="24" height="24" viewBox="0 0 24 24" |
| @@ -61,17 +61,19 @@ pub(crate) async fn mark(cx: &Cx) -> Result { | |||
| 61 | </svg> | 61 | </svg> |
| 62 | </a> | 62 | </a> |
| 63 | } | 63 | } |
| 64 | + .boxed()) | ||
| 64 | } | 65 | } |
| 65 | 66 | ||
| 66 | /// The wordmark, the monogram's other half: the name alone, in the one face | 67 | /// The wordmark, the monogram's other half: the name alone, in the one face |
| 67 | /// both skins agree on. The sign-in page wears it — see `mark`. | 68 | /// both skins agree on. The sign-in page wears it — see `mark`. |
| 68 | -pub(crate) async fn wordmark(cx: &Cx) -> Result { | 69 | +pub(crate) async fn wordmark<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 69 | - view! { | 70 | + Ok(view! { |
| 70 | cx => | 71 | cx => |
| 71 | <a class="wordmark wordmark-lone" href="/"> | 72 | <a class="wordmark wordmark-lone" href="/"> |
| 72 | <span class="wordmark-text">"in"</span> | 73 | <span class="wordmark-text">"in"</span> |
| 73 | </a> | 74 | </a> |
| 74 | } | 75 | } |
| 76 | + .boxed()) | ||
| 75 | } | 77 | } |
| 76 | 78 | ||
| 77 | /// A person as a circle (or, on the Instrument skin, a square): the initials, | 79 | /// A person as a circle (or, on the Instrument skin, a square): the initials, |
| @@ -81,7 +83,11 @@ pub(crate) async fn wordmark(cx: &Cx) -> Result { | |||
| 81 | /// always renders and hides itself on error (see `avatar_script`), leaving | 83 | /// always renders and hides itself on error (see `avatar_script`), leaving |
| 82 | /// the initials beneath as the fallback. Shared by the topbar user menu on | 84 | /// the initials beneath as the fallback. Shared by the topbar user menu on |
| 83 | /// every signed-in page. | 85 | /// every signed-in page. |
| 84 | -pub(crate) async fn avatar(cx: &Cx, user: &User, extra: &str) -> Result { | 86 | +pub(crate) async fn avatar<'a>( |
| 87 | + cx: &'a Cx, | ||
| 88 | + user: &'a User, | ||
| 89 | + extra: &'a str, | ||
| 90 | +) -> Result<impl View + 'a> { | ||
| 85 | let tone = user | 91 | let tone = user |
| 86 | .id | 92 | .id |
| 87 | .bytes() | 93 | .bytes() |
| @@ -91,13 +97,14 @@ pub(crate) async fn avatar(cx: &Cx, user: &User, extra: &str) -> Result { | |||
| 91 | let name = user.display_name.clone(); | 97 | let name = user.display_name.clone(); |
| 92 | let initials = initials_of(&user.display_name); | 98 | let initials = initials_of(&user.display_name); |
| 93 | let src = format!("/avatar/{}?v={}", user.id, user.photo_version); | 99 | let src = format!("/avatar/{}?v={}", user.id, user.photo_version); |
| 94 | - view! { | 100 | + Ok(view! { |
| 95 | cx => | 101 | cx => |
| 96 | <span class="avatar-stack"> | 102 | <span class="avatar-stack"> |
| 97 | <span class=(class.clone()) data-name=(name.clone())>(initials)</span> | 103 | <span class=(class.clone()) data-name=(name.clone())>(initials)</span> |
| 98 | <img class=(format!("{class} avatar-photo")) src=(src) alt="" data-name=(name)> | 104 | <img class=(format!("{class} avatar-photo")) src=(src) alt="" data-name=(name)> |
| 99 | </span> | 105 | </span> |
| 100 | } | 106 | } |
| 107 | + .boxed()) | ||
| 101 | } | 108 | } |
| 102 | 109 | ||
| 103 | /// The photo half's client half: a missing photo must fall back to the | 110 | /// The photo half's client half: a missing photo must fall back to the |
| @@ -107,7 +114,7 @@ pub(crate) async fn avatar(cx: &Cx, user: &User, extra: &str) -> Result { | |||
| 107 | /// before it ran; hiding is registered through `__inOwn` so the live morph | 114 | /// before it ran; hiding is registered through `__inOwn` so the live morph |
| 108 | /// — which owns no names, only what the client declares — does not strip it | 115 | /// — which owns no names, only what the client declares — does not strip it |
| 109 | /// back off on the next refresh. | 116 | /// back off on the next refresh. |
| 110 | -pub async fn avatar_script(cx: &Cx) -> Result { | 117 | +pub async fn avatar_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 111 | use topcoat::view::Unescaped; | 118 | use topcoat::view::Unescaped; |
| 112 | const JS: &str = "\ | 119 | const JS: &str = "\ |
| 113 | (function () { \ | 120 | (function () { \ |
| @@ -125,7 +132,7 @@ pub async fn avatar_script(cx: &Cx) -> Result { | |||
| 125 | if (img.complete && img.naturalWidth === 0) { hide(img); } \ | 132 | if (img.complete && img.naturalWidth === 0) { hide(img); } \ |
| 126 | }); \ | 133 | }); \ |
| 127 | })();"; | 134 | })();"; |
| 128 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 135 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 129 | } | 136 | } |
| 130 | 137 | ||
| 131 | /// The first letters of the first two words, uppercased — "Ada Lovelace" | 138 | /// The first letters of the first two words, uppercased — "Ada Lovelace" |
| @@ -146,12 +153,12 @@ fn initials_of(name: &str) -> String { | |||
| 146 | /// The topbar's signed-in identity: the display name, opening on hover or | 153 | /// The topbar's signed-in identity: the display name, opening on hover or |
| 147 | /// focus onto details (name, address) and sign-out. Shared by every | 154 | /// focus onto details (name, address) and sign-out. Shared by every |
| 148 | /// signed-in page's topbar. | 155 | /// signed-in page's topbar. |
| 149 | -pub async fn user_menu(cx: &Cx, user: &User, lang: Lang) -> Result { | 156 | +pub async fn user_menu<'a>(cx: &'a Cx, user: &'a User, lang: Lang) -> Result<impl View + 'a> { |
| 150 | - view! { | 157 | + Ok(view! { |
| 151 | cx => | 158 | cx => |
| 152 | <div class="user-menu"> | 159 | <div class="user-menu"> |
| 153 | <button type="button" class="user-menu-trigger" aria-label=(t(lang, Key::UserMenuLabel))> | 160 | <button type="button" class="user-menu-trigger" aria-label=(t(lang, Key::UserMenuLabel))> |
| 154 | - (avatar(cx, user, "").await?) | 161 | + (topcoat::view::Child::new(avatar(cx, user, "").await?)) |
| 155 | <span class="user-menu-trigger-name">(user.display_name.clone())</span> | 162 | <span class="user-menu-trigger-name">(user.display_name.clone())</span> |
| 156 | </button> | 163 | </button> |
| 157 | <div class="user-menu-panel"> | 164 | <div class="user-menu-panel"> |
| @@ -165,7 +172,7 @@ pub async fn user_menu(cx: &Cx, user: &User, lang: Lang) -> Result { | |||
| 165 | <a class="user-menu-item" href="/auth/logout" data-hard="">(t(lang, Key::SignOut))</a> | 172 | <a class="user-menu-item" href="/auth/logout" data-hard="">(t(lang, Key::SignOut))</a> |
| 166 | </div> | 173 | </div> |
| 167 | </div> | 174 | </div> |
| 168 | - } | 175 | + }.boxed()) |
| 169 | } | 176 | } |
| 170 | 177 | ||
| 171 | /// The signed-in pages, as the topbar nav links between them. | 178 | /// The signed-in pages, as the topbar nav links between them. |
| @@ -205,8 +212,8 @@ impl NavPage { | |||
| 205 | /// The topbar's page nav, shared by every signed-in page, with the current | 212 | /// The topbar's page nav, shared by every signed-in page, with the current |
| 206 | /// one marked. Plain `<a>`s — the soft-nav forwarder swaps them like any | 213 | /// one marked. Plain `<a>`s — the soft-nav forwarder swaps them like any |
| 207 | /// same-origin link, so `data-hard` stays off. | 214 | /// same-origin link, so `data-hard` stays off. |
| 208 | -pub async fn topbar_nav(cx: &Cx, active: NavPage, lang: Lang) -> Result { | 215 | +pub async fn topbar_nav<'a>(cx: &'a Cx, active: NavPage, lang: Lang) -> Result<impl View + 'a> { |
| 209 | - view! { | 216 | + Ok(view! { |
| 210 | cx => | 217 | cx => |
| 211 | <nav class="topbar-nav-links"> | 218 | <nav class="topbar-nav-links"> |
| 212 | for page in NavPage::ALL { | 219 | for page in NavPage::ALL { |
| @@ -219,6 +226,7 @@ pub async fn topbar_nav(cx: &Cx, active: NavPage, lang: Lang) -> Result { | |||
| 219 | } | 226 | } |
| 220 | </nav> | 227 | </nav> |
| 221 | } | 228 | } |
| 229 | + .boxed()) | ||
| 222 | } | 230 | } |
| 223 | 231 | ||
| 224 | /// This app's key in the family list: the entry matching it is the one | 232 | /// This app's key in the family list: the entry matching it is the one |
| @@ -245,19 +253,19 @@ async fn family_of(cx: &Cx) -> Vec<in_client::ServiceJson> { | |||
| 245 | /// `:hover` / `:focus-within`, and it stays in the DOM at opacity zero so | 253 | /// `:hover` / `:focus-within`, and it stays in the DOM at opacity zero so |
| 246 | /// Tab reaches its links. A family that is absent, or holds no one but | 254 | /// Tab reaches its links. A family that is absent, or holds no one but |
| 247 | /// this app, renders the bare mark — there is nothing to reveal. | 255 | /// this app, renders the bare mark — there is nothing to reveal. |
| 248 | -async fn family_mark(cx: &Cx) -> Result { | 256 | +async fn family_mark<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 249 | let family = family_of(cx).await; | 257 | let family = family_of(cx).await; |
| 250 | let siblings: Vec<_> = family | 258 | let siblings: Vec<_> = family |
| 251 | .into_iter() | 259 | .into_iter() |
| 252 | .filter(|service| service.key != SELF_KEY) | 260 | .filter(|service| service.key != SELF_KEY) |
| 253 | .collect(); | 261 | .collect(); |
| 254 | if siblings.is_empty() { | 262 | if siblings.is_empty() { |
| 255 | - return mark(cx).await; | 263 | + return mark(cx).await.map(|v| v.boxed()); |
| 256 | } | 264 | } |
| 257 | - view! { | 265 | + Ok(view! { |
| 258 | cx => | 266 | cx => |
| 259 | <div class="wordmark-family"> | 267 | <div class="wordmark-family"> |
| 260 | - (mark(cx).await?) | 268 | + (topcoat::view::Child::new(mark(cx).await?)) |
| 261 | <nav class="app-switcher"> | 269 | <nav class="app-switcher"> |
| 262 | for (i, service) in siblings.iter().enumerate() { | 270 | for (i, service) in siblings.iter().enumerate() { |
| 263 | if i > 0 { | 271 | if i > 0 { |
| @@ -274,20 +282,27 @@ async fn family_mark(cx: &Cx) -> Result { | |||
| 274 | </nav> | 282 | </nav> |
| 275 | </div> | 283 | </div> |
| 276 | } | 284 | } |
| 285 | + .boxed()) | ||
| 277 | } | 286 | } |
| 278 | 287 | ||
| 279 | /// The signed-in chrome: the monogram with the family behind it, the page | 288 | /// The signed-in chrome: the monogram with the family behind it, the page |
| 280 | /// nav, the identity menu. Wave-2 pages render their content under this. | 289 | /// nav, the identity menu. Wave-2 pages render their content under this. |
| 281 | -pub async fn topbar(cx: &Cx, active: NavPage, user: &User, lang: Lang) -> Result { | 290 | +pub async fn topbar<'a>( |
| 282 | - view! { | 291 | + cx: &'a Cx, |
| 292 | + active: NavPage, | ||
| 293 | + user: &'a User, | ||
| 294 | + lang: Lang, | ||
| 295 | +) -> Result<impl View + 'a> { | ||
| 296 | + Ok(view! { | ||
| 283 | cx => | 297 | cx => |
| 284 | <header class="topbar"> | 298 | <header class="topbar"> |
| 285 | - (family_mark(cx).await?) | 299 | + (topcoat::view::Child::new(family_mark(cx).await?)) |
| 286 | - (topbar_nav(cx, active, lang).await?) | 300 | + (topcoat::view::Child::new(topbar_nav(cx, active, lang).await?)) |
| 287 | - (user_menu(cx, user, lang).await?) | 301 | + (topcoat::view::Child::new(user_menu(cx, user, lang).await?)) |
| 288 | </header> | 302 | </header> |
| 289 | - (avatar_script(cx).await?) | 303 | + (topcoat::view::Child::new(avatar_script(cx).await?)) |
| 290 | } | 304 | } |
| 305 | + .boxed()) | ||
| 291 | } | 306 | } |
| 292 | 307 | ||
| 293 | /// The page-swap machinery that keeps every mutation on the same document. | 308 | /// The page-swap machinery that keeps every mutation on the same document. |
| @@ -357,7 +372,7 @@ pub async fn topbar(cx: &Cx, active: NavPage, user: &User, lang: Lang) -> Result | |||
| 357 | /// `wire()` also pins every `.comment-list` to its bottom, on initial | 372 | /// `wire()` also pins every `.comment-list` to its bottom, on initial |
| 358 | /// load (DOMContentLoaded) included. (No comment lists in v1; the hook | 373 | /// load (DOMContentLoaded) included. (No comment lists in v1; the hook |
| 359 | /// stays so wave-2 additions inherit the behavior.) | 374 | /// stays so wave-2 additions inherit the behavior.) |
| 360 | -pub async fn soft_nav_script(cx: &Cx) -> Result { | 375 | +pub async fn soft_nav_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 361 | const JS: &str = "\ | 376 | const JS: &str = "\ |
| 362 | (function () { \ | 377 | (function () { \ |
| 363 | if (window.__inSoft) { return; } \ | 378 | if (window.__inSoft) { return; } \ |
| @@ -735,7 +750,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { | |||
| 735 | }); \ | 750 | }); \ |
| 736 | if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', wire); } else { wire(); } \ | 751 | if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', wire); } else { wire(); } \ |
| 737 | })();"; | 752 | })();"; |
| 738 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 753 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 739 | } | 754 | } |
| 740 | /// Live search: the filterbar's `q` box fetches its page as the user types — | 755 | /// Live search: the filterbar's `q` box fetches its page as the user types — |
| 741 | /// debounced, morphed in place through `__inQuery`, the URL replaced rather | 756 | /// debounced, morphed in place through `__inQuery`, the URL replaced rather |
| @@ -749,7 +764,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { | |||
| 749 | /// Enter still submits through `soft_nav_script`'s GET handler (a real | 764 | /// Enter still submits through `soft_nav_script`'s GET handler (a real |
| 750 | /// navigation, history entry and all); an emptied box asks for the plain | 765 | /// navigation, history entry and all); an emptied box asks for the plain |
| 751 | /// listing, which the server already answers. | 766 | /// listing, which the server already answers. |
| 752 | -pub async fn search_script(cx: &Cx) -> Result { | 767 | +pub async fn search_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 753 | const JS: &str = "\ | 768 | const JS: &str = "\ |
| 754 | (function () { \ | 769 | (function () { \ |
| 755 | if (window.__inSearch) { return; } \ | 770 | if (window.__inSearch) { return; } \ |
| @@ -770,7 +785,7 @@ pub async fn search_script(cx: &Cx) -> Result { | |||
| 770 | timer = setTimeout(function () { timer = null; fire(); }, 200); \ | 785 | timer = setTimeout(function () { timer = null; fire(); }, 200); \ |
| 771 | }); \ | 786 | }); \ |
| 772 | })();"; | 787 | })();"; |
| 773 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 788 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 774 | } | 789 | } |
| 775 | 790 | ||
| 776 | /// The one document-level capture `keydown` listener for `Escape`, emitted | 791 | /// The one document-level capture `keydown` listener for `Escape`, emitted |
| @@ -881,7 +896,7 @@ pub async fn search_script(cx: &Cx) -> Result { | |||
| 881 | /// disagree with it — the tick re-fetches, and the server stays the only thing | 896 | /// disagree with it — the tick re-fetches, and the server stays the only thing |
| 882 | /// that decides what a moment reads as. It runs only on pages carrying a | 897 | /// that decides what a moment reads as. It runs only on pages carrying a |
| 883 | /// `data-tick` element, so a page with no clock-driven text is silent. | 898 | /// `data-tick` element, so a page with no clock-driven text is silent. |
| 884 | -pub async fn live_script(cx: &Cx) -> Result { | 899 | +pub async fn live_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 885 | const JS: &str = "\ | 900 | const JS: &str = "\ |
| 886 | (function () { \ | 901 | (function () { \ |
| 887 | if (window.__inLive) { return; } \ | 902 | if (window.__inLive) { return; } \ |
| @@ -917,10 +932,10 @@ pub async fn live_script(cx: &Cx) -> Result { | |||
| 917 | }, 60000); \ | 932 | }, 60000); \ |
| 918 | })(); \ | 933 | })(); \ |
| 919 | "; | 934 | "; |
| 920 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 935 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 921 | } | 936 | } |
| 922 | 937 | ||
| 923 | -pub async fn escape_manager_script(cx: &Cx) -> Result { | 938 | +pub async fn escape_manager_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 924 | use topcoat::view::Unescaped; | 939 | use topcoat::view::Unescaped; |
| 925 | const JS: &str = "\ | 940 | const JS: &str = "\ |
| 926 | (function () { \ | 941 | (function () { \ |
| @@ -943,13 +958,13 @@ pub async fn escape_manager_script(cx: &Cx) -> Result { | |||
| 943 | } \ | 958 | } \ |
| 944 | }, true); \ | 959 | }, true); \ |
| 945 | })();"; | 960 | })();"; |
| 946 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 961 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 947 | } | 962 | } |
| 948 | /// Registers the topbar `Escape` resolver on `window.__inEsc` | 963 | /// Registers the topbar `Escape` resolver on `window.__inEsc` |
| 949 | /// (priority 40 — the table is on `escape_manager_script`): the topbar | 964 | /// (priority 40 — the table is on `escape_manager_script`): the topbar |
| 950 | /// `.user-menu` panel — hover-open included, pinned shut by a | 965 | /// `.user-menu` panel — hover-open included, pinned shut by a |
| 951 | /// `user-menu-esc` class that a `mouseenter` inside the menu clears. | 966 | /// `user-menu-esc` class that a `mouseenter` inside the menu clears. |
| 952 | -pub async fn escape_script(cx: &Cx) -> Result { | 967 | +pub async fn escape_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 953 | const JS: &str = "\ | 968 | const JS: &str = "\ |
| 954 | (function () { \ | 969 | (function () { \ |
| 955 | if (window.__inEscTop) { return; } \ | 970 | if (window.__inEscTop) { return; } \ |
| @@ -969,7 +984,7 @@ pub async fn escape_script(cx: &Cx) -> Result { | |||
| 969 | if (menu) { menu.classList.remove('user-menu-esc'); } \ | 984 | if (menu) { menu.classList.remove('user-menu-esc'); } \ |
| 970 | }, true); \ | 985 | }, true); \ |
| 971 | })();"; | 986 | })();"; |
| 972 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 987 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 973 | } | 988 | } |
| 974 | /// The persistent notice stack's client half: upload errors and completions | 989 | /// The persistent notice stack's client half: upload errors and completions |
| 975 | /// that must stay until dismissed. Emitted from the document shell so every | 990 | /// that must stay until dismissed. Emitted from the document shell so every |
| @@ -990,7 +1005,7 @@ pub async fn escape_script(cx: &Cx) -> Result { | |||
| 990 | /// The server-rendered `?refusal` banner needs no such route: it rides the | 1005 | /// The server-rendered `?refusal` banner needs no such route: it rides the |
| 991 | /// redirect URL the swap just painted, so both paths re-render it from the | 1006 | /// redirect URL the swap just painted, so both paths re-render it from the |
| 992 | /// server's own bytes. | 1007 | /// server's own bytes. |
| 993 | -pub async fn status_script(cx: &Cx) -> Result { | 1008 | +pub async fn status_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 994 | const JS: &str = "\ | 1009 | const JS: &str = "\ |
| 995 | (function () { \ | 1010 | (function () { \ |
| 996 | if (window.__inStatus) { return; } \ | 1011 | if (window.__inStatus) { return; } \ |
| @@ -1036,14 +1051,14 @@ pub async fn status_script(cx: &Cx) -> Result { | |||
| 1036 | document.addEventListener('in:wire', render); \ | 1051 | document.addEventListener('in:wire', render); \ |
| 1037 | render(); \ | 1052 | render(); \ |
| 1038 | })();"; | 1053 | })();"; |
| 1039 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 1054 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 1040 | } | 1055 | } |
| 1041 | 1056 | ||
| 1042 | /// Every path that matches no page raises a `NotFoundError`, so it renders | 1057 | /// Every path that matches no page raises a `NotFoundError`, so it renders |
| 1043 | /// through `root_layout`'s catch below rather than the router's bare default. | 1058 | /// through `root_layout`'s catch below rather than the router's bare default. |
| 1044 | /// `/` itself is served by `landing` above and never reaches this route. | 1059 | /// `/` itself is served by `landing` above and never reaches this route. |
| 1045 | #[page("/{*path}")] | 1060 | #[page("/{*path}")] |
| 1046 | -async fn missing() -> Result { | 1061 | +async fn missing() -> Result<topcoat::view::BoxView<'static>> { |
| 1047 | Err(not_found().into()) | 1062 | Err(not_found().into()) |
| 1048 | } | 1063 | } |
| 1049 | 1064 | ||
| @@ -1059,7 +1074,10 @@ const STYLE: Asset = asset!("assets/main.css"); | |||
| 1059 | /// and the session-gated live stream stays off (`asking` is false without a | 1074 | /// and the session-gated live stream stays off (`asking` is false without a |
| 1060 | /// session), so a stranger's page carries no user data and opens no | 1075 | /// session), so a stranger's page carries no user data and opens no |
| 1061 | /// `/api/live` connection. | 1076 | /// `/api/live` connection. |
| 1062 | -pub(crate) async fn document_shell(cx: &Cx, slot: Result) -> Result { | 1077 | +pub(crate) async fn document_shell<'a>( |
| 1078 | + cx: &'a Cx, | ||
| 1079 | + slot: topcoat::view::Child<'a>, | ||
| 1080 | +) -> Result<impl View + 'a> { | ||
| 1063 | // The per-user chrome knobs, read off the request's own user: the theme | 1081 | // The per-user chrome knobs, read off the request's own user: the theme |
| 1064 | // into `data-theme`, the interface into `data-ui`, the language into | 1082 | // into `data-theme`, the interface into `data-ui`, the language into |
| 1065 | // `<html lang>`. Signed-out (or unreadable) wears the provision defaults — | 1083 | // `<html lang>`. Signed-out (or unreadable) wears the provision defaults — |
| @@ -1069,32 +1087,15 @@ pub(crate) async fn document_shell(cx: &Cx, slot: Result) -> Result { | |||
| 1069 | Err(_) => None, | 1087 | Err(_) => None, |
| 1070 | }; | 1088 | }; |
| 1071 | let asking = me.is_some(); | 1089 | let asking = me.is_some(); |
| 1072 | - let dark = me.as_ref().map_or(true, |user| user.theme == "dark"); | 1090 | + let dark = me.as_ref().is_none_or(|user| user.theme == "dark"); |
| 1073 | let ui = me.as_ref().map_or("instrument", |user| user.ui.as_str()); | 1091 | let ui = me.as_ref().map_or("instrument", |user| user.ui.as_str()); |
| 1074 | let lang = crate::i18n::lang(cx).await; | 1092 | let lang = crate::i18n::lang(cx).await; |
| 1075 | 1093 | ||
| 1076 | - let content = match slot { | 1094 | + let nothing = t(lang, Key::NothingAtThisAddress).to_string(); |
| 1077 | - Err(error) if error.downcast_ref::<NotFoundError>().is_some() => view! { | 1095 | + Ok(view! { |
| 1078 | - cx => | ||
| 1079 | - (StatusCode::NOT_FOUND) | ||
| 1080 | - <main class="scaffold-note"> | ||
| 1081 | - <p>(t(lang, Key::NothingAtThisAddress))</p> | ||
| 1082 | - </main> | ||
| 1083 | - }, | ||
| 1084 | - content => content, | ||
| 1085 | - }?; | ||
| 1086 | - | ||
| 1087 | - // The build stamp rides the html element on every render — page load, | ||
| 1088 | - // soft navigation and live refresh all answer through this layout, and | ||
| 1089 | - // the swap path reads it off the fetched document before it touches the | ||
| 1090 | - // page. A tab left open across a deploy keeps the old stylesheet link | ||
| 1091 | - // (the morph swaps body children, never the head), so a mismatch is | ||
| 1092 | - // the client's cue to hard-reload rather than wear the old css. | ||
| 1093 | - let build = STYLE.id().as_u64().to_string(); | ||
| 1094 | - view! { | ||
| 1095 | cx => | 1096 | cx => |
| 1096 | <!DOCTYPE html> | 1097 | <!DOCTYPE html> |
| 1097 | - <html lang=(lang.code()) data-theme=(dark.then_some("dark")) data-ui=(ui) data-build=(build)> | 1098 | + <html lang=(lang.code()) data-theme=(dark.then_some("dark")) data-ui=(ui) data-build=(STYLE.id().as_u64().to_string())> |
| 1098 | <head> | 1099 | <head> |
| 1099 | <meta charset="utf-8"> | 1100 | <meta charset="utf-8"> |
| 1100 | <meta name="viewport" content="width=device-width, initial-scale=1"> | 1101 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| @@ -1111,29 +1112,36 @@ pub(crate) async fn document_shell(cx: &Cx, slot: Result) -> Result { | |||
| 1111 | topcoat::dev::script() | 1112 | topcoat::dev::script() |
| 1112 | </head> | 1113 | </head> |
| 1113 | <body> | 1114 | <body> |
| 1114 | - (escape_manager_script(cx).await?) | 1115 | + (topcoat::view::Child::new(escape_manager_script(cx).await?)) |
| 1115 | - (soft_nav_script(cx).await?) | 1116 | + (topcoat::view::Child::new(soft_nav_script(cx).await?)) |
| 1116 | - (search_script(cx).await?) | 1117 | + (topcoat::view::Child::new(search_script(cx).await?)) |
| 1117 | - // Only for a signed-in page: `/api/live` answers 401 to | 1118 | + if asking { (topcoat::view::Child::new(live_script(cx).await?)) } |
| 1118 | - // everybody else, and an auth screen that opened a stream | 1119 | + error_boundary( |
| 1119 | - // would just reconnect against that refusal forever. | 1120 | + fallback: |error| { |
| 1120 | - if asking { (live_script(cx).await?) } | 1121 | + if error.downcast_ref::<NotFoundError>().is_none() { |
| 1121 | - (content) | 1122 | + return Err(error); |
| 1122 | - // The persistent corner stack: client-made upload progress | 1123 | + } |
| 1123 | - // rows and notice cards live here, marked `__inAdded` and | 1124 | + Ok(view! { |
| 1124 | - // mirrored on `window`, so both swap paths keep them while | 1125 | + cx => |
| 1125 | - // the reader moves between pages mid-upload. | 1126 | + (StatusCode::NOT_FOUND) |
| 1127 | + <main class="scaffold-note"> | ||
| 1128 | + <p>(nothing)</p> | ||
| 1129 | + </main> | ||
| 1130 | + }) | ||
| 1131 | + }, | ||
| 1132 | + (slot) | ||
| 1133 | + ) | ||
| 1126 | <div id="in-status" class="in-status-stack" aria-live="polite" | 1134 | <div id="in-status" class="in-status-stack" aria-live="polite" |
| 1127 | data-dismiss-label=(t(lang, Key::Dismiss))></div> | 1135 | data-dismiss-label=(t(lang, Key::Dismiss))></div> |
| 1128 | - (status_script(cx).await?) | 1136 | + (topcoat::view::Child::new(status_script(cx).await?)) |
| 1129 | </body> | 1137 | </body> |
| 1130 | </html> | 1138 | </html> |
| 1131 | - } | 1139 | + }.boxed()) |
| 1132 | } | 1140 | } |
| 1133 | 1141 | ||
| 1134 | /// The router's own shell route: pairing is by path prefix, so every page | 1142 | /// The router's own shell route: pairing is by path prefix, so every page |
| 1135 | /// under `/` wears `document_shell` through here. | 1143 | /// under `/` wears `document_shell` through here. |
| 1136 | #[layout("/")] | 1144 | #[layout("/")] |
| 1137 | -async fn root_layout(cx: &Cx, slot: Result) -> Result { | 1145 | +async fn root_layout(cx: &Cx, slot: topcoat::view::Child<'_>) -> Result<impl View> { |
| 1138 | document_shell(cx, slot).await | 1146 | document_shell(cx, slot).await |
| 1139 | } | 1147 | } |
crates/in-web/src/main.rsmodified+3 -2
| @@ -8,6 +8,7 @@ use topcoat::asset::{AssetBundle, RouterBuilderAssetExt}; | |||
| 8 | use topcoat::context::Cx; | 8 | use topcoat::context::Cx; |
| 9 | use topcoat::cookie::RouterBuilderCookieExt; | 9 | use topcoat::cookie::RouterBuilderCookieExt; |
| 10 | use topcoat::router::{BodyLimit, Router, RouterBuilderDiscoverExt, route}; | 10 | use topcoat::router::{BodyLimit, Router, RouterBuilderDiscoverExt, route}; |
| 11 | +use topcoat::runtime::RouterBuilderRuntimeExt; | ||
| 11 | 12 | ||
| 12 | #[route(GET "/healthz")] | 13 | #[route(GET "/healthz")] |
| 13 | async fn healthz() -> Result<&'static str> { | 14 | async fn healthz() -> Result<&'static str> { |
| @@ -262,6 +263,7 @@ async fn main() { | |||
| 262 | let router = in_client::mount( | 263 | let router = in_client::mount( |
| 263 | Router::builder() | 264 | Router::builder() |
| 264 | .discover() | 265 | .discover() |
| 266 | + .runtime() | ||
| 265 | // BodyLimit is only a memory guard here, not the upload policy: | 267 | // BodyLimit is only a memory guard here, not the upload policy: |
| 266 | // the account quota, enforced in the store at start and finish, | 268 | // the account quota, enforced in the store at start and finish, |
| 267 | // is the only size limit. `/files` takes whole multipart bodies, | 269 | // is the only size limit. `/files` takes whole multipart bodies, |
| @@ -490,8 +492,7 @@ async fn family_sync( | |||
| 490 | // im states none). A refused write is one log line — the | 492 | // im states none). A refused write is one log line — the |
| 491 | // next beat carries the same word. | 493 | // next beat carries the same word. |
| 492 | if let Err(problem) = | 494 | if let Err(problem) = |
| 493 | - in_web::service::apply_family_limits(&store, &family, default_quota_bytes) | 495 | + in_web::service::apply_family_limits(&store, &family, default_quota_bytes).await |
| 494 | - .await | ||
| 495 | { | 496 | { |
| 496 | eprintln!("family limits: {problem}"); | 497 | eprintln!("family limits: {problem}"); |
| 497 | } | 498 | } |
crates/in-web/src/pages.rsmodified+12 -10
| @@ -12,7 +12,7 @@ | |||
| 12 | use topcoat::Result; | 12 | use topcoat::Result; |
| 13 | use topcoat::context::Cx; | 13 | use topcoat::context::Cx; |
| 14 | use topcoat::router::{HeaderValue, StatusCode, header, page}; | 14 | use topcoat::router::{HeaderValue, StatusCode, header, page}; |
| 15 | -use topcoat::view::view; | 15 | +use topcoat::view::{View, ViewExt, view}; |
| 16 | 16 | ||
| 17 | use crate::i18n::{Key, Lang, lang, t}; | 17 | use crate::i18n::{Key, Lang, lang, t}; |
| 18 | use crate::layout::wordmark; | 18 | use crate::layout::wordmark; |
| @@ -21,37 +21,39 @@ use crate::server::current_user; | |||
| 21 | /// The front door: the drive for a signed-in browser, the sign-in card for | 21 | /// The front door: the drive for a signed-in browser, the sign-in card for |
| 22 | /// everybody else. | 22 | /// everybody else. |
| 23 | #[page("/")] | 23 | #[page("/")] |
| 24 | -async fn landing(cx: &Cx) -> Result { | 24 | +async fn landing(cx: &Cx) -> Result<impl View> { |
| 25 | match current_user(cx).await { | 25 | match current_user(cx).await { |
| 26 | Ok(Some(_)) => { | 26 | Ok(Some(_)) => { |
| 27 | let location = (header::LOCATION, HeaderValue::from_static("/drive")); | 27 | let location = (header::LOCATION, HeaderValue::from_static("/drive")); |
| 28 | - view! { | 28 | + Ok(view! { |
| 29 | cx => | 29 | cx => |
| 30 | (StatusCode::SEE_OTHER) | 30 | (StatusCode::SEE_OTHER) |
| 31 | (location) | 31 | (location) |
| 32 | } | 32 | } |
| 33 | + .boxed()) | ||
| 33 | } | 34 | } |
| 34 | - Ok(None) => sign_in_card(cx).await, | 35 | + Ok(None) => Ok(sign_in_card(cx).await?.boxed()), |
| 35 | - Err(_) => view! { | 36 | + Err(_) => Ok(view! { |
| 36 | cx => | 37 | cx => |
| 37 | <main class="scaffold-note"> | 38 | <main class="scaffold-note"> |
| 38 | <p>(t(Lang::En, Key::SomethingWentWrong))</p> | 39 | <p>(t(Lang::En, Key::SomethingWentWrong))</p> |
| 39 | </main> | 40 | </main> |
| 40 | - }, | 41 | + } |
| 42 | + .boxed()), | ||
| 41 | } | 43 | } |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | /// The sign-in card for a browser with nobody in it: the wordmark and one | 46 | /// The sign-in card for a browser with nobody in it: the wordmark and one |
| 45 | /// link, which starts the OIDC round-trip at `/auth/login`. | 47 | /// link, which starts the OIDC round-trip at `/auth/login`. |
| 46 | -async fn sign_in_card(cx: &Cx) -> Result { | 48 | +async fn sign_in_card<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 47 | let language = lang(cx).await; | 49 | let language = lang(cx).await; |
| 48 | - view! { | 50 | + Ok(view! { |
| 49 | cx => | 51 | cx => |
| 50 | <main class="auth-stage"> | 52 | <main class="auth-stage"> |
| 51 | <div class="auth-column"> | 53 | <div class="auth-column"> |
| 52 | <div class="auth-card"> | 54 | <div class="auth-card"> |
| 53 | <div class="auth-head"> | 55 | <div class="auth-head"> |
| 54 | - <div class="auth-title">(wordmark(cx).await?)</div> | 56 | + <div class="auth-title">(topcoat::view::Child::new(wordmark(cx).await?))</div> |
| 55 | <div class="auth-sub">(t(language, Key::WelcomeBlurb))</div> | 57 | <div class="auth-sub">(t(language, Key::WelcomeBlurb))</div> |
| 56 | </div> | 58 | </div> |
| 57 | <a class="auth-submit" href="/auth/login"> | 59 | <a class="auth-submit" href="/auth/login"> |
| @@ -60,5 +62,5 @@ async fn sign_in_card(cx: &Cx) -> Result { | |||
| 60 | </div> | 62 | </div> |
| 61 | </div> | 63 | </div> |
| 62 | </main> | 64 | </main> |
| 63 | - } | 65 | + }.boxed()) |
| 64 | } | 66 | } |
crates/in-web/src/server.rsmodified+24 -11
| @@ -72,14 +72,19 @@ pub struct DirectoryHealth { | |||
| 72 | last_pass: Arc<std::sync::atomic::AtomicI64>, | 72 | last_pass: Arc<std::sync::atomic::AtomicI64>, |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | -impl DirectoryHealth { | 75 | +impl Default for DirectoryHealth { |
| 76 | - pub fn new() -> Self { | 76 | + fn default() -> Self { |
| 77 | Self { | 77 | Self { |
| 78 | stream: Arc::new(std::sync::atomic::AtomicU8::new(0)), | 78 | stream: Arc::new(std::sync::atomic::AtomicU8::new(0)), |
| 79 | last_event: Arc::new(std::sync::atomic::AtomicI64::new(0)), | 79 | last_event: Arc::new(std::sync::atomic::AtomicI64::new(0)), |
| 80 | last_pass: Arc::new(std::sync::atomic::AtomicI64::new(0)), | 80 | last_pass: Arc::new(std::sync::atomic::AtomicI64::new(0)), |
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| 83 | +} | ||
| 84 | +impl DirectoryHealth { | ||
| 85 | + pub fn new() -> Self { | ||
| 86 | + Self::default() | ||
| 87 | + } | ||
| 83 | 88 | ||
| 84 | /// The stream opened. | 89 | /// The stream opened. |
| 85 | pub fn connected(&self) { | 90 | pub fn connected(&self) { |
| @@ -223,7 +228,15 @@ pub fn stylesheet_guard(bundle: &AssetBundle) -> Result<String, String> { | |||
| 223 | stylesheet.name() | 228 | stylesheet.name() |
| 224 | ) | 229 | ) |
| 225 | })?; | 230 | })?; |
| 226 | - let actual = format!("sha256:{:x}", sha2::Sha256::digest(&bytes)); | 231 | + let digest = sha2::Sha256::digest(&bytes); |
| 232 | + let actual = format!( | ||
| 233 | + "sha256:{}", | ||
| 234 | + digest | ||
| 235 | + .as_slice() | ||
| 236 | + .iter() | ||
| 237 | + .map(|b| format!("{b:02x}")) | ||
| 238 | + .collect::<String>() | ||
| 239 | + ); | ||
| 227 | if actual != expected { | 240 | if actual != expected { |
| 228 | return Err(format!( | 241 | return Err(format!( |
| 229 | "the asset bundle at {} is from another build: stylesheet {} is {actual} but this binary was compiled against {expected}; run `topcoat asset bundle` and redeploy", | 242 | "the asset bundle at {} is from another build: stylesheet {} is {actual} but this binary was compiled against {expected}; run `topcoat asset bundle` and redeploy", |
| @@ -312,11 +325,7 @@ pub async fn service_client(cx: &Cx) -> Option<User> { | |||
| 312 | if token.is_empty() { | 325 | if token.is_empty() { |
| 313 | return None; | 326 | return None; |
| 314 | } | 327 | } |
| 315 | - let user = app(cx) | 328 | + let user = app(cx).store.service_account_by_token(token).await.ok()??; |
| 316 | - .store | ||
| 317 | - .service_account_by_token(token) | ||
| 318 | - .await | ||
| 319 | - .ok()??; | ||
| 320 | (!user.disabled).then_some(user) | 329 | (!user.disabled).then_some(user) |
| 321 | } | 330 | } |
| 322 | 331 | ||
| @@ -337,7 +346,7 @@ static SHOWN_SECRETS: LazyLock<std::sync::Mutex<HashMap<String, (String, std::ti | |||
| 337 | /// Parks a fresh service key on the shelf and returns the claim ticket for | 346 | /// Parks a fresh service key on the shelf and returns the claim ticket for |
| 338 | /// its URL. | 347 | /// its URL. |
| 339 | pub fn stash_shown_secret(secret: String) -> String { | 348 | pub fn stash_shown_secret(secret: String) -> String { |
| 340 | - let ticket = format!("{}", ulid::Ulid::new()); | 349 | + let ticket = format!("{}", ulid::Ulid::generate()); |
| 341 | let mut shelf = SHOWN_SECRETS.lock().unwrap_or_else(PoisonError::into_inner); | 350 | let mut shelf = SHOWN_SECRETS.lock().unwrap_or_else(PoisonError::into_inner); |
| 342 | shelf.retain(|_, (_, parked)| parked.elapsed() < SHOWN_TTL); | 351 | shelf.retain(|_, (_, parked)| parked.elapsed() < SHOWN_TTL); |
| 343 | shelf.insert(ticket.clone(), (secret, std::time::Instant::now())); | 352 | shelf.insert(ticket.clone(), (secret, std::time::Instant::now())); |
| @@ -436,7 +445,9 @@ impl Refusal { | |||
| 436 | Refusal::BadTheme => "That is not a theme.".to_string(), | 445 | Refusal::BadTheme => "That is not a theme.".to_string(), |
| 437 | Refusal::BadLanguage => "That is not a language.".to_string(), | 446 | Refusal::BadLanguage => "That is not a language.".to_string(), |
| 438 | Refusal::BadLimit => "That limit is not usable.".to_string(), | 447 | Refusal::BadLimit => "That limit is not usable.".to_string(), |
| 439 | - Refusal::BadBaseUrl => "That address is not an origin links can be built on.".to_string(), | 448 | + Refusal::BadBaseUrl => { |
| 449 | + "That address is not an origin links can be built on.".to_string() | ||
| 450 | + } | ||
| 440 | Refusal::ServiceQuota => "The limit is im's to set.".to_string(), | 451 | Refusal::ServiceQuota => "The limit is im's to set.".to_string(), |
| 441 | Refusal::BadServiceKey => "That key is not usable.".to_string(), | 452 | Refusal::BadServiceKey => "That key is not usable.".to_string(), |
| 442 | } | 453 | } |
| @@ -464,7 +475,9 @@ impl Refusal { | |||
| 464 | Refusal::BadTheme => "Bu bir tema değil.".to_string(), | 475 | Refusal::BadTheme => "Bu bir tema değil.".to_string(), |
| 465 | Refusal::BadLanguage => "Bu bir dil değil.".to_string(), | 476 | Refusal::BadLanguage => "Bu bir dil değil.".to_string(), |
| 466 | Refusal::BadLimit => "Bu sınır kullanılamaz.".to_string(), | 477 | Refusal::BadLimit => "Bu sınır kullanılamaz.".to_string(), |
| 467 | - Refusal::BadBaseUrl => "Bu adres, bağlantı kurulabilecek bir kök adres değil.".to_string(), | 478 | + Refusal::BadBaseUrl => { |
| 479 | + "Bu adres, bağlantı kurulabilecek bir kök adres değil.".to_string() | ||
| 480 | + } | ||
| 468 | Refusal::ServiceQuota => "Limit im'de belirlenir.".to_string(), | 481 | Refusal::ServiceQuota => "Limit im'de belirlenir.".to_string(), |
| 469 | Refusal::BadServiceKey => "Bu anahtar kullanılamaz.".to_string(), | 482 | Refusal::BadServiceKey => "Bu anahtar kullanılamaz.".to_string(), |
| 470 | } | 483 | } |
crates/in-web/src/settings.rsmodified+169 -45
| @@ -13,6 +13,13 @@ | |||
| 13 | //! disabling yourself is refused), the third stores the origin share links | 13 | //! disabling yourself is refused), the third stores the origin share links |
| 14 | //! are built from. | 14 | //! are built from. |
| 15 | 15 | ||
| 16 | +use crate::i18n::{Key, lang, t}; | ||
| 17 | +use crate::layout::{NavPage, topbar}; | ||
| 18 | +use crate::server::{ | ||
| 19 | + Refusal, app, back_to, require_admin, require_user, share_link_url, share_origin, | ||
| 20 | +}; | ||
| 21 | +use crate::service::mintable_services; | ||
| 22 | +use crate::share::{refusal_banner, refusal_of, share_copy_script}; | ||
| 16 | use in_core::store::{ShareKind, User}; | 23 | use in_core::store::{ShareKind, User}; |
| 17 | use serde::Deserialize; | 24 | use serde::Deserialize; |
| 18 | use topcoat::Result; | 25 | use topcoat::Result; |
| @@ -20,14 +27,7 @@ use topcoat::context::Cx; | |||
| 20 | use topcoat::router::content::Form; | 27 | use topcoat::router::content::Form; |
| 21 | use topcoat::router::request::uri; | 28 | use topcoat::router::request::uri; |
| 22 | use topcoat::router::{HeaderName, StatusCode, header, page, route}; | 29 | use topcoat::router::{HeaderName, StatusCode, header, page, route}; |
| 23 | -use topcoat::view::view; | 30 | +use topcoat::view::{View, ViewExt, view}; |
| 24 | -use crate::server::{ | ||
| 25 | - Refusal, app, back_to, require_admin, require_user, share_link_url, share_origin, | ||
| 26 | -}; | ||
| 27 | -use crate::service::mintable_services; | ||
| 28 | -use crate::share::{refusal_banner, refusal_of, share_copy_script}; | ||
| 29 | -use crate::i18n::{Key, lang, t}; | ||
| 30 | -use crate::layout::{NavPage, topbar}; | ||
| 31 | 31 | ||
| 32 | /// Bytes in human units: `512 B`, `1.5 KiB`, `2.0 GiB`. One decimal past | 32 | /// Bytes in human units: `512 B`, `1.5 KiB`, `2.0 GiB`. One decimal past |
| 33 | /// bytes so a quota line reads at a glance. | 33 | /// bytes so a quota line reads at a glance. |
| @@ -151,10 +151,19 @@ async fn set_quota(cx: &Cx, Form(input): Form<QuotaForm>) -> Redirect { | |||
| 151 | .store | 151 | .store |
| 152 | .list_service_accounts() | 152 | .list_service_accounts() |
| 153 | .await | 153 | .await |
| 154 | - .map(|accounts| accounts.iter().any(|account| account.user_id == input.user_id)) | 154 | + .map(|accounts| { |
| 155 | + accounts | ||
| 156 | + .iter() | ||
| 157 | + .any(|account| account.user_id == input.user_id) | ||
| 158 | + }) | ||
| 155 | .unwrap_or(false); | 159 | .unwrap_or(false); |
| 156 | if service_target { | 160 | if service_target { |
| 157 | - return redirect_back(cx, "/settings?section=everyone", "quota", Some(Refusal::ServiceQuota)); | 161 | + return redirect_back( |
| 162 | + cx, | ||
| 163 | + "/settings?section=everyone", | ||
| 164 | + "quota", | ||
| 165 | + Some(Refusal::ServiceQuota), | ||
| 166 | + ); | ||
| 158 | } | 167 | } |
| 159 | match unit_bytes(&input.quota, &input.quota_unit) { | 168 | match unit_bytes(&input.quota, &input.quota_unit) { |
| 160 | Some(quota_bytes) => match app(cx) | 169 | Some(quota_bytes) => match app(cx) |
| @@ -163,9 +172,19 @@ async fn set_quota(cx: &Cx, Form(input): Form<QuotaForm>) -> Redirect { | |||
| 163 | .await | 172 | .await |
| 164 | { | 173 | { |
| 165 | Ok(()) => redirect_back(cx, "/settings?section=everyone", "quota", None), | 174 | Ok(()) => redirect_back(cx, "/settings?section=everyone", "quota", None), |
| 166 | - Err(error) => redirect_back(cx, "/settings?section=everyone", "quota", Some(refusal_of(error))), | 175 | + Err(error) => redirect_back( |
| 176 | + cx, | ||
| 177 | + "/settings?section=everyone", | ||
| 178 | + "quota", | ||
| 179 | + Some(refusal_of(error)), | ||
| 180 | + ), | ||
| 167 | }, | 181 | }, |
| 168 | - None => redirect_back(cx, "/settings?section=everyone", "quota", Some(Refusal::BadLimit)), | 182 | + None => redirect_back( |
| 183 | + cx, | ||
| 184 | + "/settings?section=everyone", | ||
| 185 | + "quota", | ||
| 186 | + Some(Refusal::BadLimit), | ||
| 187 | + ), | ||
| 169 | } | 188 | } |
| 170 | } | 189 | } |
| 171 | 190 | ||
| @@ -182,10 +201,17 @@ struct DisableForm { | |||
| 182 | async fn set_disabled(cx: &Cx, Form(input): Form<DisableForm>) -> Redirect { | 201 | async fn set_disabled(cx: &Cx, Form(input): Form<DisableForm>) -> Redirect { |
| 183 | let admin = match require_admin(cx).await { | 202 | let admin = match require_admin(cx).await { |
| 184 | Ok(admin) => admin, | 203 | Ok(admin) => admin, |
| 185 | - Err(refusal) => return redirect_back(cx, "/settings?section=everyone", "disable", Some(refusal)), | 204 | + Err(refusal) => { |
| 205 | + return redirect_back(cx, "/settings?section=everyone", "disable", Some(refusal)); | ||
| 206 | + } | ||
| 186 | }; | 207 | }; |
| 187 | if input.user_id == admin.id { | 208 | if input.user_id == admin.id { |
| 188 | - return redirect_back(cx, "/settings?section=everyone", "disable", Some(Refusal::Forbidden)); | 209 | + return redirect_back( |
| 210 | + cx, | ||
| 211 | + "/settings?section=everyone", | ||
| 212 | + "disable", | ||
| 213 | + Some(Refusal::Forbidden), | ||
| 214 | + ); | ||
| 189 | } | 215 | } |
| 190 | let disabled = match input.disabled.as_deref() { | 216 | let disabled = match input.disabled.as_deref() { |
| 191 | None => true, | 217 | None => true, |
| @@ -200,7 +226,12 @@ async fn set_disabled(cx: &Cx, Form(input): Form<DisableForm>) -> Redirect { | |||
| 200 | .await | 226 | .await |
| 201 | { | 227 | { |
| 202 | Ok(()) => redirect_back(cx, "/settings?section=everyone", "disable", None), | 228 | Ok(()) => redirect_back(cx, "/settings?section=everyone", "disable", None), |
| 203 | - Err(error) => redirect_back(cx, "/settings?section=everyone", "disable", Some(refusal_of(error))), | 229 | + Err(error) => redirect_back( |
| 230 | + cx, | ||
| 231 | + "/settings?section=everyone", | ||
| 232 | + "disable", | ||
| 233 | + Some(refusal_of(error)), | ||
| 234 | + ), | ||
| 204 | } | 235 | } |
| 205 | } | 236 | } |
| 206 | 237 | ||
| @@ -228,16 +259,38 @@ const LANGUAGE_OPTIONS: [&str; 2] = ["en", "tr"]; | |||
| 228 | async fn set_preferences(cx: &Cx, Form(input): Form<PreferencesForm>) -> Redirect { | 259 | async fn set_preferences(cx: &Cx, Form(input): Form<PreferencesForm>) -> Redirect { |
| 229 | let user = match require_user(cx).await { | 260 | let user = match require_user(cx).await { |
| 230 | Ok(user) => user, | 261 | Ok(user) => user, |
| 231 | - Err(refusal) => return redirect_back(cx, "/settings?section=profile", "preferences", Some(refusal)), | 262 | + Err(refusal) => { |
| 263 | + return redirect_back( | ||
| 264 | + cx, | ||
| 265 | + "/settings?section=profile", | ||
| 266 | + "preferences", | ||
| 267 | + Some(refusal), | ||
| 268 | + ); | ||
| 269 | + } | ||
| 232 | }; | 270 | }; |
| 233 | if !UI_OPTIONS.contains(&input.ui.as_str()) { | 271 | if !UI_OPTIONS.contains(&input.ui.as_str()) { |
| 234 | - return redirect_back(cx, "/settings?section=profile", "preferences", Some(Refusal::BadUi)); | 272 | + return redirect_back( |
| 273 | + cx, | ||
| 274 | + "/settings?section=profile", | ||
| 275 | + "preferences", | ||
| 276 | + Some(Refusal::BadUi), | ||
| 277 | + ); | ||
| 235 | } | 278 | } |
| 236 | if !THEME_OPTIONS.contains(&input.theme.as_str()) { | 279 | if !THEME_OPTIONS.contains(&input.theme.as_str()) { |
| 237 | - return redirect_back(cx, "/settings?section=profile", "preferences", Some(Refusal::BadTheme)); | 280 | + return redirect_back( |
| 281 | + cx, | ||
| 282 | + "/settings?section=profile", | ||
| 283 | + "preferences", | ||
| 284 | + Some(Refusal::BadTheme), | ||
| 285 | + ); | ||
| 238 | } | 286 | } |
| 239 | if !LANGUAGE_OPTIONS.contains(&input.language.as_str()) { | 287 | if !LANGUAGE_OPTIONS.contains(&input.language.as_str()) { |
| 240 | - return redirect_back(cx, "/settings?section=profile", "preferences", Some(Refusal::BadLanguage)); | 288 | + return redirect_back( |
| 289 | + cx, | ||
| 290 | + "/settings?section=profile", | ||
| 291 | + "preferences", | ||
| 292 | + Some(Refusal::BadLanguage), | ||
| 293 | + ); | ||
| 241 | } | 294 | } |
| 242 | match app(cx) | 295 | match app(cx) |
| 243 | .store | 296 | .store |
| @@ -245,7 +298,12 @@ async fn set_preferences(cx: &Cx, Form(input): Form<PreferencesForm>) -> Redirec | |||
| 245 | .await | 298 | .await |
| 246 | { | 299 | { |
| 247 | Ok(()) => redirect_back(cx, "/settings?section=profile", "preferences", None), | 300 | Ok(()) => redirect_back(cx, "/settings?section=profile", "preferences", None), |
| 248 | - Err(error) => redirect_back(cx, "/settings?section=profile", "preferences", Some(refusal_of(error))), | 301 | + Err(error) => redirect_back( |
| 302 | + cx, | ||
| 303 | + "/settings?section=profile", | ||
| 304 | + "preferences", | ||
| 305 | + Some(refusal_of(error)), | ||
| 306 | + ), | ||
| 249 | } | 307 | } |
| 250 | } | 308 | } |
| 251 | 309 | ||
| @@ -269,11 +327,21 @@ async fn set_base_url(cx: &Cx, Form(input): Form<BaseUrlForm>) -> Redirect { | |||
| 269 | } | 327 | } |
| 270 | let trimmed = input.base_url.trim().to_string(); | 328 | let trimmed = input.base_url.trim().to_string(); |
| 271 | if !trimmed.is_empty() && in_core::Config::validate_base_url(&trimmed).is_err() { | 329 | if !trimmed.is_empty() && in_core::Config::validate_base_url(&trimmed).is_err() { |
| 272 | - return redirect_back(cx, "/settings?section=server", "base_url", Some(Refusal::BadBaseUrl)); | 330 | + return redirect_back( |
| 331 | + cx, | ||
| 332 | + "/settings?section=server", | ||
| 333 | + "base_url", | ||
| 334 | + Some(Refusal::BadBaseUrl), | ||
| 335 | + ); | ||
| 273 | } | 336 | } |
| 274 | match app(cx).store.set_setting("base_url", &trimmed).await { | 337 | match app(cx).store.set_setting("base_url", &trimmed).await { |
| 275 | Ok(()) => redirect_back(cx, "/settings?section=server", "base_url", None), | 338 | Ok(()) => redirect_back(cx, "/settings?section=server", "base_url", None), |
| 276 | - Err(error) => redirect_back(cx, "/settings?section=server", "base_url", Some(refusal_of(error))), | 339 | + Err(error) => redirect_back( |
| 340 | + cx, | ||
| 341 | + "/settings?section=server", | ||
| 342 | + "base_url", | ||
| 343 | + Some(refusal_of(error)), | ||
| 344 | + ), | ||
| 277 | } | 345 | } |
| 278 | } | 346 | } |
| 279 | 347 | ||
| @@ -305,21 +373,41 @@ fn redirect_shown(cx: &Cx, ticket: &str) -> Redirect { | |||
| 305 | #[route(POST "/api/settings/service_add")] | 373 | #[route(POST "/api/settings/service_add")] |
| 306 | async fn service_add(cx: &Cx, Form(input): Form<ServiceAddForm>) -> Redirect { | 374 | async fn service_add(cx: &Cx, Form(input): Form<ServiceAddForm>) -> Redirect { |
| 307 | if let Err(refusal) = require_admin(cx).await { | 375 | if let Err(refusal) = require_admin(cx).await { |
| 308 | - return redirect_back(cx, "/settings?section=service", "service_add", Some(refusal)); | 376 | + return redirect_back( |
| 377 | + cx, | ||
| 378 | + "/settings?section=service", | ||
| 379 | + "service_add", | ||
| 380 | + Some(refusal), | ||
| 381 | + ); | ||
| 309 | } | 382 | } |
| 310 | let service = input.service.trim(); | 383 | let service = input.service.trim(); |
| 311 | let name = input.name.trim(); | 384 | let name = input.name.trim(); |
| 312 | if name.is_empty() { | 385 | if name.is_empty() { |
| 313 | - return redirect_back(cx, "/settings?section=service", "service_add", Some(Refusal::BadServiceKey)); | 386 | + return redirect_back( |
| 387 | + cx, | ||
| 388 | + "/settings?section=service", | ||
| 389 | + "service_add", | ||
| 390 | + Some(Refusal::BadServiceKey), | ||
| 391 | + ); | ||
| 314 | } | 392 | } |
| 315 | let mintable = match mintable_services(cx).await { | 393 | let mintable = match mintable_services(cx).await { |
| 316 | Ok(mintable) => mintable, | 394 | Ok(mintable) => mintable, |
| 317 | Err(refusal) => { | 395 | Err(refusal) => { |
| 318 | - return redirect_back(cx, "/settings?section=service", "service_add", Some(refusal)); | 396 | + return redirect_back( |
| 397 | + cx, | ||
| 398 | + "/settings?section=service", | ||
| 399 | + "service_add", | ||
| 400 | + Some(refusal), | ||
| 401 | + ); | ||
| 319 | } | 402 | } |
| 320 | }; | 403 | }; |
| 321 | if !mintable.iter().any(|row| row.key == service) { | 404 | if !mintable.iter().any(|row| row.key == service) { |
| 322 | - return redirect_back(cx, "/settings?section=service", "service_add", Some(Refusal::BadServiceKey)); | 405 | + return redirect_back( |
| 406 | + cx, | ||
| 407 | + "/settings?section=service", | ||
| 408 | + "service_add", | ||
| 409 | + Some(Refusal::BadServiceKey), | ||
| 410 | + ); | ||
| 323 | } | 411 | } |
| 324 | let default_quota_bytes = app(cx).config.default_quota_bytes; | 412 | let default_quota_bytes = app(cx).config.default_quota_bytes; |
| 325 | match app(cx) | 413 | match app(cx) |
| @@ -328,7 +416,12 @@ async fn service_add(cx: &Cx, Form(input): Form<ServiceAddForm>) -> Redirect { | |||
| 328 | .await | 416 | .await |
| 329 | { | 417 | { |
| 330 | Ok(token) => redirect_shown(cx, &crate::server::stash_shown_secret(token)), | 418 | Ok(token) => redirect_shown(cx, &crate::server::stash_shown_secret(token)), |
| 331 | - Err(_) => redirect_back(cx, "/settings?section=service", "service_add", Some(Refusal::Unavailable)), | 419 | + Err(_) => redirect_back( |
| 420 | + cx, | ||
| 421 | + "/settings?section=service", | ||
| 422 | + "service_add", | ||
| 423 | + Some(Refusal::Unavailable), | ||
| 424 | + ), | ||
| 332 | } | 425 | } |
| 333 | } | 426 | } |
| 334 | 427 | ||
| @@ -337,12 +430,27 @@ async fn service_add(cx: &Cx, Form(input): Form<ServiceAddForm>) -> Redirect { | |||
| 337 | #[route(POST "/api/settings/service_rotate")] | 430 | #[route(POST "/api/settings/service_rotate")] |
| 338 | async fn service_rotate(cx: &Cx, Form(input): Form<ServiceAction>) -> Redirect { | 431 | async fn service_rotate(cx: &Cx, Form(input): Form<ServiceAction>) -> Redirect { |
| 339 | if let Err(refusal) = require_admin(cx).await { | 432 | if let Err(refusal) = require_admin(cx).await { |
| 340 | - return redirect_back(cx, "/settings?section=service", "service_rotate", Some(refusal)); | 433 | + return redirect_back( |
| 434 | + cx, | ||
| 435 | + "/settings?section=service", | ||
| 436 | + "service_rotate", | ||
| 437 | + Some(refusal), | ||
| 438 | + ); | ||
| 341 | } | 439 | } |
| 342 | match app(cx).store.rotate_service_key(&input.service).await { | 440 | match app(cx).store.rotate_service_key(&input.service).await { |
| 343 | Ok(Some(token)) => redirect_shown(cx, &crate::server::stash_shown_secret(token)), | 441 | Ok(Some(token)) => redirect_shown(cx, &crate::server::stash_shown_secret(token)), |
| 344 | - Ok(None) => redirect_back(cx, "/settings?section=service", "service_rotate", Some(Refusal::BadServiceKey)), | 442 | + Ok(None) => redirect_back( |
| 345 | - Err(_) => redirect_back(cx, "/settings?section=service", "service_rotate", Some(Refusal::Unavailable)), | 443 | + cx, |
| 444 | + "/settings?section=service", | ||
| 445 | + "service_rotate", | ||
| 446 | + Some(Refusal::BadServiceKey), | ||
| 447 | + ), | ||
| 448 | + Err(_) => redirect_back( | ||
| 449 | + cx, | ||
| 450 | + "/settings?section=service", | ||
| 451 | + "service_rotate", | ||
| 452 | + Some(Refusal::Unavailable), | ||
| 453 | + ), | ||
| 346 | } | 454 | } |
| 347 | } | 455 | } |
| 348 | 456 | ||
| @@ -351,12 +459,27 @@ async fn service_rotate(cx: &Cx, Form(input): Form<ServiceAction>) -> Redirect { | |||
| 351 | #[route(POST "/api/settings/service_revoke")] | 459 | #[route(POST "/api/settings/service_revoke")] |
| 352 | async fn service_revoke(cx: &Cx, Form(input): Form<ServiceAction>) -> Redirect { | 460 | async fn service_revoke(cx: &Cx, Form(input): Form<ServiceAction>) -> Redirect { |
| 353 | if let Err(refusal) = require_admin(cx).await { | 461 | if let Err(refusal) = require_admin(cx).await { |
| 354 | - return redirect_back(cx, "/settings?section=service", "service_revoke", Some(refusal)); | 462 | + return redirect_back( |
| 463 | + cx, | ||
| 464 | + "/settings?section=service", | ||
| 465 | + "service_revoke", | ||
| 466 | + Some(refusal), | ||
| 467 | + ); | ||
| 355 | } | 468 | } |
| 356 | match app(cx).store.revoke_service_key(&input.service).await { | 469 | match app(cx).store.revoke_service_key(&input.service).await { |
| 357 | Ok(true) => redirect_back(cx, "/settings?section=service", "service_revoke", None), | 470 | Ok(true) => redirect_back(cx, "/settings?section=service", "service_revoke", None), |
| 358 | - Ok(false) => redirect_back(cx, "/settings?section=service", "service_revoke", Some(Refusal::BadServiceKey)), | 471 | + Ok(false) => redirect_back( |
| 359 | - Err(_) => redirect_back(cx, "/settings?section=service", "service_revoke", Some(Refusal::Unavailable)), | 472 | + cx, |
| 473 | + "/settings?section=service", | ||
| 474 | + "service_revoke", | ||
| 475 | + Some(Refusal::BadServiceKey), | ||
| 476 | + ), | ||
| 477 | + Err(_) => redirect_back( | ||
| 478 | + cx, | ||
| 479 | + "/settings?section=service", | ||
| 480 | + "service_revoke", | ||
| 481 | + Some(Refusal::Unavailable), | ||
| 482 | + ), | ||
| 360 | } | 483 | } |
| 361 | } | 484 | } |
| 362 | 485 | ||
| @@ -395,18 +518,19 @@ fn query_value(query: &str, key: &str) -> Option<String> { | |||
| 395 | /// links are built from. An admin section asked for by anyone else renders | 518 | /// links are built from. An admin section asked for by anyone else renders |
| 396 | /// the profile, the way an unknown section name does. | 519 | /// the profile, the way an unknown section name does. |
| 397 | #[page("/settings")] | 520 | #[page("/settings")] |
| 398 | -async fn settings(cx: &Cx) -> Result { | 521 | +async fn settings(cx: &Cx) -> Result<impl View> { |
| 399 | let user = match require_user(cx).await { | 522 | let user = match require_user(cx).await { |
| 400 | Ok(user) => user, | 523 | Ok(user) => user, |
| 401 | Err(refusal) => { | 524 | Err(refusal) => { |
| 402 | let language = lang(cx).await; | 525 | let language = lang(cx).await; |
| 403 | - return view! { | 526 | + return Ok(view! { |
| 404 | cx => | 527 | cx => |
| 405 | <main class="scaffold-note"> | 528 | <main class="scaffold-note"> |
| 406 | <p>(refusal.message_in(language))</p> | 529 | <p>(refusal.message_in(language))</p> |
| 407 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> | 530 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> |
| 408 | </main> | 531 | </main> |
| 409 | - }; | 532 | + } |
| 533 | + .boxed()); | ||
| 410 | } | 534 | } |
| 411 | }; | 535 | }; |
| 412 | let language = lang(cx).await; | 536 | let language = lang(cx).await; |
| @@ -445,7 +569,7 @@ async fn settings(cx: &Cx) -> Result { | |||
| 445 | // Only the section on show pays for its rows: the links panel names | 569 | // Only the section on show pays for its rows: the links panel names |
| 446 | // each live link's target, Everyone lists the accounts, and the server | 570 | // each live link's target, Everyone lists the accounts, and the server |
| 447 | // panel needs the origin — nothing else reads them. | 571 | // panel needs the origin — nothing else reads them. |
| 448 | - let mut link_names: Vec<(&in_core::store::ShareLink, String, Option<String>)> = Vec::new(); | 572 | + let mut link_names: Vec<(in_core::store::ShareLink, String, Option<String>)> = Vec::new(); |
| 449 | let links = if section == Section::Links { | 573 | let links = if section == Section::Links { |
| 450 | store.share_links(&user.id).await? | 574 | store.share_links(&user.id).await? |
| 451 | } else { | 575 | } else { |
| @@ -476,7 +600,7 @@ async fn settings(cx: &Cx) -> Result { | |||
| 476 | // The full address, re-derived from the token the creation | 600 | // The full address, re-derived from the token the creation |
| 477 | // sealed away; `None` keeps the row masked with the note. | 601 | // sealed away; `None` keeps the row masked with the note. |
| 478 | let url = share_link_url(cx, link).await; | 602 | let url = share_link_url(cx, link).await; |
| 479 | - link_names.push((link, name, url)); | 603 | + link_names.push((link.clone(), name, url)); |
| 480 | } | 604 | } |
| 481 | } | 605 | } |
| 482 | let users = if administers && section == Section::Everyone { | 606 | let users = if administers && section == Section::Everyone { |
| @@ -523,9 +647,9 @@ async fn settings(cx: &Cx) -> Result { | |||
| 523 | } else { | 647 | } else { |
| 524 | None | 648 | None |
| 525 | }; | 649 | }; |
| 526 | - view! { | 650 | + Ok(view! { |
| 527 | cx => | 651 | cx => |
| 528 | - (topbar(cx, NavPage::Settings, &fresh, language).await?) | 652 | + (topcoat::view::Child::new(topbar(cx, NavPage::Settings, &fresh, language).await?)) |
| 529 | <div class="settings-shell"> | 653 | <div class="settings-shell"> |
| 530 | <nav class="settings-sections"> | 654 | <nav class="settings-sections"> |
| 531 | <a class=(rail_class(section, Section::Profile)) href="/settings?section=profile">(t(language, Key::Profile))</a> | 655 | <a class=(rail_class(section, Section::Profile)) href="/settings?section=profile">(t(language, Key::Profile))</a> |
| @@ -538,7 +662,7 @@ async fn settings(cx: &Cx) -> Result { | |||
| 538 | </nav> | 662 | </nav> |
| 539 | <main class="settings-stage stage-wide"> | 663 | <main class="settings-stage stage-wide"> |
| 540 | <h1 class="settings-title">(t(language, Key::Settings))</h1> | 664 | <h1 class="settings-title">(t(language, Key::Settings))</h1> |
| 541 | - (refusal_banner(cx, language, &["create", "revoke", "add", "remove", "quota", "disable", "preferences", "base_url", "service_add", "service_rotate", "service_revoke"]).await?) | 665 | + (topcoat::view::Child::new(refusal_banner(cx, language, &["create", "revoke", "add", "remove", "quota", "disable", "preferences", "base_url", "service_add", "service_rotate", "service_revoke"]).await?)) |
| 542 | if section == Section::Profile { | 666 | if section == Section::Profile { |
| 543 | <section class="panel"> | 667 | <section class="panel"> |
| 544 | <div class="panel-head"> | 668 | <div class="panel-head"> |
| @@ -673,7 +797,7 @@ async fn settings(cx: &Cx) -> Result { | |||
| 673 | </section> | 797 | </section> |
| 674 | // One delegated listener serves every row's copy button | 798 | // One delegated listener serves every row's copy button |
| 675 | // above; the script is idempotent across re-renders. | 799 | // above; the script is idempotent across re-renders. |
| 676 | - (share_copy_script(cx).await?) | 800 | + (topcoat::view::Child::new(share_copy_script(cx).await?)) |
| 677 | } | 801 | } |
| 678 | if section == Section::Everyone { | 802 | if section == Section::Everyone { |
| 679 | <section class="panel"> | 803 | <section class="panel"> |
| @@ -856,12 +980,12 @@ async fn settings(cx: &Cx) -> Result { | |||
| 856 | </section> | 980 | </section> |
| 857 | // The banner's copy button above; one delegated listener | 981 | // The banner's copy button above; one delegated listener |
| 858 | // serves every row, idempotent across re-renders. | 982 | // serves every row, idempotent across re-renders. |
| 859 | - (share_copy_script(cx).await?) | 983 | + (topcoat::view::Child::new(share_copy_script(cx).await?)) |
| 860 | } | 984 | } |
| 861 | </main> | 985 | </main> |
| 862 | </div> | 986 | </div> |
| 863 | - (crate::dropdown::dropdown_script(cx).await?) | 987 | + (topcoat::view::Child::new(crate::dropdown::dropdown_script(cx).await?)) |
| 864 | - } | 988 | + }.boxed()) |
| 865 | } | 989 | } |
| 866 | 990 | ||
| 867 | /// The just-minted token off the redirect's `?created=` pair, if present. | 991 | /// The just-minted token off the redirect's `?created=` pair, if present. |
crates/in-web/src/share.rsmodified+71 -65
| @@ -33,7 +33,7 @@ use topcoat::router::content::Form; | |||
| 33 | use topcoat::router::request::{headers as request_headers, uri}; | 33 | use topcoat::router::request::{headers as request_headers, uri}; |
| 34 | use topcoat::router::response::IntoResponse; | 34 | use topcoat::router::response::IntoResponse; |
| 35 | use topcoat::router::{HeaderName, StatusCode, header, page, path_param, query_params, route}; | 35 | use topcoat::router::{HeaderName, StatusCode, header, page, path_param, query_params, route}; |
| 36 | -use topcoat::view::view; | 36 | +use topcoat::view::{View, ViewExt, view}; |
| 37 | 37 | ||
| 38 | use crate::files::{ViewerKind, entry_chip, media_player, media_player_script, viewer_kind}; | 38 | use crate::files::{ViewerKind, entry_chip, media_player, media_player_script, viewer_kind}; |
| 39 | use crate::i18n::{Key, Lang, lang, t}; | 39 | use crate::i18n::{Key, Lang, lang, t}; |
| @@ -49,14 +49,18 @@ path_param!(id); | |||
| 49 | /// and the `?saved=<call>` chip a clean save carries, the way iz's | 49 | /// and the `?saved=<call>` chip a clean save carries, the way iz's |
| 50 | /// `saved_or_refused` marks one. Shared by the trash and settings pages, | 50 | /// `saved_or_refused` marks one. Shared by the trash and settings pages, |
| 51 | /// which own no banner of their own. | 51 | /// which own no banner of their own. |
| 52 | -pub(crate) async fn refusal_banner(cx: &Cx, language: Lang, calls: &[&str]) -> Result { | 52 | +pub(crate) async fn refusal_banner<'a>( |
| 53 | + cx: &'a Cx, | ||
| 54 | + language: Lang, | ||
| 55 | + calls: &'a [&'a str], | ||
| 56 | +) -> Result<impl View + 'a> { | ||
| 53 | let query = uri(cx).query().unwrap_or(""); | 57 | let query = uri(cx).query().unwrap_or(""); |
| 54 | let refusal = query_value(query, "refusal").and_then(|code| Refusal::from_code(&code)); | 58 | let refusal = query_value(query, "refusal").and_then(|code| Refusal::from_code(&code)); |
| 55 | let on = query_value(query, "on").unwrap_or_default(); | 59 | let on = query_value(query, "on").unwrap_or_default(); |
| 56 | let saved = query_value(query, "saved").unwrap_or_default(); | 60 | let saved = query_value(query, "saved").unwrap_or_default(); |
| 57 | let refused = calls.iter().any(|call| *call == on); | 61 | let refused = calls.iter().any(|call| *call == on); |
| 58 | let kept = calls.iter().any(|call| *call == saved); | 62 | let kept = calls.iter().any(|call| *call == saved); |
| 59 | - view! { | 63 | + Ok(view! { |
| 60 | cx => | 64 | cx => |
| 61 | if refused { | 65 | if refused { |
| 62 | if let Some(refusal) = refusal { | 66 | if let Some(refusal) = refusal { |
| @@ -67,6 +71,7 @@ pub(crate) async fn refusal_banner(cx: &Cx, language: Lang, calls: &[&str]) -> R | |||
| 67 | <p class="field-note" role="status">(t(language, Key::Saved))</p> | 71 | <p class="field-note" role="status">(t(language, Key::Saved))</p> |
| 68 | } | 72 | } |
| 69 | } | 73 | } |
| 74 | + .boxed()) | ||
| 70 | } | 75 | } |
| 71 | 76 | ||
| 72 | /// The value of one query pair, if present. | 77 | /// The value of one query pair, if present. |
| @@ -419,7 +424,7 @@ async fn remint_link(cx: &Cx, Form(input): Form<RevokeLinkForm>) -> Redirect { | |||
| 419 | let created = store | 424 | let created = store |
| 420 | .create_share_link( | 425 | .create_share_link( |
| 421 | &user.id, | 426 | &user.id, |
| 422 | - old.kind.clone(), | 427 | + old.kind, |
| 423 | &old.target_id, | 428 | &old.target_id, |
| 424 | old.can_download, | 429 | old.can_download, |
| 425 | expires_at, | 430 | expires_at, |
| @@ -675,11 +680,12 @@ fn has_flag(query: &str, key: &str) -> bool { | |||
| 675 | /// `/s` surface stays a `#[route]` and wraps its views itself — in | 680 | /// `/s` surface stays a `#[route]` and wraps its views itself — in |
| 676 | /// `document_shell`, the same shell every `#[page]` under `/` wears, never | 681 | /// `document_shell`, the same shell every `#[page]` under `/` wears, never |
| 677 | /// a hand-copied head. | 682 | /// a hand-copied head. |
| 678 | -async fn public_page( | 683 | +async fn public_page(cx: &Cx, page: impl View) -> Result<topcoat::router::response::Response> { |
| 679 | - cx: &Cx, | 684 | + document_shell(cx, topcoat::view::Child::new(page)) |
| 680 | - page: Result, | 685 | + .await? |
| 681 | -) -> topcoat::Result<topcoat::router::response::Response> { | 686 | + .first() |
| 682 | - Ok(document_shell(cx, page).await?.into_response(cx)?) | 687 | + .await? |
| 688 | + .into_response(cx) | ||
| 683 | } | 689 | } |
| 684 | 690 | ||
| 685 | /// The dead card: a spent, expired, revoked or never-real token, a trashed | 691 | /// The dead card: a spent, expired, revoked or never-real token, a trashed |
| @@ -690,7 +696,7 @@ async fn dead_link(cx: &Cx) -> topcoat::Result<topcoat::router::response::Respon | |||
| 690 | let page = view! { | 696 | let page = view! { |
| 691 | cx => | 697 | cx => |
| 692 | <main class="scaffold-note"> | 698 | <main class="scaffold-note"> |
| 693 | - (wordmark(cx).await?) | 699 | + (topcoat::view::Child::new(wordmark(cx).await?)) |
| 694 | <p>(Refusal::ShareRevoked.message_in(language))</p> | 700 | <p>(Refusal::ShareRevoked.message_in(language))</p> |
| 695 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> | 701 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> |
| 696 | </main> | 702 | </main> |
| @@ -872,7 +878,7 @@ async fn password_gate(cx: &Cx) -> topcoat::Result<topcoat::router::response::Re | |||
| 872 | let page = view! { | 878 | let page = view! { |
| 873 | cx => | 879 | cx => |
| 874 | <main class="scaffold-note"> | 880 | <main class="scaffold-note"> |
| 875 | - (wordmark(cx).await?) | 881 | + (topcoat::view::Child::new(wordmark(cx).await?)) |
| 876 | <h1 class="settings-title">(t(language, Key::PasswordProtected))</h1> | 882 | <h1 class="settings-title">(t(language, Key::PasswordProtected))</h1> |
| 877 | <p class="field-note">(t(language, Key::PasswordPrompt))</p> | 883 | <p class="field-note">(t(language, Key::PasswordPrompt))</p> |
| 878 | if wrong { | 884 | if wrong { |
| @@ -1006,7 +1012,7 @@ async fn download_bytes( | |||
| 1006 | else { | 1012 | else { |
| 1007 | return dead_link(cx).await; | 1013 | return dead_link(cx).await; |
| 1008 | }; | 1014 | }; |
| 1009 | - Ok(parts.into_response(cx)?) | 1015 | + parts.into_response(cx) |
| 1010 | } | 1016 | } |
| 1011 | 1017 | ||
| 1012 | /// The inline media stream behind a public link: the bytes the card's | 1018 | /// The inline media stream behind a public link: the bytes the card's |
| @@ -1061,7 +1067,7 @@ async fn media_bytes( | |||
| 1061 | else { | 1067 | else { |
| 1062 | return dead_link(cx).await; | 1068 | return dead_link(cx).await; |
| 1063 | }; | 1069 | }; |
| 1064 | - Ok(parts.into_response(cx)?) | 1070 | + parts.into_response(cx) |
| 1065 | } | 1071 | } |
| 1066 | 1072 | ||
| 1067 | /// Whether a `Range` header starts at byte 0: only those ranges (and the | 1073 | /// Whether a `Range` header starts at byte 0: only those ranges (and the |
| @@ -1074,10 +1080,7 @@ fn range_starts_at_zero(header: &str) -> bool { | |||
| 1074 | if spec.contains(',') { | 1080 | if spec.contains(',') { |
| 1075 | return false; | 1081 | return false; |
| 1076 | } | 1082 | } |
| 1077 | - match spec.split_once('-') { | 1083 | + matches!(spec.split_once('-'), Some(("0", _))) |
| 1078 | - Some(("0", _)) => true, | ||
| 1079 | - _ => false, | ||
| 1080 | - } | ||
| 1081 | } | 1084 | } |
| 1082 | 1085 | ||
| 1083 | /// The stored webp preview behind a public link. Unlike the bytes, the | 1086 | /// The stored webp preview behind a public link. Unlike the bytes, the |
| @@ -1109,9 +1112,9 @@ async fn public_thumb( | |||
| 1109 | .get(header::IF_NONE_MATCH) | 1112 | .get(header::IF_NONE_MATCH) |
| 1110 | .and_then(|value| value.to_str().ok()); | 1113 | .and_then(|value| value.to_str().ok()); |
| 1111 | if if_none_match == Some(etag.as_str()) { | 1114 | if if_none_match == Some(etag.as_str()) { |
| 1112 | - return Ok((StatusCode::NOT_MODIFIED, headers, Vec::new()).into_response(cx)?); | 1115 | + return (StatusCode::NOT_MODIFIED, headers, Vec::new()).into_response(cx); |
| 1113 | } | 1116 | } |
| 1114 | - Ok((StatusCode::OK, headers, bytes).into_response(cx)?) | 1117 | + (StatusCode::OK, headers, bytes).into_response(cx) |
| 1115 | } | 1118 | } |
| 1116 | 1119 | ||
| 1117 | /// A filename safe for a header: quotes and backslashes stripped, never | 1120 | /// A filename safe for a header: quotes and backslashes stripped, never |
| @@ -1147,15 +1150,15 @@ async fn file_card( | |||
| 1147 | let page = view! { | 1150 | let page = view! { |
| 1148 | cx => | 1151 | cx => |
| 1149 | <main class="scaffold-note"> | 1152 | <main class="scaffold-note"> |
| 1150 | - (wordmark(cx).await?) | 1153 | + (topcoat::view::Child::new(wordmark(cx).await?)) |
| 1151 | <h1 class="settings-title">(file.name.clone())</h1> | 1154 | <h1 class="settings-title">(file.name.clone())</h1> |
| 1152 | <p class="field-note">(format!("{} · {}", file.mime.clone(), crate::settings::human_bytes(file.size_bytes)))</p> | 1155 | <p class="field-note">(format!("{} · {}", file.mime.clone(), crate::settings::human_bytes(file.size_bytes)))</p> |
| 1153 | if preview { | 1156 | if preview { |
| 1154 | <img src=(format!("{token_path}?thumb=1")) alt=(file.name.clone())> | 1157 | <img src=(format!("{token_path}?thumb=1")) alt=(file.name.clone())> |
| 1155 | } else if matches!(media, Some(ViewerKind::Video)) { | 1158 | } else if matches!(media, Some(ViewerKind::Video)) { |
| 1156 | - (media_player(cx, language, file.name.clone(), media_src.clone(), true).await?) | 1159 | + (topcoat::view::Child::new(media_player(cx, language, file.name.clone(), media_src.clone(), true).await?)) |
| 1157 | } else if matches!(media, Some(ViewerKind::Audio)) { | 1160 | } else if matches!(media, Some(ViewerKind::Audio)) { |
| 1158 | - (media_player(cx, language, file.name.clone(), media_src.clone(), false).await?) | 1161 | + (topcoat::view::Child::new(media_player(cx, language, file.name.clone(), media_src.clone(), false).await?)) |
| 1159 | } else { | 1162 | } else { |
| 1160 | <p class="field-note">(t(language, Key::PreviewUnavailable))</p> | 1163 | <p class="field-note">(t(language, Key::PreviewUnavailable))</p> |
| 1161 | } | 1164 | } |
| @@ -1165,7 +1168,7 @@ async fn file_card( | |||
| 1165 | <p class="field-note">(t(language, Key::ViewOnly))</p> | 1168 | <p class="field-note">(t(language, Key::ViewOnly))</p> |
| 1166 | } | 1169 | } |
| 1167 | </main> | 1170 | </main> |
| 1168 | - (media_player_script(cx).await?) | 1171 | + (topcoat::view::Child::new(media_player_script(cx).await?)) |
| 1169 | }; | 1172 | }; |
| 1170 | public_page(cx, page).await | 1173 | public_page(cx, page).await |
| 1171 | } | 1174 | } |
| @@ -1173,29 +1176,29 @@ async fn file_card( | |||
| 1173 | /// One file's chip on the public card: the link's own thumbnail where one | 1176 | /// One file's chip on the public card: the link's own thumbnail where one |
| 1174 | /// is ready, else the same mime-class glyph the signed-in lists wear. | 1177 | /// is ready, else the same mime-class glyph the signed-in lists wear. |
| 1175 | /// `/thumb/{id}` needs a session, so this points at the public `?thumb=1` | 1178 | /// `/thumb/{id}` needs a session, so this points at the public `?thumb=1` |
| 1176 | -/// route behind the same token instead. | 1179 | +async fn public_chip<'a>( |
| 1177 | -async fn public_chip(cx: &Cx, thumb_src: &str, file: &in_core::store::File) -> Result { | 1180 | + cx: &'a Cx, |
| 1181 | + thumb_src: &str, | ||
| 1182 | + file: &in_core::store::File, | ||
| 1183 | +) -> Result<impl View + 'a> { | ||
| 1178 | if file.thumb_state == ThumbState::Ready { | 1184 | if file.thumb_state == ThumbState::Ready { |
| 1179 | - return view! { | 1185 | + let src = thumb_src.to_string(); |
| 1186 | + return Ok(view! { | ||
| 1180 | cx => | 1187 | cx => |
| 1181 | - <img class="file-chip" src=(thumb_src.to_string()) alt=""> | 1188 | + <img class="file-chip" src=(src) alt=""> |
| 1182 | - }; | 1189 | + } |
| 1190 | + .boxed()); | ||
| 1183 | } | 1191 | } |
| 1184 | - entry_chip(cx, file).await | 1192 | + Ok(entry_chip(cx, file).await?.boxed()) |
| 1185 | } | 1193 | } |
| 1186 | 1194 | ||
| 1187 | -/// One shared file's chip: the thumbnail image while the target is live, | 1195 | +async fn shared_chip<'a>(cx: &'a Cx, file: &in_core::store::File) -> Result<impl View + 'a> { |
| 1188 | -/// the mime-class glyph once it is trashed — `/thumb/{id}` 404s trashed | ||
| 1189 | -/// rows, so a Ready image would render broken if the target went into the | ||
| 1190 | -/// trash after the grant. The clone only clears the thumbnail flag for the | ||
| 1191 | -/// render. | ||
| 1192 | -async fn shared_chip(cx: &Cx, file: &in_core::store::File) -> Result { | ||
| 1193 | if file.deleted_at.is_some() { | 1196 | if file.deleted_at.is_some() { |
| 1194 | let mut unthumb = file.clone(); | 1197 | let mut unthumb = file.clone(); |
| 1195 | unthumb.thumb_state = ThumbState::None; | 1198 | unthumb.thumb_state = ThumbState::None; |
| 1196 | - return entry_chip(cx, &unthumb).await; | 1199 | + return Ok(entry_chip(cx, &unthumb).await?.boxed()); |
| 1197 | } | 1200 | } |
| 1198 | - entry_chip(cx, file).await | 1201 | + Ok(entry_chip(cx, file).await?.boxed()) |
| 1199 | } | 1202 | } |
| 1200 | 1203 | ||
| 1201 | /// One row of the public folder listing, folder or file, for the unified | 1204 | /// One row of the public folder listing, folder or file, for the unified |
| @@ -1235,10 +1238,10 @@ async fn folder_card( | |||
| 1235 | let mut rows: Vec<PublicEntry> = Vec::new(); | 1238 | let mut rows: Vec<PublicEntry> = Vec::new(); |
| 1236 | rows.extend(listing.folders.iter().map(PublicEntry::Folder)); | 1239 | rows.extend(listing.folders.iter().map(PublicEntry::Folder)); |
| 1237 | rows.extend(listing.files.iter().map(PublicEntry::File)); | 1240 | rows.extend(listing.files.iter().map(PublicEntry::File)); |
| 1238 | - rows.sort_by(|a, b| a.name().to_lowercase().cmp(&b.name().to_lowercase())); | 1241 | + rows.sort_by_key(|row| row.name().to_lowercase()); |
| 1239 | let page = view! { | 1242 | let page = view! { |
| 1240 | cx => | 1243 | cx => |
| 1241 | - (wordmark(cx).await?) | 1244 | + (topcoat::view::Child::new(wordmark(cx).await?)) |
| 1242 | <main class="settings-stage stage-wide"> | 1245 | <main class="settings-stage stage-wide"> |
| 1243 | <h1 class="settings-title">(here.name.clone())</h1> | 1246 | <h1 class="settings-title">(here.name.clone())</h1> |
| 1244 | <section class="panel"> | 1247 | <section class="panel"> |
| @@ -1253,7 +1256,7 @@ async fn folder_card( | |||
| 1253 | <a class="dep-link" href=(format!("{base}?folder={}", folder.id))><span class="dep-title">(folder.name.clone())</span></a> | 1256 | <a class="dep-link" href=(format!("{base}?folder={}", folder.id))><span class="dep-title">(folder.name.clone())</span></a> |
| 1254 | </div>, | 1257 | </div>, |
| 1255 | PublicEntry::File(file) => <div class="dep-row"> | 1258 | PublicEntry::File(file) => <div class="dep-row"> |
| 1256 | - (public_chip(cx, &format!("{base}?folder={at}&file={}&thumb=1", file.id), file).await?) | 1259 | + (topcoat::view::Child::new(public_chip(cx, &format!("{base}?folder={at}&file={}&thumb=1", file.id), file).await?)) |
| 1257 | <span class="member-name dep-title">(file.name.clone())</span> | 1260 | <span class="member-name dep-title">(file.name.clone())</span> |
| 1258 | <span class="field-note">(crate::settings::human_bytes(file.size_bytes))</span> | 1261 | <span class="field-note">(crate::settings::human_bytes(file.size_bytes))</span> |
| 1259 | <div class="spacer"></div> | 1262 | <div class="spacer"></div> |
| @@ -1341,18 +1344,19 @@ impl SharedRow { | |||
| 1341 | /// Everything others shared with the reader, folders and files in one | 1344 | /// Everything others shared with the reader, folders and files in one |
| 1342 | /// list. The reader's own library never appears here. | 1345 | /// list. The reader's own library never appears here. |
| 1343 | #[page("/shared")] | 1346 | #[page("/shared")] |
| 1344 | -async fn shared(cx: &Cx) -> Result { | 1347 | +async fn shared(cx: &Cx) -> Result<impl View> { |
| 1345 | let user = match require_user(cx).await { | 1348 | let user = match require_user(cx).await { |
| 1346 | Ok(user) => user, | 1349 | Ok(user) => user, |
| 1347 | Err(refusal) => { | 1350 | Err(refusal) => { |
| 1348 | let language = lang(cx).await; | 1351 | let language = lang(cx).await; |
| 1349 | - return view! { | 1352 | + return Ok(view! { |
| 1350 | cx => | 1353 | cx => |
| 1351 | <main class="scaffold-note"> | 1354 | <main class="scaffold-note"> |
| 1352 | <p>(refusal.message_in(language))</p> | 1355 | <p>(refusal.message_in(language))</p> |
| 1353 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> | 1356 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> |
| 1354 | </main> | 1357 | </main> |
| 1355 | - }; | 1358 | + } |
| 1359 | + .boxed()); | ||
| 1356 | } | 1360 | } |
| 1357 | }; | 1361 | }; |
| 1358 | let language = lang(cx).await; | 1362 | let language = lang(cx).await; |
| @@ -1388,10 +1392,10 @@ async fn shared(cx: &Cx) -> Result { | |||
| 1388 | if kind == "files" && item.kind != ShareKind::File { | 1392 | if kind == "files" && item.kind != ShareKind::File { |
| 1389 | continue; | 1393 | continue; |
| 1390 | } | 1394 | } |
| 1391 | - if let Some(needle) = asked.as_deref() { | 1395 | + if let Some(needle) = asked.as_deref() |
| 1392 | - if !item.name.to_lowercase().contains(&needle.to_lowercase()) { | 1396 | + && !item.name.to_lowercase().contains(&needle.to_lowercase()) |
| 1393 | - continue; | 1397 | + { |
| 1394 | - } | 1398 | + continue; |
| 1395 | } | 1399 | } |
| 1396 | let owner_name = owners.get(&item.owner_id).cloned().unwrap_or_default(); | 1400 | let owner_name = owners.get(&item.owner_id).cloned().unwrap_or_default(); |
| 1397 | // The grant carries no dates or counters of its own: the file row | 1401 | // The grant carries no dates or counters of its own: the file row |
| @@ -1451,9 +1455,9 @@ async fn shared(cx: &Cx) -> Result { | |||
| 1451 | if descending { order.reverse() } else { order } | 1455 | if descending { order.reverse() } else { order } |
| 1452 | }); | 1456 | }); |
| 1453 | let sort_value = format!("{}:{}", sort, if descending { "desc" } else { "asc" }); | 1457 | let sort_value = format!("{}:{}", sort, if descending { "desc" } else { "asc" }); |
| 1454 | - view! { | 1458 | + Ok(view! { |
| 1455 | cx => | 1459 | cx => |
| 1456 | - (topbar(cx, NavPage::Shared, &user, language).await?) | 1460 | + (topcoat::view::Child::new(topbar(cx, NavPage::Shared, &user, language).await?)) |
| 1457 | <main class="settings-stage stage-wide"> | 1461 | <main class="settings-stage stage-wide"> |
| 1458 | <h1 class="settings-title">(t(language, Key::SharedWithMe))</h1> | 1462 | <h1 class="settings-title">(t(language, Key::SharedWithMe))</h1> |
| 1459 | <div class="filterbar"> | 1463 | <div class="filterbar"> |
| @@ -1525,7 +1529,7 @@ async fn shared(cx: &Cx) -> Result { | |||
| 1525 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | 1529 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> |
| 1526 | } else { | 1530 | } else { |
| 1527 | match &row.file { | 1531 | match &row.file { |
| 1528 | - Some(file) => (shared_chip(cx, file).await?), | 1532 | + Some(file) => (topcoat::view::Child::new(shared_chip(cx, file).await?)), |
| 1529 | None => <span class="file-chip file-chip-generic" aria-hidden="true">"▦"</span>, | 1533 | None => <span class="file-chip file-chip-generic" aria-hidden="true">"▦"</span>, |
| 1530 | } | 1534 | } |
| 1531 | } | 1535 | } |
| @@ -1544,8 +1548,8 @@ async fn shared(cx: &Cx) -> Result { | |||
| 1544 | } | 1548 | } |
| 1545 | </section> | 1549 | </section> |
| 1546 | </main> | 1550 | </main> |
| 1547 | - (crate::dropdown::dropdown_script(cx).await?) | 1551 | + (topcoat::view::Child::new(crate::dropdown::dropdown_script(cx).await?)) |
| 1548 | - } | 1552 | + }.boxed()) |
| 1549 | } | 1553 | } |
| 1550 | 1554 | ||
| 1551 | /// What the grant opens: the download, or the view alone. | 1555 | /// What the grant opens: the download, or the view alone. |
| @@ -1566,13 +1570,13 @@ fn access_chip(language: Lang, can_download: bool) -> &'static str { | |||
| 1566 | /// Every form inside posts to the existing share routes and comes back | 1570 | /// Every form inside posts to the existing share routes and comes back |
| 1567 | /// through `Referer`, so the modal survives them; the minted token's | 1571 | /// through `Referer`, so the modal survives them; the minted token's |
| 1568 | /// copy-once banner rides the `?created=` pair into the modal itself. | 1572 | /// copy-once banner rides the `?created=` pair into the modal itself. |
| 1569 | -pub(crate) async fn share_modal( | 1573 | +pub(crate) async fn share_modal<'a>( |
| 1570 | - cx: &Cx, | 1574 | + cx: &'a Cx, |
| 1571 | kind_raw: &str, | 1575 | kind_raw: &str, |
| 1572 | target_id: &str, | 1576 | target_id: &str, |
| 1573 | close_href: &str, | 1577 | close_href: &str, |
| 1574 | created: Option<String>, | 1578 | created: Option<String>, |
| 1575 | -) -> Result<Option<topcoat::view::View>> { | 1579 | +) -> Result<Option<impl View + 'a>> { |
| 1576 | let Some(kind) = parse_kind(kind_raw) else { | 1580 | let Some(kind) = parse_kind(kind_raw) else { |
| 1577 | return Ok(None); | 1581 | return Ok(None); |
| 1578 | }; | 1582 | }; |
| @@ -1610,7 +1614,7 @@ pub(crate) async fn share_modal( | |||
| 1610 | }; | 1614 | }; |
| 1611 | let links = store.share_links(&user.id).await?; | 1615 | let links = store.share_links(&user.id).await?; |
| 1612 | let live: Vec<_> = links | 1616 | let live: Vec<_> = links |
| 1613 | - .iter() | 1617 | + .into_iter() |
| 1614 | .filter(|link| { | 1618 | .filter(|link| { |
| 1615 | link.kind == kind && link.target_id == target_id && link.revoked_at.is_none() | 1619 | link.kind == kind && link.target_id == target_id && link.revoked_at.is_none() |
| 1616 | }) | 1620 | }) |
| @@ -1658,6 +1662,8 @@ pub(crate) async fn share_modal( | |||
| 1658 | candidates.sort_by(|a, b| a.display_name.cmp(&b.display_name)); | 1662 | candidates.sort_by(|a, b| a.display_name.cmp(&b.display_name)); |
| 1659 | let refusal = query_value(uri(cx).query().unwrap_or(""), "refusal") | 1663 | let refusal = query_value(uri(cx).query().unwrap_or(""), "refusal") |
| 1660 | .and_then(|code| Refusal::from_code(&code)); | 1664 | .and_then(|code| Refusal::from_code(&code)); |
| 1665 | + let target_id = target_id.to_string(); | ||
| 1666 | + let close_href = close_href.to_string(); | ||
| 1661 | Ok(Some(view! { | 1667 | Ok(Some(view! { |
| 1662 | cx => | 1668 | cx => |
| 1663 | <div class="modal-scrim"> | 1669 | <div class="modal-scrim"> |
| @@ -1668,7 +1674,7 @@ pub(crate) async fn share_modal( | |||
| 1668 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> | 1674 | <span class="file-chip file-chip-folder" aria-hidden="true">"▤"</span> |
| 1669 | } | 1675 | } |
| 1670 | if let Some(file) = file.as_ref() { | 1676 | if let Some(file) = file.as_ref() { |
| 1671 | - (entry_chip(cx, file).await?) | 1677 | + (topcoat::view::Child::new(entry_chip(cx, file).await?)) |
| 1672 | } | 1678 | } |
| 1673 | (format!("{} “{}”", t(language, Key::Share), name.clone())) | 1679 | (format!("{} “{}”", t(language, Key::Share), name.clone())) |
| 1674 | </h2> | 1680 | </h2> |
| @@ -1767,7 +1773,7 @@ pub(crate) async fn share_modal( | |||
| 1767 | // away. A link from before the sealing — or one whose key is gone — | 1773 | // away. A link from before the sealing — or one whose key is gone — |
| 1768 | // has no address to re-show: the row carries the mint action and the | 1774 | // has no address to re-show: the row carries the mint action and the |
| 1769 | // note below states the fact. | 1775 | // note below states the fact. |
| 1770 | - let url = share_link_url(cx, *link).await; | 1776 | + let url = share_link_url(cx, link).await; |
| 1771 | let legacy = url.is_none(); | 1777 | let legacy = url.is_none(); |
| 1772 | <div class="member-row"> | 1778 | <div class="member-row"> |
| 1773 | <span class="member-name">(t(language, Key::AnyoneWithLink))</span> | 1779 | <span class="member-name">(t(language, Key::AnyoneWithLink))</span> |
| @@ -1799,9 +1805,9 @@ pub(crate) async fn share_modal( | |||
| 1799 | } | 1805 | } |
| 1800 | </div> | 1806 | </div> |
| 1801 | </div> | 1807 | </div> |
| 1802 | - (share_copy_script(cx).await?) | 1808 | + (topcoat::view::Child::new(share_copy_script(cx).await?)) |
| 1803 | - (share_pick_script(cx).await?) | 1809 | + (topcoat::view::Child::new(share_pick_script(cx).await?)) |
| 1804 | - }?)) | 1810 | + }.boxed())) |
| 1805 | } | 1811 | } |
| 1806 | 1812 | ||
| 1807 | /// The link row's copy client: one delegated listener, idempotent across | 1813 | /// The link row's copy client: one delegated listener, idempotent across |
| @@ -1810,7 +1816,7 @@ pub(crate) async fn share_modal( | |||
| 1810 | /// wrapping link text itself copies the full address — and only where a | 1816 | /// wrapping link text itself copies the full address — and only where a |
| 1811 | /// copy button is present: the masked legacy rows carry none, so their | 1817 | /// copy button is present: the masked legacy rows carry none, so their |
| 1812 | /// placeholder can never reach a clipboard. | 1818 | /// placeholder can never reach a clipboard. |
| 1813 | -pub(crate) async fn share_copy_script(cx: &Cx) -> Result { | 1819 | +pub(crate) async fn share_copy_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 1814 | use topcoat::view::Unescaped; | 1820 | use topcoat::view::Unescaped; |
| 1815 | const JS: &str = "\ | 1821 | const JS: &str = "\ |
| 1816 | (function () { \ | 1822 | (function () { \ |
| @@ -1834,7 +1840,7 @@ pub(crate) async fn share_copy_script(cx: &Cx) -> Result { | |||
| 1834 | else { try { document.execCommand('copy'); } catch (err) {} done(); } \ | 1840 | else { try { document.execCommand('copy'); } catch (err) {} done(); } \ |
| 1835 | }); \ | 1841 | }); \ |
| 1836 | })();"; | 1842 | })();"; |
| 1837 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 1843 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 1838 | } | 1844 | } |
| 1839 | 1845 | ||
| 1840 | /// The people picker's client half. The All row checks and unchecks every | 1846 | /// The people picker's client half. The All row checks and unchecks every |
| @@ -1850,7 +1856,7 @@ pub(crate) async fn share_copy_script(cx: &Cx) -> Result { | |||
| 1850 | /// anew. Delegated listeners only, idempotent across the modal's | 1856 | /// anew. Delegated listeners only, idempotent across the modal's |
| 1851 | /// re-renders (`window.__inSharePick` guards it), so the `in:wire` morph | 1857 | /// re-renders (`window.__inSharePick` guards it), so the `in:wire` morph |
| 1852 | /// needs no per-element re-init. | 1858 | /// needs no per-element re-init. |
| 1853 | -pub(crate) async fn share_pick_script(cx: &Cx) -> Result { | 1859 | +pub(crate) async fn share_pick_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { |
| 1854 | use topcoat::view::Unescaped; | 1860 | use topcoat::view::Unescaped; |
| 1855 | const JS: &str = "\ | 1861 | const JS: &str = "\ |
| 1856 | (function () { \ | 1862 | (function () { \ |
| @@ -1902,7 +1908,7 @@ pub(crate) async fn share_pick_script(cx: &Cx) -> Result { | |||
| 1902 | } \ | 1908 | } \ |
| 1903 | }); \ | 1909 | }); \ |
| 1904 | })();"; | 1910 | })();"; |
| 1905 | - view! { cx => <script>(Unescaped::new_unchecked(JS))</script> } | 1911 | + Ok(view! { cx => <script>(Unescaped::new_unchecked(JS))</script> }.boxed()) |
| 1906 | } | 1912 | } |
| 1907 | 1913 | ||
| 1908 | /// When the link stops opening, or never on its own. Twins the settings | 1914 | /// When the link stops opening, or never on its own. Twins the settings |
crates/in-web/src/trash.rsmodified+21 -18
| @@ -18,7 +18,7 @@ use topcoat::Result; | |||
| 18 | use topcoat::context::Cx; | 18 | use topcoat::context::Cx; |
| 19 | use topcoat::router::content::Form; | 19 | use topcoat::router::content::Form; |
| 20 | use topcoat::router::{HeaderName, StatusCode, header, page, query_params, route}; | 20 | use topcoat::router::{HeaderName, StatusCode, header, page, query_params, route}; |
| 21 | -use topcoat::view::view; | 21 | +use topcoat::view::{View, ViewExt, view}; |
| 22 | 22 | ||
| 23 | use crate::files::entry_chip; | 23 | use crate::files::entry_chip; |
| 24 | use crate::i18n::{Key, lang, t}; | 24 | use crate::i18n::{Key, lang, t}; |
| @@ -146,10 +146,12 @@ async fn empty(cx: &Cx) -> Redirect { | |||
| 146 | /// A trashed file's chip: the mime-class glyph, never the thumbnail image — | 146 | /// A trashed file's chip: the mime-class glyph, never the thumbnail image — |
| 147 | /// the shelf wears its own mark, thumbnails belong to the live listings. | 147 | /// the shelf wears its own mark, thumbnails belong to the live listings. |
| 148 | /// The clone only clears the thumbnail flag for the render. | 148 | /// The clone only clears the thumbnail flag for the render. |
| 149 | -async fn trash_chip(cx: &Cx, file: &File) -> Result { | 149 | +async fn trash_chip<'a>(cx: &'a Cx, file: &File) -> Result<impl View + 'a> { |
| 150 | let mut unthumb = file.clone(); | 150 | let mut unthumb = file.clone(); |
| 151 | unthumb.thumb_state = ThumbState::None; | 151 | unthumb.thumb_state = ThumbState::None; |
| 152 | - entry_chip(cx, &unthumb).await | 152 | + let view = entry_chip(cx, &unthumb).await?; |
| 153 | + drop(unthumb); | ||
| 154 | + Ok(view) | ||
| 153 | } | 155 | } |
| 154 | 156 | ||
| 155 | #[query_params] | 157 | #[query_params] |
| @@ -193,12 +195,12 @@ fn valid_kind(raw: Option<&str>) -> &'static str { | |||
| 193 | } | 195 | } |
| 194 | 196 | ||
| 195 | /// One trashed row, folder or file, for the unified list. | 197 | /// One trashed row, folder or file, for the unified list. |
| 196 | -enum TrashEntry<'a> { | 198 | +enum TrashEntry { |
| 197 | - Folder(&'a Folder), | 199 | + Folder(Folder), |
| 198 | - File(&'a File), | 200 | + File(File), |
| 199 | } | 201 | } |
| 200 | 202 | ||
| 201 | -impl TrashEntry<'_> { | 203 | +impl TrashEntry { |
| 202 | fn id(&self) -> &str { | 204 | fn id(&self) -> &str { |
| 203 | match self { | 205 | match self { |
| 204 | TrashEntry::Folder(folder) => &folder.id, | 206 | TrashEntry::Folder(folder) => &folder.id, |
| @@ -242,18 +244,19 @@ impl TrashEntry<'_> { | |||
| 242 | /// The reader's trash: folders and files in one list, each row carrying its | 244 | /// The reader's trash: folders and files in one list, each row carrying its |
| 243 | /// way back and its way gone, plus the button that destroys them all. | 245 | /// way back and its way gone, plus the button that destroys them all. |
| 244 | #[page("/trash")] | 246 | #[page("/trash")] |
| 245 | -async fn trash(cx: &Cx) -> Result { | 247 | +async fn trash(cx: &Cx) -> Result<impl View> { |
| 246 | let user = match require_user(cx).await { | 248 | let user = match require_user(cx).await { |
| 247 | Ok(user) => user, | 249 | Ok(user) => user, |
| 248 | Err(refusal) => { | 250 | Err(refusal) => { |
| 249 | let language = lang(cx).await; | 251 | let language = lang(cx).await; |
| 250 | - return view! { | 252 | + return Ok(view! { |
| 251 | cx => | 253 | cx => |
| 252 | <main class="scaffold-note"> | 254 | <main class="scaffold-note"> |
| 253 | <p>(refusal.message_in(language))</p> | 255 | <p>(refusal.message_in(language))</p> |
| 254 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> | 256 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> |
| 255 | </main> | 257 | </main> |
| 256 | - }; | 258 | + } |
| 259 | + .boxed()); | ||
| 257 | } | 260 | } |
| 258 | }; | 261 | }; |
| 259 | let language = lang(cx).await; | 262 | let language = lang(cx).await; |
| @@ -270,10 +273,10 @@ async fn trash(cx: &Cx) -> Result { | |||
| 270 | let nothing_trashed = listing.folders.is_empty() && listing.files.is_empty(); | 273 | let nothing_trashed = listing.folders.is_empty() && listing.files.is_empty(); |
| 271 | let mut rows: Vec<TrashEntry> = Vec::new(); | 274 | let mut rows: Vec<TrashEntry> = Vec::new(); |
| 272 | if kind == "all" || kind == "folders" { | 275 | if kind == "all" || kind == "folders" { |
| 273 | - rows.extend(listing.folders.iter().map(TrashEntry::Folder)); | 276 | + rows.extend(listing.folders.into_iter().map(TrashEntry::Folder)); |
| 274 | } | 277 | } |
| 275 | if kind == "all" || kind == "files" { | 278 | if kind == "all" || kind == "files" { |
| 276 | - rows.extend(listing.files.iter().map(TrashEntry::File)); | 279 | + rows.extend(listing.files.into_iter().map(TrashEntry::File)); |
| 277 | } | 280 | } |
| 278 | if let Some(needle) = asked.as_deref() { | 281 | if let Some(needle) = asked.as_deref() { |
| 279 | let needle = needle.to_lowercase(); | 282 | let needle = needle.to_lowercase(); |
| @@ -303,9 +306,9 @@ async fn trash(cx: &Cx) -> Result { | |||
| 303 | if descending { order.reverse() } else { order } | 306 | if descending { order.reverse() } else { order } |
| 304 | }); | 307 | }); |
| 305 | let sort_value = format!("{}:{}", sort, if descending { "desc" } else { "asc" }); | 308 | let sort_value = format!("{}:{}", sort, if descending { "desc" } else { "asc" }); |
| 306 | - view! { | 309 | + Ok(view! { |
| 307 | cx => | 310 | cx => |
| 308 | - (topbar(cx, NavPage::Trash, &user, language).await?) | 311 | + (topcoat::view::Child::new(topbar(cx, NavPage::Trash, &user, language).await?)) |
| 309 | <main class="settings-stage stage-wide"> | 312 | <main class="settings-stage stage-wide"> |
| 310 | <h1 class="settings-title">(t(language, Key::Trash))</h1> | 313 | <h1 class="settings-title">(t(language, Key::Trash))</h1> |
| 311 | <div class="filterbar"> | 314 | <div class="filterbar"> |
| @@ -348,7 +351,7 @@ async fn trash(cx: &Cx) -> Result { | |||
| 348 | <input type="hidden" name="q" value=(box_text.clone())> | 351 | <input type="hidden" name="q" value=(box_text.clone())> |
| 349 | </form> | 352 | </form> |
| 350 | </div> | 353 | </div> |
| 351 | - (refusal_banner(cx, language, &["restore", "purge", "empty"]).await?) | 354 | + (topcoat::view::Child::new(refusal_banner(cx, language, &["restore", "purge", "empty"]).await?)) |
| 352 | if !nothing_trashed { | 355 | if !nothing_trashed { |
| 353 | <form method="post" action="/api/trash/empty"> | 356 | <form method="post" action="/api/trash/empty"> |
| 354 | <button class="quiet quiet-danger" type="submit">(t(language, Key::EmptyTrash))</button> | 357 | <button class="quiet quiet-danger" type="submit">(t(language, Key::EmptyTrash))</button> |
| @@ -381,7 +384,7 @@ async fn trash(cx: &Cx) -> Result { | |||
| 381 | <div class="drive-row"> | 384 | <div class="drive-row"> |
| 382 | if let TrashEntry::File(file) = row { | 385 | if let TrashEntry::File(file) = row { |
| 383 | <a class="drive-open" href=(format!("/view/{}", file.id))> | 386 | <a class="drive-open" href=(format!("/view/{}", file.id))> |
| 384 | - (trash_chip(cx, file).await?) | 387 | + (topcoat::view::Child::new(trash_chip(cx, file).await?)) |
| 385 | <span class="dep-title">(file.name.clone())</span> | 388 | <span class="dep-title">(file.name.clone())</span> |
| 386 | <span class="drive-meta drive-size">(crate::drive::human_size(file.size_bytes))</span> | 389 | <span class="drive-meta drive-size">(crate::drive::human_size(file.size_bytes))</span> |
| 387 | <span class="drive-meta drive-date">(row.deleted().date().to_string())</span> | 390 | <span class="drive-meta drive-date">(row.deleted().date().to_string())</span> |
| @@ -417,6 +420,6 @@ async fn trash(cx: &Cx) -> Result { | |||
| 417 | } | 420 | } |
| 418 | </section> | 421 | </section> |
| 419 | </main> | 422 | </main> |
| 420 | - (crate::dropdown::dropdown_script(cx).await?) | 423 | + (topcoat::view::Child::new(crate::dropdown::dropdown_script(cx).await?)) |
| 421 | - } | 424 | + }.boxed()) |
| 422 | } | 425 | } |
crates/in-web/tests/http.rsmodified+135 -85
| @@ -22,6 +22,7 @@ use topcoat::asset::{AssetBundle, RouterBuilderAssetExt}; | |||
| 22 | use topcoat::context::Cx; | 22 | use topcoat::context::Cx; |
| 23 | use topcoat::cookie::RouterBuilderCookieExt; | 23 | use topcoat::cookie::RouterBuilderCookieExt; |
| 24 | use topcoat::router::{Body, BodyLimit, Router, RouterBuilderDiscoverExt, to_bytes}; | 24 | use topcoat::router::{Body, BodyLimit, Router, RouterBuilderDiscoverExt, to_bytes}; |
| 25 | +use topcoat::runtime::RouterBuilderRuntimeExt; | ||
| 25 | use ulid::Ulid; | 26 | use ulid::Ulid; |
| 26 | 27 | ||
| 27 | /// The bundle `cargo build -p in-web` + `topcoat asset bundle --bin in-web` | 28 | /// The bundle `cargo build -p in-web` + `topcoat asset bundle --bin in-web` |
| @@ -36,13 +37,16 @@ fn asset_dir() -> PathBuf { | |||
| 36 | )) | 37 | )) |
| 37 | } | 38 | } |
| 38 | 39 | ||
| 40 | +/// Photos by file id: raw bytes plus mime, answered to `GET /photo/{id}`. | ||
| 41 | +type Photos = Arc<Mutex<HashMap<String, (Vec<u8>, String)>>>; | ||
| 42 | + | ||
| 39 | /// A fake im: answers `POST /introspect` from its token map, `{"active": | 43 | /// A fake im: answers `POST /introspect` from its token map, `{"active": |
| 40 | /// false}` for anything it does not know. Bare TCP + hand-rolled HTTP/1.1 — | 44 | /// false}` for anything it does not know. Bare TCP + hand-rolled HTTP/1.1 — |
| 41 | /// just enough for the client's form post. | 45 | /// just enough for the client's form post. |
| 42 | struct FakeIm { | 46 | struct FakeIm { |
| 43 | addr: std::net::SocketAddr, | 47 | addr: std::net::SocketAddr, |
| 44 | tokens: Arc<Mutex<HashMap<String, serde_json::Value>>>, | 48 | tokens: Arc<Mutex<HashMap<String, serde_json::Value>>>, |
| 45 | - photos: Arc<Mutex<HashMap<String, (Vec<u8>, String)>>>, | 49 | + photos: Photos, |
| 46 | directory: Arc<Mutex<Vec<serde_json::Value>>>, | 50 | directory: Arc<Mutex<Vec<serde_json::Value>>>, |
| 47 | family: Arc<Mutex<Vec<serde_json::Value>>>, | 51 | family: Arc<Mutex<Vec<serde_json::Value>>>, |
| 48 | } | 52 | } |
| @@ -53,8 +57,7 @@ impl FakeIm { | |||
| 53 | let addr = listener.local_addr().unwrap(); | 57 | let addr = listener.local_addr().unwrap(); |
| 54 | let tokens: Arc<Mutex<HashMap<String, serde_json::Value>>> = | 58 | let tokens: Arc<Mutex<HashMap<String, serde_json::Value>>> = |
| 55 | Arc::new(Mutex::new(HashMap::new())); | 59 | Arc::new(Mutex::new(HashMap::new())); |
| 56 | - let photos: Arc<Mutex<HashMap<String, (Vec<u8>, String)>>> = | 60 | + let photos: Photos = Arc::new(Mutex::new(HashMap::new())); |
| 57 | - Arc::new(Mutex::new(HashMap::new())); | ||
| 58 | let directory: Arc<Mutex<Vec<serde_json::Value>>> = Arc::new(Mutex::new(Vec::new())); | 61 | let directory: Arc<Mutex<Vec<serde_json::Value>>> = Arc::new(Mutex::new(Vec::new())); |
| 59 | let family: Arc<Mutex<Vec<serde_json::Value>>> = Arc::new(Mutex::new(Vec::new())); | 62 | let family: Arc<Mutex<Vec<serde_json::Value>>> = Arc::new(Mutex::new(Vec::new())); |
| 60 | let map = tokens.clone(); | 63 | let map = tokens.clone(); |
| @@ -192,7 +195,7 @@ const APP_BASIC: &str = "Basic aW4tdGVzdDpzM2NyM3Q="; | |||
| 192 | /// or nothing, a missing photo exactly like a missing person. `None` for | 195 | /// or nothing, a missing photo exactly like a missing person. `None` for |
| 193 | /// anything else, which stays the introspection JSON. | 196 | /// anything else, which stays the introspection JSON. |
| 194 | fn photo_answer( | 197 | fn photo_answer( |
| 195 | - photos: &Arc<Mutex<HashMap<String, (Vec<u8>, String)>>>, | 198 | + photos: &Photos, |
| 196 | head: &str, | 199 | head: &str, |
| 197 | request_line: &str, | 200 | request_line: &str, |
| 198 | ) -> Option<(&'static str, String, Vec<u8>)> { | 201 | ) -> Option<(&'static str, String, Vec<u8>)> { |
| @@ -385,7 +388,7 @@ impl TestApp { | |||
| 385 | /// way the background fetch files it: one JSON row in the `setting` | 388 | /// way the background fetch files it: one JSON row in the `setting` |
| 386 | /// store under `family`. | 389 | /// store under `family`. |
| 387 | async fn build_with(base_url: Option<&str>, family: &[(&str, &str, &str)]) -> Self { | 390 | async fn build_with(base_url: Option<&str>, family: &[(&str, &str, &str)]) -> Self { |
| 388 | - let dir = std::env::temp_dir().join(format!("in-http-{}", Ulid::new())); | 391 | + let dir = std::env::temp_dir().join(format!("in-http-{}", Ulid::generate())); |
| 389 | std::fs::create_dir_all(&dir).unwrap(); | 392 | std::fs::create_dir_all(&dir).unwrap(); |
| 390 | let db = dir.join("in.db"); | 393 | let db = dir.join("in.db"); |
| 391 | let storage = dir.join("storage"); | 394 | let storage = dir.join("storage"); |
| @@ -442,6 +445,7 @@ impl TestApp { | |||
| 442 | let router = in_client::mount( | 445 | let router = in_client::mount( |
| 443 | Router::builder() | 446 | Router::builder() |
| 444 | .discover() | 447 | .discover() |
| 448 | + .runtime() | ||
| 445 | .layer(BodyLimit::max(32 * 1024 * 1024).at("/api/upload")) | 449 | .layer(BodyLimit::max(32 * 1024 * 1024).at("/api/upload")) |
| 446 | .layer(BodyLimit::max(512 * 1024 * 1024).at("/api/service/files")) | 450 | .layer(BodyLimit::max(512 * 1024 * 1024).at("/api/service/files")) |
| 447 | .cookies() | 451 | .cookies() |
| @@ -486,17 +490,10 @@ impl TestApp { | |||
| 486 | async fn sign_in(&self, sub: &str, email: &str, name: &str) -> String { | 490 | async fn sign_in(&self, sub: &str, email: &str, name: &str) -> String { |
| 487 | let user = self | 491 | let user = self |
| 488 | .store | 492 | .store |
| 489 | - .provision_user( | 493 | + .provision_user(sub, email, name, None, 0, self.config.default_quota_bytes) |
| 490 | - sub, | ||
| 491 | - email, | ||
| 492 | - name, | ||
| 493 | - None, | ||
| 494 | - 0, | ||
| 495 | - self.config.default_quota_bytes, | ||
| 496 | - ) | ||
| 497 | .await | 494 | .await |
| 498 | .unwrap(); | 495 | .unwrap(); |
| 499 | - let token = format!("tok-{}", Ulid::new()); | 496 | + let token = format!("tok-{}", Ulid::generate()); |
| 500 | let exp = time::OffsetDateTime::now_utc() + time::Duration::hours(1); | 497 | let exp = time::OffsetDateTime::now_utc() + time::Duration::hours(1); |
| 501 | self.fake.tokens.lock().unwrap().insert( | 498 | self.fake.tokens.lock().unwrap().insert( |
| 502 | token.clone(), | 499 | token.clone(), |
| @@ -1833,7 +1830,7 @@ fn vp9_aac_matroska() -> Option<Vec<u8>> { | |||
| 1833 | eprintln!("skipping matroska preview tests: no ffmpeg on PATH"); | 1830 | eprintln!("skipping matroska preview tests: no ffmpeg on PATH"); |
| 1834 | return None; | 1831 | return None; |
| 1835 | } | 1832 | } |
| 1836 | - let dir = std::env::temp_dir().join(format!("in-mkv-{}", Ulid::new())); | 1833 | + let dir = std::env::temp_dir().join(format!("in-mkv-{}", Ulid::generate())); |
| 1837 | std::fs::create_dir_all(&dir).unwrap(); | 1834 | std::fs::create_dir_all(&dir).unwrap(); |
| 1838 | let out = dir.join("clip.mkv"); | 1835 | let out = dir.join("clip.mkv"); |
| 1839 | let status = Command::new("ffmpeg") | 1836 | let status = Command::new("ffmpeg") |
| @@ -1958,9 +1955,7 @@ async fn view_only_link_previews_a_matroska_but_cannot_download() { | |||
| 1958 | assert_eq!(media.content_type.as_deref(), Some("video/x-matroska")); | 1955 | assert_eq!(media.content_type.as_deref(), Some("video/x-matroska")); |
| 1959 | assert_eq!(media.bytes, mkv, "the media stream was not the original"); | 1956 | assert_eq!(media.bytes, mkv, "the media stream was not the original"); |
| 1960 | 1957 | ||
| 1961 | - let blocked = app | 1958 | + let blocked = app.get(&format!("/s/{}?dl=1", created.token), None).await; |
| 1962 | - .get(&format!("/s/{}?dl=1", created.token), None) | ||
| 1963 | - .await; | ||
| 1964 | assert!( | 1959 | assert!( |
| 1965 | blocked.text().contains("no longer works"), | 1960 | blocked.text().contains("no longer works"), |
| 1966 | "view-only download showed: {}", | 1961 | "view-only download showed: {}", |
| @@ -2616,7 +2611,10 @@ async fn legacy_link_states_the_carry_forward_note_and_offers_the_mint() { | |||
| 2616 | .await; | 2611 | .await; |
| 2617 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 2612 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 2618 | let text = page.text(); | 2613 | let text = page.text(); |
| 2619 | - assert!(!text.contains("/s/…"), "masked value on a legacy link: {text}"); | 2614 | + assert!( |
| 2615 | + !text.contains("/s/…"), | ||
| 2616 | + "masked value on a legacy link: {text}" | ||
| 2617 | + ); | ||
| 2620 | assert!( | 2618 | assert!( |
| 2621 | text.contains("action=\"/api/share/link/remint\""), | 2619 | text.contains("action=\"/api/share/link/remint\""), |
| 2622 | "no mint action on a legacy link: {text}" | 2620 | "no mint action on a legacy link: {text}" |
| @@ -2634,7 +2632,10 @@ async fn legacy_link_states_the_carry_forward_note_and_offers_the_mint() { | |||
| 2634 | let page = app.get("/settings?section=links", Some(&ada)).await; | 2632 | let page = app.get("/settings?section=links", Some(&ada)).await; |
| 2635 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); | 2633 | assert_eq!(page.status, StatusCode::OK, "{}", page.text()); |
| 2636 | let text = page.text(); | 2634 | let text = page.text(); |
| 2637 | - assert!(!text.contains("/s/…"), "masked value on a legacy link: {text}"); | 2635 | + assert!( |
| 2636 | + !text.contains("/s/…"), | ||
| 2637 | + "masked value on a legacy link: {text}" | ||
| 2638 | + ); | ||
| 2638 | assert!( | 2639 | assert!( |
| 2639 | text.contains("action=\"/api/share/link/remint\""), | 2640 | text.contains("action=\"/api/share/link/remint\""), |
| 2640 | "no mint action on a legacy link: {text}" | 2641 | "no mint action on a legacy link: {text}" |
| @@ -2683,7 +2684,12 @@ async fn remint_carries_a_legacy_link_forward() { | |||
| 2683 | let answer = app | 2684 | let answer = app |
| 2684 | .post("/api/share/link/remint", Some(&ada), &[("id", &old_id)]) | 2685 | .post("/api/share/link/remint", Some(&ada), &[("id", &old_id)]) |
| 2685 | .await; | 2686 | .await; |
| 2686 | - assert_eq!(answer.status, StatusCode::SEE_OTHER, "{:?}", answer.location); | 2687 | + assert_eq!( |
| 2688 | + answer.status, | ||
| 2689 | + StatusCode::SEE_OTHER, | ||
| 2690 | + "{:?}", | ||
| 2691 | + answer.location | ||
| 2692 | + ); | ||
| 2687 | let location = answer.location.as_deref().expect("remint set no location"); | 2693 | let location = answer.location.as_deref().expect("remint set no location"); |
| 2688 | let new_token = created_token(location); | 2694 | let new_token = created_token(location); |
| 2689 | assert!(!new_token.is_empty(), "remint minted no token: {location}"); | 2695 | assert!(!new_token.is_empty(), "remint minted no token: {location}"); |
| @@ -2759,7 +2765,7 @@ async fn drive_marks_shared_rows() { | |||
| 2759 | app.sign_in("sub-ember", "ember@in.test", "Ember").await; | 2765 | app.sign_in("sub-ember", "ember@in.test", "Ember").await; |
| 2760 | let owner = owner_of(&app, "sub-admin").await; | 2766 | let owner = owner_of(&app, "sub-admin").await; |
| 2761 | let linked = file_id(&app, &owner, "linked.txt", b"linked").await; | 2767 | let linked = file_id(&app, &owner, "linked.txt", b"linked").await; |
| 2762 | - let plain = file_id(&app, &owner, "plain.txt", b"plain").await; | 2768 | + let _plain = file_id(&app, &owner, "plain.txt", b"plain").await; |
| 2763 | let granted = file_id(&app, &owner, "granted.txt", b"granted").await; | 2769 | let granted = file_id(&app, &owner, "granted.txt", b"granted").await; |
| 2764 | let answer = app | 2770 | let answer = app |
| 2765 | .post( | 2771 | .post( |
| @@ -3824,7 +3830,7 @@ async fn the_settings_revoke_button_sits_inline_in_its_row() { | |||
| 3824 | .expect("form never closes"); | 3830 | .expect("form never closes"); |
| 3825 | // The row is still open around the form: its own close is the first | 3831 | // The row is still open around the form: its own close is the first |
| 3826 | // `</div>` after the form's. | 3832 | // `</div>` after the form's. |
| 3827 | - let row_close = form_close + body[form_close..].find("</div>").expect("row never closes"); | 3833 | + let _row_close = form_close + body[form_close..].find("</div>").expect("row never closes"); |
| 3828 | let form = &body[row_at + form_at..form_close]; | 3834 | let form = &body[row_at + form_at..form_close]; |
| 3829 | assert!( | 3835 | assert!( |
| 3830 | form.contains("<button class=\"quiet quiet-danger\" type=\"submit\">"), | 3836 | form.contains("<button class=\"quiet quiet-danger\" type=\"submit\">"), |
| @@ -5035,9 +5041,7 @@ async fn avatar_version_stamped_url_caches_immutable() { | |||
| 5035 | app.fake.set_photo("sub-stamp", tiny_png(), "image/png"); | 5041 | app.fake.set_photo("sub-stamp", tiny_png(), "image/png"); |
| 5036 | 5042 | ||
| 5037 | // `?v` equal to the row's version: a year of immutable, no revalidation. | 5043 | // `?v` equal to the row's version: a year of immutable, no revalidation. |
| 5038 | - let fresh = app | 5044 | + let fresh = app.get(&format!("/avatar/{me}?v=0"), Some(&cookie)).await; |
| 5039 | - .get(&format!("/avatar/{me}?v=0"), Some(&cookie)) | ||
| 5040 | - .await; | ||
| 5041 | assert_eq!(fresh.status, StatusCode::OK); | 5045 | assert_eq!(fresh.status, StatusCode::OK); |
| 5042 | assert_eq!( | 5046 | assert_eq!( |
| 5043 | fresh.cache_control.as_deref(), | 5047 | fresh.cache_control.as_deref(), |
| @@ -5045,9 +5049,7 @@ async fn avatar_version_stamped_url_caches_immutable() { | |||
| 5045 | ); | 5049 | ); |
| 5046 | // A stale stamp — the browser holds a face the row has moved past — | 5050 | // A stale stamp — the browser holds a face the row has moved past — |
| 5047 | // falls back to revalidate, so the next answer is the truth. | 5051 | // falls back to revalidate, so the next answer is the truth. |
| 5048 | - let stale = app | 5052 | + let stale = app.get(&format!("/avatar/{me}?v=7"), Some(&cookie)).await; |
| 5049 | - .get(&format!("/avatar/{me}?v=7"), Some(&cookie)) | ||
| 5050 | - .await; | ||
| 5051 | assert_eq!(stale.status, StatusCode::OK); | 5053 | assert_eq!(stale.status, StatusCode::OK); |
| 5052 | assert_eq!(stale.cache_control.as_deref(), Some("private, no-cache")); | 5054 | assert_eq!(stale.cache_control.as_deref(), Some("private, no-cache")); |
| 5053 | assert_eq!(stale.etag.as_deref(), Some("\"p0\"")); | 5055 | assert_eq!(stale.etag.as_deref(), Some("\"p0\"")); |
| @@ -5452,10 +5454,7 @@ async fn connection_card_shows_issuer_client_id_and_stream_state() { | |||
| 5452 | body.contains(app.config.oidc.issuer.as_str()), | 5454 | body.contains(app.config.oidc.issuer.as_str()), |
| 5453 | "no issuer: {body}" | 5455 | "no issuer: {body}" |
| 5454 | ); | 5456 | ); |
| 5455 | - assert!( | 5457 | + assert!(body.contains("in-test"), "no client id: {body}"); |
| 5456 | - body.contains("in-test"), | ||
| 5457 | - "no client id: {body}" | ||
| 5458 | - ); | ||
| 5459 | assert!(body.contains("Reconnecting"), "no amber wording: {body}"); | 5458 | assert!(body.contains("Reconnecting"), "no amber wording: {body}"); |
| 5460 | assert!(body.contains("connection-wait"), "no amber dot: {body}"); | 5459 | assert!(body.contains("connection-wait"), "no amber dot: {body}"); |
| 5461 | // Before the first occurrences both ages read never — the row is | 5460 | // Before the first occurrences both ages read never — the row is |
| @@ -5487,7 +5486,10 @@ async fn connection_card_shows_issuer_client_id_and_stream_state() { | |||
| 5487 | !body.contains("<dd>never</dd>"), | 5486 | !body.contains("<dd>never</dd>"), |
| 5488 | "ages still read never after both stamps: {body}" | 5487 | "ages still read never after both stamps: {body}" |
| 5489 | ); | 5488 | ); |
| 5490 | - assert!(body.matches(" ago</dd>").count() >= 2, "ages not sentenced: {body}"); | 5489 | + assert!( |
| 5490 | + body.matches(" ago</dd>").count() >= 2, | ||
| 5491 | + "ages not sentenced: {body}" | ||
| 5492 | + ); | ||
| 5491 | // The stream ends: amber again, no event line retraction needed — the | 5493 | // The stream ends: amber again, no event line retraction needed — the |
| 5492 | // last event stays but the wording names the truth. | 5494 | // last event stays but the wording names the truth. |
| 5493 | app.health.reconnecting(); | 5495 | app.health.reconnecting(); |
| @@ -5497,7 +5499,6 @@ async fn connection_card_shows_issuer_client_id_and_stream_state() { | |||
| 5497 | assert!(!body.contains("connection-on"), "green lingered: {body}"); | 5499 | assert!(!body.contains("connection-on"), "green lingered: {body}"); |
| 5498 | } | 5500 | } |
| 5499 | 5501 | ||
| 5500 | - | ||
| 5501 | // --------------------------------------------------------------------------- | 5502 | // --------------------------------------------------------------------------- |
| 5502 | // The service storage API: bearer keys, machine answers, im's ceilings. | 5503 | // The service storage API: bearer keys, machine answers, im's ceilings. |
| 5503 | // --------------------------------------------------------------------------- | 5504 | // --------------------------------------------------------------------------- |
| @@ -5521,10 +5522,7 @@ async fn service_key(store: &Arc<dyn Store>, service: &str, name: &str) -> (Stri | |||
| 5521 | #[tokio::test] | 5522 | #[tokio::test] |
| 5522 | async fn service_routes_refuse_a_missing_or_wrong_key() { | 5523 | async fn service_routes_refuse_a_missing_or_wrong_key() { |
| 5523 | let app = TestApp::build().await; | 5524 | let app = TestApp::build().await; |
| 5524 | - for path in [ | 5525 | + for path in ["/api/service/status", "/api/service/file/some-id"] { |
| 5525 | - "/api/service/status", | ||
| 5526 | - "/api/service/file/some-id", | ||
| 5527 | - ] { | ||
| 5528 | let raw = app.get_bearer(path, None).await; | 5526 | let raw = app.get_bearer(path, None).await; |
| 5529 | assert_eq!(raw.status, StatusCode::UNAUTHORIZED, "{path}"); | 5527 | assert_eq!(raw.status, StatusCode::UNAUTHORIZED, "{path}"); |
| 5530 | let raw = app.get_bearer(path, None).await; | 5528 | let raw = app.get_bearer(path, None).await; |
| @@ -5564,9 +5562,7 @@ async fn the_service_happy_path_pushes_fetches_counts_and_takes_away() { | |||
| 5564 | let file_id = pushed["ok"].as_str().unwrap().to_string(); | 5562 | let file_id = pushed["ok"].as_str().unwrap().to_string(); |
| 5565 | 5563 | ||
| 5566 | // Status: the account's ceiling and what it now holds. | 5564 | // Status: the account's ceiling and what it now holds. |
| 5567 | - let raw = app | 5565 | + let raw = app.get_bearer("/api/service/status", Some(&token)).await; |
| 5568 | - .get_bearer("/api/service/status", Some(&token)) | ||
| 5569 | - .await; | ||
| 5570 | assert_eq!(raw.status, StatusCode::OK); | 5566 | assert_eq!(raw.status, StatusCode::OK); |
| 5571 | let status: serde_json::Value = serde_json::from_str(&raw.text()).unwrap(); | 5567 | let status: serde_json::Value = serde_json::from_str(&raw.text()).unwrap(); |
| 5572 | assert_eq!(status["ok"], serde_json::Value::Bool(true)); | 5568 | assert_eq!(status["ok"], serde_json::Value::Bool(true)); |
| @@ -5680,16 +5676,12 @@ async fn the_service_quota_is_the_ceiling_the_word_names() { | |||
| 5680 | async fn a_human_browser_is_a_stranger_on_the_machine_routes() { | 5676 | async fn a_human_browser_is_a_stranger_on_the_machine_routes() { |
| 5681 | let app = TestApp::build().await; | 5677 | let app = TestApp::build().await; |
| 5682 | let (token, _) = service_key(&app.store, "iz", "İz").await; | 5678 | let (token, _) = service_key(&app.store, "iz", "İz").await; |
| 5683 | - let admin = app | 5679 | + let admin = app.sign_in("sub-admin", "admin@example.com", "Admin").await; |
| 5684 | - .sign_in("sub-admin", "admin@example.com", "Admin") | ||
| 5685 | - .await; | ||
| 5686 | // The admin's session cookie buys nothing here. | 5680 | // The admin's session cookie buys nothing here. |
| 5687 | let raw = app.get("/api/service/status", Some(&admin)).await; | 5681 | let raw = app.get("/api/service/status", Some(&admin)).await; |
| 5688 | assert_eq!(raw.status, StatusCode::UNAUTHORIZED); | 5682 | assert_eq!(raw.status, StatusCode::UNAUTHORIZED); |
| 5689 | // And the bearer key buys nothing on the human drive. | 5683 | // And the bearer key buys nothing on the human drive. |
| 5690 | - let raw = app | 5684 | + let raw = app.get_bearer("/drive", Some(&token)).await; |
| 5691 | - .get_bearer("/drive", Some(&token)) | ||
| 5692 | - .await; | ||
| 5693 | assert!(raw.status.is_redirection() || raw.status == StatusCode::UNAUTHORIZED); | 5685 | assert!(raw.status.is_redirection() || raw.status == StatusCode::UNAUTHORIZED); |
| 5694 | } | 5686 | } |
| 5695 | 5687 | ||
| @@ -5698,18 +5690,25 @@ async fn the_everyone_quota_write_refuses_a_service_account() { | |||
| 5698 | let app = TestApp::build().await; | 5690 | let app = TestApp::build().await; |
| 5699 | // The admin signs in first: the first human sight is the admin, and a | 5691 | // The admin signs in first: the first human sight is the admin, and a |
| 5700 | // service row must not claim that. | 5692 | // service row must not claim that. |
| 5701 | - let admin = app | 5693 | + let admin = app.sign_in("sub-admin", "admin@example.com", "Admin").await; |
| 5702 | - .sign_in("sub-admin", "admin@example.com", "Admin") | ||
| 5703 | - .await; | ||
| 5704 | let (_, user_id) = service_key(&app.store, "iz", "İz").await; | 5694 | let (_, user_id) = service_key(&app.store, "iz", "İz").await; |
| 5705 | let answer = app | 5695 | let answer = app |
| 5706 | .post( | 5696 | .post( |
| 5707 | "/api/settings/quota", | 5697 | "/api/settings/quota", |
| 5708 | Some(&admin), | 5698 | Some(&admin), |
| 5709 | - &[("user_id", user_id.as_str()), ("quota", "5"), ("quota_unit", "GiB")], | 5699 | + &[ |
| 5700 | + ("user_id", user_id.as_str()), | ||
| 5701 | + ("quota", "5"), | ||
| 5702 | + ("quota_unit", "GiB"), | ||
| 5703 | + ], | ||
| 5710 | ) | 5704 | ) |
| 5711 | .await; | 5705 | .await; |
| 5712 | - assert!(answer.refused("service-quota", "quota"), "{} {}", answer.location.as_deref().unwrap_or(""), answer.body); | 5706 | + assert!( |
| 5707 | + answer.refused("service-quota", "quota"), | ||
| 5708 | + "{} {}", | ||
| 5709 | + answer.location.as_deref().unwrap_or(""), | ||
| 5710 | + answer.body | ||
| 5711 | + ); | ||
| 5713 | // The ceiling is untouched. | 5712 | // The ceiling is untouched. |
| 5714 | let holder = app.store.user(&user_id).await.unwrap().unwrap(); | 5713 | let holder = app.store.user(&user_id).await.unwrap().unwrap(); |
| 5715 | assert_eq!(holder.quota_bytes, 1024 * 1024); | 5714 | assert_eq!(holder.quota_bytes, 1024 * 1024); |
| @@ -5725,16 +5724,16 @@ async fn the_mint_shows_its_key_once_and_refuses_a_stranger() { | |||
| 5725 | ) | 5724 | ) |
| 5726 | .await | 5725 | .await |
| 5727 | .unwrap(); | 5726 | .unwrap(); |
| 5728 | - let admin = app | 5727 | + let admin = app.sign_in("sub-admin", "admin@example.com", "Admin").await; |
| 5729 | - .sign_in("sub-admin", "admin@example.com", "Admin") | ||
| 5730 | - .await; | ||
| 5731 | let plain = app.sign_in("sub-plain", "plain@example.com", "Plain").await; | 5728 | let plain = app.sign_in("sub-plain", "plain@example.com", "Plain").await; |
| 5732 | 5729 | ||
| 5733 | // Non-admin: the section reads as the profile, the mint refuses. | 5730 | // Non-admin: the section reads as the profile, the mint refuses. |
| 5734 | - let page = app | 5731 | + let page = app.get("/settings?section=service", Some(&plain)).await; |
| 5735 | - .get("/settings?section=service", Some(&plain)) | 5732 | + assert!( |
| 5736 | - .await; | 5733 | + !page.text().contains("Service keys"), |
| 5737 | - assert!(!page.text().contains("Service keys"), "rail leaked: {}", page.text()); | 5734 | + "rail leaked: {}", |
| 5735 | + page.text() | ||
| 5736 | + ); | ||
| 5738 | let answer = app | 5737 | let answer = app |
| 5739 | .post( | 5738 | .post( |
| 5740 | "/api/settings/service_add", | 5739 | "/api/settings/service_add", |
| @@ -5742,7 +5741,12 @@ async fn the_mint_shows_its_key_once_and_refuses_a_stranger() { | |||
| 5742 | &[("service", "iz"), ("name", "İz")], | 5741 | &[("service", "iz"), ("name", "İz")], |
| 5743 | ) | 5742 | ) |
| 5744 | .await; | 5743 | .await; |
| 5745 | - assert!(answer.refused("forbidden", "service_add"), "{} {}", answer.location.as_deref().unwrap_or(""), answer.body); | 5744 | + assert!( |
| 5745 | + answer.refused("forbidden", "service_add"), | ||
| 5746 | + "{} {}", | ||
| 5747 | + answer.location.as_deref().unwrap_or(""), | ||
| 5748 | + answer.body | ||
| 5749 | + ); | ||
| 5746 | 5750 | ||
| 5747 | // The admin mints; the redirect carries a ticket, not the key. | 5751 | // The admin mints; the redirect carries a ticket, not the key. |
| 5748 | let answer = app | 5752 | let answer = app |
| @@ -5752,7 +5756,12 @@ async fn the_mint_shows_its_key_once_and_refuses_a_stranger() { | |||
| 5752 | &[("service", "iz"), ("name", "İz")], | 5756 | &[("service", "iz"), ("name", "İz")], |
| 5753 | ) | 5757 | ) |
| 5754 | .await; | 5758 | .await; |
| 5755 | - assert!(answer.accepted(), "{} {}", answer.location.as_deref().unwrap_or(""), answer.body); | 5759 | + assert!( |
| 5760 | + answer.accepted(), | ||
| 5761 | + "{} {}", | ||
| 5762 | + answer.location.as_deref().unwrap_or(""), | ||
| 5763 | + answer.body | ||
| 5764 | + ); | ||
| 5756 | let location = answer.location.unwrap(); | 5765 | let location = answer.location.unwrap(); |
| 5757 | let ticket = location | 5766 | let ticket = location |
| 5758 | .split("shown=") | 5767 | .split("shown=") |
| @@ -5766,7 +5775,10 @@ async fn the_mint_shows_its_key_once_and_refuses_a_stranger() { | |||
| 5766 | 5775 | ||
| 5767 | // First render: the key stands in the banner. Second: nothing. | 5776 | // First render: the key stands in the banner. Second: nothing. |
| 5768 | let page = app | 5777 | let page = app |
| 5769 | - .get(&format!("/settings?section=service&shown={ticket}"), Some(&admin)) | 5778 | + .get( |
| 5779 | + &format!("/settings?section=service&shown={ticket}"), | ||
| 5780 | + Some(&admin), | ||
| 5781 | + ) | ||
| 5770 | .await; | 5782 | .await; |
| 5771 | let body = page.text(); | 5783 | let body = page.text(); |
| 5772 | assert!(body.contains("service-secret"), "no banner: {body}"); | 5784 | assert!(body.contains("service-secret"), "no banner: {body}"); |
| @@ -5791,11 +5803,17 @@ async fn the_mint_shows_its_key_once_and_refuses_a_stranger() { | |||
| 5791 | assert_eq!(account.oidc_sub, "service:iz"); | 5803 | assert_eq!(account.oidc_sub, "service:iz"); |
| 5792 | // The replayed URL — the live tick, a reload — renders no banner. | 5804 | // The replayed URL — the live tick, a reload — renders no banner. |
| 5793 | let page = app | 5805 | let page = app |
| 5794 | - .get(&format!("/settings?section=service&shown={ticket}"), Some(&admin)) | 5806 | + .get( |
| 5807 | + &format!("/settings?section=service&shown={ticket}"), | ||
| 5808 | + Some(&admin), | ||
| 5809 | + ) | ||
| 5795 | .await; | 5810 | .await; |
| 5796 | assert!(!page.text().contains("service-secret\"")); | 5811 | assert!(!page.text().contains("service-secret\"")); |
| 5797 | let page = app | 5812 | let page = app |
| 5798 | - .get("/settings?section=service&shown=forged-ticket", Some(&admin)) | 5813 | + .get( |
| 5814 | + "/settings?section=service&shown=forged-ticket", | ||
| 5815 | + Some(&admin), | ||
| 5816 | + ) | ||
| 5799 | .await; | 5817 | .await; |
| 5800 | assert!(!page.text().contains("service-secret\"")); | 5818 | assert!(!page.text().contains("service-secret\"")); |
| 5801 | 5819 | ||
| @@ -5807,10 +5825,24 @@ async fn the_mint_shows_its_key_once_and_refuses_a_stranger() { | |||
| 5807 | &[("service", "iz")], | 5825 | &[("service", "iz")], |
| 5808 | ) | 5826 | ) |
| 5809 | .await; | 5827 | .await; |
| 5810 | - assert!(answer.accepted(), "{} {}", answer.location.as_deref().unwrap_or(""), answer.body); | 5828 | + assert!( |
| 5811 | - let ticket = answer.location.unwrap().split("shown=").nth(1).unwrap().to_string(); | 5829 | + answer.accepted(), |
| 5830 | + "{} {}", | ||
| 5831 | + answer.location.as_deref().unwrap_or(""), | ||
| 5832 | + answer.body | ||
| 5833 | + ); | ||
| 5834 | + let ticket = answer | ||
| 5835 | + .location | ||
| 5836 | + .unwrap() | ||
| 5837 | + .split("shown=") | ||
| 5838 | + .nth(1) | ||
| 5839 | + .unwrap() | ||
| 5840 | + .to_string(); | ||
| 5812 | let page = app | 5841 | let page = app |
| 5813 | - .get(&format!("/settings?section=service&shown={ticket}"), Some(&admin)) | 5842 | + .get( |
| 5843 | + &format!("/settings?section=service&shown={ticket}"), | ||
| 5844 | + Some(&admin), | ||
| 5845 | + ) | ||
| 5814 | .await; | 5846 | .await; |
| 5815 | let rotated = page | 5847 | let rotated = page |
| 5816 | .text() | 5848 | .text() |
| @@ -5825,7 +5857,13 @@ async fn the_mint_shows_its_key_once_and_refuses_a_stranger() { | |||
| 5825 | .unwrap() | 5857 | .unwrap() |
| 5826 | .to_string(); | 5858 | .to_string(); |
| 5827 | assert_ne!(rotated, key); | 5859 | assert_ne!(rotated, key); |
| 5828 | - assert!(app.store.service_account_by_token(&key).await.unwrap().is_none()); | 5860 | + assert!( |
| 5861 | + app.store | ||
| 5862 | + .service_account_by_token(&key) | ||
| 5863 | + .await | ||
| 5864 | + .unwrap() | ||
| 5865 | + .is_none() | ||
| 5866 | + ); | ||
| 5829 | let answer = app | 5867 | let answer = app |
| 5830 | .post( | 5868 | .post( |
| 5831 | "/api/settings/service_revoke", | 5869 | "/api/settings/service_revoke", |
| @@ -5833,23 +5871,36 @@ async fn the_mint_shows_its_key_once_and_refuses_a_stranger() { | |||
| 5833 | &[("service", "iz")], | 5871 | &[("service", "iz")], |
| 5834 | ) | 5872 | ) |
| 5835 | .await; | 5873 | .await; |
| 5836 | - assert!(answer.accepted(), "{} {}", answer.location.as_deref().unwrap_or(""), answer.body); | 5874 | + assert!( |
| 5837 | - assert!(app.store.service_account_by_token(&rotated).await.unwrap().is_none()); | 5875 | + answer.accepted(), |
| 5876 | + "{} {}", | ||
| 5877 | + answer.location.as_deref().unwrap_or(""), | ||
| 5878 | + answer.body | ||
| 5879 | + ); | ||
| 5880 | + assert!( | ||
| 5881 | + app.store | ||
| 5882 | + .service_account_by_token(&rotated) | ||
| 5883 | + .await | ||
| 5884 | + .unwrap() | ||
| 5885 | + .is_none() | ||
| 5886 | + ); | ||
| 5838 | let accounts = app.store.list_service_accounts().await.unwrap(); | 5887 | let accounts = app.store.list_service_accounts().await.unwrap(); |
| 5839 | - assert!(accounts.is_empty(), "revoke took the row, not the account: the account row stays"); | 5888 | + assert!( |
| 5889 | + accounts.is_empty(), | ||
| 5890 | + "revoke took the row, not the account: the account row stays" | ||
| 5891 | + ); | ||
| 5840 | } | 5892 | } |
| 5841 | 5893 | ||
| 5842 | #[tokio::test] | 5894 | #[tokio::test] |
| 5843 | async fn the_family_limit_lands_on_the_account() { | 5895 | async fn the_family_limit_lands_on_the_account() { |
| 5844 | let app = TestApp::build().await; | 5896 | let app = TestApp::build().await; |
| 5845 | // im names a 5 GiB ceiling for iz; the beat carries it. | 5897 | // im names a 5 GiB ceiling for iz; the beat carries it. |
| 5846 | - app.fake | 5898 | + app.fake.set_family(vec![serde_json::json!({ |
| 5847 | - .set_family(vec![serde_json::json!({ | 5899 | + "key": "iz", |
| 5848 | - "key": "iz", | 5900 | + "name": "İz", |
| 5849 | - "name": "İz", | 5901 | + "url": "http://127.0.0.1:7654", |
| 5850 | - "url": "http://127.0.0.1:7654", | 5902 | + "limit_bytes": 5 * 1024 * 1024 * 1024u64, |
| 5851 | - "limit_bytes": 5 * 1024 * 1024 * 1024u64, | 5903 | + })]); |
| 5852 | - })]); | ||
| 5853 | let client = in_client::InClient::new(app.client.clone()); | 5904 | let client = in_client::InClient::new(app.client.clone()); |
| 5854 | let family = client.family().await.expect("the fake answered"); | 5905 | let family = client.family().await.expect("the fake answered"); |
| 5855 | assert_eq!(family[0].limit_bytes, Some(5 * 1024 * 1024 * 1024)); | 5906 | assert_eq!(family[0].limit_bytes, Some(5 * 1024 * 1024 * 1024)); |
| @@ -5867,12 +5918,11 @@ async fn the_family_limit_lands_on_the_account() { | |||
| 5867 | let holder = app.store.user(&user_id).await.unwrap().unwrap(); | 5918 | let holder = app.store.user(&user_id).await.unwrap().unwrap(); |
| 5868 | assert_eq!(holder.quota_bytes, 5 * 1024 * 1024 * 1024); | 5919 | assert_eq!(holder.quota_bytes, 5 * 1024 * 1024 * 1024); |
| 5869 | // No limit named: the house default. | 5920 | // No limit named: the house default. |
| 5870 | - app.fake | 5921 | + app.fake.set_family(vec![serde_json::json!({ |
| 5871 | - .set_family(vec![serde_json::json!({ | 5922 | + "key": "iz", |
| 5872 | - "key": "iz", | 5923 | + "name": "İz", |
| 5873 | - "name": "İz", | 5924 | + "url": "http://127.0.0.1:7654", |
| 5874 | - "url": "http://127.0.0.1:7654", | 5925 | + })]); |
| 5875 | - })]); | ||
| 5876 | let family = client.family().await.unwrap(); | 5926 | let family = client.family().await.unwrap(); |
| 5877 | assert_eq!(family[0].limit_bytes, None); | 5927 | assert_eq!(family[0].limit_bytes, None); |
| 5878 | in_web::service::apply_family_limits(&app.store, &family, 1024 * 1024) | 5928 | in_web::service::apply_family_limits(&app.store, &family, 1024 * 1024) |