From 90856717e4ba13ce31cbafde24ce9211932d9d11 Mon Sep 17 00:00:00 2001 From: Pakin Date: Thu, 8 Jan 2026 14:15:27 +0700 Subject: [PATCH 01/21] update: repo & deps --- .dockerignore | 5 + Cargo.lock | 747 ++++++++------------------------------------------ Cargo.toml | 2 +- Dockerfile | 41 +++ 4 files changed, 164 insertions(+), 631 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6d7a285 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +/target +.tbcfg +*.txt +*.log + diff --git a/Cargo.lock b/Cargo.lock index 7b07015..844e65e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,7 +110,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -127,9 +127,9 @@ checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "axum" -version = "0.8.7" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b098575ebe77cb6d14fc7f32749631a6e44edbef6b796f89b020e99ba20d425" +checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" dependencies = [ "axum-core", "bytes", @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59446ce19cd142f8833f856eb31f3eb097812d1479ab224f54d72428ca21ea22" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" dependencies = [ "bytes", "futures-core", @@ -183,19 +183,6 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "bigdecimal" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "560f42649de9fa436b73517378a147ec21f6c997a546581df4b4b31677828934" -dependencies = [ - "autocfg", - "libm", - "num-bigint", - "num-integer", - "num-traits", -] - [[package]] name = "bitflags" version = "2.10.0" @@ -211,22 +198,11 @@ dependencies = [ "generic-array", ] -[[package]] -name = "bstr" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" -dependencies = [ - "memchr", - "regex-automata", - "serde", -] - [[package]] name = "bumpalo" -version = "3.19.0" +version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" [[package]] name = "bytes" @@ -245,9 +221,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.49" +version = "1.2.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90583009037521a116abf44494efecd645ba48b6622457080f080b85544e2215" +checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203" dependencies = [ "find-msvc-tools", "jobserver", @@ -255,24 +231,12 @@ dependencies = [ "shlex", ] -[[package]] -name = "cesu8" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" - [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" -[[package]] -name = "cfg_aliases" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" - [[package]] name = "chrono" version = "0.4.42" @@ -296,53 +260,12 @@ dependencies = [ "inout", ] -[[package]] -name = "clap" -version = "4.5.53" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8" -dependencies = [ - "clap_builder", -] - -[[package]] -name = "clap_builder" -version = "4.5.53" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", - "terminal_size", -] - -[[package]] -name = "clap_lex" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" - [[package]] name = "colorchoice" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" -[[package]] -name = "console" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b430743a6eb14e9764d4260d4c0d8123087d504eeb9c48f2b2a5e810dd369df4" -dependencies = [ - "encode_unicode", - "libc", - "once_cell", - "unicode-width", - "windows-sys 0.61.2", -] - [[package]] name = "constant_time_eq" version = "0.3.1" @@ -456,7 +379,7 @@ checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -478,27 +401,15 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] -[[package]] -name = "dunce" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" - [[package]] name = "either" version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" -[[package]] -name = "encode_unicode" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" - [[package]] name = "encoding_rs" version = "0.8.35" @@ -567,9 +478,9 @@ dependencies = [ [[package]] name = "find-msvc-tools" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" +checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff" [[package]] name = "fixedbitset" @@ -588,51 +499,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "fluent" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8137a6d5a2c50d6b0ebfcb9aaa91a28154e0a70605f112d30cb0cd4a78670477" -dependencies = [ - "fluent-bundle", - "unic-langid", -] - -[[package]] -name = "fluent-bundle" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01203cb8918f5711e73891b347816d932046f95f54207710bda99beaeb423bf4" -dependencies = [ - "fluent-langneg", - "fluent-syntax", - "intl-memoizer", - "intl_pluralrules", - "rustc-hash", - "self_cell", - "smallvec", - "unic-langid", -] - -[[package]] -name = "fluent-langneg" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eebbe59450baee8282d71676f3bfed5689aeab00b27545e83e5f14b1195e8b0" -dependencies = [ - "unic-langid", -] - -[[package]] -name = "fluent-syntax" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54f0d287c53ffd184d04d8677f590f4ac5379785529e5e08b1c8083acdd5c198" -dependencies = [ - "memchr", - "thiserror", -] - [[package]] name = "fnv" version = "1.0.7" @@ -663,27 +529,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fs_extra" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" - -[[package]] -name = "futures" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.31" @@ -691,7 +536,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -700,34 +544,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" -[[package]] -name = "futures-executor" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" - -[[package]] -name = "futures-macro" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.111", -] - [[package]] name = "futures-sink" version = "0.3.31" @@ -746,16 +562,10 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", - "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -806,17 +616,11 @@ dependencies = [ "url", ] -[[package]] -name = "glob" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" - [[package]] name = "h2" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c0b69cfcb4e1b9f1bf2f53f95f766e4661169728ec61cd3fe5a0166f2d1386" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" dependencies = [ "atomic-waker", "bytes", @@ -1119,27 +923,14 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.12.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", "hashbrown", ] -[[package]] -name = "indicatif" -version = "0.18.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9375e112e4b463ec1b1c6c011953545c65a30164fbab5b581df32b3abf0dcb88" -dependencies = [ - "console", - "portable-atomic", - "unicode-width", - "unit-prefix", - "web-time", -] - [[package]] name = "inout" version = "0.1.4" @@ -1149,25 +940,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "intl-memoizer" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "310da2e345f5eb861e7a07ee182262e94975051db9e4223e909ba90f392f163f" -dependencies = [ - "type-map", - "unic-langid", -] - -[[package]] -name = "intl_pluralrules" -version = "7.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "078ea7b7c29a2b4df841a7f6ac8775ff6074020c6776d48491ce2268e068f972" -dependencies = [ - "unic-langid", -] - [[package]] name = "ipnet" version = "2.11.0" @@ -1176,9 +948,9 @@ checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "iri-string" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f867b9d1d896b67beb18518eda36fdb77a32ea590de864f1325b294a6d14397" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" dependencies = [ "memchr", "serde", @@ -1201,44 +973,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" - -[[package]] -name = "j4rs" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dacf87fdd07b36f3124894a5bf20c8d418aaa28d4974d717672507f6d05cd31c" -dependencies = [ - "cesu8", - "dunce", - "fs_extra", - "futures", - "java-locator", - "jni-sys", - "lazy_static", - "libc", - "libloading", - "log", - "serde", - "serde_json", -] - -[[package]] -name = "java-locator" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09c46c1fe465c59b1474e665e85e1256c3893dd00927b8d55f63b09044c1e64f" -dependencies = [ - "glob", -] +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" [[package]] name = "jiff" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49cce2b81f2098e7e3efc35bc2e0a6b7abec9d34128283d7a26fa8f32a6dbb35" +checksum = "e67e8da4c49d6d9909fe03361f9b620f58898859f5c7aded68351e85e71ecf50" dependencies = [ "jiff-static", "log", @@ -1249,32 +992,13 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "980af8b43c3ad5d8d349ace167ec8170839f753a42d233ba19e08afe1850fa69" +checksum = "e0c84ee7f197eca9a86c6fd6cb771e55eb991632f15f2bc3ca6ec838929e6e78" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", -] - -[[package]] -name = "jni-sys" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c30a312d782b8d56a1e0897d45c1af33f31f9b4a4d13d31207a8675e0223b818" -dependencies = [ - "jni-sys-macros", -] - -[[package]] -name = "jni-sys-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c199962dfd5610ced8eca382606e349f7940a4ac7d867b58a046123411cbb4" -dependencies = [ - "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -1297,12 +1021,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libbz2-rs-sys" version = "0.2.2" @@ -1311,9 +1029,9 @@ checksum = "2c4a545a15244c7d945065b5d392b2d2d7f21526fba56ce51467b06ed445e8f7" [[package]] name = "libc" -version = "0.2.178" +version = "0.2.179" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37c93d8daa9d8a012fd8ab92f088405fb202ea0b6ab73ee2482ae66af4f42091" +checksum = "c5a2d376baa530d1238d133232d15e239abad80d05838b4b59354e5268af431f" [[package]] name = "libgit2-sys" @@ -1329,31 +1047,15 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "libloading" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" -dependencies = [ - "cfg-if", - "windows-link", -] - -[[package]] -name = "libm" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" - [[package]] name = "libredox" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" dependencies = [ "bitflags", "libc", - "redox_syscall", + "redox_syscall 0.7.0", ] [[package]] @@ -1373,28 +1075,26 @@ dependencies = [ [[package]] name = "libtbr" version = "0.1.1" -source = "git+https://gitlab.forthrd.io/Pakin/libtbr.git#0dd4b8a4f189c2a53b463d4ffb787be396637f5e" +source = "git+https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/libtbr.git#9ef23af0fd411c1434d5d8fe967a717eca445b96" dependencies = [ "chrono", "flate2", "git2", - "j4rs", "log", "rand", "rayon", "serde", "serde_json", "tar", - "uu_cp", "walkdir", "zip", ] [[package]] name = "libz-rs-sys" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15413ef615ad868d4d65dce091cb233b229419c7c0c4bcaa746c0901c49ff39c" +checksum = "c10501e7805cee23da17c7790e59df2870c0d4043ec6d03f67d31e2b53e77415" dependencies = [ "zlib-rs", ] @@ -1510,43 +1210,12 @@ dependencies = [ "tempfile", ] -[[package]] -name = "nix" -version = "0.30.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" -dependencies = [ - "bitflags", - "cfg-if", - "cfg_aliases", - "libc", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -1556,12 +1225,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "number_prefix" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" - [[package]] name = "once_cell" version = "1.21.3" @@ -1597,7 +1260,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -1618,15 +1281,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "os_display" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad5fd71b79026fb918650dde6d125000a233764f1c2f1659a1c71118e33ea08f" -dependencies = [ - "unicode-width", -] - [[package]] name = "parking_lot" version = "0.12.5" @@ -1645,7 +1299,7 @@ checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.18", "smallvec", "windows-link", ] @@ -1693,7 +1347,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -1716,9 +1370,9 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "portable-atomic" -version = "1.11.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" +checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" [[package]] name = "portable-atomic-util" @@ -1766,14 +1420,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn 2.0.111", + "syn", ] [[package]] name = "proc-macro2" -version = "1.0.103" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" dependencies = [ "unicode-ident", ] @@ -1806,7 +1460,7 @@ dependencies = [ "pulldown-cmark", "pulldown-cmark-to-cmark", "regex", - "syn 2.0.111", + "syn", "tempfile", ] @@ -1820,7 +1474,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -1854,9 +1508,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.42" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" dependencies = [ "proc-macro2", ] @@ -1925,6 +1579,15 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_syscall" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" +dependencies = [ + "bitflags", +] + [[package]] name = "regex" version = "1.12.2" @@ -1956,9 +1619,9 @@ checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "reqwest" -version = "0.12.25" +version = "0.12.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6eff9328d40131d43bd911d42d79eb6a47312002a4daefc9e37f17e74a7701a" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" dependencies = [ "base64", "bytes", @@ -2008,17 +1671,11 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rustc-hash" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" - [[package]] name = "rustix" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" +checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" dependencies = [ "bitflags", "errno", @@ -2029,9 +1686,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.35" +version = "0.23.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "533f54bc6a7d4f647e46ad909549eda97bf5afc1585190ef692b4286b198bd8f" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" dependencies = [ "once_cell", "rustls-pki-types", @@ -2042,9 +1699,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "708c0f9d5f54ba0272468c1d306a52c495b31fa155e91bc25371e6df7996908c" +checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282" dependencies = [ "zeroize", ] @@ -2068,9 +1725,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" [[package]] name = "same-file" @@ -2119,12 +1776,6 @@ dependencies = [ "libc", ] -[[package]] -name = "self_cell" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16c2f82143577edb4921b71ede051dac62ca3c16084e918bf7b40c96ae10eb33" - [[package]] name = "serde" version = "1.0.228" @@ -2152,21 +1803,21 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] name = "serde_json" -version = "1.0.145" +version = "1.0.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" dependencies = [ "indexmap", "itoa", "memchr", - "ryu", "serde", "serde_core", + "zmij", ] [[package]] @@ -2222,10 +1873,11 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" -version = "1.4.7" +version = "1.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7664a098b8e616bdfcc2dc0e9ac44eb231eedf41db4e9fe95d8d32ec728dedad" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" dependencies = [ + "errno", "libc", ] @@ -2263,12 +1915,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - [[package]] name = "subtle" version = "2.6.1" @@ -2277,20 +1923,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.111" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -2314,7 +1949,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -2371,9 +2006,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.23.0" +version = "3.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" +checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c" dependencies = [ "fastrand", "getrandom 0.3.4", @@ -2382,36 +2017,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "terminal_size" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b8cb979cb11c32ce1603f8137b22262a9d131aaa5c37b5678025f22b8becd0" -dependencies = [ - "rustix", - "windows-sys 0.60.2", -] - -[[package]] -name = "thiserror" -version = "2.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.111", -] - [[package]] name = "time" version = "0.3.44" @@ -2438,15 +2043,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" dependencies = [ "displaydoc", - "serde_core", "zerovec", ] [[package]] name = "tokio" -version = "1.48.0" +version = "1.49.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" dependencies = [ "bytes", "libc", @@ -2467,7 +2071,7 @@ checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -2492,9 +2096,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047" +checksum = "32da49809aab5c3bc678af03902d4ccddea2a87d028d86392a4b1560c6906c70" dependencies = [ "futures-core", "pin-project-lite", @@ -2503,9 +2107,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.17" +version = "0.7.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2efa149fe76073d6e8fd97ef4f4eca7b67f599660115591483572e406e165594" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" dependencies = [ "bytes", "futures-core", @@ -2552,7 +2156,7 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -2577,7 +2181,7 @@ dependencies = [ "prost-build", "prost-types", "quote", - "syn 2.0.111", + "syn", "tempfile", "tonic-build", ] @@ -2633,9 +2237,9 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d15d90a0b5c19378952d479dc858407149d7bb45a14de0142f6c534b16fc647" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "log", "pin-project-lite", @@ -2651,14 +2255,14 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] name = "tracing-core" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a04e24fab5c89c6a36eb8558c9656f30d81de51dfa4d3b45f26b21d61fa0a6c" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" dependencies = [ "once_cell", ] @@ -2669,44 +2273,17 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" -[[package]] -name = "type-map" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb30dbbd9036155e74adad6812e9898d03ec374946234fbcebd5dfc7b9187b90" -dependencies = [ - "rustc-hash", -] - [[package]] name = "typenum" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" -[[package]] -name = "unic-langid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28ba52c9b05311f4f6e62d5d9d46f094bd6e84cb8df7b3ef952748d752a7d05" -dependencies = [ - "unic-langid-impl", -] - -[[package]] -name = "unic-langid-impl" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dce1bf08044d4b7a94028c93786f8566047edc11110595914de93362559bc658" -dependencies = [ - "tinystr", -] - [[package]] name = "unicase" -version = "2.8.1" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75b844d17643ee918803943289730bec8aac480150456169e647ed0b576ba539" +checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" [[package]] name = "unicode-ident" @@ -2714,18 +2291,6 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" -[[package]] -name = "unicode-width" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" - -[[package]] -name = "unit-prefix" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81e544489bf3d8ef66c953931f56617f423cd4b5494be343d9b9d3dda037b9a3" - [[package]] name = "untrusted" version = "0.9.0" @@ -2734,9 +2299,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.7" +version = "2.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" dependencies = [ "form_urlencoded", "idna", @@ -2756,70 +2321,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" -[[package]] -name = "uu_cp" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7900736932032ced4815471b4dff36aade3964d79c2682ab4b5d6a7b2b9ce42c" -dependencies = [ - "clap", - "filetime", - "fluent", - "indicatif", - "libc", - "linux-raw-sys", - "thiserror", - "uucore", - "walkdir", - "xattr", -] - -[[package]] -name = "uucore" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7203e48e80ac344450cba5323d8b4a71967ec1e81ae4022775ada90d2b0e08ac" -dependencies = [ - "bigdecimal", - "bstr", - "clap", - "dunce", - "fluent", - "fluent-bundle", - "fluent-syntax", - "glob", - "libc", - "nix", - "num-traits", - "number_prefix", - "os_display", - "thiserror", - "unic-langid", - "uucore_procs", - "walkdir", - "wild", - "winapi-util", - "windows-sys 0.61.2", - "xattr", -] - -[[package]] -name = "uucore_procs" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "449e64ce116ed0cc8c5897bd8706d36aed1ec027b647494df4eae6996d8d59de" -dependencies = [ - "proc-macro2", - "quote", - "uuhelp_parser", -] - -[[package]] -name = "uuhelp_parser" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9e4945611996e885dc4eeae23f3d6f20cfb6e8f4bad4985c2222bbcf9a9745" - [[package]] name = "vcpkg" version = "0.2.15" @@ -2911,7 +2412,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 2.0.111", + "syn", "wasm-bindgen-shared", ] @@ -2934,25 +2435,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "web-time" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "wild" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3131afc8c575281e1e80f36ed6a092aa502c08b18ed7524e86fbbb12bb410e1" -dependencies = [ - "glob", -] - [[package]] name = "winapi-util" version = "0.1.11" @@ -2983,7 +2465,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -2994,7 +2476,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -3229,28 +2711,28 @@ checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", "synstructure", ] [[package]] name = "zerocopy" -version = "0.8.31" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd74ec98b9250adb3ca554bdde269adf631549f51d8a8f8f0a10b50f1cb298c3" +checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.31" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a8d209fdf45cf5138cbb5a506f6b52522a25afccc534d1475dad8e31105c6a" +checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -3270,7 +2752,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", "synstructure", ] @@ -3285,13 +2767,13 @@ dependencies = [ [[package]] name = "zeroize_derive" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -3311,7 +2793,6 @@ version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" dependencies = [ - "serde", "yoke", "zerofrom", "zerovec-derive", @@ -3325,7 +2806,7 @@ checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn", ] [[package]] @@ -3357,9 +2838,15 @@ dependencies = [ [[package]] name = "zlib-rs" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51f936044d677be1a1168fae1d03b583a285a5dd9d8cbf7b24c23aa1fc775235" +checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" + +[[package]] +name = "zmij" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc5a66a20078bf1251bde995aa2fdcc4b800c70b5d92dd2c62abc5c60f679f8" [[package]] name = "zopfli" diff --git a/Cargo.toml b/Cargo.toml index a553349..9d14956 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ axum = "0.8.7" env_logger = "0.11.8" git2 = { version = "0.20.3", features = ["https", "ssh"] } libgit2-sys = { version = "0.18.3", features = ["ssh"] } -libtbr = { git = "https://gitlab.forthrd.io/Pakin/libtbr.git", version = "0.1.1" } +libtbr = { git = "https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/libtbr.git", version = "0.1.1" } log = "0.4.29" prost = "0.14.1" reqwest = { version = "0.12.25", features = ["json"] } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1b4abed --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +FROM rustlang/rust:nightly-slim AS builder + +WORKDIR /app + +# Install build dependencies +RUN apt update && apt install -y \ + musl-tools \ + musl-dev \ + build-essential \ + libssl-dev \ + curl \ + pkg-config \ + ca-certificates \ + protobuf-compiler + +# Copy dependency files first for better caching +COPY Cargo.toml Cargo.lock ./ +COPY ./src ./src +COPY build.rs ./ +COPY tbm-proto ./tbm-proto + +# Download config +RUN curl -X GET https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/tbm-git-repo-service/releases/download/config/.tbcfg -o .tbcfg + +# Build the application +RUN cargo build --release + +# Builder +FROM gcr.io/distroless/cc + +# Copy the binary +COPY --from=builder /app/target/release/tbm-git-repo-service / +COPY --from=builder /app/.tbcfg / + +# Create data directory + +EXPOSE 36583 + +# Environment defaults + +CMD ["./tbm-git-repo-service"] \ No newline at end of file From 9f4fb6c274cb1436cd9b97a9561d5ae67cd94011 Mon Sep 17 00:00:00 2001 From: Pakin Date: Thu, 8 Jan 2026 14:40:58 +0700 Subject: [PATCH 02/21] update dockerfile --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1b4abed..442836b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,8 @@ RUN apt update && apt install -y \ curl \ pkg-config \ ca-certificates \ - protobuf-compiler + protobuf-compiler \ + zlib1g # Copy dependency files first for better caching COPY Cargo.toml Cargo.lock ./ @@ -23,6 +24,7 @@ COPY tbm-proto ./tbm-proto RUN curl -X GET https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/tbm-git-repo-service/releases/download/config/.tbcfg -o .tbcfg # Build the application +ENV RUSTFLAGS="-C target-feature=+crt-static" RUN cargo build --release # Builder From 4e3b561f6136d4c121e3e2da62f35cfbf655c4a3 Mon Sep 17 00:00:00 2001 From: Pakin Date: Fri, 9 Jan 2026 09:46:51 +0700 Subject: [PATCH 03/21] fix: missing token --- src/main.rs | 7 ++++++- src/reg.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2d59208..4ed980a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{fs::File}; +use std::{env, fs::File}; use env_logger::Builder; use libtbr::recipe_functions::common; @@ -27,6 +27,11 @@ async fn setup_registry(config: gcm::Configure) -> gcm::StandardResult { let name = cfg_clone.get("SERVICE_NAME").expect("missing service name"); let url = cfg_clone.get("SERVICE_URL").expect("missing service url"); + let token = cfg_clone.get("REGISTRY_TOKEN").expect("token not provided"); + unsafe { + env::set_var("REGISTRY_TOKEN", token); + } + let mut client = RegistryClient::connect(register_server_address.clone()).await?; reg::register_service(&mut client, name, url).await; diff --git a/src/reg.rs b/src/reg.rs index acac43b..099ead8 100644 --- a/src/reg.rs +++ b/src/reg.rs @@ -1,5 +1,6 @@ use std::time::Duration; +use log::{error, info}; use tokio::time::sleep; use tonic::transport::Channel; @@ -17,7 +18,11 @@ pub async fn register_service(client: &mut RegistryClient, name: &str, token: std::env::var("REGISTRY_TOKEN").unwrap_or_default(), }); - let _ = client.register(req).await; + let resp = client.register(req).await; + match resp { + Ok(r) => info!("{:?}", r), + Err(e) => error!("error register: {:?}", e) + } } pub async fn heartbeat_loop(name: String, url: String) { From 59d0dd7ab40e04c153081464ddb84b5b758ba080 Mon Sep 17 00:00:00 2001 From: Pakin Date: Fri, 9 Jan 2026 11:25:33 +0700 Subject: [PATCH 04/21] feature: enable get root files - allow get files/dirs at root repo --- src/app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 60c80e0..7a739b2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -42,7 +42,7 @@ async fn checkout_handler(State(state): State, Query(param): Query { + legit_path if param.path.contains("/") || state.check_country_existed(param.path.as_str()) || param.path.is_empty() => { let rpath = repo_path.unwrap().clone(); let repo = match Repository::open_bare(rpath) { Ok(repo) => repo, From 2dd165b451a4abd5c5c448e61deba075c572134c Mon Sep 17 00:00:00 2001 From: Pakin Date: Fri, 9 Jan 2026 11:36:50 +0700 Subject: [PATCH 05/21] fix: cannot get file at root --- src/app.rs | 98 +++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/src/app.rs b/src/app.rs index 7a739b2..77f23aa 100644 --- a/src/app.rs +++ b/src/app.rs @@ -41,59 +41,67 @@ async fn checkout_handler(State(state): State, Query(param): Query { - let rpath = repo_path.unwrap().clone(); - let repo = match Repository::open_bare(rpath) { - Ok(repo) => repo, - Err(_) => { - let error_log = "unable to open repo as bare"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) - ); - } - }; - let fpath = format!("master:{}", legit_path); - let obj = match repo.revparse_single(&fpath){ - Ok(obj) => obj, - Err(e) => { - let error_log = format!("unexpected revparse single: {err}", err = e.message()); - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log.clone())); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) - ); - } - }; + let legit_path = param.path.as_str(); - if let Some(blob) = obj.as_blob() { - let content = unsafe { - str::from_utf8_unchecked(blob.content()) - }; - response.insert("result".to_string(), json!(content.to_string())); - } else if let Some(tree) = obj.as_tree() { - let dir_list = tree.iter().map(|x| x.name().unwrap_or("").to_string()).collect::>(); - response.insert("result".to_string(), json!(dir_list)); - } else { - let error_log = "not obj nor tree"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - } - } - _ => { - let error_log = "requested path is unexpected"; + // match param.path.as_str() { + // legit_path if param.path.contains("/") || state.check_country_existed(param.path.as_str()) || param.path.is_empty() => { + + // } + // _ => { + // let error_log = "requested path is unexpected"; + // error!("{error_log}"); + // response.insert("error".to_string(), json!(error_log)); + // } + // } + let rpath = repo_path.unwrap().clone(); + let repo = match Repository::open_bare(rpath) { + Ok(repo) => repo, + Err(_) => { + let error_log = "unable to open repo as bare"; error!("{error_log}"); response.insert("error".to_string(), json!(error_log)); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)) + ); } + }; + + let fpath = format!("master:{}", legit_path); + let obj = match repo.revparse_single(&fpath){ + Ok(obj) => obj, + Err(e) => { + let error_log = format!("unexpected revparse single: {err}", err = e.message()); + error!("{error_log}"); + response.insert("error".to_string(), json!(error_log.clone())); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)) + ); + } + }; + + if let Some(blob) = obj.as_blob() { + let content = unsafe { + str::from_utf8_unchecked(blob.content()) + }; + response.insert("result".to_string(), json!(content.to_string())); + } else if let Some(tree) = obj.as_tree() { + let dir_list = tree.iter().map(|x| x.name().unwrap_or("").to_string()).collect::>(); + response.insert("result".to_string(), json!(dir_list)); + } else { + let error_log = "not obj nor tree"; + error!("{error_log}"); + response.insert("error".to_string(), json!(error_log)); + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!(response)) + ) } ( - axum::http::StatusCode::BAD_REQUEST, + axum::http::StatusCode::OK, Json(json!(response)) ) } From 3043f3001263234e3ea9c45b54684f4c98fc493f Mon Sep 17 00:00:00 2001 From: Pakin Date: Thu, 22 Jan 2026 17:20:03 +0700 Subject: [PATCH 06/21] feat: add commit, push handler - add new feature commit changes and push to remote Signed-off-by: Pakin --- .gitignore | 2 +- Cargo.lock | 237 ++++++++++++------- Cargo.toml | 2 + src/app.rs | 657 ++++++++++++++++++++++++++++++++++++++++------------- 4 files changed, 667 insertions(+), 231 deletions(-) diff --git a/.gitignore b/.gitignore index db92e80..2b1bee5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /target -.tbcfg +.tbcfg* *.txt *.log diff --git a/Cargo.lock b/Cargo.lock index 844e65e..b68a3f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,6 +102,12 @@ dependencies = [ "derive_arbitrary", ] +[[package]] +name = "arcstr" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03918c3dbd7701a85c6b9887732e2921175f26c350b4563841d0958c21d57e6d" + [[package]] name = "async-trait" version = "0.1.89" @@ -177,6 +183,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "axum-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "base64" version = "0.22.1" @@ -221,9 +238,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.51" +version = "1.2.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a0aeaff4ff1a90589618835a598e545176939b97874f7abc7851caa0618f203" +checksum = "755d2fce177175ffca841e9a06afdb2c4ab0f593d53b4dee48147dfaade85932" dependencies = [ "find-msvc-tools", "jobserver", @@ -239,9 +256,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "chrono" -version = "0.4.42" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2" +checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" dependencies = [ "iana-time-zone", "js-sys", @@ -266,6 +283,16 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "combine" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -466,21 +493,20 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "filetime" -version = "0.2.26" +version = "0.2.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0505cd1b6fa6580283f6bdf70a73fcf4aba1184038c90902b92b3dd0df63ed" +checksum = "f98844151eee8917efc50bd9e8318cb963ae8b297431495d3f758616ea5c57db" dependencies = [ "cfg-if", "libc", "libredox", - "windows-sys 0.60.2", ] [[package]] name = "find-msvc-tools" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645cbb3a84e60b7531617d5ae4e57f7e27308f6445f5abf653209ea76dec8dff" +checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" [[package]] name = "fixedbitset" @@ -490,13 +516,13 @@ checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" [[package]] name = "flate2" -version = "1.1.5" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb" +checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369" dependencies = [ "crc32fast", - "libz-rs-sys", "miniz_oxide", + "zlib-rs", ] [[package]] @@ -505,6 +531,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "foreign-types" version = "0.3.2" @@ -566,6 +598,7 @@ dependencies = [ "futures-task", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -580,9 +613,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", "libc", @@ -635,6 +668,15 @@ dependencies = [ "tracing", ] +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + [[package]] name = "hashbrown" version = "0.16.1" @@ -928,7 +970,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.16.1", ] [[package]] @@ -1013,9 +1055,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.83" +version = "0.3.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8" +checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" dependencies = [ "once_cell", "wasm-bindgen", @@ -1029,9 +1071,9 @@ checksum = "2c4a545a15244c7d945065b5d392b2d2d7f21526fba56ce51467b06ed445e8f7" [[package]] name = "libc" -version = "0.2.179" +version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5a2d376baa530d1238d133232d15e239abad80d05838b4b59354e5268af431f" +checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" [[package]] name = "libgit2-sys" @@ -1075,7 +1117,7 @@ dependencies = [ [[package]] name = "libtbr" version = "0.1.1" -source = "git+https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/libtbr.git#9ef23af0fd411c1434d5d8fe967a717eca445b96" +source = "git+https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/libtbr.git#2b6b0626642a41a582864052e909e2585886ff89" dependencies = [ "chrono", "flate2", @@ -1090,15 +1132,6 @@ dependencies = [ "zip", ] -[[package]] -name = "libz-rs-sys" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c10501e7805cee23da17c7790e59df2870c0d4043ec6d03f67d31e2b53e77415" -dependencies = [ - "zlib-rs", -] - [[package]] name = "libz-sys" version = "1.1.23" @@ -1210,12 +1243,31 @@ dependencies = [ "tempfile", ] +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -1322,11 +1374,12 @@ checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "petgraph" -version = "0.7.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3672b37090dbd86368a4145bc067582552b29c27377cad4e0a306c97f9bd7772" +checksum = "8701b58ea97060d5e5b155d383a69952a60943f0e6dfe30b04c287beb0b27455" dependencies = [ "fixedbitset", + "hashbrown 0.15.5", "indexmap", ] @@ -1425,18 +1478,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.105" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "prost" -version = "0.14.1" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7231bd9b3d3d33c86b58adbac74b5ec0ad9f496b19d22801d773636feaa95f3d" +checksum = "d2ea70524a2f82d518bce41317d0fae74151505651af45faf1ffbd6fd33f0568" dependencies = [ "bytes", "prost-derive", @@ -1444,15 +1497,14 @@ dependencies = [ [[package]] name = "prost-build" -version = "0.14.1" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac6c3320f9abac597dcbc668774ef006702672474aad53c6d596b62e487b40b1" +checksum = "343d3bd7056eda839b03204e68deff7d1b13aba7af2b2fd16890697274262ee7" dependencies = [ "heck", "itertools", "log", "multimap", - "once_cell", "petgraph", "prettyplease", "prost", @@ -1466,9 +1518,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.14.1" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9120690fafc389a67ba3803df527d0ec9cbbc9cc45e4cc20b332996dfb672425" +checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b" dependencies = [ "anyhow", "itertools", @@ -1479,9 +1531,9 @@ dependencies = [ [[package]] name = "prost-types" -version = "0.14.1" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9b4db3d6da204ed77bb26ba83b6122a73aeb2e87e25fbf7ad2e84c4ccbf8f72" +checksum = "8991c4cbdb8bc5b11f0b074ffe286c30e523de90fee5ba8132f1399f23cb3dd7" dependencies = [ "prost", ] @@ -1499,9 +1551,9 @@ dependencies = [ [[package]] name = "pulldown-cmark-to-cmark" -version = "21.1.0" +version = "22.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8246feae3db61428fd0bb94285c690b460e4517d83152377543ca802357785f1" +checksum = "50793def1b900256624a709439404384204a5dc3a6ec580281bfaac35e882e90" dependencies = [ "pulldown-cmark", ] @@ -1543,9 +1595,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" dependencies = [ "getrandom 0.3.4", ] @@ -1570,6 +1622,24 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "redis" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfe20977fe93830c0e9817a16fbf1ed1cfd8d4bba366087a1841d2c6033c251" +dependencies = [ + "arcstr", + "combine", + "itoa", + "num-bigint", + "percent-encoding", + "ryu", + "sha1_smol", + "socket2", + "url", + "xxhash-rust", +] + [[package]] name = "redox_syscall" version = "0.5.18" @@ -1665,7 +1735,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.16", + "getrandom 0.2.17", "libc", "untrusted", "windows-sys 0.52.0", @@ -1699,18 +1769,18 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.13.2" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e6f2ab2928ca4291b86736a8bd920a277a399bba1589409d72154ff87c1282" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" dependencies = [ "zeroize", ] [[package]] name = "rustls-webpki" -version = "0.103.8" +version = "0.103.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffdfa2f5286e2247234e03f680868ac2815974dc39e00ea15adc445d0aafe52" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" dependencies = [ "ring", "rustls-pki-types", @@ -1854,6 +1924,12 @@ dependencies = [ "digest", ] +[[package]] +name = "sha1_smol" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfa15b3dddfee50a0fff136974b3e1bde555604ba463834a7eb7deb6417705d" + [[package]] name = "sha2" version = "0.10.9" @@ -1989,12 +2065,14 @@ name = "tbm-git-repo-service" version = "0.1.0" dependencies = [ "axum", + "axum-macros", "env_logger", "git2", "libgit2-sys", "libtbr", "log", "prost", + "redis", "reqwest", "serde", "serde_json", @@ -2019,22 +2097,22 @@ dependencies = [ [[package]] name = "time" -version = "0.3.44" +version = "0.3.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d" +checksum = "f9e442fc33d7fdb45aa9bfeb312c095964abdf596f7567261062b2a7107aaabd" dependencies = [ "deranged", "num-conv", "powerfmt", - "serde", + "serde_core", "time-core", ] [[package]] name = "time-core" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" +checksum = "8b36ee98fd31ec7426d599183e8fe26932a8dc1fb76ddb6214d05493377d34ca" [[package]] name = "tinystr" @@ -2188,9 +2266,9 @@ dependencies = [ [[package]] name = "tower" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" dependencies = [ "futures-core", "futures-util", @@ -2360,18 +2438,18 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.1+wasi-0.2.4" +version = "1.0.2+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" dependencies = [ "wit-bindgen", ] [[package]] name = "wasm-bindgen" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd" +checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" dependencies = [ "cfg-if", "once_cell", @@ -2382,11 +2460,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.56" +version = "0.4.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c" +checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f" dependencies = [ "cfg-if", + "futures-util", "js-sys", "once_cell", "wasm-bindgen", @@ -2395,9 +2474,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3" +checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2405,9 +2484,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40" +checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" dependencies = [ "bumpalo", "proc-macro2", @@ -2418,18 +2497,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.106" +version = "0.2.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4" +checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" dependencies = [ "unicode-ident", ] [[package]] name = "web-sys" -version = "0.3.83" +version = "0.3.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac" +checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598" dependencies = [ "js-sys", "wasm-bindgen", @@ -2672,9 +2751,9 @@ checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" [[package]] name = "wit-bindgen" -version = "0.46.0" +version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" [[package]] name = "writeable" @@ -2692,6 +2771,12 @@ dependencies = [ "rustix", ] +[[package]] +name = "xxhash-rust" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3" + [[package]] name = "yoke" version = "0.8.1" @@ -2844,9 +2929,9 @@ checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" [[package]] name = "zmij" -version = "1.0.12" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fc5a66a20078bf1251bde995aa2fdcc4b800c70b5d92dd2c62abc5c60f679f8" +checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65" [[package]] name = "zopfli" diff --git a/Cargo.toml b/Cargo.toml index 9d14956..24a0aa3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,12 +5,14 @@ edition = "2024" [dependencies] axum = "0.8.7" +axum-macros = "0.5.0" env_logger = "0.11.8" git2 = { version = "0.20.3", features = ["https", "ssh"] } libgit2-sys = { version = "0.18.3", features = ["ssh"] } libtbr = { git = "https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/libtbr.git", version = "0.1.1" } log = "0.4.29" prost = "0.14.1" +redis = "1.0.2" reqwest = { version = "0.12.25", features = ["json"] } serde = { version = "1.0.228", features = ["derive"] } serde_json = { version = "1.0.145", features = ["preserve_order"] } diff --git a/src/app.rs b/src/app.rs index 77f23aa..6a87c2a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,197 +1,546 @@ -use std::collections::HashMap; +use std::{collections::HashMap, sync::Arc}; -use axum::{extract::{Query, State}, response::IntoResponse, routing::get, Json, Router}; -use git2::{Repository, RemoteCallbacks, FetchOptions, Cred}; -use log::{error, warn}; -use libtbr::recipe_functions::common; -use serde::Deserialize; -use serde_json::{json, Value}; +use axum::{ + Json, Router, + extract::{Query, State}, + response::IntoResponse, + routing::{get, post}, +}; +use axum_macros::debug_handler; +use git2::{Cred, FetchOptions, PushOptions, RemoteCallbacks, Repository}; +use libtbr::{models, recipe_functions::common}; +use log::{error, info, warn}; +use redis::TypedCommands; +use serde::{Deserialize, Serialize}; +use serde_json::{Value, json}; +use tokio::sync::Mutex; use crate::{gcm, reg}; #[derive(Clone)] pub struct AppState { - cached_country_names: Vec<&'static str>, - configures: gcm::Configure + // cached_country_names: Vec<&'static str>, + configures: gcm::Configure, + repo: Arc>, + redis: Arc>, } impl AppState { - pub fn check_country_existed(&self, req: &str) -> bool { - self.cached_country_names.contains(&req) - } + // pub fn check_country_existed(&self, req: &str) -> bool { + // self.cached_country_names.contains(&req) + // } - pub fn get_config(&self, config_name: &str) -> Option<&String> { - self.configures.get(config_name) - } + pub fn get_config(&self, config_name: &str) -> Option<&String> { + self.configures.get(config_name) + } + + pub fn get_all_configures(self) -> gcm::Configure { + self.configures.clone() + } } #[derive(Deserialize)] struct CheckoutParams { - path: String + path: String, } -async fn checkout_handler(State(state): State, Query(param): Query) -> impl IntoResponse { - let mut response: HashMap = HashMap::new(); +async fn checkout_handler( + State(state): State, + Query(param): Query, +) -> impl IntoResponse { + let mut response: HashMap = HashMap::new(); - let repo_path = state.get_config("GIT_REPO_LOCAL_DEST"); - if repo_path.is_none() { - response.insert("error".to_string(), json!("config repo dest not found".to_string())); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) - ); - } - - let legit_path = param.path.as_str(); - - // match param.path.as_str() { - // legit_path if param.path.contains("/") || state.check_country_existed(param.path.as_str()) || param.path.is_empty() => { - - // } - // _ => { - // let error_log = "requested path is unexpected"; - // error!("{error_log}"); - // response.insert("error".to_string(), json!(error_log)); - // } - // } - let rpath = repo_path.unwrap().clone(); - let repo = match Repository::open_bare(rpath) { - Ok(repo) => repo, - Err(_) => { - let error_log = "unable to open repo as bare"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) - ); + let repo_path = state.get_config("GIT_REPO_LOCAL_DEST"); + if repo_path.is_none() { + response.insert( + "error".to_string(), + json!("config repo dest not found".to_string()), + ); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)), + ); } - }; - let fpath = format!("master:{}", legit_path); - let obj = match repo.revparse_single(&fpath){ - Ok(obj) => obj, - Err(e) => { - let error_log = format!("unexpected revparse single: {err}", err = e.message()); - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log.clone())); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) - ); - } - }; + let legit_path = param.path.as_str(); - if let Some(blob) = obj.as_blob() { - let content = unsafe { - str::from_utf8_unchecked(blob.content()) + // match param.path.as_str() { + // legit_path if param.path.contains("/") || state.check_country_existed(param.path.as_str()) || param.path.is_empty() => { + + // } + // _ => { + // let error_log = "requested path is unexpected"; + // error!("{error_log}"); + // response.insert("error".to_string(), json!(error_log)); + // } + // } + let rpath = repo_path.unwrap().clone(); + let repo = match Repository::open_bare(rpath) { + Ok(repo) => repo, + Err(_) => { + let error_log = "unable to open repo as bare"; + error!("{error_log}"); + response.insert("error".to_string(), json!(error_log)); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)), + ); + } }; - response.insert("result".to_string(), json!(content.to_string())); - } else if let Some(tree) = obj.as_tree() { - let dir_list = tree.iter().map(|x| x.name().unwrap_or("").to_string()).collect::>(); - response.insert("result".to_string(), json!(dir_list)); - } else { - let error_log = "not obj nor tree"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - return ( - axum::http::StatusCode::BAD_REQUEST, - Json(json!(response)) - ) - } - ( - axum::http::StatusCode::OK, - Json(json!(response)) - ) + let fpath = format!("master:{}", legit_path); + let obj = match repo.revparse_single(&fpath) { + Ok(obj) => obj, + Err(e) => { + let error_log = format!("unexpected revparse single: {err}", err = e.message()); + error!("{error_log}"); + response.insert("error".to_string(), json!(error_log.clone())); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)), + ); + } + }; + + if let Some(blob) = obj.as_blob() { + let content = unsafe { str::from_utf8_unchecked(blob.content()) }; + response.insert("result".to_string(), json!(content.to_string())); + } else if let Some(tree) = obj.as_tree() { + let dir_list = tree + .iter() + .map(|x| x.name().unwrap_or("").to_string()) + .collect::>(); + response.insert("result".to_string(), json!(dir_list)); + } else { + let error_log = "not obj nor tree"; + error!("{error_log}"); + response.insert("error".to_string(), json!(error_log)); + return (axum::http::StatusCode::BAD_REQUEST, Json(json!(response))); + } + + (axum::http::StatusCode::OK, Json(json!(response))) } async fn fetch_handler(State(state): State) -> impl IntoResponse { - let mut response: HashMap = HashMap::new(); - if let Some(repo_path) = state.get_config("GIT_REPO_LOCAL_DEST") { - let rpath = repo_path.clone(); + let mut response: HashMap = HashMap::new(); + if let Some(repo_path) = state.get_config("GIT_REPO_LOCAL_DEST") { + let rpath = repo_path.clone(); - let repo = match Repository::open_bare(rpath) { - Ok(repo) => repo, - Err(_) => { - let error_log = "unable to open bare repo"; + let repo = match Repository::open_bare(rpath) { + Ok(repo) => repo, + Err(_) => { + let error_log = "unable to open bare repo"; + error!("{error_log}"); + response.insert("error".to_string(), json!(error_log)); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)), + ); + } + }; + + let mut remote = match repo.find_remote("origin") { + Ok(remote) => remote, + Err(e) => { + let error_log = format!("unable to find remote, {}", e.message()); + error!("{error_log}"); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)), + ); + } + }; + + if state.get_config("GIT_REPO_USERNAME").is_none() + || state.get_config("GIT_REPO_PASSWORD").is_none() + { + warn!("username or password not provided may cause fetching fail"); + } + + let mut callbacks = RemoteCallbacks::new(); + callbacks.credentials(|_, _, _| { + Cred::userpass_plaintext( + state + .get_config("GIT_REPO_USERNAME") + .unwrap_or(&"".to_string()), + state + .get_config("GIT_REPO_PASSWORD") + .unwrap_or(&"".to_string()), + ) + }); + + let mut fetch_options = FetchOptions::new(); + fetch_options.remote_callbacks(callbacks); + + match remote.fetch(&["origin"], Some(&mut fetch_options), None) { + Ok(_) => {} + Err(e) => { + error!("error while fetching {}", e.message()); + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": format!("error while fetching {}", e.message())})), + ); + } + } + } else { + let error_log = "cannot find local repo"; error!("{error_log}"); response.insert("error".to_string(), json!(error_log)); return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(response)), ); - } - }; - - let mut remote = match repo.find_remote("origin") { - Ok(remote) => remote, - Err(e) => { - let error_log = format!("unable to find remote, {}", e.message()); - error!("{error_log}"); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) - ); - } - }; - - if state.get_config("GIT_REPO_USERNAME").is_none() || state.get_config("GIT_REPO_PASSWORD").is_none() { - warn!("username or password not provided may cause fetching fail"); } - let mut callbacks = RemoteCallbacks::new(); - callbacks.credentials(|_, _, _| { - Cred::userpass_plaintext( - state.get_config("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), - state.get_config("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()) - ) - }); + ( + axum::http::StatusCode::OK, + Json(json!({"result": "fetch success"})), + ) +} - let mut fetch_options = FetchOptions::new(); - fetch_options.remote_callbacks(callbacks); +// { path: "/path/to/file", signature: { +// username: "", email: "" +// }, patch_key: "edit_id_from_redis"} +#[derive(Deserialize)] +struct CommitBody { + // Actual file path + path: String, + // Signature of user + signature: Signature, + // Key to grep content changes from redis + patch_key: String, + // user message + message: Option, + #[serde(flatten)] + extra: HashMap, +} - match remote.fetch(&["origin"], Some(&mut fetch_options), None) { - Ok(_) => {} - Err(e) => { - error!("error while fetching {}", e.message()); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!({"error": format!("error while fetching {}", e.message())})) - ); - } +#[derive(Deserialize)] +struct Signature { + username: String, + email: String, +} + +#[debug_handler] +async fn commit_handler( + State(state): State, + // request body + Json(payload): Json, +) -> impl IntoResponse { + let mut content = match fetch_content_from_redis(state.redis.clone(), &payload.patch_key).await + { + Ok(c) => c, + Err(e) => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!({"error": e})), + ); + } + }; + + let is_patch_file = content.starts_with("patch"); + // do apply patch first + if is_patch_file { + content = apply_patch_to_file(state.redis.clone(), &payload.path, &mut content).await; } - } else { - let error_log = "cannot find local repo"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)) - ); - } - ( - axum::http::StatusCode::OK, - Json(json!({"result": "fetch success"})) - ) + let commit_oid = match commit_file_content( + state.repo, + &payload.path, + &content.as_bytes(), + payload.signature, + &payload.message.unwrap_or("update: from api".to_string()), + ) + .await + { + Ok(oid) => oid, + Err(e) => { + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": e.to_string()})), + ); + } + }; + + // save history + let redis_pre_lock = state.redis.clone(); + { + if let Ok(mut rl) = redis_pre_lock.try_lock() { + let _ = rl.rpush(format!("{}.history", payload.path), payload.patch_key); + } + } + + ( + axum::http::StatusCode::OK, + Json(json!({"result": format!("{commit_oid}")})), + ) +} + +async fn fetch_content_from_redis( + redis: Arc>, + key: &str, +) -> Result { + match redis.lock().await.get(key) { + Ok(s) => { + if let Some(res) = s { + Ok(res) + } else { + Err(format!("result error from key: {key}")) + } + } + Err(e) => Err(format!("redis get failed: {e}")), + } +} + +fn read_patch_from_str(patch_changes: &str) -> Option { + // + + let pv = patch_changes.replace("patch ", ""); + + let change_map: Value = match serde_json::from_str(&pv) { + Ok(s) => s, + Err(_) => return None, + }; + Some(change_map) +} + +fn get_product_code(v: &Value) -> Option<&str> { + v.get("productCode")?.as_str() +} + +fn diff_apply(target: &mut Value, patch: &Value) -> Result<(), String> { + match (target, patch) { + (Value::Object(target_map), Value::Object(patch_map)) => { + for (k, v_patch) in patch_map { + let v_target = target_map + .get_mut(k) + .ok_or_else(|| format!("Unknown key in patch: {k}"))?; + + diff_apply(v_target, v_patch)?; + } + + Ok(()) + } + (Value::Array(target_arr), Value::Array(patch_arr)) => { + for patch_elem in patch_arr { + // NOTE: support only `Recipe01` + let patch_id = get_product_code(patch_elem) + .ok_or("Patch array element missing product code")?; + let target_elem = target_arr + .iter_mut() + .find(|e| get_product_code(e) == Some(patch_id)) + .ok_or_else(|| format!("Unknown id in patch array: {patch_id}"))?; + + diff_apply(target_elem, patch_elem)?; + } + + Ok(()) + } + (target_slot, patch_value) => { + *target_slot = patch_value.clone(); + Ok(()) + } + } +} + +async fn apply_patch_to_file( + redis: Arc>, + path: &str, + patch_changes: &mut String, +) -> String { + use libtbr::*; + // expect the path to already has in redis + let full_file = match fetch_content_from_redis(redis, path).await { + Ok(f) => f, + Err(_) => String::new(), + }; + + if full_file.is_empty() { + return full_file; + } + + // read into struct + // + let full_recipe: models::recipe::Recipe = match serde_json::from_str(&full_file) { + Ok(f) => f, + Err(_) => return String::new(), + }; + + // read patch + let patch_map = read_patch_from_str(patch_changes); + let mut current_full_map = match serde_json::to_value(full_recipe.clone()) { + Ok(m) => m, + Err(_) => return String::new(), + }; + + if let Some(pm) = patch_map { + match diff_apply(&mut current_full_map, &pm) { + Ok(_) => {} + Err(x) => { + error!("error while applied patch: {x}"); + } + } + } + + match serde_json::to_string(¤t_full_map.clone()) { + Ok(ss) => ss, + Err(_) => String::new(), + } +} + +async fn commit_file_content( + repo: Arc>, + path: &str, + content: &[u8], + author: Signature, + message: &str, +) -> Result> { + let repo_clone = repo.clone(); + let blob_oid = repo_clone.lock().await.blob(content)?; + info!("blob oid: {blob_oid}"); + let mut index = repo_clone.lock().await.index()?; + info!("index pass"); + let rlock = repo_clone.try_lock()?; + let parent = match rlock.head() { + Ok(head) => { + let commit = head.peel_to_commit()?; + index.read_tree(&commit.tree()?)?; + Some(commit.clone()) + } + Err(_) => None, + }; + + info!("parent pass"); + + index.add(&git2::IndexEntry { + ctime: git2::IndexTime::new(0, 0), + mtime: git2::IndexTime::new(0, 0), + dev: 0, + ino: 0, + mode: 0o100644, + uid: 0, + gid: 0, + file_size: content.len() as u32, + id: blob_oid, + flags: 0, + flags_extended: 0, + path: path.as_bytes().to_vec(), + })?; + + info!("index added"); + + let tree_oid = index.write_tree()?; + + info!("write to tree"); + // let tlock = repo_clone.try_lock()?; + info!("acquire try lock"); + let tree = rlock.find_tree(tree_oid)?; + info!("find tree ok"); + + let sig = git2::Signature::now(&author.username, &author.email)?; + info!("generated signature"); + + let parents: Vec<&git2::Commit> = parent.iter().collect(); + let oid = rlock.commit( + Some("refs/heads/master"), + &sig, + &sig, + message, + &tree, + &parents, + )?; + + info!("commit oid: {oid}"); + + Ok(oid) +} + +async fn push_handler(State(state): State) -> impl IntoResponse { + let config = state.clone().get_all_configures(); + let repo = state.repo.clone(); + let remote_name = match state.get_config("GIT_REPO_REMOTE") { + Some(s) => s, + None => { + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": "repo remote not existed"})), + ); + } + }; + + let branch = "master"; + + if let Err(e) = push(config, repo, remote_name, branch) { + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": e.to_string()})), + ); + } + + ( + axum::http::StatusCode::OK, + Json(json!({"result": "push completed"})), + ) +} + +fn push( + config: gcm::Configure, + repo: Arc>, + remote_name: &str, + branch: &str, +) -> Result<(), Box> { + if let Ok(rlock) = repo.try_lock() { + let mut rem = rlock.find_remote(remote_name)?; + let mut callback = RemoteCallbacks::new(); + callback.credentials(|_url, _user, _allowed| { + Cred::userpass_plaintext( + config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), + config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()), + ) + }); + let mut push_opts = PushOptions::new(); + push_opts.remote_callbacks(callback); + let refspec = format!("refs/heads/{0}:refs/heads/{0}", branch); + rem.push(&[&refspec], Some(&mut push_opts))?; + + return Ok(()); + } + + Err("cannot lock repo".into()) } pub async fn run(config: gcm::Configure) -> gcm::StandardResult { - let state = AppState { - cached_country_names: common::valid_country_name(), - configures: config.clone() - }; + let state = AppState { + // cached_country_names: common::valid_country_name(), + configures: config.clone(), + repo: Arc::new(Mutex::new(Repository::open_bare( + config.get("GIT_REPO_LOCAL_DEST").unwrap_or(&"".to_string()), + )?)), + redis: Arc::new(Mutex::new(redis::Client::open(format!( + "redis://{}:{}", + config.get("REDIS_URI").unwrap_or(&"".to_string()), + config.get("REDIS_PORT").unwrap_or(&"".to_string()) + ))?)), + }; - let app = Router::new() - .route("/checkout", get(checkout_handler)) - .route("/fetch", get(fetch_handler)) - .route("/healthz", get(reg::health)) - .with_state(state); + let app = Router::new() + .route("/checkout", get(checkout_handler)) + .route("/fetch", get(fetch_handler)) + .route("/commit", post(commit_handler)) + .route("/push", get(push_handler)) + .route("/healthz", get(reg::health)) + .with_state(state); - let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", config.clone().get("PUBLIC_PORT").unwrap_or(&"36583".to_string()))).await?; + let listener = tokio::net::TcpListener::bind(format!( + "0.0.0.0:{}", + config + .clone() + .get("PUBLIC_PORT") + .unwrap_or(&"36583".to_string()) + )) + .await?; - axum::serve(listener, app).await?; + axum::serve(listener, app).await?; - Ok(()) -} \ No newline at end of file + Ok(()) +} From 03263815e6b45ada54475b3a65812e903fff8112 Mon Sep 17 00:00:00 2001 From: Pakin Date: Mon, 2 Feb 2026 14:12:16 +0700 Subject: [PATCH 07/21] feat: fetch from cache if existed Signed-off-by: Pakin --- src/app.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++---- src/main.rs | 66 ++++++++++++++++++++++++++++++++--------------------- 2 files changed, 98 insertions(+), 31 deletions(-) diff --git a/src/app.rs b/src/app.rs index 6a87c2a..5a6dcc6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -8,10 +8,10 @@ use axum::{ }; use axum_macros::debug_handler; use git2::{Cred, FetchOptions, PushOptions, RemoteCallbacks, Repository}; -use libtbr::{models, recipe_functions::common}; + use log::{error, info, warn}; use redis::TypedCommands; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; use serde_json::{Value, json}; use tokio::sync::Mutex; @@ -23,6 +23,8 @@ pub struct AppState { configures: gcm::Configure, repo: Arc>, redis: Arc>, + // save already fetched path, further calls should fetch from redis instead. + fetched: Vec, } impl AppState { @@ -45,11 +47,30 @@ struct CheckoutParams { } async fn checkout_handler( - State(state): State, + State(mut state): State, Query(param): Query, ) -> impl IntoResponse { let mut response: HashMap = HashMap::new(); + // quick response from redis + if let Ok(mut rcli) = state.redis.try_lock() + && state + .fetched + .contains(¶m.path.clone().as_str().to_string()) + { + if let Ok(res) = rcli.get(param.path.clone().as_str().to_string()) { + match res { + Some(res) => { + response.insert("result".to_string(), json!(res)); + return (axum::http::StatusCode::OK, Json(json!(response))); + } + None => { + // continue + } + } + } + } + let repo_path = state.get_config("GIT_REPO_LOCAL_DEST"); if repo_path.is_none() { response.insert( @@ -105,12 +126,22 @@ async fn checkout_handler( if let Some(blob) = obj.as_blob() { let content = unsafe { str::from_utf8_unchecked(blob.content()) }; response.insert("result".to_string(), json!(content.to_string())); + + if let Ok(mut rcli) = state.redis.try_lock() { + let _ = rcli.set(legit_path.to_string(), content.to_string()); + state.fetched.push(legit_path.to_string()); + } } else if let Some(tree) = obj.as_tree() { let dir_list = tree .iter() .map(|x| x.name().unwrap_or("").to_string()) .collect::>(); response.insert("result".to_string(), json!(dir_list)); + + if let Ok(mut rcli) = state.redis.try_lock() { + let _ = rcli.set(legit_path.to_string(), dir_list.join(",")); + state.fetched.push(legit_path.to_string()); + } } else { let error_log = "not obj nor tree"; error!("{error_log}"); @@ -123,7 +154,7 @@ async fn checkout_handler( async fn fetch_handler(State(state): State) -> impl IntoResponse { let mut response: HashMap = HashMap::new(); - if let Some(repo_path) = state.get_config("GIT_REPO_LOCAL_DEST") { + if let Some(repo_path) = state.clone().get_config("GIT_REPO_LOCAL_DEST") { let rpath = repo_path.clone(); let repo = match Repository::open_bare(rpath) { @@ -192,12 +223,33 @@ async fn fetch_handler(State(state): State) -> impl IntoResponse { ); } + tokio::spawn(async move { + let _ = broadcast_need_update_new_data_after_fetch(state.clone()).await; + }); + ( axum::http::StatusCode::OK, Json(json!({"result": "fetch success"})), ) } +// refetch data after request `/fetch` +async fn broadcast_need_update_new_data_after_fetch( + state: AppState, +) -> Result<(), Box> { + // clear out saved state, user must request again + // state.fetched.clear(); // ----> background fetch into redis + // + // + let state_cl = state.clone(); + let mut rcli = state_cl.redis.try_lock()?; + for s in state.fetched { + let _ = rcli.publish("recipe_repo_news", s); + } + + Ok(()) +} + // { path: "/path/to/file", signature: { // username: "", email: "" // }, patch_key: "edit_id_from_redis"} @@ -382,7 +434,7 @@ async fn apply_patch_to_file( } } - match serde_json::to_string(¤t_full_map.clone()) { + match serde_json::to_string_pretty(¤t_full_map.clone()) { Ok(ss) => ss, Err(_) => String::new(), } @@ -521,6 +573,7 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { config.get("REDIS_URI").unwrap_or(&"".to_string()), config.get("REDIS_PORT").unwrap_or(&"".to_string()) ))?)), + fetched: Vec::new(), }; let app = Router::new() diff --git a/src/main.rs b/src/main.rs index 4ed980a..a201bfd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,10 @@ use env_logger::Builder; use libtbr::recipe_functions::common; use log::info; -use crate::{git::setup_git_repo, reg::{heartbeat_loop, registry::registry_client::RegistryClient}}; +use crate::{ + git::setup_git_repo, + reg::{heartbeat_loop, registry::registry_client::RegistryClient}, +}; mod app; mod gcm; @@ -12,49 +15,60 @@ mod git; mod reg; fn setup_log(config: gcm::Configure) -> gcm::StandardResult { - let logfile = File::create(config.get("LOG_NAME").unwrap_or(&"run.log".to_string()))?; + let logfile = File::create(config.get("LOG_NAME").unwrap_or(&"run.log".to_string()))?; - Builder::from_env(env_logger::Env::default().default_filter_or("debug")) - .target(env_logger::Target::Pipe(Box::new(logfile))).init(); + Builder::from_env(env_logger::Env::default().default_filter_or("debug")) + .target(env_logger::Target::Pipe(Box::new(logfile))) + .init(); - - Ok(()) + Ok(()) } async fn setup_registry(config: gcm::Configure) -> gcm::StandardResult { - let cfg_clone = config.clone(); - let register_server_address = cfg_clone.get("REGISTRY_SERVER").expect("not found registry server"); - let name = cfg_clone.get("SERVICE_NAME").expect("missing service name"); - let url = cfg_clone.get("SERVICE_URL").expect("missing service url"); + let cfg_clone = config.clone(); + let register_server_address = cfg_clone + .get("REGISTRY_SERVER") + .expect("not found registry server"); + let name = cfg_clone.get("SERVICE_NAME").expect("missing service name"); + let url = cfg_clone.get("SERVICE_URL").expect("missing service url"); - let token = cfg_clone.get("REGISTRY_TOKEN").expect("token not provided"); - unsafe { - env::set_var("REGISTRY_TOKEN", token); - } + let token = cfg_clone.get("REGISTRY_TOKEN").expect("token not provided"); + unsafe { + env::set_var("REGISTRY_TOKEN", token); + } - let mut client = RegistryClient::connect(register_server_address.clone()).await?; - reg::register_service(&mut client, name, url).await; + let mut client = RegistryClient::connect(register_server_address.clone()).await?; + reg::register_service(&mut client, name, url).await; - tokio::spawn(heartbeat_loop(name.to_string(), url.to_string())); + tokio::spawn(heartbeat_loop(name.to_string(), url.to_string())); - Ok(()) + Ok(()) } - - #[tokio::main] async fn main() -> gcm::StandardResult { let config: gcm::Configure = common::get_config(); setup_log(config.clone())?; match std::fs::read_dir(config.get("GIT_REPO_LOCAL_DEST").expect("not exist")) { - Ok(_) => { - info!("GIT_REPO `{dest}` already setup", dest = config.get("GIT_REPO_LOCAL_DEST").unwrap()) - }, - Err(_) => { - setup_git_repo(config.clone())?; - } + Ok(_) => { + info!( + "GIT_REPO `{dest}` already setup", + dest = config.get("GIT_REPO_LOCAL_DEST").unwrap() + ) + } + Err(_) => { + setup_git_repo(config.clone())?; + } } + + info!( + "APP VERSION: {}", + config + .get("CONFIG_VERSION") + .expect("config version not defined") + ); + setup_registry(config.clone()).await?; app::run(config.clone()).await?; From a2da030a9958de50066eb2da190e4cb87fa22e1e Mon Sep 17 00:00:00 2001 From: Pakin Date: Tue, 17 Feb 2026 14:23:31 +0700 Subject: [PATCH 08/21] add tx, cold boot --- Cargo.lock | 174 +++++++++++++++- Cargo.toml | 10 +- src/app.rs | 522 ++++++++++++++++++++++++++++++++++++++++------ src/main.rs | 30 +-- src/tx/handler.rs | 323 ++++++++++++++++++++++++++++ src/tx/helpers.rs | 294 ++++++++++++++++++++++++++ src/tx/mod.rs | 4 + src/tx/patcher.rs | 119 +++++++++++ src/tx/types.rs | 51 +++++ 9 files changed, 1433 insertions(+), 94 deletions(-) create mode 100644 src/tx/handler.rs create mode 100644 src/tx/helpers.rs create mode 100644 src/tx/mod.rs create mode 100644 src/tx/patcher.rs create mode 100644 src/tx/types.rs diff --git a/Cargo.lock b/Cargo.lock index b68a3f5..90a1483 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "android_system_properties" version = "0.1.5" @@ -108,6 +123,18 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03918c3dbd7701a85c6b9887732e2921175f26c350b4563841d0958c21d57e6d" +[[package]] +name = "async-compression" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68650b7df54f0293fd061972a0fb05aaf4fc0879d3b3d21a638a182c5c543b9f" +dependencies = [ + "compression-codecs", + "compression-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "async-trait" version = "0.1.89" @@ -200,6 +227,28 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "bb8" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "457d7ed3f888dfd2c7af56d4975cade43c622f74bdcddfed6d4352f57acc6310" +dependencies = [ + "futures-util", + "parking_lot", + "portable-atomic", + "tokio", +] + +[[package]] +name = "bb8-redis" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1063effc7f6cf848bcbcc6e31b5962be75215835587d3109607c643d616f66" +dependencies = [ + "bb8", + "redis", +] + [[package]] name = "bitflags" version = "2.10.0" @@ -215,6 +264,27 @@ dependencies = [ "generic-array", ] +[[package]] +name = "brotli" +version = "8.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bd8b9603c7aa97359dbd97ecf258968c95f3adddd6db2f7e7a5bef101c84560" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "874bb8112abecc98cbd6d81ea4fa7e94fb9449648c93cc89aa40c81c24d7de03" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bumpalo" version = "3.19.1" @@ -223,9 +293,9 @@ checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" [[package]] name = "bytes" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" [[package]] name = "bzip2" @@ -290,9 +360,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" dependencies = [ "bytes", + "futures-core", "memchr", + "pin-project-lite", + "tokio", + "tokio-util", ] +[[package]] +name = "compression-codecs" +version = "0.4.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00828ba6fd27b45a448e57dbfe84f1029d4c9f26b368157e9a448a5f49a2ec2a" +dependencies = [ + "brotli", + "compression-core", +] + +[[package]] +name = "compression-core" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75984efb6ed102a0d42db99afb6c1948f0380d1d91808d5529916e6c08b49d8d" + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -576,6 +666,17 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "futures-sink" version = "0.3.31" @@ -595,6 +696,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-core", + "futures-macro", + "futures-sink", "futures-task", "pin-project-lite", "pin-utils", @@ -1063,6 +1166,28 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json-patch" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f300e415e2134745ef75f04562dd0145405c2f7fd92065db029ac4b16b57fe90" +dependencies = [ + "jsonptr", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "jsonptr" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5a3cc660ba5d72bce0b3bb295bf20847ccbb40fd423f3f05b61273672e561fe" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "libbz2-rs-sys" version = "0.2.2" @@ -1629,13 +1754,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfe20977fe93830c0e9817a16fbf1ed1cfd8d4bba366087a1841d2c6033c251" dependencies = [ "arcstr", + "bytes", + "cfg-if", "combine", + "futures-util", "itoa", "num-bigint", "percent-encoding", + "pin-project-lite", "ryu", "sha1_smol", "socket2", + "tokio", + "tokio-util", "url", "xxhash-rust", ] @@ -2064,10 +2195,16 @@ dependencies = [ name = "tbm-git-repo-service" version = "0.1.0" dependencies = [ + "async-compression", "axum", "axum-macros", + "bb8", + "bb8-redis", + "bytes", "env_logger", + "futures-util", "git2", + "json-patch", "libgit2-sys", "libtbr", "log", @@ -2077,9 +2214,11 @@ dependencies = [ "serde", "serde_json", "tokio", + "tokio-util", "tonic", "tonic-prost", "tonic-prost-build", + "uuid", ] [[package]] @@ -2095,6 +2234,26 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "time" version = "0.3.45" @@ -2399,6 +2558,17 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "uuid" +version = "1.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee48d38b119b0cd71fe4141b30f5ba9c7c5d9f4e7a3a8b4a674e4b6ef789976f" +dependencies = [ + "getrandom 0.3.4", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 24a0aa3..1b72069 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,21 +4,29 @@ version = "0.1.0" edition = "2024" [dependencies] +async-compression = { version = "0.4.39", features = ["tokio", "brotli"] } axum = "0.8.7" axum-macros = "0.5.0" +bb8 = "0.9.1" +bb8-redis = "0.26.0" +bytes = "1.11.1" env_logger = "0.11.8" +futures-util = "0.3.31" git2 = { version = "0.20.3", features = ["https", "ssh"] } +json-patch = "4.1.0" libgit2-sys = { version = "0.18.3", features = ["ssh"] } libtbr = { git = "https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/libtbr.git", version = "0.1.1" } log = "0.4.29" prost = "0.14.1" -redis = "1.0.2" +redis = { version = "1.0.2", features = ["tokio-comp"] } reqwest = { version = "0.12.25", features = ["json"] } serde = { version = "1.0.228", features = ["derive"] } serde_json = { version = "1.0.145", features = ["preserve_order"] } tokio = { version = "1.48.0", features = ["full"] } +tokio-util = { version = "0.7.18", features = ["io"] } tonic = { version = "0.14.2", features = ["transport"] } tonic-prost = "0.14.2" +uuid = { version = "1.20.0", features = ["v4"] } [build-dependencies] tonic-prost-build = "0.14.2" diff --git a/src/app.rs b/src/app.rs index 5a6dcc6..108d9a2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,5 +1,6 @@ -use std::{collections::HashMap, sync::Arc}; +use std::{collections::HashMap, io::Cursor, sync::Arc, time::Duration}; +use async_compression::tokio::bufread::BrotliEncoder; use axum::{ Json, Router, extract::{Query, State}, @@ -7,24 +8,53 @@ use axum::{ routing::{get, post}, }; use axum_macros::debug_handler; +use bb8::Pool; +use bb8_redis::RedisConnectionManager; use git2::{Cred, FetchOptions, PushOptions, RemoteCallbacks, Repository}; use log::{error, info, warn}; -use redis::TypedCommands; +use redis::{AsyncTypedCommands, TypedCommands, aio::MultiplexedConnection}; use serde::Deserialize; use serde_json::{Value, json}; -use tokio::sync::Mutex; +use tokio::{ + io::{AsyncReadExt, BufReader}, + sync::{ + Mutex, + mpsc::{Receiver, Sender, channel}, + }, + task::JoinSet, +}; -use crate::{gcm, reg}; +use uuid::Uuid; + +use crate::{ + gcm, + tx::{ + self, + helpers::{doc_snap_key, doc_tx_stream_key, doc_ver_key, now_unix}, + patcher::apply_ops, + types::PatchOp, + }, +}; + +type RedisPool = Pool; + +#[derive(Debug, Clone)] +pub struct CacheJob { + pub rel_path: String, + pub file_data: Option, +} #[derive(Clone)] pub struct AppState { // cached_country_names: Vec<&'static str>, configures: gcm::Configure, repo: Arc>, - redis: Arc>, + redis: RedisPool, // save already fetched path, further calls should fetch from redis instead. fetched: Vec, + // queue + enqueue_tx: Sender, } impl AppState { @@ -41,7 +71,7 @@ impl AppState { } } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] struct CheckoutParams { path: String, } @@ -52,21 +82,24 @@ async fn checkout_handler( ) -> impl IntoResponse { let mut response: HashMap = HashMap::new(); + // println!( + // "req: {param:?}, has_cached: {}, saved: {:?}", + // state + // .fetched + // .contains(¶m.path.clone().as_str().to_string()), + // state.fetched.clone() + // ); + // quick response from redis - if let Ok(mut rcli) = state.redis.try_lock() + if let Ok(mut conn) = state.redis.get().await && state .fetched .contains(¶m.path.clone().as_str().to_string()) { - if let Ok(res) = rcli.get(param.path.clone().as_str().to_string()) { - match res { - Some(res) => { - response.insert("result".to_string(), json!(res)); - return (axum::http::StatusCode::OK, Json(json!(response))); - } - None => { - // continue - } + if let Ok(res) = conn.get(param.path.clone().as_str().to_string()).await { + if let Some(res) = res { + response.insert("result".to_string(), json!(res)); + return (axum::http::StatusCode::OK, Json(json!(response))); } } } @@ -109,7 +142,14 @@ async fn checkout_handler( } }; - let fpath = format!("master:{}", legit_path); + let fpath = format!( + "{}:{}", + state + .get_config("GIT_REPO_BRANCH_NAME") + .map(|x| x.to_string()) + .unwrap_or("master".to_string()), + legit_path + ); let obj = match repo.revparse_single(&fpath) { Ok(obj) => obj, Err(e) => { @@ -127,10 +167,12 @@ async fn checkout_handler( let content = unsafe { str::from_utf8_unchecked(blob.content()) }; response.insert("result".to_string(), json!(content.to_string())); - if let Ok(mut rcli) = state.redis.try_lock() { - let _ = rcli.set(legit_path.to_string(), content.to_string()); - state.fetched.push(legit_path.to_string()); - } + return (axum::http::StatusCode::OK, Json(json!(content))); + + // if let Ok(mut conn) = state.redis.get().await { + // let _ = conn.set(legit_path.to_string(), content.to_string()).await; + // state.fetched.push(legit_path.to_string()); + // } } else if let Some(tree) = obj.as_tree() { let dir_list = tree .iter() @@ -138,10 +180,12 @@ async fn checkout_handler( .collect::>(); response.insert("result".to_string(), json!(dir_list)); - if let Ok(mut rcli) = state.redis.try_lock() { - let _ = rcli.set(legit_path.to_string(), dir_list.join(",")); - state.fetched.push(legit_path.to_string()); - } + return (axum::http::StatusCode::OK, Json(json!(dir_list))); + + // if let Ok(mut conn) = state.redis.get().await { + // let _ = conn.set(legit_path.to_string(), dir_list.join(",")).await; + // state.fetched.push(legit_path.to_string()); + // } } else { let error_log = "not obj nor tree"; error!("{error_log}"); @@ -149,7 +193,9 @@ async fn checkout_handler( return (axum::http::StatusCode::BAD_REQUEST, Json(json!(response))); } - (axum::http::StatusCode::OK, Json(json!(response))) + // println!("checkout response: {response:?}"); + + // (axum::http::StatusCode::OK, Json(json!(response))) } async fn fetch_handler(State(state): State) -> impl IntoResponse { @@ -223,9 +269,9 @@ async fn fetch_handler(State(state): State) -> impl IntoResponse { ); } - tokio::spawn(async move { - let _ = broadcast_need_update_new_data_after_fetch(state.clone()).await; - }); + // tokio::spawn(async move { + // let _ = broadcast_need_update_new_data_after_fetch(state.clone()).await; + // }); ( axum::http::StatusCode::OK, @@ -234,21 +280,21 @@ async fn fetch_handler(State(state): State) -> impl IntoResponse { } // refetch data after request `/fetch` -async fn broadcast_need_update_new_data_after_fetch( - state: AppState, -) -> Result<(), Box> { - // clear out saved state, user must request again - // state.fetched.clear(); // ----> background fetch into redis - // - // - let state_cl = state.clone(); - let mut rcli = state_cl.redis.try_lock()?; - for s in state.fetched { - let _ = rcli.publish("recipe_repo_news", s); - } +// async fn broadcast_need_update_new_data_after_fetch( +// state: AppState, +// ) -> Result<(), Box> { +// // clear out saved state, user must request again +// // state.fetched.clear(); // ----> background fetch into redis +// // +// // +// let state_cl = state.clone(); +// let mut rcli = state_cl.redis.try_lock()?; +// for s in state.fetched { +// let _ = rcli.publish("recipe_repo_news", s); +// } - Ok(()) -} +// Ok(()) +// } // { path: "/path/to/file", signature: { // username: "", email: "" @@ -297,11 +343,16 @@ async fn commit_handler( } let commit_oid = match commit_file_content( - state.repo, + state.clone().repo, &payload.path, &content.as_bytes(), payload.signature, &payload.message.unwrap_or("update: from api".to_string()), + state + .clone() + .get_config("GIT_REPO_BRANCH_NAME") + .map(|x| x.to_string()) + .unwrap_or("master".to_string()), ) .await { @@ -317,7 +368,7 @@ async fn commit_handler( // save history let redis_pre_lock = state.redis.clone(); { - if let Ok(mut rl) = redis_pre_lock.try_lock() { + if let Ok(mut rl) = redis_pre_lock.get().await { let _ = rl.rpush(format!("{}.history", payload.path), payload.patch_key); } } @@ -328,13 +379,12 @@ async fn commit_handler( ) } -async fn fetch_content_from_redis( - redis: Arc>, - key: &str, -) -> Result { - match redis.lock().await.get(key) { - Ok(s) => { - if let Some(res) = s { +async fn fetch_content_from_redis(redis: RedisPool, key: &str) -> Result { + match redis.get().await { + Ok(mut s) => { + if let Ok(res) = s.get(key).await + && let Some(res) = res + { Ok(res) } else { Err(format!("result error from key: {key}")) @@ -395,11 +445,7 @@ fn diff_apply(target: &mut Value, patch: &Value) -> Result<(), String> { } } -async fn apply_patch_to_file( - redis: Arc>, - path: &str, - patch_changes: &mut String, -) -> String { +async fn apply_patch_to_file(redis: RedisPool, path: &str, patch_changes: &mut String) -> String { use libtbr::*; // expect the path to already has in redis let full_file = match fetch_content_from_redis(redis, path).await { @@ -446,6 +492,7 @@ async fn commit_file_content( content: &[u8], author: Signature, message: &str, + branch: String, ) -> Result> { let repo_clone = repo.clone(); let blob_oid = repo_clone.lock().await.blob(content)?; @@ -494,7 +541,8 @@ async fn commit_file_content( let parents: Vec<&git2::Commit> = parent.iter().collect(); let oid = rlock.commit( - Some("refs/heads/master"), + //"refs/heads/master" + Some(&format!("refs/heads/{branch}")), &sig, &sig, message, @@ -520,7 +568,10 @@ async fn push_handler(State(state): State) -> impl IntoResponse { } }; - let branch = "master"; + let branch = &config + .get("GIT_REPO_BRANCH_NAME") + .map(|x| x.to_string()) + .unwrap_or("master".to_string()); if let Err(e) = push(config, repo, remote_name, branch) { return ( @@ -561,27 +612,242 @@ fn push( Err("cannot lock repo".into()) } +/// Return git state & server state +async fn health_handler(State(_): State) -> impl IntoResponse { + ( + axum::http::StatusCode::OK, + Json(json!({ + "status": "ok", + "git": "", + "server": "" + })), + ) +} + +async fn handle_system_message(redis: Arc>, mut msg: serde_json::Value) { + let topic = if let Some(t) = msg["topic"].as_str() { + t + } else { + "" + }; + + match topic { + "generate_stx" => { + // expect target, base_version, value + let target = msg["target"].as_str().unwrap_or("").to_string(); + let base_version = msg["base_version"].as_str().unwrap_or("").to_string(); + let full_base_filename = msg["full_base_filename"].as_str().unwrap_or("").to_string(); + let value = msg["value"].take(); + + let rclone = redis.clone(); + let mut rcli = rclone.lock().await; + + let doc_id = format!("{target}_{base_version}"); + let doc_version_key = doc_ver_key(&doc_id); + let doc_snap = doc_snap_key(&doc_id); + + let _ = rcli.set( + format!("{target}/{full_base_filename}"), + serde_json::to_string(&value).unwrap_or("".to_string()), + ); + + let _ = rcli.set(format!("{target}/version"), base_version); + + info!("publish {full_base_filename} as main file"); + + // create commit transaction base + + let mut con = match rcli.get_multiplexed_async_connection().await { + Ok(conn) => conn, + Err(e) => { + return; + } + }; + + let stream_key = doc_tx_stream_key(&doc_id); + let tx_event = json!({ + "doc_id": doc_id, + "tx_id": Uuid::new_v4().to_string(), + "version": 1, + "base_version": 0, + "author": "from stx", + "ts": now_unix(), + "ops": vec![ + PatchOp::Add { path: "/".to_string(), value: value.clone() } + ] + }); + + let tx_str = tx_event.to_string(); + + let _: String = redis::cmd("XADD") + .arg(&stream_key) + .arg("*") + .arg("data") + .arg(&tx_str) + .query_async(&mut con) + .await + .unwrap(); + let _: () = con.set(doc_ver_key(&doc_id), 1.to_string()).await.unwrap(); + + // if let Ok(state) = build_state_at(&mut con, &doc_id, 1).await { + // let _: () = con + // .set(doc_snap_key(&doc_id), state.to_string()) + // .await + // .unwrap(); + // let _: () = con + // .set(doc_snapver_key(&doc_id), 1.to_string()) + // .await + // .unwrap(); + // } + } + _ => {} + } +} + +async fn build_state_at( + con: &mut MultiplexedConnection, + doc_id: &str, + target_version: u64, +) -> Result { + let snap_ver: u64 = con + .get(doc_snap_key(&doc_id)) + .await + .ok() + .flatten() + .and_then(|s| s.parse().ok()) + .unwrap_or(0); + + let snap_json: Value = if snap_ver > 0 { + let raw: Option = con.get(doc_snap_key(&doc_id)).await.unwrap_or(None); + raw.and_then(|s| serde_json::from_str(&s).ok()) + .unwrap_or_else(|| json!({})) + } else { + json!({}) + }; + + let stream_key = doc_tx_stream_key(doc_id); + + let start_id = "0-0"; + let entries: Vec<(String, Vec<(String, String)>)> = redis::cmd("XRANGE") + .arg(&stream_key) + .arg(start_id) + .arg("+") + .query_async(con) + .await + .map_err(|e| e.to_string())?; + + let mut ops_list: Vec = Vec::new(); + for (_id, fields) in entries { + let mut data_opts = None; + for (k, v) in fields { + if k == "data" { + data_opts = Some(v); + break; + } + } + let data = match data_opts { + Some(x) => x, + None => continue, + }; + + let ev: Value = serde_json::from_str(&data).map_err(|e| e.to_string())?; + let ver = ev.get("version").and_then(|v| v.as_u64()).unwrap_or(0); + if ver == 0 || ver > target_version { + continue; + } + + if ver <= snap_ver { + continue; + } + + let ops: Vec = + serde_json::from_value(ev["ops"].clone()).map_err(|e| e.to_string())?; + ops_list.extend(ops); + } + + apply_ops(snap_json, &ops_list) +} + pub async fn run(config: gcm::Configure) -> gcm::StandardResult { + let queue_capacity = config + .get("BOOT_QUEUE_CAP") + .and_then(|x| x.parse().ok()) + .unwrap_or(512); + + let worker_count: usize = config + .get("CACHE_WORKERS") + .and_then(|x| x.parse().ok()) + .unwrap_or(4); + + // REDIS POOL + // + // + // + // + let manager = RedisConnectionManager::new(format!( + "redis://{}:{}", + config.get("REDIS_URI").unwrap_or(&"".to_string()), + config.get("REDIS_PORT").unwrap_or(&"".to_string()) + )) + .expect("failed to create redis conn manager"); + let redis_pool = Pool::builder() + .max_size(16) + .build(manager) + .await + .expect("failed to build redis pool"); + + let (enqueue_tx, enqueue_rx) = channel::(queue_capacity); + let state = AppState { // cached_country_names: common::valid_country_name(), configures: config.clone(), repo: Arc::new(Mutex::new(Repository::open_bare( config.get("GIT_REPO_LOCAL_DEST").unwrap_or(&"".to_string()), )?)), - redis: Arc::new(Mutex::new(redis::Client::open(format!( - "redis://{}:{}", - config.get("REDIS_URI").unwrap_or(&"".to_string()), - config.get("REDIS_PORT").unwrap_or(&"".to_string()) - ))?)), + redis: redis_pool.clone(), fetched: Vec::new(), + enqueue_tx: enqueue_tx.clone(), }; + let sys_redis_cli = state.redis.clone(); + + // tokio::spawn(async move { + // while let Some(msg) = sys_rx.recv().await { + // handle_system_message(sys_redis_cli.clone(), msg).await; + // } + // }) + // .await?; + + // SPAWN WORKER + let worker_handle = spawn_cache_workers(redis_pool.clone(), enqueue_rx, worker_count); + + // COLD BOOT PRELOAD + { + let enqueue_tx = enqueue_tx.clone(); + let cfg = config.clone(); + + let enable_cold_start = if let Some(flag) = config.clone().get("COLD_START_ENABLE") { + flag.contains("1") + } else { + false + }; + + if enable_cold_start { + tokio::spawn(async move { + if let Err(e) = cold_boot_enqueue_json(cfg, enqueue_tx).await { + error!("cold boot enqueue failed {e}"); + } + }); + } + } + let app = Router::new() .route("/checkout", get(checkout_handler)) .route("/fetch", get(fetch_handler)) .route("/commit", post(commit_handler)) .route("/push", get(push_handler)) - .route("/healthz", get(reg::health)) + .route("/health", get(health_handler)) + // .route("/healthz", get(reg::health)) .with_state(state); let listener = tokio::net::TcpListener::bind(format!( @@ -595,5 +861,131 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { axum::serve(listener, app).await?; + drop(worker_handle); + + Ok(()) +} + +// Cold Boot +// +// +async fn cold_boot_enqueue_json( + config: gcm::Configure, + enqueue_tx: Sender, +) -> Result<(), Box> { + info!("cold boot scanning"); + + let root_repo = config + .get("GIT_REPO_LOCAL_DEST") + .expect("git repo local not define"); + + tx::helpers::setup_prebuild_tx_cache(enqueue_tx, root_repo).await?; + + Ok(()) +} + +// Worker pool +// spawn_cache_workers(config.clone(), redis_pool.clone(), enqueue_rx, worker_count); +fn spawn_cache_workers( + redis_pool: RedisPool, + mut rx: Receiver, + worker_count: usize, +) -> tokio::task::JoinHandle<()> { + tokio::spawn(async move { + info!("starting {worker_count} cache workers"); + + let mut joinset = JoinSet::new(); + + for worker_id in 0..worker_count { + // let redis_pool = redis_pool.clone(); + // let repo_root = config + // .clone() + // .get("GIT_REPO_LOCAL_DEST") + // .expect("unable to get git repo local dest"); + + joinset.spawn(async move { + loop { + tokio::time::sleep(Duration::from_millis(10)).await; + // pull job + let _ = worker_id; + break; + } + }); + } + + // dispatcher + + let max_inflight = worker_count; + + while let Some(job) = rx.recv().await { + while joinset.len() >= max_inflight { + if let Some(res) = joinset.join_next().await { + if let Err(e) = res { + warn!("job task join error: {e}"); + } + } + } + + let redis_pool = redis_pool.clone(); + // let repo_root = config + // .clone() + // .get("GIT_REPO_LOCAL_DEST") + // .expect("unable to get git repo local dest"); + + joinset.spawn(async move { + if let Err(e) = cache_one_file_streaming(redis_pool, job.clone()).await { + warn!("cache job failed: {e:?} {job:?}"); + } + }); + } + + while let Some(res) = joinset.join_next().await { + if let Err(e) = res { + warn!("job task join error: {e:?}"); + } + } + + info!("cache worker stopped (queue closed)"); + }) +} + +async fn cache_one_file_streaming(redis_pool: RedisPool, job: CacheJob) -> gcm::StandardResult { + if job.file_data.is_none() { + return Ok(()); + } + + let final_key = job.rel_path.clone(); + let tmp_key = format!("tmp:{}:{}", final_key, Uuid::new_v4()); + + let file_string = job.file_data.unwrap().to_string(); + let cursor = Cursor::new(file_string.into_bytes()); + let reader = BufReader::new(cursor); + + // brotli + let mut encoder = BrotliEncoder::new(reader); + + let mut conn = redis_pool.get().await?; + let _ = conn.del(&tmp_key).await?; + + let mut buf = vec![0u8; 64 * 1024]; + let mut compressed_total = 0u64; + + loop { + let n = encoder.read(&mut buf).await?; + if n == 0 { + break; + } + + compressed_total += n as u64; + + // append chunk to redis + let _: usize = conn.append(&tmp_key, &buf[..n]).await?; + } + + let _ = conn.del(&final_key).await?; + let _ = conn.rename(tmp_key, &final_key).await?; + + info!("cached {} ({} bytes)", job.rel_path, compressed_total); + Ok(()) } diff --git a/src/main.rs b/src/main.rs index a201bfd..2f77339 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{env, fs::File}; +use std::fs::File; use env_logger::Builder; use libtbr::recipe_functions::common; @@ -6,13 +6,14 @@ use log::info; use crate::{ git::setup_git_repo, - reg::{heartbeat_loop, registry::registry_client::RegistryClient}, + // reg::{heartbeat_loop, registry::registry_client::RegistryClient}, }; mod app; mod gcm; mod git; -mod reg; +mod tx; +// mod reg; fn setup_log(config: gcm::Configure) -> gcm::StandardResult { let logfile = File::create(config.get("LOG_NAME").unwrap_or(&"run.log".to_string()))?; @@ -24,27 +25,6 @@ fn setup_log(config: gcm::Configure) -> gcm::StandardResult { Ok(()) } -async fn setup_registry(config: gcm::Configure) -> gcm::StandardResult { - let cfg_clone = config.clone(); - let register_server_address = cfg_clone - .get("REGISTRY_SERVER") - .expect("not found registry server"); - let name = cfg_clone.get("SERVICE_NAME").expect("missing service name"); - let url = cfg_clone.get("SERVICE_URL").expect("missing service url"); - - let token = cfg_clone.get("REGISTRY_TOKEN").expect("token not provided"); - unsafe { - env::set_var("REGISTRY_TOKEN", token); - } - - let mut client = RegistryClient::connect(register_server_address.clone()).await?; - reg::register_service(&mut client, name, url).await; - - tokio::spawn(heartbeat_loop(name.to_string(), url.to_string())); - - Ok(()) -} - #[tokio::main] async fn main() -> gcm::StandardResult { let config: gcm::Configure = common::get_config(); @@ -68,8 +48,6 @@ async fn main() -> gcm::StandardResult { .get("CONFIG_VERSION") .expect("config version not defined") ); - - setup_registry(config.clone()).await?; app::run(config.clone()).await?; Ok(()) diff --git a/src/tx/handler.rs b/src/tx/handler.rs new file mode 100644 index 0000000..f6c5968 --- /dev/null +++ b/src/tx/handler.rs @@ -0,0 +1,323 @@ +use axum::{ + Json, Router, + extract::{Path, Query, State}, + response::IntoResponse, + routing::{get, post}, +}; +use redis::{AsyncTypedCommands, TypedCommands, aio::MultiplexedConnection}; +use reqwest::StatusCode; +use serde::Deserialize; +use serde_json::{Value, json}; +use uuid::Uuid; + +use crate::tx::{ + helpers::*, + patcher::apply_ops, + types::{PatchOp, Reservation, ReserveReq, ReserveRes, TxCommitReq, TxCommitRes}, +}; + +async fn reserve_tx( + State(state): State, + Path(doc_id): Path, + Json(req): Json, +) -> impl IntoResponse { + let rsv_id = Uuid::new_v4().to_string(); + let ttl_secs: i64 = 30; // ttl reserve 30s + let expires_at = now_unix() + ttl_secs; + + let mut rcli = state.redis_cli.clone(); + + // check version + let ver_key = doc_ver_key(&doc_id); + let base_version: u64 = match rcli.get(ver_key) { + Ok(res) => { + if let Some(r) = res { + r.parse().ok().unwrap() + } else { + 0 + } + } + Err(_) => 0, + }; + + let rsv = Reservation { + reservation_id: rsv_id.clone(), + doc_id: doc_id.clone(), + author: req.author, + base_version, + expires_at, + }; + + let key = rsv_key(&doc_id, &rsv_id); + let payload = serde_json::to_string(&rsv).unwrap(); + + let _: () = rcli.set_ex(key, payload, ttl_secs as u64).unwrap(); + + ( + StatusCode::OK, + Json(ReserveRes { + reservation_id: rsv_id, + base_version, + expires_at, + }), + ) +} + +async fn commit_tx( + State(state): State, + Path(doc_id): Path, + Json(req): Json, +) -> impl IntoResponse { + if req.tx_id.is_empty() || req.reservation_id.is_empty() { + return ( + StatusCode::BAD_REQUEST, + "missing tx_id or reservation_id ".into_response(), + ); + } + + let mut con = match state.redis_cli.get_multiplexed_async_connection().await { + Ok(conn) => conn, + Err(e) => { + return ( + StatusCode::INTERNAL_SERVER_ERROR, + format!("{}", e.to_string()).into_response(), + ); + } + }; + + // lock commit + let lock_key = commit_lock_key(&doc_id); + if let Err(_) = wait_lock(&mut con, &lock_key, 1200, 20).await { + return (StatusCode::CONFLICT, "doc busy, retry".into_response()); + } + + let txid_k = txid_key(&doc_id, &req.tx_id); + if let Ok(Some(v)) = con.get(&txid_k).await { + if let Ok(committed_version) = v.parse::() { + let res = TxCommitRes { + doc_id, + tx_id: req.tx_id, + committed_version, + }; + return (StatusCode::OK, Json(res).into_response()); + } + } + + let rsv_k = rsv_key(&doc_id, &req.reservation_id); + let rsv_raw: Option = con.get(&rsv_k).await.unwrap_or(None); + let rsv_raw = match rsv_raw { + Some(x) => x, + None => { + return ( + StatusCode::CONFLICT, + "reservation missing/expired".into_response(), + ); + } + }; + + let rsv: Reservation = match serde_json::from_str(&rsv_raw) { + Ok(x) => x, + Err(_) => return (StatusCode::CONFLICT, "bad reservation".into_response()), + }; + + if rsv.doc_id != doc_id || rsv.author != req.author || rsv.base_version != req.base_version { + return (StatusCode::CONFLICT, "reservation mismatch".into_response()); + } + + if now_unix() > rsv.expires_at { + return (StatusCode::CONFLICT, "reservation expired".into_response()); + } + + let curr_ver: u64 = con + .get(doc_ver_key(&doc_id)) + .await + .ok() + .flatten() + .and_then(|s| s.parse().ok()) + .unwrap_or(0); + + if req.base_version != curr_ver { + let body = json!({ + "error": "version_conflict", + "server_version": curr_ver, + }); + return (StatusCode::CONFLICT, Json(body).into_response()); + } + + let next_ver = curr_ver + 1; + + let stream_key = doc_tx_stream_key(&doc_id); + + let tx_event = json!({ + "doc_id": doc_id, + "tx_id": req.tx_id, + "version": next_ver, + "base_version": req.base_version, + "author": req.author, + "ts": now_unix(), + "ops": req.ops + }); + + let tx_event_str = tx_event.to_string(); + let _: String = redis::cmd("XADD") + .arg(&stream_key) + .arg("*") + .arg("data") + .arg(&tx_event_str) + .query_async(&mut con) + .await + .unwrap(); + + let _: () = con + .set(doc_ver_key(&doc_id), next_ver.to_string()) + .await + .unwrap(); + let _: () = con.set(&txid_k, next_ver.to_string()).await.unwrap(); + let _: usize = con.del(&rsv_k).await.unwrap(); + + let snapshot_every: u64 = 50; + if next_ver % snapshot_every == 0 { + if let Ok(state) = build_state_at(&mut con, &doc_id, next_ver).await { + let _: () = con + .set(doc_snap_key(&doc_id), state.to_string()) + .await + .unwrap(); + let _: () = con + .set(doc_snapver_key(&doc_id), next_ver.to_string()) + .await + .unwrap(); + } + } + + ( + StatusCode::OK, + Json(TxCommitRes { + doc_id, + tx_id: req.tx_id, + committed_version: next_ver, + }) + .into_response(), + ) +} + +async fn build_state_at( + con: &mut MultiplexedConnection, + doc_id: &str, + target_version: u64, +) -> Result { + let snap_ver: u64 = con + .get(doc_snap_key(&doc_id)) + .await + .ok() + .flatten() + .and_then(|s| s.parse().ok()) + .unwrap_or(0); + + let snap_json: Value = if snap_ver > 0 { + let raw: Option = con.get(doc_snap_key(&doc_id)).await.unwrap_or(None); + raw.and_then(|s| serde_json::from_str(&s).ok()) + .unwrap_or_else(|| json!({})) + } else { + json!({}) + }; + + let stream_key = doc_tx_stream_key(doc_id); + + let start_id = "0-0"; + let entries: Vec<(String, Vec<(String, String)>)> = redis::cmd("XRANGE") + .arg(&stream_key) + .arg(start_id) + .arg("+") + .query_async(con) + .await + .map_err(|e| e.to_string())?; + + let mut ops_list: Vec = Vec::new(); + for (_id, fields) in entries { + let mut data_opts = None; + for (k, v) in fields { + if k == "data" { + data_opts = Some(v); + break; + } + } + let data = match data_opts { + Some(x) => x, + None => continue, + }; + + let ev: Value = serde_json::from_str(&data).map_err(|e| e.to_string())?; + let ver = ev.get("version").and_then(|v| v.as_u64()).unwrap_or(0); + if ver == 0 || ver > target_version { + continue; + } + + if ver <= snap_ver { + continue; + } + + let ops: Vec = + serde_json::from_value(ev["ops"].clone()).map_err(|e| e.to_string())?; + ops_list.extend(ops); + } + + apply_ops(snap_json, &ops_list) +} + +#[derive(Deserialize)] +struct StateQuery { + at_version: Option, +} + +async fn get_state( + State(state): State, + Path(doc_id): Path, + Query(q): Query, +) -> impl IntoResponse { + let rcli = state.redis_cli.clone(); + let mut con = match rcli.get_multiplexed_async_connection().await { + Ok(sc) => sc, + Err(_) => { + return ( + StatusCode::INTERNAL_SERVER_ERROR, + "cannot get connection".into_response(), + ); + } + }; + + let cur_ver: u64 = con + .get(doc_ver_key(&doc_id)) + .await + .ok() + .flatten() + .and_then(|s| s.parse().ok()) + .unwrap_or(0); + + let target = q.at_version.unwrap_or(cur_ver).min(cur_ver); + + match build_state_at(&mut con, &doc_id, target).await { + Ok(state) => ( + StatusCode::OK, + Json(json!({ + "doc_id": doc_id, + "version": target, + "state": state + })) + .into_response(), + ), + Err(e) => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({ + "error": e + })) + .into_response(), + ), + } +} + +// pub async fn create_tx_patcher_route() -> Router { +// Router::new() +// .route("/{id}/tx-reserve", post(reserve_tx)) +// .route("/{id}/tx-commit", post(commit_tx)) +// .route("/{id}/state", get(get_state)) +// } diff --git a/src/tx/helpers.rs b/src/tx/helpers.rs new file mode 100644 index 0000000..07b5e5b --- /dev/null +++ b/src/tx/helpers.rs @@ -0,0 +1,294 @@ +use std::{ + clone, + collections::HashMap, + sync::{Arc, Mutex}, + time::{Duration, SystemTime, UNIX_EPOCH}, +}; + +use git2::Repository; +use json_patch::{Patch, diff}; +use log::info; +use redis::{RedisResult, aio::MultiplexedConnection}; +use serde::Deserialize; +use tokio::{sync::mpsc::Sender, time::sleep}; +use uuid::Uuid; + +use crate::app::CacheJob; + +pub fn now_unix() -> i64 { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs() as i64 +} + +pub fn doc_ver_key(doc: &str) -> String { + format!("doc:{doc}:ver") +} +pub fn doc_tx_stream_key(doc: &str) -> String { + format!("doc:{doc}:tx") +} +pub fn doc_snap_key(doc: &str) -> String { + format!("doc:{doc}:snap") +} +pub fn doc_snapver_key(doc: &str) -> String { + format!("doc:{doc}:snapver") +} +pub fn rsv_key(doc: &str, rsv: &str) -> String { + format!("doc:{doc}:rsv:{rsv}") +} +pub fn txid_key(doc: &str, tx_id: &str) -> String { + format!("doc:{doc}:txid:{tx_id}") +} +pub fn commit_lock_key(doc: &str) -> String { + format!("doc:{doc}:lock") +} + +pub async fn acquire_lock( + con: &mut MultiplexedConnection, + key: &str, + ttl_ms: u64, +) -> RedisResult { + let token = Uuid::new_v4().to_string(); + let ok: Option = redis::cmd("SET") + .arg(key) + .arg(token) + .arg("NX") + .arg("PX") + .arg(ttl_ms) + .query_async(con) + .await?; + Ok(ok.is_some()) +} + +pub async fn wait_lock( + con: &mut MultiplexedConnection, + key: &str, + ttl_ms: u64, + attempts: u32, +) -> RedisResult<()> { + for _ in 0..attempts { + if acquire_lock(con, key, ttl_ms).await? { + return Ok(()); + } + + sleep(Duration::from_millis(30)).await; + } + Err(redis::RedisError::from((redis::ErrorKind::Io, "lock busy"))) +} + +pub fn build_tx_from_diff(base: serde_json::Value, alt: serde_json::Value) -> Patch { + diff(&base, &alt) +} + +fn get_file_from_repo( + repo: Arc>, + path: &str, +) -> Result> { + if let Ok(repo_m) = repo.try_lock() { + let obj = repo_m.revparse_single(path)?; + if let Some(blob) = obj.as_blob() { + let content = unsafe { str::from_utf8_unchecked(blob.content()) }; + return Ok(content.to_string()); + } else if let Some(tree) = obj.as_tree() { + let dir_list = tree + .iter() + .map(|x| x.name().unwrap_or("").to_string()) + .collect::>(); + + return Ok(dir_list.join(",")); + } + } + Err("FileNotFound".into()) +} + +pub async fn setup_prebuild_tx_cache( + tx: Sender, + git_repo: &str, +) -> Result<(), Box> { + // import tx files + let repo = match Repository::open_bare(git_repo) { + Ok(repo) => repo, + Err(_) => return Err("cannot open repo".into()), + }; + + let repo_m = Arc::new(Mutex::new(repo)); + + let root_path = String::from("master:"); + let all_folders = match get_file_from_repo(repo_m.clone(), root_path.as_str()) { + Ok(af) => af, + Err(e) => return Err(e), + }; + + let folders = all_folders + .split(",") + .map(|x| x.to_string()) + .collect::>(); + + for folder in folders { + let current_path = format!("master:{folder}"); + + println!("trying {folder}..."); + + // test get version + // + // NOTE: version may miss if there is file with `versionXXXX` + // + // + if let Ok(current_files) = get_file_from_repo(repo_m.clone(), current_path.as_str()) + && current_files.contains(",version") + { + let expected_version_path = format!("{current_path}/version"); + println!("\tmay have version --> {expected_version_path}, \ncurrent: {current_files}"); + + // get version content + + let version_str = + if let Ok(v) = get_file_from_repo(repo_m.clone(), expected_version_path.as_str()) { + v + } else { + "".to_string() + }; + // let version = version_str.parse::().unwrap_or(0); + if version_str.is_empty() { + // unexpected + return Err("cannot get version".into()); + } + + if tx + .send(CacheJob { + rel_path: expected_version_path.clone(), + file_data: Some(serde_json::json!(version_str)), + }) + .await + .is_ok() + { + info!("cache ok {current_path}/version"); + } + + println!("try get {folder}:{version_str}"); + + let files = current_files + .split(",") + .map(|x| x.to_string()) + .collect::>(); + + let base_file: String = match files.iter().find(|x| { + x.ends_with(".json") && x.starts_with(&format!("coffeethai02_{version_str}")) + }) { + Some(f) => f.to_string(), + None => "".to_string(), + }; + + println!("{folder}: {base_file}"); + + if base_file.is_empty() { + println!("base file empty skip"); + continue; + } + + let base_recipe_str = if let Ok(r) = + get_file_from_repo(repo_m.clone(), &format!("{current_path}/{base_file}")) + { + r.to_string() + } else { + "".to_string() + }; + + if base_recipe_str.is_empty() { + println!("empty recipe skip!"); + continue; + } + + let base_recipe: serde_json::Value = match serde_json::from_str(&base_recipe_str) { + Ok(r) => r, + Err(e) => return Err(e.into()), + }; + + let mut current_recipes = HashMap::new(); + + current_recipes.insert("base".to_string(), base_recipe); + + for cfile in files { + if cfile.ne(&base_file) + && cfile.ends_with(".json") + && cfile.starts_with("coffeethai02") + { + // + // fetch file content + // read into value + // do diff + + let current_fetch_path = format!("{current_path}/{cfile}"); + let current_file_str = + if let Ok(cr) = get_file_from_repo(repo_m.clone(), ¤t_fetch_path) { + cr.to_string() + } else { + "".to_string() + }; + + if !current_file_str.is_empty() { + // into value + let alt_recipe: serde_json::Value = + match serde_json::from_str(¤t_file_str) { + Ok(crr) => crr, + Err(e) => { + println!("get error while alt {current_fetch_path}: {e}"); + continue; + } + }; + + current_recipes.insert(cfile, alt_recipe); + } + } + } + + // process diffing + // + + let base_recipe_clone = current_recipes.get("base").unwrap().clone(); + + for (key, value) in current_recipes.iter() { + if key != "base" { + let patch_diff = diff(&base_recipe_clone, value); + let tx_name = format!( + "stx_{}", + key.replace("coffeethai02_", "").replace(".json", "") + ); + + let base_path_out = format!("./recipe_tx/{folder}"); + if !std::path::Path::new(&base_path_out).exists() { + std::fs::create_dir_all(&base_path_out)?; + } + + let file_out = format!("{base_path_out}/{tx_name}.json"); + + std::fs::write(file_out, serde_json::to_string_pretty(&patch_diff)?)?; + } + } + + // let _ = tx + // .send(serde_json::json!({ + // "topic": "generate_stx", + // "target": folder, + // "base_version": version_str, + // "full_base_filename": base_file, + // "value": base_recipe_clone + // })) + // .await; + + if tx + .send(CacheJob { + rel_path: format!("{current_path}/{base_file}"), + file_data: Some(base_recipe_clone), + }) + .await + .is_ok() + { + info!("cache ok {current_path}/{base_file}"); + } + } + } + + Ok(()) +} diff --git a/src/tx/mod.rs b/src/tx/mod.rs new file mode 100644 index 0000000..b4579dd --- /dev/null +++ b/src/tx/mod.rs @@ -0,0 +1,4 @@ +// pub mod handler; +pub mod helpers; +pub mod patcher; +pub mod types; diff --git a/src/tx/patcher.rs b/src/tx/patcher.rs new file mode 100644 index 0000000..d96121b --- /dev/null +++ b/src/tx/patcher.rs @@ -0,0 +1,119 @@ +use serde_json::Value; + +use crate::tx::types::PatchOp; + +pub fn json_pointer_parent<'a>( + root: &'a mut Value, + path: &str, +) -> Result<(&'a mut Value, String), String> { + if !path.starts_with('/') && path != "" { + return Err("path must be JSON pointer starting with '/'".into()); + } + + let part: Vec = path + .split('/') + .skip(1) + .map(|x| x.replace("~1", "/").replace("~0", "~")) + .collect(); + if path.is_empty() { + return Ok((root, "".into())); + } + + let last = part.last().unwrap().clone(); + + let mut cur = root; + + for key in &part[..part.len() - 1] { + match cur { + Value::Object(map) => { + cur = map + .get_mut(key) + .ok_or_else(|| format!("missing object key {key}"))?; + } + Value::Array(arr) => { + let idx: usize = key.parse().map_err(|_| format!("bad array idx {key}"))?; + cur = arr + .get_mut(idx) + .ok_or_else(|| format!("array index out of bounds {idx}"))?; + } + _ => return Err("cannot traverse non-container".into()), + } + } + + Ok((cur, last)) +} + +pub fn apply_ops(mut state: Value, ops: &[PatchOp]) -> Result { + for op in ops { + match op { + PatchOp::Replace { path, value } => { + if path == "" || path == "/" { + state = value.clone(); + continue; + } + let (parent, last) = json_pointer_parent(&mut state, path)?; + match parent { + Value::Object(map) => { + if !map.contains_key(&last) { + return Err(format!("replace target missing key {last}")); + } + map.insert(last, value.clone()); + } + Value::Array(arr) => { + let idx: usize = last + .parse() + .map_err(|_| format!("bad array index {last}"))?; + if idx >= arr.len() { + return Err(format!("replace index out of bounds {idx}")); + } + arr[idx] = value.clone(); + } + _ => return Err("replace parent not container".into()), + } + } + PatchOp::Add { path, value } => { + let (parent, last) = json_pointer_parent(&mut state, path)?; + match parent { + Value::Object(map) => { + map.insert(last, value.clone()); + } + Value::Array(arr) => { + if last == "-" { + arr.push(value.clone()); + } else { + let idx: usize = last + .parse() + .map_err(|_| format!("bad array index {last}"))?; + if idx > arr.len() { + return Err(format!("add index out of bounds {idx}")); + } + arr.insert(idx, value.clone()); + } + } + _ => return Err("add parent not container".into()), + } + } + PatchOp::Remove { path } => { + let (parent, last) = json_pointer_parent(&mut state, path)?; + match parent { + Value::Object(map) => { + map.remove(&last) + .ok_or_else(|| format!("remove missing key {last}"))?; + } + Value::Array(arr) => { + let idx: usize = last + .parse() + .map_err(|_| format!("bad array index {last}"))?; + if idx > arr.len() { + return Err(format!("remove index out of bounds {idx}")); + } + arr.remove(idx); + } + _ => return Err("remove parent not container".into()), + } + } + } + } + + Ok(state) +} diff --git a/src/tx/types.rs b/src/tx/types.rs new file mode 100644 index 0000000..661ad90 --- /dev/null +++ b/src/tx/types.rs @@ -0,0 +1,51 @@ +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +#[derive(Debug, Serialize, Deserialize)] +pub struct ReserveReq { + pub author: String, + hint_paths: Option>, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct ReserveRes { + pub reservation_id: String, + pub base_version: u64, + pub expires_at: i64, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct TxCommitReq { + pub reservation_id: String, + pub tx_id: String, + pub base_version: u64, + pub author: String, + pub ops: Vec, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct TxCommitRes { + pub doc_id: String, + pub tx_id: String, + pub committed_version: u64, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(tag = "op")] +pub enum PatchOp { + #[serde(rename = "replace")] + Replace { path: String, value: Value }, + #[serde(rename = "add")] + Add { path: String, value: Value }, + #[serde(rename = "remove")] + Remove { path: String }, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct Reservation { + pub reservation_id: String, + pub doc_id: String, + pub author: String, + pub base_version: u64, + pub expires_at: i64, +} From 6fe3357efeeec6b10781c69e7beda553a76210e7 Mon Sep 17 00:00:00 2001 From: Pakin Date: Tue, 17 Feb 2026 15:17:04 +0700 Subject: [PATCH 09/21] feat: add support for image file in checkout Signed-off-by: Pakin --- Cargo.lock | 599 ++++++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/app.rs | 63 +++++- 3 files changed, 651 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 90a1483..ec0a2fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -28,6 +28,24 @@ dependencies = [ "memchr", ] +[[package]] +name = "aligned" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee4508988c62edf04abd8d92897fca0c2995d907ce1dfeaf369dac3716a40685" +dependencies = [ + "as-slice", +] + +[[package]] +name = "aligned-vec" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc890384c8602f339876ded803c97ad529f3842aba97f6392b3dba0dd171769b" +dependencies = [ + "equator", +] + [[package]] name = "alloc-no-stdlib" version = "2.0.4" @@ -123,6 +141,32 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03918c3dbd7701a85c6b9887732e2921175f26c350b4563841d0958c21d57e6d" +[[package]] +name = "arg_enum_proc_macro" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "as-slice" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "516b6b4f0e40d50dcda9365d53964ec74560ad4284da2e7fc97122cd83174516" +dependencies = [ + "stable_deref_trait", +] + [[package]] name = "async-compression" version = "0.4.39" @@ -158,6 +202,49 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "av-scenechange" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f321d77c20e19b92c39e7471cf986812cbb46659d2af674adc4331ef3f18394" +dependencies = [ + "aligned", + "anyhow", + "arg_enum_proc_macro", + "arrayvec", + "log", + "num-rational", + "num-traits", + "pastey", + "rayon", + "thiserror 2.0.18", + "v_frame", + "y4m", +] + +[[package]] +name = "av1-grain" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cfddb07216410377231960af4fcab838eaa12e013417781b78bd95ee22077f8" +dependencies = [ + "anyhow", + "arrayvec", + "log", + "nom", + "num-rational", + "v_frame", +] + +[[package]] +name = "avif-serialize" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375082f007bd67184fb9c0374614b29f9aaa604ec301635f72338bb65386a53d" +dependencies = [ + "arrayvec", +] + [[package]] name = "axum" version = "0.8.8" @@ -249,12 +336,27 @@ dependencies = [ "redis", ] +[[package]] +name = "bit_field" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" + [[package]] name = "bitflags" version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +[[package]] +name = "bitstream-io" +version = "4.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60d4bd9d1db2c6bdf285e223a7fa369d5ce98ec767dec949c6ca62863ce61757" +dependencies = [ + "core2", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -285,12 +387,30 @@ dependencies = [ "alloc-stdlib", ] +[[package]] +name = "built" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ad8f11f288f48ca24471bbd51ac257aaeaaa07adae295591266b792902ae64" + [[package]] name = "bumpalo" version = "3.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" +[[package]] +name = "bytemuck" +version = "1.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec" + +[[package]] +name = "byteorder-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" + [[package]] name = "bytes" version = "1.11.1" @@ -347,6 +467,12 @@ dependencies = [ "inout", ] +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "colorchoice" version = "1.0.4" @@ -405,6 +531,15 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr", +] + [[package]] name = "cpufeatures" version = "0.2.17" @@ -463,6 +598,12 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + [[package]] name = "crypto-common" version = "0.1.7" @@ -559,6 +700,26 @@ dependencies = [ "log", ] +[[package]] +name = "equator" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4711b213838dfee0117e3be6ac926007d7f433d7bbe33595975d4190cb07e6fc" +dependencies = [ + "equator-macro", +] + +[[package]] +name = "equator-macro" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "equivalent" version = "1.0.2" @@ -575,12 +736,56 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "exr" +version = "1.74.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4300e043a56aa2cb633c01af81ca8f699a321879a7854d3896a0ba89056363be" +dependencies = [ + "bit_field", + "half", + "lebe", + "miniz_oxide", + "rayon-core", + "smallvec", + "zune-inflate", +] + [[package]] name = "fastrand" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "fax" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05de7d48f37cd6730705cbca900770cab77a89f413d23e100ad7fad7795a0ab" +dependencies = [ + "fax_derive", +] + +[[package]] +name = "fax_derive" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0aca10fb742cb43f9e7bb8467c91aa9bcb8e3ffbc6a6f7389bb93ffc920577d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "fdeflate" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" +dependencies = [ + "simd-adler32", +] + [[package]] name = "filetime" version = "0.2.27" @@ -737,6 +942,16 @@ dependencies = [ "wasip2", ] +[[package]] +name = "gif" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5df2ba84018d80c213569363bdcd0c64e6933c67fe4c1d60ecf822971a3c35e" +dependencies = [ + "color_quant", + "weezl", +] + [[package]] name = "git2" version = "0.20.3" @@ -771,6 +986,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "cfg-if", + "crunchy", + "zerocopy", +] + [[package]] name = "hashbrown" version = "0.15.5" @@ -1066,6 +1292,46 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "image" +version = "0.25.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6506c6c10786659413faa717ceebcb8f70731c0a60cbae39795fdf114519c1a" +dependencies = [ + "bytemuck", + "byteorder-lite", + "color_quant", + "exr", + "gif", + "image-webp", + "moxcms", + "num-traits", + "png", + "qoi", + "ravif", + "rayon", + "rgb", + "tiff", + "zune-core 0.5.1", + "zune-jpeg 0.5.12", +] + +[[package]] +name = "image-webp" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525e9ff3e1a4be2fbea1fdf0e98686a6d98b4d8f937e1bf7402245af1909e8c3" +dependencies = [ + "byteorder-lite", + "quick-error", +] + +[[package]] +name = "imgref" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c5cedc30da3a610cac6b4ba17597bdf7152cf974e8aab3afb3d54455e371c8" + [[package]] name = "indexmap" version = "2.13.0" @@ -1085,6 +1351,17 @@ dependencies = [ "generic-array", ] +[[package]] +name = "interpolate_name" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "ipnet" version = "2.11.0" @@ -1175,7 +1452,7 @@ dependencies = [ "jsonptr", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1188,6 +1465,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "lebe" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8" + [[package]] name = "libbz2-rs-sys" version = "0.2.2" @@ -1200,6 +1483,16 @@ version = "0.2.180" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +[[package]] +name = "libfuzzer-sys" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12a681b7dd8ce12bff52488013ba614b869148d54dd79836ab85aafdd53f08d" +dependencies = [ + "arbitrary", + "cc", +] + [[package]] name = "libgit2-sys" version = "0.18.3+1.9.2" @@ -1296,6 +1589,15 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "loop9" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fae87c125b03c1d2c0150c90365d7d6bcc53fb73a9acaef207d2d065860f062" +dependencies = [ + "imgref", +] + [[package]] name = "lzma-rust2" version = "0.13.0" @@ -1312,6 +1614,16 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" +[[package]] +name = "maybe-rayon" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519" +dependencies = [ + "cfg-if", + "rayon", +] + [[package]] name = "memchr" version = "2.7.6" @@ -1345,6 +1657,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "moxcms" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac9557c559cd6fc9867e122e20d2cbefc9ca29d80d027a8e39310920ed2f0a97" +dependencies = [ + "num-traits", + "pxfm", +] + [[package]] name = "multimap" version = "0.10.1" @@ -1368,6 +1690,27 @@ dependencies = [ "tempfile", ] +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "nom" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] + +[[package]] +name = "noop_proc_macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" + [[package]] name = "num-bigint" version = "0.4.6" @@ -1384,6 +1727,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "num-integer" version = "0.1.46" @@ -1393,6 +1747,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -1481,6 +1846,18 @@ dependencies = [ "windows-link", ] +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pastey" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35fb2e5f958ec131621fdd531e9fc186ed768cbe395337403ae56c17a74c68ec" + [[package]] name = "pbkdf2" version = "0.12.2" @@ -1546,6 +1923,19 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "png" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61" +dependencies = [ + "bitflags", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide", +] + [[package]] name = "portable-atomic" version = "1.13.0" @@ -1610,6 +2000,25 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "profiling" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773" +dependencies = [ + "profiling-procmacros", +] + +[[package]] +name = "profiling-procmacros" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52717f9a02b6965224f95ca2a81e2e0c5c43baacd28ca057577988930b6c3d5b" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "prost" version = "0.14.3" @@ -1683,6 +2092,30 @@ dependencies = [ "pulldown-cmark", ] +[[package]] +name = "pxfm" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7186d3822593aa4393561d186d1393b3923e9d6163d3fbfd6e825e3e6cf3e6a8" +dependencies = [ + "num-traits", +] + +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "quick-error" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" + [[package]] name = "quote" version = "1.0.43" @@ -1727,6 +2160,56 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "rav1e" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43b6dd56e85d9483277cde964fd1bdb0428de4fec5ebba7540995639a21cb32b" +dependencies = [ + "aligned-vec", + "arbitrary", + "arg_enum_proc_macro", + "arrayvec", + "av-scenechange", + "av1-grain", + "bitstream-io", + "built", + "cfg-if", + "interpolate_name", + "itertools", + "libc", + "libfuzzer-sys", + "log", + "maybe-rayon", + "new_debug_unreachable", + "noop_proc_macro", + "num-derive", + "num-traits", + "paste", + "profiling", + "rand", + "rand_chacha", + "simd_helpers", + "thiserror 2.0.18", + "v_frame", + "wasm-bindgen", +] + +[[package]] +name = "ravif" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef69c1990ceef18a116855938e74793a5f7496ee907562bd0857b6ac734ab285" +dependencies = [ + "avif-serialize", + "imgref", + "loop9", + "quick-error", + "rav1e", + "rayon", + "rgb", +] + [[package]] name = "rayon" version = "1.11.0" @@ -1858,6 +2341,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "rgb" +version = "0.8.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce" + [[package]] name = "ring" version = "0.17.14" @@ -2094,6 +2583,15 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" +[[package]] +name = "simd_helpers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95890f873bec569a0362c235787f3aca6e1e887302ba4840839bcc6459c42da6" +dependencies = [ + "quote", +] + [[package]] name = "slab" version = "0.4.11" @@ -2204,6 +2702,7 @@ dependencies = [ "env_logger", "futures-util", "git2", + "image", "json-patch", "libgit2-sys", "libtbr", @@ -2240,7 +2739,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", ] [[package]] @@ -2254,6 +2762,31 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tiff" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af9605de7fee8d9551863fd692cce7637f548dbd9db9180fcc07ccc6d26c336f" +dependencies = [ + "fax", + "flate2", + "half", + "quick-error", + "weezl", + "zune-jpeg 0.4.21", +] + [[package]] name = "time" version = "0.3.45" @@ -2569,6 +3102,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "v_frame" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "666b7727c8875d6ab5db9533418d7c764233ac9c0cff1d469aec8fa127597be2" +dependencies = [ + "aligned-vec", + "num-traits", + "wasm-bindgen", +] + [[package]] name = "vcpkg" version = "0.2.15" @@ -2684,6 +3228,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "weezl" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88" + [[package]] name = "winapi-util" version = "0.1.11" @@ -2947,6 +3497,12 @@ version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3" +[[package]] +name = "y4m" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5a4b21e1a62b67a2970e6831bc091d7b87e119e7f9791aef9702e3bef04448" + [[package]] name = "yoke" version = "0.8.1" @@ -3142,3 +3698,42 @@ dependencies = [ "cc", "pkg-config", ] + +[[package]] +name = "zune-core" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a" + +[[package]] +name = "zune-core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb8a0807f7c01457d0379ba880ba6322660448ddebc890ce29bb64da71fb40f9" + +[[package]] +name = "zune-inflate" +version = "0.2.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" +dependencies = [ + "simd-adler32", +] + +[[package]] +name = "zune-jpeg" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ce2c8a9384ad323cf564b67da86e21d3cfdff87908bc1223ed5c99bc792713" +dependencies = [ + "zune-core 0.4.12", +] + +[[package]] +name = "zune-jpeg" +version = "0.5.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "410e9ecef634c709e3831c2cfdb8d9c32164fae1c67496d5b68fff728eec37fe" +dependencies = [ + "zune-core 0.5.1", +] diff --git a/Cargo.toml b/Cargo.toml index 1b72069..9d35c40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ bytes = "1.11.1" env_logger = "0.11.8" futures-util = "0.3.31" git2 = { version = "0.20.3", features = ["https", "ssh"] } +image = "0.25.9" json-patch = "4.1.0" libgit2-sys = { version = "0.18.3", features = ["ssh"] } libtbr = { git = "https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/libtbr.git", version = "0.1.1" } diff --git a/src/app.rs b/src/app.rs index 108d9a2..1358f81 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3,8 +3,9 @@ use std::{collections::HashMap, io::Cursor, sync::Arc, time::Duration}; use async_compression::tokio::bufread::BrotliEncoder; use axum::{ Json, Router, + body::Body, extract::{Query, State}, - response::IntoResponse, + response::{IntoResponse, Response}, routing::{get, post}, }; use axum_macros::debug_handler; @@ -12,8 +13,10 @@ use bb8::Pool; use bb8_redis::RedisConnectionManager; use git2::{Cred, FetchOptions, PushOptions, RemoteCallbacks, Repository}; +use image::load_from_memory; use log::{error, info, warn}; use redis::{AsyncTypedCommands, TypedCommands, aio::MultiplexedConnection}; +use reqwest::header; use serde::Deserialize; use serde_json::{Value, json}; use tokio::{ @@ -71,6 +74,14 @@ impl AppState { } } +const SUPPORTED_IMAGES: [&str; 6] = ["jpg", "jpeg", "png", "gif", "bmp", "webp"]; + +fn is_supported_image_file_type(name: String) -> bool { + let ext = name.split(".").last().unwrap_or(""); + + SUPPORTED_IMAGES.contains(&ext) +} + #[derive(Deserialize, Debug)] struct CheckoutParams { path: String, @@ -99,7 +110,7 @@ async fn checkout_handler( if let Ok(res) = conn.get(param.path.clone().as_str().to_string()).await { if let Some(res) = res { response.insert("result".to_string(), json!(res)); - return (axum::http::StatusCode::OK, Json(json!(response))); + return (axum::http::StatusCode::OK, Json(json!(response))).into_response(); } } } @@ -113,7 +124,8 @@ async fn checkout_handler( return ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!(response)), - ); + ) + .into_response(); } let legit_path = param.path.as_str(); @@ -138,7 +150,8 @@ async fn checkout_handler( return ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!(response)), - ); + ) + .into_response(); } }; @@ -159,15 +172,45 @@ async fn checkout_handler( return ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!(response)), - ); + ) + .into_response(); } }; if let Some(blob) = obj.as_blob() { - let content = unsafe { str::from_utf8_unchecked(blob.content()) }; - response.insert("result".to_string(), json!(content.to_string())); + // image + if is_supported_image_file_type(fpath.clone()) { + let fc = fpath.clone(); + let ext = fc.split(".").last().unwrap_or(""); + let content: &[u8] = blob.content(); + let img = match load_from_memory(content) { + Ok(img) => img, + Err(err) => { + //.map_err(|err| format!("Failed tp load image from memory: {err}")) + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!(format!("Failed tp load image from memory: {err}"))), + ) + .into_response(); + } + }; - return (axum::http::StatusCode::OK, Json(json!(content))); + let mut image_buffer = Vec::new(); + img.write_to( + &mut Cursor::new(&mut image_buffer), + image::ImageFormat::from_extension(ext).unwrap_or(image::ImageFormat::Png), + ) + .unwrap(); + + return Response::builder() + .header(header::CONTENT_TYPE, format!("image/{ext}")) + .body(Body::from(image_buffer)) + .unwrap(); + } + + let content = unsafe { str::from_utf8_unchecked(blob.content()) }; + + return (axum::http::StatusCode::OK, Json(json!(content))).into_response(); // if let Ok(mut conn) = state.redis.get().await { // let _ = conn.set(legit_path.to_string(), content.to_string()).await; @@ -180,7 +223,7 @@ async fn checkout_handler( .collect::>(); response.insert("result".to_string(), json!(dir_list)); - return (axum::http::StatusCode::OK, Json(json!(dir_list))); + return (axum::http::StatusCode::OK, Json(json!(dir_list))).into_response(); // if let Ok(mut conn) = state.redis.get().await { // let _ = conn.set(legit_path.to_string(), dir_list.join(",")).await; @@ -190,7 +233,7 @@ async fn checkout_handler( let error_log = "not obj nor tree"; error!("{error_log}"); response.insert("error".to_string(), json!(error_log)); - return (axum::http::StatusCode::BAD_REQUEST, Json(json!(response))); + return (axum::http::StatusCode::BAD_REQUEST, Json(json!(response))).into_response(); } // println!("checkout response: {response:?}"); From febf91d417e68f32ff55c6d3ad25d7fa2b49fe33 Mon Sep 17 00:00:00 2001 From: Pakin Date: Wed, 25 Feb 2026 15:11:29 +0700 Subject: [PATCH 10/21] disable cold boot caching & optimizing - caused by too much ram usage - optimize memory usage on checkout code Signed-off-by: Pakin --- Cargo.lock | 1 + Cargo.toml | 1 + src/app.rs | 657 ++++++++++++++-------------------------------- src/tx/helpers.rs | 10 +- 4 files changed, 203 insertions(+), 466 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec0a2fb..1a3f576 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2698,6 +2698,7 @@ dependencies = [ "axum-macros", "bb8", "bb8-redis", + "brotli", "bytes", "env_logger", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index 9d35c40..9ec73b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ axum = "0.8.7" axum-macros = "0.5.0" bb8 = "0.9.1" bb8-redis = "0.26.0" +brotli = "8.0.2" bytes = "1.11.1" env_logger = "0.11.8" futures-util = "0.3.31" diff --git a/src/app.rs b/src/app.rs index 1358f81..60c29d8 100644 --- a/src/app.rs +++ b/src/app.rs @@ -9,20 +9,21 @@ use axum::{ routing::{get, post}, }; use axum_macros::debug_handler; -use bb8::Pool; +use bb8::{Pool, PooledConnection}; use bb8_redis::RedisConnectionManager; -use git2::{Cred, FetchOptions, PushOptions, RemoteCallbacks, Repository}; +use brotli::CompressorWriter; +use git2::{Cred, FetchOptions, Object, PushOptions, RemoteCallbacks, Repository}; use image::load_from_memory; use log::{error, info, warn}; -use redis::{AsyncTypedCommands, TypedCommands, aio::MultiplexedConnection}; +use redis::{AsyncTypedCommands, Connection, TypedCommands, aio::MultiplexedConnection}; use reqwest::header; use serde::Deserialize; use serde_json::{Value, json}; use tokio::{ io::{AsyncReadExt, BufReader}, sync::{ - Mutex, + Mutex, MutexGuard, mpsc::{Receiver, Sender, channel}, }, task::JoinSet, @@ -45,7 +46,7 @@ type RedisPool = Pool; #[derive(Debug, Clone)] pub struct CacheJob { pub rel_path: String, - pub file_data: Option, + pub file_data: Option>, } #[derive(Clone)] @@ -82,16 +83,34 @@ fn is_supported_image_file_type(name: String) -> bool { SUPPORTED_IMAGES.contains(&ext) } +fn detect_content_type(path: &str) -> String { + let ext = path.split(".").last().unwrap_or(""); + if ext.eq(".json") { + "application/json".to_string() + } else if SUPPORTED_IMAGES.contains(&ext) { + format!("image/{ext}").to_string() + } else { + "application/octet-stream".to_string() + } +} + #[derive(Deserialize, Debug)] struct CheckoutParams { path: String, } async fn checkout_handler( - State(mut state): State, + State(state): State, Query(param): Query, ) -> impl IntoResponse { - let mut response: HashMap = HashMap::new(); + let fpath = format!( + "{}:{}", + state + .get_config("GIT_REPO_BRANCH_NAME") + .map(|x| x.to_string()) + .unwrap_or("master".to_string()), + param.path + ); // println!( // "req: {param:?}, has_cached: {}, saved: {:?}", @@ -102,140 +121,147 @@ async fn checkout_handler( // ); // quick response from redis - if let Ok(mut conn) = state.redis.get().await - && state - .fetched - .contains(¶m.path.clone().as_str().to_string()) - { - if let Ok(res) = conn.get(param.path.clone().as_str().to_string()).await { - if let Some(res) = res { - response.insert("result".to_string(), json!(res)); - return (axum::http::StatusCode::OK, Json(json!(response))).into_response(); - } - } - } + if let Ok(conn) = state.redis.dedicated_connection().await { + println!("conneciton ok"); + if let Ok(raw) = fetch_content_from_redis_byte(conn, &fpath).await + && !raw.is_empty() + { + // detect content type + let content_type = detect_content_type(&fpath); - let repo_path = state.get_config("GIT_REPO_LOCAL_DEST"); - if repo_path.is_none() { - response.insert( - "error".to_string(), - json!("config repo dest not found".to_string()), - ); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)), - ) - .into_response(); - } - - let legit_path = param.path.as_str(); - - // match param.path.as_str() { - // legit_path if param.path.contains("/") || state.check_country_existed(param.path.as_str()) || param.path.is_empty() => { - - // } - // _ => { - // let error_log = "requested path is unexpected"; - // error!("{error_log}"); - // response.insert("error".to_string(), json!(error_log)); - // } - // } - let rpath = repo_path.unwrap().clone(); - let repo = match Repository::open_bare(rpath) { - Ok(repo) => repo, - Err(_) => { - let error_log = "unable to open repo as bare"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)), - ) - .into_response(); - } - }; - - let fpath = format!( - "{}:{}", - state - .get_config("GIT_REPO_BRANCH_NAME") - .map(|x| x.to_string()) - .unwrap_or("master".to_string()), - legit_path - ); - let obj = match repo.revparse_single(&fpath) { - Ok(obj) => obj, - Err(e) => { - let error_log = format!("unexpected revparse single: {err}", err = e.message()); - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log.clone())); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)), - ) - .into_response(); - } - }; - - if let Some(blob) = obj.as_blob() { - // image - if is_supported_image_file_type(fpath.clone()) { - let fc = fpath.clone(); - let ext = fc.split(".").last().unwrap_or(""); - let content: &[u8] = blob.content(); - let img = match load_from_memory(content) { - Ok(img) => img, - Err(err) => { - //.map_err(|err| format!("Failed tp load image from memory: {err}")) - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(format!("Failed tp load image from memory: {err}"))), - ) - .into_response(); - } - }; - - let mut image_buffer = Vec::new(); - img.write_to( - &mut Cursor::new(&mut image_buffer), - image::ImageFormat::from_extension(ext).unwrap_or(image::ImageFormat::Png), - ) - .unwrap(); + println!("content-len: {}", raw.len()); return Response::builder() - .header(header::CONTENT_TYPE, format!("image/{ext}")) - .body(Body::from(image_buffer)) + .header(header::CONTENT_TYPE, content_type) + .body(Body::from(raw)) .unwrap(); } - - let content = unsafe { str::from_utf8_unchecked(blob.content()) }; - - return (axum::http::StatusCode::OK, Json(json!(content))).into_response(); - - // if let Ok(mut conn) = state.redis.get().await { - // let _ = conn.set(legit_path.to_string(), content.to_string()).await; - // state.fetched.push(legit_path.to_string()); - // } - } else if let Some(tree) = obj.as_tree() { - let dir_list = tree - .iter() - .map(|x| x.name().unwrap_or("").to_string()) - .collect::>(); - response.insert("result".to_string(), json!(dir_list)); - - return (axum::http::StatusCode::OK, Json(json!(dir_list))).into_response(); - - // if let Ok(mut conn) = state.redis.get().await { - // let _ = conn.set(legit_path.to_string(), dir_list.join(",")).await; - // state.fetched.push(legit_path.to_string()); - // } - } else { - let error_log = "not obj nor tree"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - return (axum::http::StatusCode::BAD_REQUEST, Json(json!(response))).into_response(); } + println!("failed to get from redis, continue ..."); + + let repo = state.repo.clone(); + + // let obj = match repo.revparse_single(&fpath) { + // Ok(obj) => obj, + // Err(e) => { + // let error_log = format!("unexpected revparse single: {err}", err = e.message()); + // error!("{error_log}"); + // response.insert("error".to_string(), json!(error_log.clone())); + // return ( + // axum::http::StatusCode::INTERNAL_SERVER_ERROR, + // Json(json!(response)), + // ) + // .into_response(); + // } + // }; + // + + // let obj_bytes = match get_git_object(repo, &fpath).await { + // Ok(ob) => ob, + // Err(e) => { + // return ( + // axum::http::StatusCode::INTERNAL_SERVER_ERROR, + // Json(json!(format!("{e}"))), + // ) + // .into_response(); + // } + // }; + + let fpath_clone = fpath.clone(); + let result = tokio::task::spawn_blocking(move || { + let repo = repo.try_lock()?; + + get_git_object(repo, &fpath_clone) + }) + .await; + + match result { + Ok(Ok(o)) => { + let state_clone = state.clone(); + let key_clone = fpath.clone(); + let data_clone = o.clone(); + + tokio::spawn(async move { + if let Ok(mut conn) = state_clone.redis.dedicated_connection().await { + let _: Result<(), _> = redis::cmd("SET") + .arg(&key_clone) + .arg(&data_clone) + .arg("EX") + .arg(3600) + .query_async(&mut conn) + .await; + } + }); + + let content_type = detect_content_type(&fpath); + Response::builder() + .header(header::CONTENT_TYPE, content_type) + .body(Body::from(o)) + .unwrap() + } + _ => (axum::http::StatusCode::NOT_FOUND, "File not found").into_response(), + } + + // if let Some(blob) = obj.as_blob() { + // // image + // if is_supported_image_file_type(fpath.clone()) { + // let fc = fpath.clone(); + // let ext = fc.split(".").last().unwrap_or(""); + // let content: &[u8] = blob.content(); + // let img = match load_from_memory(content) { + // Ok(img) => img, + // Err(err) => { + // //.map_err(|err| format!("Failed tp load image from memory: {err}")) + // return ( + // axum::http::StatusCode::INTERNAL_SERVER_ERROR, + // Json(json!(format!("Failed tp load image from memory: {err}"))), + // ) + // .into_response(); + // } + // }; + + // let mut image_buffer = Vec::new(); + // img.write_to( + // &mut Cursor::new(&mut image_buffer), + // image::ImageFormat::from_extension(ext).unwrap_or(image::ImageFormat::Png), + // ) + // .unwrap(); + + // return Response::builder() + // .header(header::CONTENT_TYPE, format!("image/{ext}")) + // .body(Body::from(image_buffer)) + // .unwrap(); + // } + + // let content = unsafe { str::from_utf8_unchecked(blob.content()) }; + + // return (axum::http::StatusCode::OK, Json(json!(content))).into_response(); + + // // if let Ok(mut conn) = state.redis.get().await { + // // let _ = conn.set(legit_path.to_string(), content.to_string()).await; + // // state.fetched.push(legit_path.to_string()); + // // } + // } else if let Some(tree) = obj.as_tree() { + // let dir_list = tree + // .iter() + // .map(|x| x.name().unwrap_or("").to_string()) + // .collect::>(); + // response.insert("result".to_string(), json!(dir_list)); + + // return (axum::http::StatusCode::OK, Json(json!(dir_list))).into_response(); + + // // if let Ok(mut conn) = state.redis.get().await { + // // let _ = conn.set(legit_path.to_string(), dir_list.join(",")).await; + // // state.fetched.push(legit_path.to_string()); + // // } + // } else { + // let error_log = "not obj nor tree"; + // error!("{error_log}"); + // response.insert("error".to_string(), json!(error_log)); + // return (axum::http::StatusCode::BAD_REQUEST, Json(json!(response))).into_response(); + // } + // println!("checkout response: {response:?}"); // (axum::http::StatusCode::OK, Json(json!(response))) @@ -244,20 +270,7 @@ async fn checkout_handler( async fn fetch_handler(State(state): State) -> impl IntoResponse { let mut response: HashMap = HashMap::new(); if let Some(repo_path) = state.clone().get_config("GIT_REPO_LOCAL_DEST") { - let rpath = repo_path.clone(); - - let repo = match Repository::open_bare(rpath) { - Ok(repo) => repo, - Err(_) => { - let error_log = "unable to open bare repo"; - error!("{error_log}"); - response.insert("error".to_string(), json!(error_log)); - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!(response)), - ); - } - }; + let repo = state.repo.lock().await; let mut remote = match repo.find_remote("origin") { Ok(remote) => remote, @@ -437,6 +450,38 @@ async fn fetch_content_from_redis(redis: RedisPool, key: &str) -> Result Result, String> { + let res = redis::cmd("GET").arg(key).query_async(&mut conn).await; + + match res { + Ok(res) => Ok(res), + Err(e) => { + return Err(format!("{e}")); + } + } +} + +fn get_git_object( + repo: MutexGuard<'_, Repository>, + path: &str, +) -> Result, Box> { + let obj = repo.revparse_single(&path)?; + if let Some(blob) = obj.as_blob() { + Ok(blob.content().to_vec()) + } else if let Some(tree) = obj.as_tree() { + let dir_list = tree + .iter() + .map(|x| x.name().unwrap_or("").to_string()) + .collect::>(); + Ok(dir_list.join(",").as_bytes().to_vec()) + } else { + Err("Unknown or not supported".into()) + } +} + fn read_patch_from_str(patch_changes: &str) -> Option { // @@ -667,161 +712,7 @@ async fn health_handler(State(_): State) -> impl IntoResponse { ) } -async fn handle_system_message(redis: Arc>, mut msg: serde_json::Value) { - let topic = if let Some(t) = msg["topic"].as_str() { - t - } else { - "" - }; - - match topic { - "generate_stx" => { - // expect target, base_version, value - let target = msg["target"].as_str().unwrap_or("").to_string(); - let base_version = msg["base_version"].as_str().unwrap_or("").to_string(); - let full_base_filename = msg["full_base_filename"].as_str().unwrap_or("").to_string(); - let value = msg["value"].take(); - - let rclone = redis.clone(); - let mut rcli = rclone.lock().await; - - let doc_id = format!("{target}_{base_version}"); - let doc_version_key = doc_ver_key(&doc_id); - let doc_snap = doc_snap_key(&doc_id); - - let _ = rcli.set( - format!("{target}/{full_base_filename}"), - serde_json::to_string(&value).unwrap_or("".to_string()), - ); - - let _ = rcli.set(format!("{target}/version"), base_version); - - info!("publish {full_base_filename} as main file"); - - // create commit transaction base - - let mut con = match rcli.get_multiplexed_async_connection().await { - Ok(conn) => conn, - Err(e) => { - return; - } - }; - - let stream_key = doc_tx_stream_key(&doc_id); - let tx_event = json!({ - "doc_id": doc_id, - "tx_id": Uuid::new_v4().to_string(), - "version": 1, - "base_version": 0, - "author": "from stx", - "ts": now_unix(), - "ops": vec![ - PatchOp::Add { path: "/".to_string(), value: value.clone() } - ] - }); - - let tx_str = tx_event.to_string(); - - let _: String = redis::cmd("XADD") - .arg(&stream_key) - .arg("*") - .arg("data") - .arg(&tx_str) - .query_async(&mut con) - .await - .unwrap(); - let _: () = con.set(doc_ver_key(&doc_id), 1.to_string()).await.unwrap(); - - // if let Ok(state) = build_state_at(&mut con, &doc_id, 1).await { - // let _: () = con - // .set(doc_snap_key(&doc_id), state.to_string()) - // .await - // .unwrap(); - // let _: () = con - // .set(doc_snapver_key(&doc_id), 1.to_string()) - // .await - // .unwrap(); - // } - } - _ => {} - } -} - -async fn build_state_at( - con: &mut MultiplexedConnection, - doc_id: &str, - target_version: u64, -) -> Result { - let snap_ver: u64 = con - .get(doc_snap_key(&doc_id)) - .await - .ok() - .flatten() - .and_then(|s| s.parse().ok()) - .unwrap_or(0); - - let snap_json: Value = if snap_ver > 0 { - let raw: Option = con.get(doc_snap_key(&doc_id)).await.unwrap_or(None); - raw.and_then(|s| serde_json::from_str(&s).ok()) - .unwrap_or_else(|| json!({})) - } else { - json!({}) - }; - - let stream_key = doc_tx_stream_key(doc_id); - - let start_id = "0-0"; - let entries: Vec<(String, Vec<(String, String)>)> = redis::cmd("XRANGE") - .arg(&stream_key) - .arg(start_id) - .arg("+") - .query_async(con) - .await - .map_err(|e| e.to_string())?; - - let mut ops_list: Vec = Vec::new(); - for (_id, fields) in entries { - let mut data_opts = None; - for (k, v) in fields { - if k == "data" { - data_opts = Some(v); - break; - } - } - let data = match data_opts { - Some(x) => x, - None => continue, - }; - - let ev: Value = serde_json::from_str(&data).map_err(|e| e.to_string())?; - let ver = ev.get("version").and_then(|v| v.as_u64()).unwrap_or(0); - if ver == 0 || ver > target_version { - continue; - } - - if ver <= snap_ver { - continue; - } - - let ops: Vec = - serde_json::from_value(ev["ops"].clone()).map_err(|e| e.to_string())?; - ops_list.extend(ops); - } - - apply_ops(snap_json, &ops_list) -} - pub async fn run(config: gcm::Configure) -> gcm::StandardResult { - let queue_capacity = config - .get("BOOT_QUEUE_CAP") - .and_then(|x| x.parse().ok()) - .unwrap_or(512); - - let worker_count: usize = config - .get("CACHE_WORKERS") - .and_then(|x| x.parse().ok()) - .unwrap_or(4); - // REDIS POOL // // @@ -834,12 +725,12 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { )) .expect("failed to create redis conn manager"); let redis_pool = Pool::builder() - .max_size(16) + .max_size(8) .build(manager) .await .expect("failed to build redis pool"); - let (enqueue_tx, enqueue_rx) = channel::(queue_capacity); + let (enqueue_tx, enqueue_rx) = channel::(8); let state = AppState { // cached_country_names: common::valid_country_name(), @@ -852,38 +743,6 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { enqueue_tx: enqueue_tx.clone(), }; - let sys_redis_cli = state.redis.clone(); - - // tokio::spawn(async move { - // while let Some(msg) = sys_rx.recv().await { - // handle_system_message(sys_redis_cli.clone(), msg).await; - // } - // }) - // .await?; - - // SPAWN WORKER - let worker_handle = spawn_cache_workers(redis_pool.clone(), enqueue_rx, worker_count); - - // COLD BOOT PRELOAD - { - let enqueue_tx = enqueue_tx.clone(); - let cfg = config.clone(); - - let enable_cold_start = if let Some(flag) = config.clone().get("COLD_START_ENABLE") { - flag.contains("1") - } else { - false - }; - - if enable_cold_start { - tokio::spawn(async move { - if let Err(e) = cold_boot_enqueue_json(cfg, enqueue_tx).await { - error!("cold boot enqueue failed {e}"); - } - }); - } - } - let app = Router::new() .route("/checkout", get(checkout_handler)) .route("/fetch", get(fetch_handler)) @@ -904,131 +763,5 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { axum::serve(listener, app).await?; - drop(worker_handle); - - Ok(()) -} - -// Cold Boot -// -// -async fn cold_boot_enqueue_json( - config: gcm::Configure, - enqueue_tx: Sender, -) -> Result<(), Box> { - info!("cold boot scanning"); - - let root_repo = config - .get("GIT_REPO_LOCAL_DEST") - .expect("git repo local not define"); - - tx::helpers::setup_prebuild_tx_cache(enqueue_tx, root_repo).await?; - - Ok(()) -} - -// Worker pool -// spawn_cache_workers(config.clone(), redis_pool.clone(), enqueue_rx, worker_count); -fn spawn_cache_workers( - redis_pool: RedisPool, - mut rx: Receiver, - worker_count: usize, -) -> tokio::task::JoinHandle<()> { - tokio::spawn(async move { - info!("starting {worker_count} cache workers"); - - let mut joinset = JoinSet::new(); - - for worker_id in 0..worker_count { - // let redis_pool = redis_pool.clone(); - // let repo_root = config - // .clone() - // .get("GIT_REPO_LOCAL_DEST") - // .expect("unable to get git repo local dest"); - - joinset.spawn(async move { - loop { - tokio::time::sleep(Duration::from_millis(10)).await; - // pull job - let _ = worker_id; - break; - } - }); - } - - // dispatcher - - let max_inflight = worker_count; - - while let Some(job) = rx.recv().await { - while joinset.len() >= max_inflight { - if let Some(res) = joinset.join_next().await { - if let Err(e) = res { - warn!("job task join error: {e}"); - } - } - } - - let redis_pool = redis_pool.clone(); - // let repo_root = config - // .clone() - // .get("GIT_REPO_LOCAL_DEST") - // .expect("unable to get git repo local dest"); - - joinset.spawn(async move { - if let Err(e) = cache_one_file_streaming(redis_pool, job.clone()).await { - warn!("cache job failed: {e:?} {job:?}"); - } - }); - } - - while let Some(res) = joinset.join_next().await { - if let Err(e) = res { - warn!("job task join error: {e:?}"); - } - } - - info!("cache worker stopped (queue closed)"); - }) -} - -async fn cache_one_file_streaming(redis_pool: RedisPool, job: CacheJob) -> gcm::StandardResult { - if job.file_data.is_none() { - return Ok(()); - } - - let final_key = job.rel_path.clone(); - let tmp_key = format!("tmp:{}:{}", final_key, Uuid::new_v4()); - - let file_string = job.file_data.unwrap().to_string(); - let cursor = Cursor::new(file_string.into_bytes()); - let reader = BufReader::new(cursor); - - // brotli - let mut encoder = BrotliEncoder::new(reader); - - let mut conn = redis_pool.get().await?; - let _ = conn.del(&tmp_key).await?; - - let mut buf = vec![0u8; 64 * 1024]; - let mut compressed_total = 0u64; - - loop { - let n = encoder.read(&mut buf).await?; - if n == 0 { - break; - } - - compressed_total += n as u64; - - // append chunk to redis - let _: usize = conn.append(&tmp_key, &buf[..n]).await?; - } - - let _ = conn.del(&final_key).await?; - let _ = conn.rename(tmp_key, &final_key).await?; - - info!("cached {} ({} bytes)", job.rel_path, compressed_total); - Ok(()) } diff --git a/src/tx/helpers.rs b/src/tx/helpers.rs index 07b5e5b..c935bc6 100644 --- a/src/tx/helpers.rs +++ b/src/tx/helpers.rs @@ -158,7 +158,7 @@ pub async fn setup_prebuild_tx_cache( if tx .send(CacheJob { rel_path: expected_version_path.clone(), - file_data: Some(serde_json::json!(version_str)), + file_data: Some(serde_json::to_vec(&version_str)?), }) .await .is_ok() @@ -246,11 +246,11 @@ pub async fn setup_prebuild_tx_cache( // process diffing // - let base_recipe_clone = current_recipes.get("base").unwrap().clone(); + let base_recipe_ref = current_recipes.get("base").unwrap(); for (key, value) in current_recipes.iter() { if key != "base" { - let patch_diff = diff(&base_recipe_clone, value); + let patch_diff = diff(&base_recipe_ref, value); let tx_name = format!( "stx_{}", key.replace("coffeethai02_", "").replace(".json", "") @@ -277,10 +277,12 @@ pub async fn setup_prebuild_tx_cache( // })) // .await; + let json_bytes = serde_json::to_vec(base_recipe_ref)?; + if tx .send(CacheJob { rel_path: format!("{current_path}/{base_file}"), - file_data: Some(base_recipe_clone), + file_data: Some(json_bytes), }) .await .is_ok() From bb3e55eecb2ab255e1a438a2b013203268812e1b Mon Sep 17 00:00:00 2001 From: Pakin Date: Tue, 24 Mar 2026 10:21:02 +0700 Subject: [PATCH 11/21] feat: enable full clone Signed-off-by: Pakin --- src/app.rs | 2 +- src/git.rs | 90 +++++++++++++++++++++++++---------------------- src/tx/helpers.rs | 2 +- 3 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/app.rs b/src/app.rs index 60c29d8..d9dddaa 100644 --- a/src/app.rs +++ b/src/app.rs @@ -735,7 +735,7 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { let state = AppState { // cached_country_names: common::valid_country_name(), configures: config.clone(), - repo: Arc::new(Mutex::new(Repository::open_bare( + repo: Arc::new(Mutex::new(Repository::open( config.get("GIT_REPO_LOCAL_DEST").unwrap_or(&"".to_string()), )?)), redis: redis_pool.clone(), diff --git a/src/git.rs b/src/git.rs index c0ab2da..779141d 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,16 +1,21 @@ -use std::{cell::RefCell, collections::HashMap, io::{self, Write}, path::{Path, PathBuf}}; +use std::{ + cell::RefCell, + collections::HashMap, + io::{self, Write}, + path::{Path, PathBuf}, +}; -use git2::{build::RepoBuilder, Cred, FetchOptions, Progress, RemoteCallbacks}; -use log::{info}; +use git2::{Cred, FetchOptions, Progress, RemoteCallbacks, build::RepoBuilder}; +use log::info; use crate::gcm; struct GitState { - progress: Option>, - total: usize, - current: usize, - path: Option, - newline: bool + progress: Option>, + total: usize, + current: usize, + path: Option, + newline: bool, } fn print(state: &mut GitState) { @@ -29,10 +34,11 @@ fn print(state: &mut GitState) { state.newline = true; } - info!("Resolving deltas {}/{}", - stats.indexed_deltas(), - stats.total_deltas()); - + info!( + "Resolving deltas {}/{}", + stats.indexed_deltas(), + stats.total_deltas() + ); } else { info!( "net {:3}% ({:4} kb, {:5}/{:5}) / idx {:3}% ({:5}/{:5}) \ @@ -58,40 +64,38 @@ fn print(state: &mut GitState) { } pub fn setup_git_repo(config: HashMap) -> gcm::StandardResult { - let state = RefCell::new(GitState { - progress: None, - total: 0, - current: 0, - path: None, - newline: true - }); + let state = RefCell::new(GitState { + progress: None, + total: 0, + current: 0, + path: None, + newline: true, + }); - let mut cb = RemoteCallbacks::new(); - cb.transfer_progress(|stats| { - let mut state = state.borrow_mut(); - state.progress = Some(stats.to_owned()); - print(&mut state); - true - }); + let mut cb = RemoteCallbacks::new(); + cb.transfer_progress(|stats| { + let mut state = state.borrow_mut(); + state.progress = Some(stats.to_owned()); + print(&mut state); + true + }); - cb.credentials(|_,_,_| { - Cred::userpass_plaintext( - config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), - config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()) - ) - }); + cb.credentials(|_, _, _| { + Cred::userpass_plaintext( + config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), + config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()), + ) + }); - let mut fo = FetchOptions::new(); - fo.remote_callbacks(cb); - fo.depth(1); + let mut fo = FetchOptions::new(); + fo.remote_callbacks(cb); - RepoBuilder::new() - .bare(true) - .fetch_options(fo) - .clone( - config.get("GIT_REPO_REMOTE").unwrap_or(&"".to_string()), - Path::new(config.get("GIT_REPO_LOCAL_DEST").unwrap()).into() + let _ = RepoBuilder::new().bare(false).fetch_options(fo).clone( + config.get("GIT_REPO_REMOTE").unwrap_or(&"".to_string()), + Path::new(config.get("GIT_REPO_LOCAL_DEST").unwrap()).into(), )?; - Ok(()) -} \ No newline at end of file + println!("clone completed !"); + + Ok(()) +} diff --git a/src/tx/helpers.rs b/src/tx/helpers.rs index c935bc6..233a93c 100644 --- a/src/tx/helpers.rs +++ b/src/tx/helpers.rs @@ -107,7 +107,7 @@ pub async fn setup_prebuild_tx_cache( git_repo: &str, ) -> Result<(), Box> { // import tx files - let repo = match Repository::open_bare(git_repo) { + let repo = match Repository::open(git_repo) { Ok(repo) => repo, Err(_) => return Err("cannot open repo".into()), }; From d19dab756109cb25b190a8932cd9006a2c4f82bd Mon Sep 17 00:00:00 2001 From: Pakin Date: Fri, 10 Apr 2026 10:11:53 +0700 Subject: [PATCH 12/21] feat: pull handler - test simple pull ok Signed-off-by: Pakin --- src/app.rs | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index d9dddaa..1e85aa0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -661,7 +661,7 @@ async fn push_handler(State(state): State) -> impl IntoResponse { .map(|x| x.to_string()) .unwrap_or("master".to_string()); - if let Err(e) = push(config, repo, remote_name, branch) { + if let Err(e) = push(config, repo, "origin", branch) { return ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})), @@ -700,6 +700,84 @@ fn push( Err("cannot lock repo".into()) } +async fn pull_handler(State(state): State) -> impl IntoResponse { + let config = state.clone().get_all_configures(); + let repo = state.repo.clone(); + let remote_name = match state.get_config("GIT_REPO_REMOTE") { + Some(s) => s, + None => { + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": "repo remote not existed"})), + ); + } + }; + + let branch = &config + .get("GIT_REPO_BRANCH_NAME") + .map(|x| x.to_string()) + .unwrap_or("master".to_string()); + + if let Err(e) = pull(config, repo, "origin", branch) { + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": e.to_string()})), + ); + } + + ( + axum::http::StatusCode::OK, + Json(json!({"result": "pull completed"})), + ) +} + +// Pull is fetch + merge +fn pull( + config: gcm::Configure, + repo: Arc>, + remote_name: &str, + branch: &str, +) -> Result<(), Box> { + if let Ok(rlock) = repo.try_lock() { + let mut rem = rlock.find_remote(remote_name)?; + let mut callback = RemoteCallbacks::new(); + callback.credentials(|_url, _user, _allowed| { + Cred::userpass_plaintext( + config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), + config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()), + ) + }); + let mut fetch_options = FetchOptions::new(); + fetch_options.remote_callbacks(callback); + fetch_options.download_tags(git2::AutotagOption::All); + + info!("fetching from {}...", remote_name); + rem.fetch(&[branch], Some(&mut fetch_options), None)?; + + // resolve fetch vs merge + let fetch_head = rlock.find_reference("FETCH_HEAD")?; + let fetch_commit = rlock.reference_to_annotated_commit(&fetch_head)?; + + let analysis = rlock.merge_analysis(&[&fetch_commit])?; + if analysis.0.is_fast_forward() { + let refname = format!("refs/heads/{branch}"); + let mut reference = rlock.find_reference(&refname)?; + reference.set_target(fetch_commit.id(), "Fast-Forward")?; + rlock.set_head(&refname)?; + rlock.checkout_head(Some(git2::build::CheckoutBuilder::default().force()))?; + info!("Fast-forwared to {}", fetch_commit.id()); + } else if analysis.0.is_normal() { + warn!("need manual merge"); + } else { + info!("already up to date"); + } + + return Ok(()); + } + + Err("cannot lock repo".into()) +} + /// Return git state & server state async fn health_handler(State(_): State) -> impl IntoResponse { ( @@ -748,6 +826,7 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { .route("/fetch", get(fetch_handler)) .route("/commit", post(commit_handler)) .route("/push", get(push_handler)) + .route("/pull", get(pull_handler)) .route("/health", get(health_handler)) // .route("/healthz", get(reg::health)) .with_state(state); From 5bb2a6c192b167991c2f05652f512bb38765d378 Mon Sep 17 00:00:00 2001 From: Pakin Date: Mon, 27 Apr 2026 15:47:11 +0700 Subject: [PATCH 13/21] change: change get from json cache file to multipart Signed-off-by: Pakin --- Cargo.lock | 51 ++++++++++++++++- Cargo.toml | 1 + src/app.rs | 159 +++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 187 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a3f576..32470fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -247,9 +247,9 @@ dependencies = [ [[package]] name = "axum" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" +checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90" dependencies = [ "axum-core", "bytes", @@ -297,6 +297,29 @@ dependencies = [ "tracing", ] +[[package]] +name = "axum-extra" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be44683b41ccb9ab2d23a5230015c9c3c55be97a25e4428366de8873103f7970" +dependencies = [ + "axum", + "axum-core", + "bytes", + "fastrand", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "mime", + "multer", + "pin-project-lite", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "axum-macros" version = "0.5.0" @@ -1667,6 +1690,23 @@ dependencies = [ "pxfm", ] +[[package]] +name = "multer" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e87776546dc87511aa5ee218730c92b666d7264ab6ed41f9d215af9cd5224b" +dependencies = [ + "bytes", + "encoding_rs", + "futures-util", + "http", + "httparse", + "memchr", + "mime", + "spin", + "version_check", +] + [[package]] name = "multimap" version = "0.10.1" @@ -2614,6 +2654,12 @@ dependencies = [ "windows-sys 0.60.2", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -2695,6 +2741,7 @@ version = "0.1.0" dependencies = [ "async-compression", "axum", + "axum-extra", "axum-macros", "bb8", "bb8-redis", diff --git a/Cargo.toml b/Cargo.toml index 9ec73b0..d15588c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" async-compression = { version = "0.4.39", features = ["tokio", "brotli"] } axum = "0.8.7" axum-macros = "0.5.0" +axum-extra = { version = "0.12.6", features = ["multipart"] } bb8 = "0.9.1" bb8-redis = "0.26.0" brotli = "8.0.2" diff --git a/src/app.rs b/src/app.rs index 1e85aa0..bfa0e2f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -8,6 +8,7 @@ use axum::{ response::{IntoResponse, Response}, routing::{get, post}, }; +use axum_extra::extract::multipart::Multipart; use axum_macros::debug_handler; use bb8::{Pool, PooledConnection}; use bb8_redis::RedisConnectionManager; @@ -378,37 +379,148 @@ struct Signature { #[debug_handler] async fn commit_handler( State(state): State, - // request body - Json(payload): Json, + // request body as multipart/form-data + mut payload: Multipart, ) -> impl IntoResponse { - let mut content = match fetch_content_from_redis(state.redis.clone(), &payload.patch_key).await - { - Ok(c) => c, - Err(e) => { + // Extract multipart fields + let mut path: Option = None; + let mut signature_username: Option = None; + let mut signature_email: Option = None; + let mut message: Option = None; + let mut file_bytes: Option> = None; + + // Process each field in the multipart payload + while let Ok(Some(field)) = payload.next_field().await { + let name = field.name().unwrap_or("").to_string(); + + match name.as_str() { + "path" => { + path = Some(match field.text().await { + Ok(t) => t, + Err(e) => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!({"error": format!("Failed to read path field: {}", e)})), + ); + } + }); + } + "signature_username" => { + signature_username = Some(match field.text().await { + Ok(t) => t, + Err(e) => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json( + json!({"error": format!("Failed to read signature_username field: {}", e)}), + ), + ); + } + }); + } + "signature_email" => { + signature_email = Some(match field.text().await { + Ok(t) => t, + Err(e) => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json( + json!({"error": format!("Failed to read signature_email field: {}", e)}), + ), + ); + } + }); + } + "message" => { + message = Some(match field.text().await { + Ok(t) => t, + Err(e) => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!({"error": format!("Failed to read message field: {}", e)})), + ); + } + }); + } + "file" => { + file_bytes = Some(match field.bytes().await { + Ok(b) => b.to_vec(), + Err(e) => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!({"error": format!("Failed to read file field: {}", e)})), + ); + } + }); + } + _ => { + // Ignore unknown fields + } + } + } + + // Validate required fields + let path = match path { + Some(p) => p, + None => { return ( axum::http::StatusCode::BAD_REQUEST, - Json(json!({"error": e})), + Json(json!({"error": "Missing required field: path"})), ); } }; - let is_patch_file = content.starts_with("patch"); - // do apply patch first - if is_patch_file { - content = apply_patch_to_file(state.redis.clone(), &payload.path, &mut content).await; - } + let signature_username = match signature_username { + Some(su) => su, + None => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!({"error": "Missing required field: signature_username"})), + ); + } + }; + let signature_email = match signature_email { + Some(se) => se, + None => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!({"error": "Missing required field: signature_email"})), + ); + } + }; + + let file_bytes = match file_bytes { + Some(fb) => fb, + None => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!({"error": "Missing required field: file"})), + ); + } + }; + + // Create signature + let signature = Signature { + username: signature_username, + email: signature_email, + }; + + // Get branch name from config + let branch = state + .clone() + .get_config("GIT_REPO_BRANCH_NAME") + .map(|x| x.to_string()) + .unwrap_or("master".to_string()); + + // Commit the file content directly from multipart upload let commit_oid = match commit_file_content( state.clone().repo, - &payload.path, - &content.as_bytes(), - payload.signature, - &payload.message.unwrap_or("update: from api".to_string()), - state - .clone() - .get_config("GIT_REPO_BRANCH_NAME") - .map(|x| x.to_string()) - .unwrap_or("master".to_string()), + &path, + &file_bytes, + signature, + &message.unwrap_or("update: from api".to_string()), + branch, ) .await { @@ -425,7 +537,10 @@ async fn commit_handler( let redis_pre_lock = state.redis.clone(); { if let Ok(mut rl) = redis_pre_lock.get().await { - let _ = rl.rpush(format!("{}.history", payload.path), payload.patch_key); + let _ = rl.rpush( + format!("{}.history", path), + format!("commit-{}", commit_oid), + ); } } From bca1c911d3be36b4ea12bf522098abb88da552a5 Mon Sep 17 00:00:00 2001 From: Pakin Date: Tue, 28 Apr 2026 11:43:03 +0700 Subject: [PATCH 14/21] add commit logging --- src/app.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/app.rs b/src/app.rs index bfa0e2f..ce5d490 100644 --- a/src/app.rs +++ b/src/app.rs @@ -370,7 +370,7 @@ struct CommitBody { extra: HashMap, } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] struct Signature { username: String, email: String, @@ -459,6 +459,8 @@ async fn commit_handler( } } + info!("committing ..."); + // Validate required fields let path = match path { Some(p) => p, @@ -470,6 +472,8 @@ async fn commit_handler( } }; + info!("path: [{path}]"); + let signature_username = match signature_username { Some(su) => su, None => { @@ -506,6 +510,8 @@ async fn commit_handler( email: signature_email, }; + info!("sig: {signature:?}"); + // Get branch name from config let branch = state .clone() @@ -533,14 +539,22 @@ async fn commit_handler( } }; + info!("commit success! [{commit_oid}]"); + // save history let redis_pre_lock = state.redis.clone(); { if let Ok(mut rl) = redis_pre_lock.get().await { - let _ = rl.rpush( - format!("{}.history", path), - format!("commit-{}", commit_oid), - ); + match rl + .rpush( + format!("{}.history", path), + format!("commit-{}", commit_oid), + ) + .await + { + Ok(_) => info!("history saved"), + Err(e) => error!("save history fail: {e:?}"), + } } } @@ -881,10 +895,10 @@ fn pull( rlock.set_head(&refname)?; rlock.checkout_head(Some(git2::build::CheckoutBuilder::default().force()))?; info!("Fast-forwared to {}", fetch_commit.id()); - } else if analysis.0.is_normal() { - warn!("need manual merge"); - } else { + } else if analysis.0.is_up_to_date() { info!("already up to date"); + } else { + return Err("cannot fast-forward, local changes would be overwritten".into()); } return Ok(()); From ae9d9fa66bf0abf2f825a3302af73f46d9e94829 Mon Sep 17 00:00:00 2001 From: Pakin Date: Tue, 5 May 2026 16:55:09 +0700 Subject: [PATCH 15/21] feat: commit, push, pull - test ok but must call pull first before do commit or push Signed-off-by: Pakin --- Cargo.lock | 1034 ++++++++++++++++++++++++++++----------------------- src/app.rs | 183 +++++---- src/main.rs | 5 +- 3 files changed, 667 insertions(+), 555 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 32470fc..a04d933 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,9 +72,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.21" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" dependencies = [ "anstyle", "anstyle-parse", @@ -87,15 +87,15 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" [[package]] name = "anstyle-parse" -version = "0.2.7" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" dependencies = [ "utf8parse", ] @@ -122,9 +122,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.100" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "arbitrary" @@ -169,9 +169,9 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.4.39" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68650b7df54f0293fd061972a0fb05aaf4fc0879d3b3d21a638a182c5c543b9f" +checksum = "e79b3f8a79cccc2898f31920fc69f304859b3bd567490f75ebf51ae1c792a9ac" dependencies = [ "compression-codecs", "compression-core", @@ -179,6 +179,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "async-lock" +version = "3.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311" +dependencies = [ + "event-listener", + "event-listener-strategy", + "pin-project-lite", +] + [[package]] name = "async-trait" version = "0.1.89" @@ -217,7 +228,7 @@ dependencies = [ "num-traits", "pastey", "rayon", - "thiserror 2.0.18", + "thiserror", "v_frame", "y4m", ] @@ -322,9 +333,9 @@ dependencies = [ [[package]] name = "axum-macros" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c" +checksum = "7aa268c23bfbbd2c4363b9cd302a4f504fb2a9dfe7e3451d66f35dd392e20aca" dependencies = [ "proc-macro2", "quote", @@ -367,17 +378,17 @@ checksum = "1e4b40c7323adcfc0a41c4b88143ed58346ff65a288fc144329c5c45e05d70c6" [[package]] name = "bitflags" -version = "2.10.0" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" [[package]] name = "bitstream-io" -version = "4.9.0" +version = "4.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60d4bd9d1db2c6bdf285e223a7fa369d5ce98ec767dec949c6ca62863ce61757" +checksum = "7eff00be299a18769011411c9def0d827e8f2d7bf0c3dbf53633147a8867fd1f" dependencies = [ - "core2", + "no_std_io2", ] [[package]] @@ -418,9 +429,9 @@ checksum = "f4ad8f11f288f48ca24471bbd51ac257aaeaaa07adae295591266b792902ae64" [[package]] name = "bumpalo" -version = "3.19.1" +version = "3.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dd9dc738b7a8311c7ade152424974d8115f2cdad61e8dab8dac9f2362298510" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" [[package]] name = "bytemuck" @@ -451,9 +462,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.53" +version = "1.2.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "755d2fce177175ffca841e9a06afdb2c4ab0f593d53b4dee48147dfaade85932" +checksum = "d16d90359e986641506914ba71350897565610e87ce0ad9e6f28569db3dd5c6d" dependencies = [ "find-msvc-tools", "jobserver", @@ -469,9 +480,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "chrono" -version = "0.4.43" +version = "0.4.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fac4744fb15ae8337dc853fee7fb3f4e48c0fbaa23d0afe49c447b4fab126118" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" dependencies = [ "iana-time-zone", "js-sys", @@ -498,9 +509,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "colorchoice" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" [[package]] name = "combine" @@ -518,9 +529,9 @@ dependencies = [ [[package]] name = "compression-codecs" -version = "0.4.36" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00828ba6fd27b45a448e57dbfe84f1029d4c9f26b368157e9a448a5f49a2ec2a" +checksum = "ce2548391e9c1929c21bf6aa2680af86fe4c1b33e6cea9ac1cfeec0bd11218cf" dependencies = [ "brotli", "compression-core", @@ -528,9 +539,18 @@ dependencies = [ [[package]] name = "compression-core" -version = "0.4.31" +version = "0.4.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75984efb6ed102a0d42db99afb6c1948f0380d1d91808d5529916e6c08b49d8d" +checksum = "cc14f565cf027a105f7a44ccf9e5b424348421a1d8952a8fc9d499d313107789" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] [[package]] name = "constant_time_eq" @@ -548,21 +568,22 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "core2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" -dependencies = [ - "memchr", -] - [[package]] name = "cpufeatures" version = "0.2.17" @@ -583,9 +604,9 @@ dependencies = [ [[package]] name = "crc-catalog" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" +checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853" [[package]] name = "crc32fast" @@ -639,15 +660,15 @@ dependencies = [ [[package]] name = "deflate64" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26bf8fc351c5ed29b5c2f0cbbac1b209b74f60ecd62e675a998df72c49af5204" +checksum = "ac6b926516df9c60bfa16e107b21086399f8285a44ca9711344b9e553c5146e2" [[package]] name = "deranged" -version = "0.5.5" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" dependencies = [ "powerfmt", ] @@ -702,9 +723,9 @@ dependencies = [ [[package]] name = "env_filter" -version = "0.1.4" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" +checksum = "32e90c2accc4b07a8456ea0debdc2e7587bdd890680d71173a15d4ae604f6eef" dependencies = [ "log", "regex", @@ -712,9 +733,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.11.8" +version = "0.11.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" +checksum = "0621c04f2196ac3f488dd583365b9c09be011a4ab8b9f37248ffcc8f6198b56a" dependencies = [ "anstream", "anstyle", @@ -759,6 +780,27 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + [[package]] name = "exr" version = "1.74.0" @@ -776,29 +818,15 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.3.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" [[package]] name = "fax" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f05de7d48f37cd6730705cbca900770cab77a89f413d23e100ad7fad7795a0ab" -dependencies = [ - "fax_derive", -] - -[[package]] -name = "fax_derive" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0aca10fb742cb43f9e7bb8467c91aa9bcb8e3ffbc6a6f7389bb93ffc920577d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "caf1079563223d5d59d83c85886a56e586cfd5c1a26292e971a0fa266531ac5a" [[package]] name = "fdeflate" @@ -822,9 +850,9 @@ dependencies = [ [[package]] name = "find-msvc-tools" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8591b0bcc8a98a64310a2fae1bb3e9b8564dd10e381e6e28010fde8e8e8568db" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "fixedbitset" @@ -834,9 +862,9 @@ checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" [[package]] name = "flate2" -version = "1.1.8" +version = "1.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" dependencies = [ "crc32fast", "miniz_oxide", @@ -881,24 +909,24 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" [[package]] name = "futures-macro" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" dependencies = [ "proc-macro2", "quote", @@ -907,28 +935,27 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" [[package]] name = "futures-task" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" [[package]] name = "futures-util" -version = "0.3.31" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" dependencies = [ "futures-core", "futures-macro", "futures-sink", "futures-task", "pin-project-lite", - "pin-utils", "slab", ] @@ -961,15 +988,28 @@ checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", "libc", - "r-efi", + "r-efi 5.3.0", "wasip2", ] [[package]] -name = "gif" -version = "0.14.1" +name = "getrandom" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5df2ba84018d80c213569363bdcd0c64e6933c67fe4c1d60ecf822971a3c35e" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", + "wasip2", + "wasip3", +] + +[[package]] +name = "gif" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee8cfcc411d9adbbaba82fb72661cc1bcca13e8bba98b364e62b2dba8f960159" dependencies = [ "color_quant", "weezl", @@ -977,15 +1017,15 @@ dependencies = [ [[package]] name = "git2" -version = "0.20.3" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2b37e2f62729cdada11f0e6b3b6fe383c69c29fc619e391223e12856af308c" +checksum = "7b88256088d75a56f8ecfa070513a775dd9107f6530ef14919dac831af9cfe2b" dependencies = [ "bitflags", "libc", "libgit2-sys", "log", - "openssl-probe", + "openssl-probe 0.1.6", "openssl-sys", "url", ] @@ -1031,9 +1071,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.16.1" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" [[package]] name = "heck" @@ -1097,9 +1137,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +checksum = "6299f016b246a94207e63da54dbe807655bf9e00044f73ded42c3ac5305fbcca" dependencies = [ "atomic-waker", "bytes", @@ -1112,7 +1152,6 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "pin-utils", "smallvec", "tokio", "want", @@ -1120,15 +1159,14 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.7" +version = "0.27.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" dependencies = [ "http", "hyper", "hyper-util", "rustls", - "rustls-pki-types", "tokio", "tokio-rustls", "tower-service", @@ -1165,14 +1203,13 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "727805d60e7938b76b826a6ef209eb70eaa1812794f9424d4a4e2d740662df5f" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" dependencies = [ "base64", "bytes", "futures-channel", - "futures-core", "futures-util", "http", "http-body", @@ -1191,9 +1228,9 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.64" +version = "0.1.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33e57f83510bb73707521ebaffa789ec8caf86f9657cad665b092b581d40e9fb" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -1215,12 +1252,13 @@ dependencies = [ [[package]] name = "icu_collections" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" dependencies = [ "displaydoc", "potential_utf", + "utf8_iter", "yoke", "zerofrom", "zerovec", @@ -1228,9 +1266,9 @@ dependencies = [ [[package]] name = "icu_locale_core" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" dependencies = [ "displaydoc", "litemap", @@ -1241,9 +1279,9 @@ dependencies = [ [[package]] name = "icu_normalizer" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" dependencies = [ "icu_collections", "icu_normalizer_data", @@ -1255,15 +1293,15 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" [[package]] name = "icu_properties" -version = "2.1.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" dependencies = [ "icu_collections", "icu_locale_core", @@ -1275,15 +1313,15 @@ dependencies = [ [[package]] name = "icu_properties_data" -version = "2.1.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" [[package]] name = "icu_provider" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" dependencies = [ "displaydoc", "icu_locale_core", @@ -1294,6 +1332,12 @@ dependencies = [ "zerovec", ] +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + [[package]] name = "idna" version = "1.1.0" @@ -1307,9 +1351,9 @@ dependencies = [ [[package]] name = "idna_adapter" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" dependencies = [ "icu_normalizer", "icu_properties", @@ -1317,9 +1361,9 @@ dependencies = [ [[package]] name = "image" -version = "0.25.9" +version = "0.25.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6506c6c10786659413faa717ceebcb8f70731c0a60cbae39795fdf114519c1a" +checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104" dependencies = [ "bytemuck", "byteorder-lite", @@ -1335,8 +1379,8 @@ dependencies = [ "rayon", "rgb", "tiff", - "zune-core 0.5.1", - "zune-jpeg 0.5.12", + "zune-core", + "zune-jpeg", ] [[package]] @@ -1351,18 +1395,20 @@ dependencies = [ [[package]] name = "imgref" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c5cedc30da3a610cac6b4ba17597bdf7152cf974e8aab3afb3d54455e371c8" +checksum = "40fac9d56ed6437b198fddba683305e8e2d651aa42647f00f5ae542e7f5c94a2" [[package]] name = "indexmap" -version = "2.13.0" +version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown 0.16.1", + "hashbrown 0.17.0", + "serde", + "serde_core", ] [[package]] @@ -1387,15 +1433,15 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.11.0" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" +checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" [[package]] name = "iri-string" -version = "0.7.10" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +checksum = "25e659a4bb38e810ebc252e53b5814ff908a8c58c2a9ce2fae1bbec24cbf4e20" dependencies = [ "memchr", "serde", @@ -1418,15 +1464,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "jiff" -version = "0.2.18" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e67e8da4c49d6d9909fe03361f9b620f58898859f5c7aded68351e85e71ecf50" +checksum = "f00b5dbd620d61dfdcb6007c9c1f6054ebd75319f163d886a9055cec1155073d" dependencies = [ "jiff-static", "log", @@ -1437,9 +1483,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.18" +version = "0.2.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0c84ee7f197eca9a86c6fd6cb771e55eb991632f15f2bc3ca6ec838929e6e78" +checksum = "e000de030ff8022ea1da3f466fbb0f3a809f5e51ed31f6dd931c35181ad8e6d7" dependencies = [ "proc-macro2", "quote", @@ -1458,24 +1504,26 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.85" +version = "0.3.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c942ebf8e95485ca0d52d97da7c5a2c387d0e7f0ba4c35e93bfcaee045955b3" +checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf" dependencies = [ + "cfg-if", + "futures-util", "once_cell", "wasm-bindgen", ] [[package]] name = "json-patch" -version = "4.1.0" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f300e415e2134745ef75f04562dd0145405c2f7fd92065db029ac4b16b57fe90" +checksum = "7421438de105a0827e44fadd05377727847d717c80ce29a229f85fd04c427b72" dependencies = [ "jsonptr", "serde", "serde_json", - "thiserror 1.0.69", + "thiserror", ] [[package]] @@ -1488,6 +1536,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + [[package]] name = "lebe" version = "0.5.3" @@ -1496,15 +1550,15 @@ checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8" [[package]] name = "libbz2-rs-sys" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c4a545a15244c7d945065b5d392b2d2d7f21526fba56ce51467b06ed445e8f7" +checksum = "b3a6a8c165077efc8f3a971534c50ea6a1a18b329ef4a66e897a7e3a1494565f" [[package]] name = "libc" -version = "0.2.180" +version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] name = "libfuzzer-sys" @@ -1532,13 +1586,14 @@ dependencies = [ [[package]] name = "libredox" -version = "0.1.12" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" +checksum = "e02f3bb43d335493c96bf3fd3a321600bf6bd07ed34bc64118e9293bdffea46c" dependencies = [ "bitflags", "libc", - "redox_syscall 0.7.0", + "plain", + "redox_syscall 0.7.4", ] [[package]] @@ -1558,12 +1613,14 @@ dependencies = [ [[package]] name = "libtbr" version = "0.1.1" -source = "git+https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/libtbr.git#2b6b0626642a41a582864052e909e2585886ff89" +source = "git+https://pakin-inspiron-15-3530.tail110d9.ts.net/pakin/libtbr.git#21984bdfba3f9f9ab0f31b44a8010d173402cd25" dependencies = [ "chrono", "flate2", "git2", + "indexmap", "log", + "quick-xml", "rand", "rayon", "serde", @@ -1575,9 +1632,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.23" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15d118bbf3771060e7311cc7bb0545b01d08a8b4a7de949198dec1fa0ca1c0f7" +checksum = "fc3a226e576f50782b3305c5ccf458698f92798987f551c6a02efe8276721e22" dependencies = [ "cc", "libc", @@ -1587,15 +1644,15 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.11.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "litemap" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" [[package]] name = "lock_api" @@ -1649,9 +1706,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.7.6" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" [[package]] name = "mime" @@ -1671,9 +1728,9 @@ dependencies = [ [[package]] name = "mio" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" dependencies = [ "libc", "wasi", @@ -1682,9 +1739,9 @@ dependencies = [ [[package]] name = "moxcms" -version = "0.7.11" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac9557c559cd6fc9867e122e20d2cbefc9ca29d80d027a8e39310920ed2f0a97" +checksum = "bb85c154ba489f01b25c0d36ae69a87e4a1c73a72631fc6c0eb6dde34a73e44b" dependencies = [ "num-traits", "pxfm", @@ -1715,14 +1772,14 @@ checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" [[package]] name = "native-tls" -version = "0.2.14" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" +checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2" dependencies = [ "libc", "log", "openssl", - "openssl-probe", + "openssl-probe 0.2.1", "openssl-sys", "schannel", "security-framework", @@ -1736,6 +1793,15 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" +[[package]] +name = "no_std_io2" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b51ed7824b6e07d354605f4abb3d9d300350701299da96642ee084f5ce631550" +dependencies = [ + "memchr", +] + [[package]] name = "nom" version = "8.0.0" @@ -1763,9 +1829,9 @@ dependencies = [ [[package]] name = "num-conv" -version = "0.1.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +checksum = "c6673768db2d862beb9b39a78fdcb1a69439615d5794a1be50caa9bc92c81967" [[package]] name = "num-derive" @@ -1809,9 +1875,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.21.3" +version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "once_cell_polyfill" @@ -1821,15 +1887,14 @@ checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "openssl" -version = "0.10.75" +version = "0.10.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08838db121398ad17ab8531ce9de97b244589089e290a384c900cb9ff7434328" +checksum = "bf0b434746ee2832f4f0baf10137e1cabb18cbe6912c69e2e33263c45250f542" dependencies = [ "bitflags", "cfg-if", "foreign-types", "libc", - "once_cell", "openssl-macros", "openssl-sys", ] @@ -1852,10 +1917,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" [[package]] -name = "openssl-sys" -version = "0.9.111" +name = "openssl-probe" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82cab2d520aa75e3c58898289429321eb788c3106963d0dc886ec7a5f4adc321" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "openssl-sys" +version = "0.9.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "158fe5b292746440aa6e7a7e690e55aeb72d41505e2804c23c6973ad0e9c9781" dependencies = [ "cc", "libc", @@ -1863,6 +1934,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "parking_lot" version = "0.12.5" @@ -1927,18 +2004,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.10" +version = "1.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.10" +version = "1.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6" dependencies = [ "proc-macro2", "quote", @@ -1947,21 +2024,21 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pkg-config" -version = "0.3.32" +version = "0.3.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" + +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" [[package]] name = "png" @@ -1978,24 +2055,24 @@ dependencies = [ [[package]] name = "portable-atomic" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" +checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" [[package]] name = "portable-atomic-util" -version = "0.2.4" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" +checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" dependencies = [ "portable-atomic", ] [[package]] name = "potential_utf" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" dependencies = [ "zerovec", ] @@ -2008,9 +2085,9 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppmd-rust" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d558c559f0450f16f2a27a1f017ef38468c1090c9ce63c8e51366232d53717b4" +checksum = "efca4c95a19a79d1c98f791f10aebd5c1363b473244630bb7dbde1dc98455a24" [[package]] name = "ppv-lite86" @@ -2114,9 +2191,9 @@ dependencies = [ [[package]] name = "pulldown-cmark" -version = "0.13.0" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e8bbe1a966bd2f362681a44f6edce3c2310ac21e4d5067a6e7ec396297a6ea0" +checksum = "7c3a14896dfa883796f1cb410461aef38810ea05f2b2c33c5aded3649095fdad" dependencies = [ "bitflags", "memchr", @@ -2134,12 +2211,9 @@ dependencies = [ [[package]] name = "pxfm" -version = "0.1.27" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7186d3822593aa4393561d186d1393b3923e9d6163d3fbfd6e825e3e6cf3e6a8" -dependencies = [ - "num-traits", -] +checksum = "e0c5ccf5294c6ccd63a74f1565028353830a9c2f5eb0c682c355c471726a6e3f" [[package]] name = "qoi" @@ -2157,10 +2231,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] -name = "quote" -version = "1.0.43" +name = "quick-xml" +version = "0.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" +checksum = "958f21e8e7ceb5a1aa7fa87fab28e7c75976e0bfe7e23ff069e0a260f894067d" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] @@ -2172,10 +2255,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] -name = "rand" -version = "0.9.2" +name = "r-efi" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" dependencies = [ "rand_chacha", "rand_core", @@ -2230,16 +2319,16 @@ dependencies = [ "rand", "rand_chacha", "simd_helpers", - "thiserror 2.0.18", + "thiserror", "v_frame", "wasm-bindgen", ] [[package]] name = "ravif" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef69c1990ceef18a116855938e74793a5f7496ee907562bd0857b6ac734ab285" +checksum = "e52310197d971b0f5be7fe6b57530dcd27beb35c1b013f29d66c1ad73fbbcc45" dependencies = [ "avif-serialize", "imgref", @@ -2252,9 +2341,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" +checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d" dependencies = [ "either", "rayon-core", @@ -2272,11 +2361,12 @@ dependencies = [ [[package]] name = "redis" -version = "1.0.2" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfe20977fe93830c0e9817a16fbf1ed1cfd8d4bba366087a1841d2c6033c251" +checksum = "72d32a1ac9123f0d84fda64bfc02a271d9868483162dd2d9099b5c362ece064c" dependencies = [ "arcstr", + "async-lock", "bytes", "cfg-if", "combine", @@ -2305,18 +2395,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.7.0" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f3fe0889e69e2ae9e41f4d6c4c0181701d00e4697b356fb1f74173a5e0ee27" +checksum = "f450ad9c3b1da563fb6948a8e0fb0fb9269711c9c73d9ea1de5058c79c8d643a" dependencies = [ "bitflags", ] [[package]] name = "regex" -version = "1.12.2" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" dependencies = [ "aho-corasick", "memchr", @@ -2326,9 +2416,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" dependencies = [ "aho-corasick", "memchr", @@ -2337,9 +2427,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.8" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" [[package]] name = "reqwest" @@ -2383,9 +2473,9 @@ dependencies = [ [[package]] name = "rgb" -version = "0.8.52" +version = "0.8.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6a884d2998352bb4daf0183589aec883f16a6da1f4dde84d8e2e9a5409a1ce" +checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4" [[package]] name = "ring" @@ -2403,9 +2493,9 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c9e247ccc180c1f61615433868c99f3de3ae256a30a43b49f67c2d9171f34" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ "bitflags", "errno", @@ -2416,9 +2506,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.36" +version = "0.23.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" +checksum = "ef86cd5876211988985292b91c96a8f2d298df24e75989a43a3c73f2d4d8168b" dependencies = [ "once_cell", "rustls-pki-types", @@ -2429,18 +2519,18 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.14.0" +version = "1.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +checksum = "30a7197ae7eb376e574fe940d068c30fe0462554a3ddbe4eca7838e049c937a9" dependencies = [ "zeroize", ] [[package]] name = "rustls-webpki" -version = "0.103.9" +version = "0.103.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +checksum = "61c429a8649f110dddef65e2a5ad240f747e85f7758a6bccc7e5777bd33f756e" dependencies = [ "ring", "rustls-pki-types", @@ -2455,9 +2545,9 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a50f4cf475b65d88e057964e0e9bb1f0aa9bbb2036dc65c64596b42932536984" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" [[package]] name = "same-file" @@ -2470,9 +2560,9 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +checksum = "91c1b7e4904c873ef0710c1f407dde2e6287de2bebc1bbbf7d430bb7cbffd939" dependencies = [ "windows-sys 0.61.2", ] @@ -2485,12 +2575,12 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "security-framework" -version = "2.11.1" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" dependencies = [ "bitflags", - "core-foundation", + "core-foundation 0.10.1", "core-foundation-sys", "libc", "security-framework-sys", @@ -2498,14 +2588,20 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.15.0" +version = "2.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc1f0cbffaac4852523ce30d8bd3c5cdc873501d96ff467ca09b6767bb8cd5c0" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" dependencies = [ "core-foundation-sys", "libc", ] +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + [[package]] name = "serde" version = "1.0.228" @@ -2619,9 +2715,9 @@ dependencies = [ [[package]] name = "simd-adler32" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" +checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214" [[package]] name = "simd_helpers" @@ -2634,9 +2730,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" @@ -2646,12 +2742,12 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "socket2" -version = "0.6.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -2674,9 +2770,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.114" +version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" dependencies = [ "proc-macro2", "quote", @@ -2705,12 +2801,12 @@ dependencies = [ [[package]] name = "system-configuration" -version = "0.6.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b" dependencies = [ "bitflags", - "core-foundation", + "core-foundation 0.9.4", "system-configuration-sys", ] @@ -2726,9 +2822,9 @@ dependencies = [ [[package]] name = "tar" -version = "0.4.44" +version = "0.4.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a" +checksum = "22692a6476a21fa75fdfc11d452fda482af402c008cdbaf3476414e122040973" dependencies = [ "filetime", "libc", @@ -2770,44 +2866,24 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.24.0" +version = "3.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "655da9c7eb6305c55742045d5a8d2037996d61d8de95806335c7c86ce0f82e9c" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.3.4", + "getrandom 0.4.2", "once_cell", "rustix", "windows-sys 0.61.2", ] -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - [[package]] name = "thiserror" version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ - "thiserror-impl 2.0.18", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "thiserror-impl", ] [[package]] @@ -2823,23 +2899,23 @@ dependencies = [ [[package]] name = "tiff" -version = "0.10.3" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af9605de7fee8d9551863fd692cce7637f548dbd9db9180fcc07ccc6d26c336f" +checksum = "b63feaf3343d35b6ca4d50483f94843803b0f51634937cc2ec519fc32232bc52" dependencies = [ "fax", "flate2", "half", "quick-error", "weezl", - "zune-jpeg 0.4.21", + "zune-jpeg", ] [[package]] name = "time" -version = "0.3.45" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9e442fc33d7fdb45aa9bfeb312c095964abdf596f7567261062b2a7107aaabd" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" dependencies = [ "deranged", "num-conv", @@ -2850,15 +2926,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b36ee98fd31ec7426d599183e8fe26932a8dc1fb76ddb6214d05493377d34ca" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" [[package]] name = "tinystr" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" dependencies = [ "displaydoc", "zerovec", @@ -2866,9 +2942,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.49.0" +version = "1.52.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6" dependencies = [ "bytes", "libc", @@ -2883,9 +2959,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", @@ -2938,9 +3014,9 @@ dependencies = [ [[package]] name = "tonic" -version = "0.14.2" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb7613188ce9f7df5bfe185db26c5814347d110db17920415cf2fbcad85e7203" +checksum = "fec7c61a0695dc1887c1b53952990f3ad2e3a31453e1f49f10e75424943a93ec" dependencies = [ "async-trait", "axum", @@ -2967,9 +3043,9 @@ dependencies = [ [[package]] name = "tonic-build" -version = "0.14.2" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40aaccc9f9eccf2cd82ebc111adc13030d23e887244bc9cfa5d1d636049de3" +checksum = "1882ac3bf5ef12877d7ed57aad87e75154c11931c2ba7e6cde5e22d63522c734" dependencies = [ "prettyplease", "proc-macro2", @@ -2979,9 +3055,9 @@ dependencies = [ [[package]] name = "tonic-prost" -version = "0.14.2" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66bd50ad6ce1252d87ef024b3d64fe4c3cf54a86fb9ef4c631fdd0ded7aeaa67" +checksum = "a55376a0bbaa4975a3f10d009ad763d8f4108f067c7c2e74f3001fb49778d309" dependencies = [ "bytes", "prost", @@ -2990,9 +3066,9 @@ dependencies = [ [[package]] name = "tonic-prost-build" -version = "0.14.2" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4a16cba4043dc3ff43fcb3f96b4c5c154c64cbd18ca8dce2ab2c6a451d058a2" +checksum = "f3144df636917574672e93d0f56d7edec49f90305749c668df5101751bb8f95a" dependencies = [ "prettyplease", "proc-macro2", @@ -3093,9 +3169,9 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typenum" -version = "1.19.0" +version = "1.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" [[package]] name = "unicase" @@ -3105,9 +3181,15 @@ checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" [[package]] name = "unicode-ident" -version = "1.0.22" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "untrusted" @@ -3141,11 +3223,11 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.20.0" +version = "1.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee48d38b119b0cd71fe4141b30f5ba9c7c5d9f4e7a3a8b4a674e4b6ef789976f" +checksum = "ddd74a9687298c6858e9b88ec8935ec45d22e8fd5e6394fa1bd4e99a87789c76" dependencies = [ - "getrandom 0.3.4", + "getrandom 0.4.2", "js-sys", "wasm-bindgen", ] @@ -3200,18 +3282,27 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.2+wasi-0.2.9" +version = "1.0.3+wasi-0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.57.1", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", ] [[package]] name = "wasm-bindgen" -version = "0.2.108" +version = "0.2.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64024a30ec1e37399cf85a7ffefebdb72205ca1c972291c51512360d90bd8566" +checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1" dependencies = [ "cfg-if", "once_cell", @@ -3222,23 +3313,19 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.58" +version = "0.4.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70a6e77fd0ae8029c9ea0063f87c46fde723e7d887703d74ad2616d792e51e6f" +checksum = "af934872acec734c2d80e6617bbb5ff4f12b052dd8e6332b0817bce889516084" dependencies = [ - "cfg-if", - "futures-util", "js-sys", - "once_cell", "wasm-bindgen", - "web-sys", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.108" +version = "0.2.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "008b239d9c740232e71bd39e8ef6429d27097518b6b30bdf9086833bd5b6d608" +checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3246,9 +3333,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.108" +version = "0.2.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5256bae2d58f54820e6490f9839c49780dff84c65aeab9e772f15d5f0e913a55" +checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41" dependencies = [ "bumpalo", "proc-macro2", @@ -3259,18 +3346,52 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.108" +version = "0.2.120" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f01b580c9ac74c8d8f0c0e4afb04eeef2acf145458e52c03845ee9cd23e3d12" +checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea" dependencies = [ "unicode-ident", ] [[package]] -name = "web-sys" -version = "0.3.85" +name = "wasm-encoder" +version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "312e32e551d92129218ea9a2452120f4aabc03529ef03e4d0d82fb2780608598" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-sys" +version = "0.3.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eadbac71025cd7b0834f20d1fe8472e8495821b4e9801eb0a60bd1f19827602" dependencies = [ "js-sys", "wasm-bindgen", @@ -3367,16 +3488,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets 0.53.5", + "windows-targets", ] [[package]] @@ -3394,31 +3506,14 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm 0.53.1", - "windows_aarch64_msvc 0.53.1", - "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm 0.53.1", - "windows_i686_msvc 0.53.1", - "windows_x86_64_gnu 0.53.1", - "windows_x86_64_gnullvm 0.53.1", - "windows_x86_64_msvc 0.53.1", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] @@ -3427,107 +3522,147 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - [[package]] name = "wit-bindgen" version = "0.51.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] [[package]] name = "writeable" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" [[package]] name = "xattr" @@ -3553,9 +3688,9 @@ checksum = "7a5a4b21e1a62b67a2970e6831bc091d7b87e119e7f9791aef9702e3bef04448" [[package]] name = "yoke" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" dependencies = [ "stable_deref_trait", "yoke-derive", @@ -3564,9 +3699,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" dependencies = [ "proc-macro2", "quote", @@ -3576,18 +3711,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.33" +version = "0.8.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668f5168d10b9ee831de31933dc111a459c97ec93225beb307aed970d1372dfd" +checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.33" +version = "0.8.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c7962b26b0a8685668b671ee4b54d007a67d4eaf05fda79ac0ecf41e32270f1" +checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" dependencies = [ "proc-macro2", "quote", @@ -3596,18 +3731,18 @@ dependencies = [ [[package]] name = "zerofrom" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df" dependencies = [ "zerofrom-derive", ] [[package]] name = "zerofrom-derive" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" dependencies = [ "proc-macro2", "quote", @@ -3637,9 +3772,9 @@ dependencies = [ [[package]] name = "zerotrie" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" dependencies = [ "displaydoc", "yoke", @@ -3648,9 +3783,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.5" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" dependencies = [ "yoke", "zerofrom", @@ -3659,9 +3794,9 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" dependencies = [ "proc-macro2", "quote", @@ -3697,15 +3832,15 @@ dependencies = [ [[package]] name = "zlib-rs" -version = "0.5.5" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" +checksum = "3be3d40e40a133f9c916ee3f9f4fa2d9d63435b5fbe1bfc6d9dae0aa0ada1513" [[package]] name = "zmij" -version = "1.0.16" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" [[package]] name = "zopfli" @@ -3747,12 +3882,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "zune-core" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a" - [[package]] name = "zune-core" version = "0.5.1" @@ -3770,18 +3899,9 @@ dependencies = [ [[package]] name = "zune-jpeg" -version = "0.4.21" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29ce2c8a9384ad323cf564b67da86e21d3cfdff87908bc1223ed5c99bc792713" +checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296" dependencies = [ - "zune-core 0.4.12", -] - -[[package]] -name = "zune-jpeg" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "410e9ecef634c709e3831c2cfdb8d9c32164fae1c67496d5b68fff728eec37fe" -dependencies = [ - "zune-core 0.5.1", + "zune-core", ] diff --git a/src/app.rs b/src/app.rs index ce5d490..ea7c5db 100644 --- a/src/app.rs +++ b/src/app.rs @@ -13,7 +13,10 @@ use axum_macros::debug_handler; use bb8::{Pool, PooledConnection}; use bb8_redis::RedisConnectionManager; use brotli::CompressorWriter; -use git2::{Cred, FetchOptions, Object, PushOptions, RemoteCallbacks, Repository}; +use git2::{ + Cred, FetchOptions, Object, ObjectType, PushOptions, RemoteCallbacks, Repository, ResetType, + build::CheckoutBuilder, +}; use image::load_from_memory; use log::{error, info, warn}; @@ -711,23 +714,22 @@ async fn commit_file_content( message: &str, branch: String, ) -> Result> { - let repo_clone = repo.clone(); - let blob_oid = repo_clone.lock().await.blob(content)?; - info!("blob oid: {blob_oid}"); - let mut index = repo_clone.lock().await.index()?; - info!("index pass"); - let rlock = repo_clone.try_lock()?; - let parent = match rlock.head() { - Ok(head) => { - let commit = head.peel_to_commit()?; + let repo_guard = repo.lock().await; + + let blob_oid = repo_guard.blob(content)?; + + let mut index = repo_guard.index()?; + + let target_ref = format!("refs/heads/{branch}"); + let parent_commit = match repo_guard.find_reference(&target_ref) { + Ok(reference) => { + let commit = reference.peel_to_commit()?; index.read_tree(&commit.tree()?)?; - Some(commit.clone()) + Some(commit) } Err(_) => None, }; - info!("parent pass"); - index.add(&git2::IndexEntry { ctime: git2::IndexTime::new(0, 0), mtime: git2::IndexTime::new(0, 0), @@ -743,23 +745,19 @@ async fn commit_file_content( path: path.as_bytes().to_vec(), })?; - info!("index added"); - let tree_oid = index.write_tree()?; - - info!("write to tree"); - // let tlock = repo_clone.try_lock()?; - info!("acquire try lock"); - let tree = rlock.find_tree(tree_oid)?; - info!("find tree ok"); + let tree = repo_guard.find_tree(tree_oid)?; let sig = git2::Signature::now(&author.username, &author.email)?; - info!("generated signature"); - let parents: Vec<&git2::Commit> = parent.iter().collect(); - let oid = rlock.commit( + let parents = match &parent_commit { + Some(c) => vec![c], + None => vec![], + }; + + let oid = repo_guard.commit( //"refs/heads/master" - Some(&format!("refs/heads/{branch}")), + Some(&target_ref), &sig, &sig, message, @@ -775,22 +773,13 @@ async fn commit_file_content( async fn push_handler(State(state): State) -> impl IntoResponse { let config = state.clone().get_all_configures(); let repo = state.repo.clone(); - let remote_name = match state.get_config("GIT_REPO_REMOTE") { - Some(s) => s, - None => { - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!({"error": "repo remote not existed"})), - ); - } - }; let branch = &config .get("GIT_REPO_BRANCH_NAME") .map(|x| x.to_string()) .unwrap_or("master".to_string()); - if let Err(e) = push(config, repo, "origin", branch) { + if let Err(e) = push(config, repo, "origin", branch).await { return ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})), @@ -803,51 +792,52 @@ async fn push_handler(State(state): State) -> impl IntoResponse { ) } -fn push( +async fn push( config: gcm::Configure, repo: Arc>, remote_name: &str, branch: &str, ) -> Result<(), Box> { - if let Ok(rlock) = repo.try_lock() { - let mut rem = rlock.find_remote(remote_name)?; - let mut callback = RemoteCallbacks::new(); - callback.credentials(|_url, _user, _allowed| { - Cred::userpass_plaintext( - config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), - config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()), - ) - }); - let mut push_opts = PushOptions::new(); - push_opts.remote_callbacks(callback); - let refspec = format!("refs/heads/{0}:refs/heads/{0}", branch); - rem.push(&[&refspec], Some(&mut push_opts))?; + // 1. Acquire lock (awaiting if another task is committing/pulling) + let repo_guard = repo.lock().await; - return Ok(()); - } + // 2. Find the remote + let mut remote = repo_guard.find_remote(remote_name)?; - Err("cannot lock repo".into()) + // 3. Setup Credentials + let mut callbacks = RemoteCallbacks::new(); + callbacks.credentials(|_url, _user, _allowed| { + Cred::userpass_plaintext( + config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), + config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()), + ) + }); + + let mut push_opts = git2::PushOptions::new(); + push_opts.remote_callbacks(callbacks); + + // 4. Define the Refspec + // format: local_ref:remote_ref + let refspec = format!("refs/heads/{}:refs/heads/{}", branch, branch); + + // 5. Execute Push + info!("Pushing {branch} to {remote_name}..."); + remote.push(&[&refspec], Some(&mut push_opts))?; + + info!("Push successful."); + Ok(()) } async fn pull_handler(State(state): State) -> impl IntoResponse { let config = state.clone().get_all_configures(); let repo = state.repo.clone(); - let remote_name = match state.get_config("GIT_REPO_REMOTE") { - Some(s) => s, - None => { - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!({"error": "repo remote not existed"})), - ); - } - }; let branch = &config .get("GIT_REPO_BRANCH_NAME") .map(|x| x.to_string()) .unwrap_or("master".to_string()); - if let Err(e) = pull(config, repo, "origin", branch) { + if let Err(e) = pull(config, repo, "origin", branch).await { return ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})), @@ -861,50 +851,51 @@ async fn pull_handler(State(state): State) -> impl IntoResponse { } // Pull is fetch + merge -fn pull( +async fn pull( config: gcm::Configure, repo: Arc>, remote_name: &str, branch: &str, ) -> Result<(), Box> { - if let Ok(rlock) = repo.try_lock() { - let mut rem = rlock.find_remote(remote_name)?; - let mut callback = RemoteCallbacks::new(); - callback.credentials(|_url, _user, _allowed| { - Cred::userpass_plaintext( - config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), - config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()), - ) - }); - let mut fetch_options = FetchOptions::new(); - fetch_options.remote_callbacks(callback); - fetch_options.download_tags(git2::AutotagOption::All); + let repo_guard = repo.lock().await; - info!("fetching from {}...", remote_name); - rem.fetch(&[branch], Some(&mut fetch_options), None)?; + // 1. Fetch from remote + let mut remote = repo_guard.find_remote(remote_name)?; + let mut callbacks = RemoteCallbacks::new(); + callbacks.credentials(|_url, _user, _allowed| { + Cred::userpass_plaintext( + config.get("GIT_REPO_USERNAME").unwrap_or(&"".to_string()), + config.get("GIT_REPO_PASSWORD").unwrap_or(&"".to_string()), + ) + }); - // resolve fetch vs merge - let fetch_head = rlock.find_reference("FETCH_HEAD")?; - let fetch_commit = rlock.reference_to_annotated_commit(&fetch_head)?; + let mut fetch_options = FetchOptions::new(); + fetch_options.remote_callbacks(callbacks); + fetch_options.download_tags(git2::AutotagOption::All); - let analysis = rlock.merge_analysis(&[&fetch_commit])?; - if analysis.0.is_fast_forward() { - let refname = format!("refs/heads/{branch}"); - let mut reference = rlock.find_reference(&refname)?; - reference.set_target(fetch_commit.id(), "Fast-Forward")?; - rlock.set_head(&refname)?; - rlock.checkout_head(Some(git2::build::CheckoutBuilder::default().force()))?; - info!("Fast-forwared to {}", fetch_commit.id()); - } else if analysis.0.is_up_to_date() { - info!("already up to date"); - } else { - return Err("cannot fast-forward, local changes would be overwritten".into()); - } + info!("Fetching {branch} from {remote_name}..."); + remote.fetch(&[branch], Some(&mut fetch_options), None)?; - return Ok(()); - } + // 2. Get FETCH_HEAD (the tip of what we just fetched) + let fetch_head = repo_guard.find_reference("FETCH_HEAD")?; + let fetch_commit = repo_guard.reference_to_annotated_commit(&fetch_head)?; + let target_object = repo_guard.find_object(fetch_commit.id(), Some(ObjectType::Commit))?; - Err("cannot lock repo".into()) + // 3. Force Hard Reset + // This moves the branch pointer AND updates the working directory files, + // effectively wiping away your 50-commit reset or any local uncommitted changes. + let mut checkout_opts = CheckoutBuilder::new(); + checkout_opts.force(); + + repo_guard.reset(&target_object, ResetType::Hard, Some(&mut checkout_opts))?; + + // 4. Ensure local branch reference is updated to this OID + let refname = format!("refs/heads/{}", branch); + repo_guard.reference(&refname, fetch_commit.id(), true, "Force Sync Pull")?; + repo_guard.set_head(&refname)?; + + info!("Repository synced to remote tip: {}", fetch_commit.id()); + Ok(()) } /// Return git state & server state diff --git a/src/main.rs b/src/main.rs index 2f77339..4a905d8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,10 +16,11 @@ mod tx; // mod reg; fn setup_log(config: gcm::Configure) -> gcm::StandardResult { - let logfile = File::create(config.get("LOG_NAME").unwrap_or(&"run.log".to_string()))?; + // NOTE: disable logging file, use send to log service instead + // let logfile = File::create(config.get("LOG_NAME").unwrap_or(&"run.log".to_string()))?; Builder::from_env(env_logger::Env::default().default_filter_or("debug")) - .target(env_logger::Target::Pipe(Box::new(logfile))) + // .target(env_logger::Target::Pipe(Box::new(logfile))) .init(); Ok(()) From 166b7079ca3a25eda368bd546c7edb0391f3275e Mon Sep 17 00:00:00 2001 From: Pakin Date: Wed, 6 May 2026 10:00:06 +0700 Subject: [PATCH 16/21] feat: add multi files support for commit Signed-off-by: Pakin --- src/app.rs | 203 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 146 insertions(+), 57 deletions(-) diff --git a/src/app.rs b/src/app.rs index ea7c5db..a4a8a7d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -14,8 +14,8 @@ use bb8::{Pool, PooledConnection}; use bb8_redis::RedisConnectionManager; use brotli::CompressorWriter; use git2::{ - Cred, FetchOptions, Object, ObjectType, PushOptions, RemoteCallbacks, Repository, ResetType, - build::CheckoutBuilder, + Cred, FetchOptions, Object, ObjectType, Oid, PushOptions, RemoteCallbacks, Repository, + ResetType, build::CheckoutBuilder, }; use image::load_from_memory; @@ -392,6 +392,10 @@ async fn commit_handler( let mut message: Option = None; let mut file_bytes: Option> = None; + let mut file_mappings: HashMap> = HashMap::new(); + let mut filex_map: HashMap> = HashMap::new(); + let mut pathx_map: HashMap = HashMap::new(); + // Process each field in the multipart payload while let Ok(Some(field)) = payload.next_field().await { let name = field.name().unwrap_or("").to_string(); @@ -456,26 +460,48 @@ async fn commit_handler( } }); } + + filex if name.starts_with("file") => match field.bytes().await { + Ok(fx) => { + filex_map.insert(filex.to_string(), fx.to_vec()); + } + Err(e) => { + warn!("fail to read field multi file: {}", e); + } + }, + pathx if name.starts_with("path") => match field.text().await { + Ok(px) => { + pathx_map.insert(pathx.to_string(), px); + } + Err(e) => { + warn!("fail to read field multi path: {}", e); + } + }, _ => { + // Ignore unknown fields } } } - info!("committing ..."); + // start do multi file if has any - // Validate required fields - let path = match path { - Some(p) => p, - None => { - return ( - axum::http::StatusCode::BAD_REQUEST, - Json(json!({"error": "Missing required field: path"})), - ); + if pathx_map.len() == filex_map.len() { + info!("mapping multi files"); + + for (_, (path_key, path_val)) in pathx_map.iter().enumerate() { + let expected_file_key = format!("file{}", path_key.replace("path", "")); + + if filex_map.contains_key(&expected_file_key) + && let Some(file_bytes) = filex_map.get(&expected_file_key) + { + info!("[multi-files] {}: {}", path_val, file_bytes.len()); + file_mappings.insert(path_val.to_owned(), file_bytes.to_owned()); + } } - }; + } - info!("path: [{path}]"); + info!("committing ..."); let signature_username = match signature_username { Some(su) => su, @@ -497,16 +523,6 @@ async fn commit_handler( } }; - let file_bytes = match file_bytes { - Some(fb) => fb, - None => { - return ( - axum::http::StatusCode::BAD_REQUEST, - Json(json!({"error": "Missing required field: file"})), - ); - } - }; - // Create signature let signature = Signature { username: signature_username, @@ -522,43 +538,53 @@ async fn commit_handler( .map(|x| x.to_string()) .unwrap_or("master".to_string()); - // Commit the file content directly from multipart upload - let commit_oid = match commit_file_content( - state.clone().repo, - &path, - &file_bytes, - signature, - &message.unwrap_or("update: from api".to_string()), - branch, - ) - .await + let commit_oid = if let Some(file_bytes) = file_bytes + && let Some(path) = path { - Ok(oid) => oid, - Err(e) => { - return ( - axum::http::StatusCode::INTERNAL_SERVER_ERROR, - Json(json!({"error": e.to_string()})), - ); - } - }; - - info!("commit success! [{commit_oid}]"); - - // save history - let redis_pre_lock = state.redis.clone(); - { - if let Ok(mut rl) = redis_pre_lock.get().await { - match rl - .rpush( - format!("{}.history", path), - format!("commit-{}", commit_oid), - ) - .await - { - Ok(_) => info!("history saved"), - Err(e) => error!("save history fail: {e:?}"), + match commit_file_content( + state.clone().repo, + &path, + &file_bytes, + signature, + &message.unwrap_or("update: from api".to_string()), + branch, + ) + .await + { + Ok(oid) => oid, + Err(e) => { + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": e.to_string()})), + ); } } + } else if !file_mappings.is_empty() { + match commit_multiple_file_contents( + state.clone().repo, + file_mappings, + signature, + &message.unwrap_or("update: from api".to_string()), + branch, + ) + .await + { + Ok(oid) => oid, + Err(e) => { + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": e.to_string()})), + ); + } + } + } else { + Oid::zero() + }; + + if commit_oid.is_zero() { + info!("invalid commit process, return 0"); + } else { + info!("commit success! [{commit_oid}]"); } ( @@ -770,6 +796,69 @@ async fn commit_file_content( Ok(oid) } +async fn commit_multiple_file_contents( + repo: Arc>, + file_mapping: HashMap>, + author: Signature, + message: &str, + branch: String, +) -> Result> { + let repo_guard = repo.lock().await; + let mut index = repo_guard.index()?; + + let target_ref = format!("refs/heads/{branch}"); + let parent_commit = match repo_guard.find_reference(&target_ref) { + Ok(reference) => { + let commit = reference.peel_to_commit()?; + index.read_tree(&commit.tree()?)?; + Some(commit) + } + Err(_) => None, + }; + + for (_, (path, file)) in file_mapping.iter().enumerate() { + let blob_oid = repo_guard.blob(file.as_slice())?; + index.add(&git2::IndexEntry { + ctime: git2::IndexTime::new(0, 0), + mtime: git2::IndexTime::new(0, 0), + dev: 0, + ino: 0, + mode: 0o100644, + uid: 0, + gid: 0, + file_size: file.len() as u32, + id: blob_oid, + flags: 0, + flags_extended: 0, + path: path.as_bytes().to_vec(), + })?; + } + + let tree_oid = index.write_tree()?; + let tree = repo_guard.find_tree(tree_oid)?; + + let sig = git2::Signature::now(&author.username, &author.email)?; + + let parents = match &parent_commit { + Some(c) => vec![c], + None => vec![], + }; + + let oid = repo_guard.commit( + //"refs/heads/master" + Some(&target_ref), + &sig, + &sig, + message, + &tree, + &parents, + )?; + + info!("commit oid: {oid}"); + + Ok(oid) +} + async fn push_handler(State(state): State) -> impl IntoResponse { let config = state.clone().get_all_configures(); let repo = state.repo.clone(); From caa0833ea24da5ddae16074f39622948aaeafc50 Mon Sep 17 00:00:00 2001 From: Pakin Date: Fri, 8 May 2026 15:43:13 +0700 Subject: [PATCH 17/21] fix: fail git clone by case empty folder Signed-off-by: Pakin --- src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4a905d8..91de988 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,9 +34,21 @@ async fn main() -> gcm::StandardResult { match std::fs::read_dir(config.get("GIT_REPO_LOCAL_DEST").expect("not exist")) { Ok(_) => { info!( - "GIT_REPO `{dest}` already setup", + "GIT_REPO `{dest}` existed, checking if has git", dest = config.get("GIT_REPO_LOCAL_DEST").unwrap() - ) + ); + + match std::fs::read_dir(format!( + "{}/.git", + config.get("GIT_REPO_LOCAL_DEST").expect("not exist") + )) { + Ok(_) => { + info!("GIT REPO already set up!") + } + Err(_) => { + setup_git_repo(config.clone())?; + } + } } Err(_) => { setup_git_repo(config.clone())?; From c8f820e238af41b3c6514109872e38dd03e9d3ee Mon Sep 17 00:00:00 2001 From: Pakin Date: Fri, 15 May 2026 14:27:18 +0700 Subject: [PATCH 18/21] add usages Signed-off-by: Pakin --- README.md | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..2e0bce6 --- /dev/null +++ b/README.md @@ -0,0 +1,171 @@ +# tbm-git-service + +Git repo as a service with operational endpoints + +--- + +## Endpoints + +### Checkout file + +Get file content or list of file in directory from HEAD + +``` +GET .../checkout?path= +``` + +Examples + +Get list of files in directory + +```bash +curl -X GET http://localhost:36593/checkout\?path\=inter +aus,common,dev,gbr,gbr_premium,hkg,ltu,mys,rou,sgp,tha,tha_premium,uae_dubai,usa,whatthecup +``` + +Get file + +```bash +curl -X GET http://localhost:36593/checkout\?path\=inter/mys/xml/page_catalog_group_other.lxml + + + "Enable" + 1080 + 1920 +; "0xeae6e1" + SoundVolume + + ; On open + +``` + +Error + +```bash +curl -X GET http://localhost:36593/checkout\?path\=inter2 +File not found +``` + +--- + +### Fetch + +Fetching & update index of current repo + +``` +GET .../fetch +``` + +Expected result + +``` +{"result": "fetch success"} +``` + +Error + +``` +{"error": "..."} +``` + +--- + +### Commit + +Commit changes of file i.e. editing, adding, etc. + +``` +POST .../commit +``` + +Body must be multipart + +- Single file + +``` +path: string +file: text/binary is acceptable +signature_username: string +signature_email: stirng +message: string +``` + +- Multiple file + +``` +signature_username: string +signature_email: stirng +message: string +fileX1: text/binary is acceptable +pathX1: string +fileX2: text/binary is acceptable +pathX2: string +... +``` + +Example + +```curl +curl --request POST \ + --url http://localhost:36583/commit \ + --header 'content-type: multipart/form-data' \ + --form path=mys/version.dev \ + --form 'signature_username=git api' \ + --form signature_email=supra.m2.dev@forth.co.th \ + --form 'message=test commit' \ + --form file=@./mys.version.test +``` + +NOTE: file & path in multiple file must have the same name after + +--- + +### Push + +Push local commits to remote + +``` +GET .../push +``` + +Expected result + +``` +{"result": "push completed"} +``` + +Error + +``` +{"error": "..."} +``` + +--- + +### Pull + +Pull commits from remote. This operation always does git reset hard first before pull for reason of no conflicts. + +``` +GET .../pull +``` + +Expected result + +``` +{"result": "pull completed"} +``` + +Error + +``` +{"error": "..."} +``` + +NOTE: Commit did lost but could be checkout later + +--- + +### Recovery + +WIP... From b70a35135c7d853b1eac3c8867d91d11c730a80d Mon Sep 17 00:00:00 2001 From: Pakin Date: Fri, 15 May 2026 14:38:27 +0700 Subject: [PATCH 19/21] update usage of commit Signed-off-by: Pakin --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 2e0bce6..26d9dc8 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,18 @@ pathX2: string ... ``` +Expected result + +``` +{"result": "commit hash id"} +``` + +Error + +``` +{"error": "..."} +``` + Example ```curl From a69ef7b9278cb84931139ebf9b5bacaaf8537b50 Mon Sep 17 00:00:00 2001 From: Pakin Date: Mon, 18 May 2026 09:56:23 +0700 Subject: [PATCH 20/21] disable cache from redis - reason from value not updated Signed-off-by: Pakin --- src/app.rs | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/app.rs b/src/app.rs index a4a8a7d..cf20e75 100644 --- a/src/app.rs +++ b/src/app.rs @@ -125,24 +125,6 @@ async fn checkout_handler( // ); // quick response from redis - if let Ok(conn) = state.redis.dedicated_connection().await { - println!("conneciton ok"); - if let Ok(raw) = fetch_content_from_redis_byte(conn, &fpath).await - && !raw.is_empty() - { - // detect content type - let content_type = detect_content_type(&fpath); - - println!("content-len: {}", raw.len()); - - return Response::builder() - .header(header::CONTENT_TYPE, content_type) - .body(Body::from(raw)) - .unwrap(); - } - } - - println!("failed to get from redis, continue ..."); let repo = state.repo.clone(); @@ -186,18 +168,6 @@ async fn checkout_handler( let key_clone = fpath.clone(); let data_clone = o.clone(); - tokio::spawn(async move { - if let Ok(mut conn) = state_clone.redis.dedicated_connection().await { - let _: Result<(), _> = redis::cmd("SET") - .arg(&key_clone) - .arg(&data_clone) - .arg("EX") - .arg(3600) - .query_async(&mut conn) - .await; - } - }); - let content_type = detect_content_type(&fpath); Response::builder() .header(header::CONTENT_TYPE, content_type) From 24664722356230e9d67a0c2e91992cd6892682c5 Mon Sep 17 00:00:00 2001 From: Pakin Date: Tue, 19 May 2026 12:10:31 +0700 Subject: [PATCH 21/21] feat: add replay feature for recovery - fix bug commit not update index Signed-off-by: Pakin --- Cargo.lock | 460 +++++++++++++++++++++++++++++++++++++++++++--------- Cargo.toml | 1 + src/app.rs | 371 ++++++++++++++++++++++++++++++++++-------- src/main.rs | 1 + 4 files changed, 693 insertions(+), 140 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a04d933..84fb2e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,7 @@ checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", "cipher", - "cpufeatures", + "cpufeatures 0.2.17", ] [[package]] @@ -400,6 +400,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" +dependencies = [ + "hybrid-array", +] + [[package]] name = "brotli" version = "8.0.2" @@ -439,6 +448,12 @@ version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8efb64bd706a16a1bdde310ae86b351e4d21550d98d056f22f8a7f7a2183fec" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "byteorder-lite" version = "0.1.0" @@ -478,6 +493,17 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.1", +] + [[package]] name = "chrono" version = "0.4.44" @@ -497,10 +523,16 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ - "crypto-common", + "crypto-common 0.1.7", "inout", ] +[[package]] +name = "cmov" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f88a43d011fc4a6876cb7344703e297c71dda42494fee094d5f7c76bf13f746" + [[package]] name = "color_quant" version = "1.1.0" @@ -552,6 +584,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "constant_time_eq" version = "0.3.1" @@ -593,6 +631,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + [[package]] name = "crc" version = "3.4.0" @@ -658,6 +705,24 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "ctutils" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d5515a3834141de9eafb9717ad39eea8247b5674e6066c404e8c4b365d2a29e" +dependencies = [ + "cmov", +] + [[package]] name = "deflate64" version = "0.1.12" @@ -690,11 +755,23 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", - "crypto-common", + "block-buffer 0.10.4", + "crypto-common 0.1.7", "subtle", ] +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.0", + "const-oid", + "crypto-common 0.2.1", + "ctutils", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -816,6 +893,12 @@ dependencies = [ "zune-inflate", ] +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fastrand" version = "2.4.1" @@ -914,6 +997,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -977,7 +1061,7 @@ checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.11.1+wasi-snapshot-preview1", ] [[package]] @@ -1001,6 +1085,7 @@ dependencies = [ "cfg-if", "libc", "r-efi 6.0.0", + "rand_core 0.10.1", "wasip2", "wasip3", ] @@ -1032,9 +1117,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" +checksum = "171fefbc92fe4a4de27e0698d6a5b392d6a0e333506bc49133760b3bcf948733" dependencies = [ "atomic-waker", "bytes", @@ -1087,7 +1172,16 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest", + "digest 0.10.7", +] + +[[package]] +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest 0.11.3", ] [[package]] @@ -1135,6 +1229,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "hybrid-array" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9155a582abd142abc056962c29e3ce5ff2ad5469f4246b537ed42c5deba857da" +dependencies = [ + "typenum", +] + [[package]] name = "hyper" version = "1.9.0" @@ -1437,16 +1540,6 @@ version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2" -[[package]] -name = "iri-string" -version = "0.7.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25e659a4bb38e810ebc252e53b5814ff908a8c58c2a9ce2fae1bbec24cbf4e20" -dependencies = [ - "memchr", - "serde", -] - [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -1504,9 +1597,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.97" +version = "0.3.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1840c94c045fbcf8ba2812c95db44499f7c64910a912551aaaa541decebcacf" +checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08" dependencies = [ "cfg-if", "futures-util", @@ -1593,7 +1686,7 @@ dependencies = [ "bitflags", "libc", "plain", - "redox_syscall 0.7.4", + "redox_syscall 0.7.5", ] [[package]] @@ -1621,7 +1714,7 @@ dependencies = [ "indexmap", "log", "quick-xml", - "rand", + "rand 0.9.4", "rayon", "serde", "serde_json", @@ -1685,7 +1778,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c60a23ffb90d527e23192f1246b14746e2f7f071cb84476dd879071696c18a4a" dependencies = [ "crc", - "sha2", + "sha2 0.10.9", ] [[package]] @@ -1704,6 +1797,16 @@ dependencies = [ "rayon", ] +[[package]] +name = "md-5" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69b6441f590336821bb897fb28fc622898ccceb1d6cea3fde5ea86b090c4de98" +dependencies = [ + "cfg-if", + "digest 0.11.3", +] + [[package]] name = "memchr" version = "2.8.0" @@ -1733,7 +1836,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" dependencies = [ "libc", - "wasi", + "wasi 0.11.1+wasi-snapshot-preview1", "windows-sys 0.61.2", ] @@ -1795,9 +1898,9 @@ checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" [[package]] name = "no_std_io2" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b51ed7824b6e07d354605f4abb3d9d300350701299da96642ee084f5ce631550" +checksum = "418abd1b6d34fbf6cae440dc874771b0525a604428704c76e48b29a5e67b8003" dependencies = [ "memchr", ] @@ -1873,6 +1976,24 @@ dependencies = [ "autocfg", ] +[[package]] +name = "objc2-core-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" +dependencies = [ + "bitflags", +] + +[[package]] +name = "objc2-system-configuration" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7216bd11cbda54ccabcab84d523dc93b858ec75ecfb3a7d89513fa22464da396" +dependencies = [ + "objc2-core-foundation", +] + [[package]] name = "once_cell" version = "1.21.4" @@ -1981,8 +2102,8 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ - "digest", - "hmac", + "digest 0.10.7", + "hmac 0.12.1", ] [[package]] @@ -2003,19 +2124,38 @@ dependencies = [ ] [[package]] -name = "pin-project" -version = "1.1.11" +name = "phf" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517" +checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" +dependencies = [ + "phf_shared", + "serde", +] + +[[package]] +name = "phf_shared" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project" +version = "1.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf0d9e68100b3a7989b4901972f265cd542e560a3a8a724e1e20322f4d06ce9" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.11" +version = "1.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6" +checksum = "a990e22f43e84855daf260dded30524ef4a9021cc7541c26540500a50b624389" dependencies = [ "proc-macro2", "quote", @@ -2068,6 +2208,35 @@ dependencies = [ "portable-atomic", ] +[[package]] +name = "postgres-protocol" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56201207dac53e2f38e848e31b4b91616a6bb6e0c7205b77718994a7f49e70fc" +dependencies = [ + "base64", + "byteorder", + "bytes", + "fallible-iterator", + "hmac 0.13.0", + "md-5", + "memchr", + "rand 0.10.1", + "sha2 0.11.0", + "stringprep", +] + +[[package]] +name = "postgres-types" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc729a129e682e8d24170cd30ae1aa01b336b096cbb56df6d534ffec133d186" +dependencies = [ + "bytes", + "fallible-iterator", + "postgres-protocol", +] + [[package]] name = "potential_utf" version = "0.1.5" @@ -2119,18 +2288,18 @@ dependencies = [ [[package]] name = "profiling" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb8486b569e12e2c32ad3e204dbaba5e4b5b216e9367044f25f1dba42341773" +checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5" dependencies = [ "profiling-procmacros", ] [[package]] name = "profiling-procmacros" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52717f9a02b6965224f95ca2a81e2e0c5c43baacd28ca057577988930b6c3d5b" +checksum = "4488a4a36b9a4ba6b9334a32a39971f77c1436ec82c38707bce707699cc3bbcb" dependencies = [ "quote", "syn", @@ -2232,9 +2401,9 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quick-xml" -version = "0.39.2" +version = "0.39.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "958f21e8e7ceb5a1aa7fa87fab28e7c75976e0bfe7e23ff069e0a260f894067d" +checksum = "721da970c312655cde9b4ffe0547f20a8494866a4af5ff51f18b7c633d0c870b" dependencies = [ "memchr", ] @@ -2267,7 +2436,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" dependencies = [ "rand_chacha", - "rand_core", + "rand_core 0.9.5", +] + +[[package]] +name = "rand" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" +dependencies = [ + "chacha20", + "getrandom 0.4.2", + "rand_core 0.10.1", ] [[package]] @@ -2277,7 +2457,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.5", ] [[package]] @@ -2289,6 +2469,12 @@ dependencies = [ "getrandom 0.3.4", ] +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + [[package]] name = "rav1e" version = "0.8.1" @@ -2316,7 +2502,7 @@ dependencies = [ "num-traits", "paste", "profiling", - "rand", + "rand 0.9.4", "rand_chacha", "simd_helpers", "thiserror", @@ -2395,9 +2581,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f450ad9c3b1da563fb6948a8e0fb0fb9269711c9c73d9ea1de5058c79c8d643a" +checksum = "4666a1a60d8412eab19d94f6d13dcc9cea0a5ef4fdf6a5db306537413c661b1b" dependencies = [ "bitflags", ] @@ -2676,8 +2862,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.2.17", + "digest 0.10.7", ] [[package]] @@ -2693,8 +2879,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "digest 0.11.3", ] [[package]] @@ -2728,6 +2925,12 @@ dependencies = [ "quote", ] +[[package]] +name = "siphasher" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649" + [[package]] name = "slab" version = "0.4.12" @@ -2762,6 +2965,17 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + [[package]] name = "subtle" version = "2.6.1" @@ -2857,6 +3071,7 @@ dependencies = [ "serde", "serde_json", "tokio", + "tokio-postgres", "tokio-util", "tonic", "tonic-prost", @@ -2941,10 +3156,25 @@ dependencies = [ ] [[package]] -name = "tokio" -version = "1.52.1" +name = "tinyvec" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6" +checksum = "3e61e67053d25a4e82c844e8424039d9745781b3fc4f32b8d55ed50f5f667ef3" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.52.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "110a78583f19d5cdb2c5ccf321d1290344e71313c6c37d43520d386027d18386" dependencies = [ "bytes", "libc", @@ -2978,6 +3208,32 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-postgres" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dd8df5ef180f6364759a6f00f7aadda4fbbac86cdee37480826a6ff9f3574ce" +dependencies = [ + "async-trait", + "byteorder", + "bytes", + "fallible-iterator", + "futures-channel", + "futures-util", + "log", + "parking_lot", + "percent-encoding", + "phf", + "pin-project-lite", + "postgres-protocol", + "postgres-types", + "rand 0.10.1", + "socket2", + "tokio", + "tokio-util", + "whoami", +] + [[package]] name = "tokio-rustls" version = "0.26.4" @@ -3014,9 +3270,9 @@ dependencies = [ [[package]] name = "tonic" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fec7c61a0695dc1887c1b53952990f3ad2e3a31453e1f49f10e75424943a93ec" +checksum = "ac2a5518c70fa84342385732db33fb3f44bc4cc748936eb5833d2df34d6445ef" dependencies = [ "async-trait", "axum", @@ -3043,9 +3299,9 @@ dependencies = [ [[package]] name = "tonic-build" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1882ac3bf5ef12877d7ed57aad87e75154c11931c2ba7e6cde5e22d63522c734" +checksum = "c68f61875ac5293cf72e6c8cf0158086428c82c37229e98c840878f1706b0322" dependencies = [ "prettyplease", "proc-macro2", @@ -3055,9 +3311,9 @@ dependencies = [ [[package]] name = "tonic-prost" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55376a0bbaa4975a3f10d009ad763d8f4108f067c7c2e74f3001fb49778d309" +checksum = "50849f68853be452acf590cde0b146665b8d507b3b8af17261df47e02c209ea0" dependencies = [ "bytes", "prost", @@ -3066,9 +3322,9 @@ dependencies = [ [[package]] name = "tonic-prost-build" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3144df636917574672e93d0f56d7edec49f90305749c668df5101751bb8f95a" +checksum = "654e5643eff75d7f8c99197ce1440ed19a3474eada74c12bbac488b2cafdae27" dependencies = [ "prettyplease", "proc-macro2", @@ -3101,20 +3357,20 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.8" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +checksum = "68d6fdd9f81c2819c9a8b0e0cd91660e7746a8e6ea2ba7c6b2b057985f6bcb51" dependencies = [ "bitflags", "bytes", "futures-util", "http", "http-body", - "iri-string", "pin-project-lite", "tower", "tower-layer", "tower-service", + "url", ] [[package]] @@ -3179,12 +3435,33 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142" +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + [[package]] name = "unicode-ident" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + [[package]] name = "unicode-xid" version = "0.2.6" @@ -3280,6 +3557,15 @@ version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" +[[package]] +name = "wasi" +version = "0.14.7+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" +dependencies = [ + "wasip2", +] + [[package]] name = "wasip2" version = "1.0.3+wasi-0.2.9" @@ -3299,10 +3585,19 @@ dependencies = [ ] [[package]] -name = "wasm-bindgen" -version = "0.2.120" +name = "wasite" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df52b6d9b87e0c74c9edfa1eb2d9bf85e5d63515474513aa50fa181b3c4f5db1" +checksum = "66fe902b4a6b8028a753d5424909b764ccf79b7a209eac9bf97e59cda9f71a42" +dependencies = [ + "wasi 0.14.7+wasi-0.2.4", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790" dependencies = [ "cfg-if", "once_cell", @@ -3313,9 +3608,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.70" +version = "0.4.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af934872acec734c2d80e6617bbb5ff4f12b052dd8e6332b0817bce889516084" +checksum = "96492d0d3ffba25305a7dc88720d250b1401d7edca02cc3bcd50633b424673b8" dependencies = [ "js-sys", "wasm-bindgen", @@ -3323,9 +3618,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.120" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b1041f495fb322e64aca85f5756b2172e35cd459376e67f2a6c9dffcedb103" +checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3333,9 +3628,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.120" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dcd0ff20416988a18ac686d4d4d0f6aae9ebf08a389ff5d29012b05af2a1b41" +checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2" dependencies = [ "bumpalo", "proc-macro2", @@ -3346,9 +3641,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.120" +version = "0.2.121" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49757b3c82ebf16c57d69365a142940b384176c24df52a087fb748e2085359ea" +checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441" dependencies = [ "unicode-ident", ] @@ -3389,9 +3684,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.97" +version = "0.3.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eadbac71025cd7b0834f20d1fe8472e8495821b4e9801eb0a60bd1f19827602" +checksum = "4b572dff8bcf38bad0fa19729c89bb5748b2b9b1d8be70cf90df697e3a8f32aa" dependencies = [ "js-sys", "wasm-bindgen", @@ -3403,6 +3698,19 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88" +[[package]] +name = "whoami" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "998767ef88740d1f5b0682a9c53c24431453923962269c2db68ee43788c5a40d" +dependencies = [ + "libc", + "libredox", + "objc2-system-configuration", + "wasite", + "web-sys", +] + [[package]] name = "winapi-util" version = "0.1.11" @@ -3817,7 +4125,7 @@ dependencies = [ "deflate64", "flate2", "getrandom 0.3.4", - "hmac", + "hmac 0.12.1", "indexmap", "lzma-rust2", "memchr", diff --git a/Cargo.toml b/Cargo.toml index d15588c..0121b2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,7 @@ tokio-util = { version = "0.7.18", features = ["io"] } tonic = { version = "0.14.2", features = ["transport"] } tonic-prost = "0.14.2" uuid = { version = "1.20.0", features = ["v4"] } +tokio-postgres = "0.7.17" [build-dependencies] tonic-prost-build = "0.14.2" diff --git a/src/app.rs b/src/app.rs index cf20e75..77c26c0 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,10 +1,16 @@ -use std::{collections::HashMap, io::Cursor, sync::Arc, time::Duration}; +use std::{ + collections::HashMap, + io::Cursor, + path::{Path, PathBuf}, + sync::Arc, + time::Duration, +}; use async_compression::tokio::bufread::BrotliEncoder; use axum::{ Json, Router, body::Body, - extract::{Query, State}, + extract::{DefaultBodyLimit, Query, State}, response::{IntoResponse, Response}, routing::{get, post}, }; @@ -22,7 +28,7 @@ use image::load_from_memory; use log::{error, info, warn}; use redis::{AsyncTypedCommands, Connection, TypedCommands, aio::MultiplexedConnection}; use reqwest::header; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use serde_json::{Value, json}; use tokio::{ io::{AsyncReadExt, BufReader}, @@ -33,6 +39,7 @@ use tokio::{ task::JoinSet, }; +use tokio_postgres::NoTls; use uuid::Uuid; use crate::{ @@ -58,11 +65,11 @@ pub struct AppState { // cached_country_names: Vec<&'static str>, configures: gcm::Configure, repo: Arc>, + // commit external db + postgres: Arc>, redis: RedisPool, // save already fetched path, further calls should fetch from redis instead. fetched: Vec, - // queue - enqueue_tx: Sender, } impl AppState { @@ -349,12 +356,18 @@ struct Signature { email: String, } -#[debug_handler] async fn commit_handler( State(state): State, // request body as multipart/form-data mut payload: Multipart, ) -> impl IntoResponse { + // operate on repo + let op_repo = state + .get_config("GIT_REPO_LOCAL_DEST") + .cloned() + .unwrap_or_default() + .replace("./", ""); + // Extract multipart fields let mut path: Option = None; let mut signature_username: Option = None; @@ -362,6 +375,8 @@ async fn commit_handler( let mut message: Option = None; let mut file_bytes: Option> = None; + let mut ref_message: Option = None; + let mut file_mappings: HashMap> = HashMap::new(); let mut filex_map: HashMap> = HashMap::new(); let mut pathx_map: HashMap = HashMap::new(); @@ -420,7 +435,8 @@ async fn commit_handler( }); } "file" => { - file_bytes = Some(match field.bytes().await { + let _file_bytes = field.bytes().await; + file_bytes = Some(match _file_bytes { Ok(b) => b.to_vec(), Err(e) => { return ( @@ -430,6 +446,17 @@ async fn commit_handler( } }); } + "ref" => { + ref_message = Some(match field.text().await { + Ok(r) => r, + Err(e) => { + return ( + axum::http::StatusCode::BAD_REQUEST, + Json(json!({"error": format!("Failed to read ref field: {}", e)})), + ); + } + }) + } filex if name.starts_with("file") => match field.bytes().await { Ok(fx) => { @@ -495,8 +522,8 @@ async fn commit_handler( // Create signature let signature = Signature { - username: signature_username, - email: signature_email, + username: signature_username.clone(), + email: signature_email.clone(), }; info!("sig: {signature:?}"); @@ -557,6 +584,44 @@ async fn commit_handler( info!("commit success! [{commit_oid}]"); } + // TODO: save to db + + let mut plock = state.postgres.lock().await; + let tx = match plock.transaction().await { + Ok(x) => x, + Err(_) => { + return ( + axum::http::StatusCode::CREATED, + Json( + json!({"result": format!("{commit_oid}"), "reason": "CannotConnect_CommitMayBeLost"}), + ), + ); + } + }; + + let insert_commit = tx.execute("INSERT INTO recovery_commit (commit_hash, commit_user, email, repo, ref) VALUES ($1, $2, $3, $4, $5)", &[ + &commit_oid.to_string(), + &signature_username.clone(), + &signature_email.clone(), + &op_repo, + &ref_message.unwrap_or_default(), + ]).await; + if insert_commit.is_ok() { + match tx.commit().await { + Ok(_) => { + info!("successfully inserted into postgres"); + } + Err(e) => { + error!("commit postgres failed: {e}"); + } + } + } else { + error!("failed to commit to postgres & rolling back ..."); + if let Err(rollback_error) = tx.rollback().await { + error!("failed to rollback, {rollback_error}"); + } + } + ( axum::http::StatusCode::OK, Json(json!({"result": format!("{commit_oid}")})), @@ -712,11 +777,34 @@ async fn commit_file_content( ) -> Result> { let repo_guard = repo.lock().await; - let blob_oid = repo_guard.blob(content)?; + let workdir = repo_guard.workdir().ok_or_else(|| { + git2::Error::from_str("Repository must have a working directory for this strategy") + })?; - let mut index = repo_guard.index()?; + let full_path = if Path::new(path).is_absolute() { + Path::new(path).to_path_buf() + } else { + workdir.join(path) + }; + if let Some(parent) = full_path.parent() { + std::fs::create_dir_all(parent)?; + } + + std::fs::write(&full_path, content)?; let target_ref = format!("refs/heads/{branch}"); + + let relative_git_path = if full_path.is_absolute() { + full_path.strip_prefix(workdir).map_err(|_| { + git2::Error::from_str( + "The provided path is outside of the repository working directory", + ) + })? + } else { + Path::new(path) + }; + let mut index = repo_guard.index()?; + let parent_commit = match repo_guard.find_reference(&target_ref) { Ok(reference) => { let commit = reference.peel_to_commit()?; @@ -726,20 +814,8 @@ async fn commit_file_content( Err(_) => None, }; - index.add(&git2::IndexEntry { - ctime: git2::IndexTime::new(0, 0), - mtime: git2::IndexTime::new(0, 0), - dev: 0, - ino: 0, - mode: 0o100644, - uid: 0, - gid: 0, - file_size: content.len() as u32, - id: blob_oid, - flags: 0, - flags_extended: 0, - path: path.as_bytes().to_vec(), - })?; + index.add_path(relative_git_path)?; + index.write()?; let tree_oid = index.write_tree()?; let tree = repo_guard.find_tree(tree_oid)?; @@ -753,14 +829,17 @@ async fn commit_file_content( let oid = repo_guard.commit( //"refs/heads/master" - Some(&target_ref), - &sig, - &sig, - message, - &tree, - &parents, + None, &sig, &sig, message, &tree, &parents, )?; + repo_guard.reference(&target_ref, oid, true, "api commit log update")?; + + if let Ok(mut head) = repo_guard.head() { + if head.name() == Some(&target_ref) { + repo_guard.set_head(&target_ref)?; + } + } + info!("commit oid: {oid}"); Ok(oid) @@ -774,9 +853,59 @@ async fn commit_multiple_file_contents( branch: String, ) -> Result> { let repo_guard = repo.lock().await; - let mut index = repo_guard.index()?; + let workdir = repo_guard.workdir().ok_or_else(|| { + git2::Error::from_str("Repository must have a working directory for this strategy") + })?; + + // Pre-calculate and normalize paths into a standard vector so we don't have + // path-resolution discrepancies between loops. + // Keeps: (Absolute Path on Disk, Relative Path for Git Index, Content Buffer) + let mut processing_queue: Vec<(PathBuf, PathBuf, &[u8])> = Vec::new(); + + for (raw_path, content) in &file_mapping { + let path_obj = Path::new(raw_path); + + // 1. Compute a clean, guaranteed absolute path for writing to disk + let full_path = if path_obj.is_absolute() { + path_obj.to_path_buf() + } else { + // This handles files starting with "./", "../", or raw filenames safely + workdir.join(path_obj) + }; + + // Canonicalize or cleanly normalize the path syntax relative to the workdir + // to strip out relative quirks like "." or ".." components + let clean_full_path = match full_path.canonicalize() { + Ok(p) => p, + Err(_) => full_path, // Fallback if file doesn't exist yet on disk + }; + + // 2. Compute a strict relative path matching how Git sees the workspace + let relative_git_path = clean_full_path + .strip_prefix(workdir) + .map_err(|_| { + git2::Error::from_str( + "A provided path lives outside the repository working directory", + ) + })? + .to_path_buf(); + + processing_queue.push((clean_full_path, relative_git_path, content)); + } + + // Loop 1: Safely write all processed files to disk first + for (full_path, _, content) in &processing_queue { + if let Some(parent) = full_path.parent() { + std::fs::create_dir_all(parent)?; + } + std::fs::write(full_path, content)?; + } + + let mut index = repo_guard.index()?; let target_ref = format!("refs/heads/{branch}"); + + // Loop 2: Hydrate index from previous branch commit tree let parent_commit = match repo_guard.find_reference(&target_ref) { Ok(reference) => { let commit = reference.peel_to_commit()?; @@ -786,24 +915,15 @@ async fn commit_multiple_file_contents( Err(_) => None, }; - for (_, (path, file)) in file_mapping.iter().enumerate() { - let blob_oid = repo_guard.blob(file.as_slice())?; - index.add(&git2::IndexEntry { - ctime: git2::IndexTime::new(0, 0), - mtime: git2::IndexTime::new(0, 0), - dev: 0, - ino: 0, - mode: 0o100644, - uid: 0, - gid: 0, - file_size: file.len() as u32, - id: blob_oid, - flags: 0, - flags_extended: 0, - path: path.as_bytes().to_vec(), - })?; + // Loop 3: Stage all files using the matching pre-calculated relative path + for (_, relative_git_path, _) in &processing_queue { + index.add_path(relative_git_path)?; } + // Flush changes to .git/index + index.write()?; + + // Create tree layout from updated index state let tree_oid = index.write_tree()?; let tree = repo_guard.find_tree(tree_oid)?; @@ -814,17 +934,20 @@ async fn commit_multiple_file_contents( None => vec![], }; - let oid = repo_guard.commit( - //"refs/heads/master" - Some(&target_ref), - &sig, - &sig, - message, - &tree, - &parents, - )?; + // Commit changes to the object database + let oid = repo_guard.commit(None, &sig, &sig, message, &tree, &parents)?; - info!("commit oid: {oid}"); + // Advance branch reference explicitly + repo_guard.reference(&target_ref, oid, true, "api multi-file commit update")?; + + // Sync active workspace reference state if checking out the branch locally + if let Ok(head) = repo_guard.head() { + if head.name() == Some(&target_ref) { + repo_guard.set_head(&target_ref)?; + } + } + + info!("Multi-file transaction successfully committed. OID: {oid}"); Ok(oid) } @@ -909,6 +1032,102 @@ async fn pull_handler(State(state): State) -> impl IntoResponse { ) } +#[derive(Debug, Serialize, Deserialize)] +struct ReplayPayload { + commit_hashes: Vec, +} + +async fn replay_handler( + State(state): State, + Json(payload): Json, +) -> impl IntoResponse { + let repo = state.repo.clone(); + + let commit_hashes: Vec<&str> = payload.commit_hashes.iter().map(|x| x.as_str()).collect(); + + if let Err(e) = replay(repo, &commit_hashes.as_slice()).await { + return ( + axum::http::StatusCode::INTERNAL_SERVER_ERROR, + Json(json!({"error": e.to_string()})), + ); + } + + ( + axum::http::StatusCode::OK, + Json(json!({"result": "replay completed"})), + ) +} + +async fn replay( + repo: Arc>, + commit_hashes: &[&str], +) -> Result<(), Box> { + let repo_guard = repo.lock().await; + + let initial_head = repo_guard.head()?.peel_to_commit()?; + info!( + "Starting transaction replay. Initial HEAD: {}", + initial_head.id() + ); + + for (index, hash) in commit_hashes.iter().enumerate() { + let oid = Oid::from_str(hash)?; + let commit_to_apply = repo_guard.find_commit(oid)?; + + info!( + "#[{}/{}] Doing {} - \"{}\"", + index + 1, + commit_hashes.len(), + &hash[0..7], + commit_to_apply.summary().unwrap_or("[No summary]") + ); + + let mut cherrypick_opts = git2::CherrypickOptions::new(); + repo_guard.cherrypick(&commit_to_apply, Some(&mut cherrypick_opts))?; + + let mut repo_index = repo_guard.index()?; + + if repo_index.has_conflicts() { + error!("[CONFLICTED] at commit {}, aborting ...", &hash[0..7]); + let current_head_commit = repo_guard.head()?.peel_to_commit()?; + repo_guard.reset(current_head_commit.as_object(), ResetType::Hard, None)?; + return Err(format!("index_{}/conflicted", index).into()); + } + + let tree_id = repo_index.write_tree()?; + let tree = repo_guard.find_tree(tree_id)?; + + let original_author = commit_to_apply.author(); + + let author = git2::Signature::now( + original_author.name().unwrap_or("Transaction Processor"), + original_author + .email() + .unwrap_or("processor@local.internal"), + )?; + + let current_head = repo_guard.head()?.peel_to_commit()?; + let _new_commit_oid = repo_guard.commit( + Some("HEAD"), + &author, + &author, + &format!( + "Replay transaction: {}", + commit_to_apply.summary().unwrap_or("") + ), + &tree, + &[¤t_head], + )?; + + repo_guard.cleanup_state()?; + info!("applied success!"); + } + + info!("all transaction applied successfully!"); + + Ok(()) +} + // Pull is fetch + merge async fn pull( config: gcm::Configure, @@ -971,10 +1190,6 @@ async fn health_handler(State(_): State) -> impl IntoResponse { pub async fn run(config: gcm::Configure) -> gcm::StandardResult { // REDIS POOL - // - // - // - // let manager = RedisConnectionManager::new(format!( "redis://{}:{}", config.get("REDIS_URI").unwrap_or(&"".to_string()), @@ -987,7 +1202,33 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { .await .expect("failed to build redis pool"); - let (enqueue_tx, enqueue_rx) = channel::(8); + // let connect_str = "host=localhost user=postgres password=my_password dbname=my_database"; + let connect_str = config + .get("POSTGRES_CONN") + .expect("failed to connect postgres"); + info!("connect config: {connect_str}"); + let (mut client, connection) = tokio_postgres::connect(connect_str, NoTls).await?; + tokio::spawn(async move { + if let Err(e) = connection.await { + error!("connection postgres error: {e}"); + } + }); + info!("Creating 'commit' table ..."); + client + .execute( + "CREATE TABLE IF NOT EXISTS recovery_commit ( + id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + commit_hash TEXT NOT NULL, + commit_user TEXT NOT NULL, + email TEXT NOT NULL, + repo TEXT NOT NULL, + ref TEXT NOT NULL, + commit_at TIMESTAMPTZ DEFAULT NOW(), + expire_at TIMESTAMPTZ DEFAULT NOW() + interval '1 hour' + )", + &[], + ) + .await?; let state = AppState { // cached_country_names: common::valid_country_name(), @@ -995,9 +1236,9 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { repo: Arc::new(Mutex::new(Repository::open( config.get("GIT_REPO_LOCAL_DEST").unwrap_or(&"".to_string()), )?)), + postgres: Arc::new(Mutex::new(client)), redis: redis_pool.clone(), fetched: Vec::new(), - enqueue_tx: enqueue_tx.clone(), }; let app = Router::new() @@ -1007,6 +1248,8 @@ pub async fn run(config: gcm::Configure) -> gcm::StandardResult { .route("/push", get(push_handler)) .route("/pull", get(pull_handler)) .route("/health", get(health_handler)) + .route("/replay", post(replay_handler)) + .layer(DefaultBodyLimit::max(100 * 1024 * 1024)) // .route("/healthz", get(reg::health)) .with_state(state); diff --git a/src/main.rs b/src/main.rs index 91de988..c17d195 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,7 @@ async fn main() -> gcm::StandardResult { .get("CONFIG_VERSION") .expect("config version not defined") ); + info!("RUNNING: {:?}", config.get("PUBLIC_PORT")); app::run(config.clone()).await?; Ok(())