π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
feat(rust): Implement SQLite storage layer
Manav Rathi7dffdfaecf18
diff --git a/rust/Cargo.lock b/rust/Cargo.lockindex 4e4f5578ec..0a13d2d1b2 100644--- a/rust/Cargo.lock+++ b/rust/Cargo.lock@@ -168,6 +168,15 @@ dependencies = ["syn",]+[[package]]+name = "atoi"+version = "2.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f28d99ec8bfea296261ca1af174f24225171fea9664ba9003cbebee704810528"+dependencies = [+ "num-traits",+]+[[package]]name = "atomic-waker"version = "1.1.2"@@ -208,19 +217,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"[[package]]-name = "bincode"-version = "1.3.3"+name = "base64ct"+version = "1.8.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"-dependencies = [- "serde",-]--[[package]]-name = "bitflags"-version = "1.3.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"+checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba"[[package]]name = "bitflags"@@ -373,6 +373,15 @@ dependencies = ["windows-sys 0.59.0",]+[[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 = "config"version = "0.14.1"@@ -405,6 +414,12 @@ dependencies = ["windows-sys 0.59.0",]+[[package]]+name = "const-oid"+version = "0.9.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"+[[package]]name = "const-random"version = "0.1.18"@@ -499,10 +514,10 @@ dependencies = [][[package]]-name = "crossbeam-epoch"-version = "0.9.18"+name = "crossbeam-queue"+version = "0.3.12"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"+checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115"dependencies = ["crossbeam-utils",]@@ -541,6 +556,17 @@ version = "0.1.9"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "da692b8d1080ea3045efaab14434d40468c3d8657e42abddfffca87b428f4c1b"+[[package]]+name = "der"+version = "0.7.10"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb"+dependencies = [+ "const-oid",+ "pem-rfc7468",+ "zeroize",+]+[[package]]name = "deranged"version = "0.4.0"@@ -568,6 +594,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"dependencies = ["block-buffer",+ "const-oid","crypto-common","subtle",]@@ -613,6 +640,21 @@ dependencies = ["const-random",]+[[package]]+name = "dotenvy"+version = "0.15.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"++[[package]]+name = "either"+version = "1.15.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"+dependencies = [+ "serde",+]+[[package]]name = "encode_unicode"version = "1.0.0"@@ -634,7 +676,6 @@ version = "0.0.1"dependencies = ["anyhow","base64 0.22.1",- "bincode","chrono","clap","config",@@ -649,10 +690,11 @@ dependencies = ["num-bigint","reqwest","rpassword",+ "rusqlite","serde","serde_json","serde_yaml",- "sled",+ "sqlx","srp","tempdir","tempfile",@@ -704,6 +746,40 @@ dependencies = ["windows-sys 0.60.2",]+[[package]]+name = "etcetera"+version = "0.8.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "136d1b5283a1ab77bd9257427ffd09d8667ced0570b6f938942bc7568ed5b943"+dependencies = [+ "cfg-if",+ "home",+ "windows-sys 0.48.0",+]++[[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 = "fallible-iterator"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649"++[[package]]+name = "fallible-streaming-iterator"+version = "0.1.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a"+[[package]]name = "fastrand"version = "2.3.0"@@ -732,12 +808,29 @@ dependencies = ["miniz_oxide",]+[[package]]+name = "flume"+version = "0.11.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "da0e4dd2a88388a1f4ccc7c9ce104604dab68d9f408dc34cd45823d5a9069095"+dependencies = [+ "futures-core",+ "futures-sink",+ "spin",+]+[[package]]name = "fnv"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"@@ -762,16 +855,6 @@ dependencies = ["percent-encoding",]-[[package]]-name = "fs2"-version = "0.4.3"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"-dependencies = [- "libc",- "winapi",-]-[[package]]name = "fuchsia-cprng"version = "0.1.1"@@ -820,6 +903,17 @@ dependencies = ["futures-util",]+[[package]]+name = "futures-intrusive"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1d930c203dd0b6ff06e0201a4a2fe9149b43c684fd4420555b26d21b1a02956f"+dependencies = [+ "futures-core",+ "lock_api",+ "parking_lot",+]+[[package]]name = "futures-io"version = "0.3.31"@@ -867,15 +961,6 @@ dependencies = ["slab",]-[[package]]-name = "fxhash"-version = "0.2.1"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"-dependencies = [- "byteorder",-]-[[package]]name = "generic-array"version = "0.14.7"@@ -951,6 +1036,11 @@ name = "hashbrown"version = "0.15.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"+dependencies = [+ "allocator-api2",+ "equivalent",+ "foldhash",+][[package]]name = "hashlink"@@ -961,6 +1051,24 @@ dependencies = ["hashbrown 0.14.5",]+[[package]]+name = "hashlink"+version = "0.9.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af"+dependencies = [+ "hashbrown 0.14.5",+]++[[package]]+name = "hashlink"+version = "0.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1"+dependencies = [+ "hashbrown 0.15.5",+]+[[package]]name = "heck"version = "0.5.0"@@ -973,6 +1081,15 @@ version = "0.4.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"+[[package]]+name = "hkdf"+version = "0.12.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"+dependencies = [+ "hmac",+]+[[package]]name = "hmac"version = "0.12.1"@@ -982,6 +1099,15 @@ dependencies = ["digest",]+[[package]]+name = "home"+version = "0.5.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf"+dependencies = [+ "windows-sys 0.59.0",+]+[[package]]name = "http"version = "1.3.1"@@ -1272,22 +1398,13 @@ dependencies = ["generic-array",]-[[package]]-name = "instant"-version = "0.1.13"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"-dependencies = [- "cfg-if",-]-[[package]]name = "io-uring"version = "0.7.9"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d93587f37623a1a17d94ef2bc9ada592f5465fe7732084ab7beefabe5c77c0c4"dependencies = [- "bitflags 2.9.2",+ "bitflags","cfg-if","libc",]@@ -1380,6 +1497,9 @@ name = "lazy_static"version = "1.5.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"+dependencies = [+ "spin",+][[package]]name = "libc"@@ -1411,15 +1531,21 @@ dependencies = ["rle-decode-fast",]+[[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.9"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3"dependencies = [- "bitflags 2.9.2",+ "bitflags","libc",- "redox_syscall 0.5.17",+ "redox_syscall",][[package]]@@ -1439,6 +1565,17 @@ dependencies = ["zip",]+[[package]]+name = "libsqlite3-sys"+version = "0.30.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149"+dependencies = [+ "cc",+ "pkg-config",+ "vcpkg",+]+[[package]]name = "linux-raw-sys"version = "0.9.4"@@ -1488,6 +1625,16 @@ dependencies = ["pkg-config",]+[[package]]+name = "md-5"+version = "0.10.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"+dependencies = [+ "cfg-if",+ "digest",+]+[[package]]name = "memchr"version = "2.7.5"@@ -1593,6 +1740,23 @@ dependencies = ["num-traits",]+[[package]]+name = "num-bigint-dig"+version = "0.8.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151"+dependencies = [+ "byteorder",+ "lazy_static",+ "libm",+ "num-integer",+ "num-iter",+ "num-traits",+ "rand 0.8.5",+ "smallvec",+ "zeroize",+]+[[package]]name = "num-conv"version = "0.1.0"@@ -1608,6 +1772,17 @@ dependencies = ["num-traits",]+[[package]]+name = "num-iter"+version = "0.1.45"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"+dependencies = [+ "autocfg",+ "num-integer",+ "num-traits",+]+[[package]]name = "num-traits"version = "0.2.19"@@ -1615,6 +1790,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"dependencies = ["autocfg",+ "libm",][[package]]@@ -1650,7 +1826,7 @@ version = "0.10.73"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8"dependencies = [- "bitflags 2.9.2",+ "bitflags","cfg-if","foreign-types","libc",@@ -1705,15 +1881,10 @@ dependencies = [][[package]]-name = "parking_lot"-version = "0.11.2"+name = "parking"+version = "2.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"-dependencies = [- "instant",- "lock_api",- "parking_lot_core 0.8.6",-]+checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"[[package]]name = "parking_lot"@@ -1722,21 +1893,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13"dependencies = ["lock_api",- "parking_lot_core 0.9.11",-]--[[package]]-name = "parking_lot_core"-version = "0.8.6"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"-dependencies = [- "cfg-if",- "instant",- "libc",- "redox_syscall 0.2.16",- "smallvec",- "winapi",+ "parking_lot_core",][[package]]@@ -1747,7 +1904,7 @@ checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5"dependencies = ["cfg-if","libc",- "redox_syscall 0.5.17",+ "redox_syscall","smallvec","windows-targets 0.52.6",]@@ -1768,6 +1925,15 @@ dependencies = ["hmac",]+[[package]]+name = "pem-rfc7468"+version = "0.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412"+dependencies = [+ "base64ct",+]+[[package]]name = "percent-encoding"version = "2.3.1"@@ -1830,6 +1996,27 @@ version = "0.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"+[[package]]+name = "pkcs1"+version = "0.7.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f"+dependencies = [+ "der",+ "pkcs8",+ "spki",+]++[[package]]+name = "pkcs8"+version = "0.10.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7"+dependencies = [+ "der",+ "spki",+]+[[package]]name = "pkg-config"version = "0.3.32"@@ -1912,16 +2099,37 @@ dependencies = ["winapi",]+[[package]]+name = "rand"+version = "0.8.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"+dependencies = [+ "libc",+ "rand_chacha 0.3.1",+ "rand_core 0.6.4",+]+[[package]]name = "rand"version = "0.9.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"dependencies = [- "rand_chacha",+ "rand_chacha 0.9.0","rand_core 0.9.3",]+[[package]]+name = "rand_chacha"+version = "0.3.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"+dependencies = [+ "ppv-lite86",+ "rand_core 0.6.4",+]+[[package]]name = "rand_chacha"version = "0.9.0"@@ -1947,6 +2155,15 @@ version = "0.4.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"+[[package]]+name = "rand_core"+version = "0.6.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"+dependencies = [+ "getrandom 0.2.16",+]+[[package]]name = "rand_core"version = "0.9.3"@@ -1965,22 +2182,13 @@ dependencies = ["rand_core 0.3.1",]-[[package]]-name = "redox_syscall"-version = "0.2.16"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"-dependencies = [- "bitflags 1.3.2",-]-[[package]]name = "redox_syscall"version = "0.5.17"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77"dependencies = [- "bitflags 2.9.2",+ "bitflags",][[package]]@@ -2102,7 +2310,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"dependencies = ["base64 0.21.7",- "bitflags 2.9.2",+ "bitflags","serde","serde_derive",]@@ -2118,6 +2326,26 @@ dependencies = ["windows-sys 0.59.0",]+[[package]]+name = "rsa"+version = "0.9.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "78928ac1ed176a5ca1d17e578a1825f3d81ca54cf41053a592584b020cfd691b"+dependencies = [+ "const-oid",+ "digest",+ "num-bigint-dig",+ "num-integer",+ "num-traits",+ "pkcs1",+ "pkcs8",+ "rand_core 0.6.4",+ "signature",+ "spki",+ "subtle",+ "zeroize",+]+[[package]]name = "rtoolbox"version = "0.0.3"@@ -2128,6 +2356,21 @@ dependencies = ["windows-sys 0.52.0",]+[[package]]+name = "rusqlite"+version = "0.32.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7753b721174eb8ff87a9a0e799e2d7bc3749323e773db92e0984debb00019d6e"+dependencies = [+ "bitflags",+ "fallible-iterator",+ "fallible-streaming-iterator",+ "hashlink 0.9.1",+ "libsqlite3-sys",+ "serde_json",+ "smallvec",+]+[[package]]name = "rust-ini"version = "0.20.0"@@ -2150,7 +2393,7 @@ version = "1.0.8"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"dependencies = [- "bitflags 2.9.2",+ "bitflags","errno","libc","linux-raw-sys",@@ -2232,7 +2475,7 @@ version = "2.11.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"dependencies = [- "bitflags 2.9.2",+ "bitflags","core-foundation","core-foundation-sys","libc",@@ -2352,6 +2595,16 @@ dependencies = ["libc",]+[[package]]+name = "signature"+version = "2.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"+dependencies = [+ "digest",+ "rand_core 0.6.4",+]+[[package]]name = "simd-adler32"version = "0.3.7"@@ -2370,27 +2623,14 @@ version = "0.4.11"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589"-[[package]]-name = "sled"-version = "0.34.7"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935"-dependencies = [- "crc32fast",- "crossbeam-epoch",- "crossbeam-utils",- "fs2",- "fxhash",- "libc",- "log",- "parking_lot 0.11.2",-]-[[package]]name = "smallvec"version = "1.15.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"+dependencies = [+ "serde",+][[package]]name = "socket2"@@ -2402,6 +2642,213 @@ dependencies = ["windows-sys 0.59.0",]+[[package]]+name = "spin"+version = "0.9.8"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"+dependencies = [+ "lock_api",+]++[[package]]+name = "spki"+version = "0.7.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d"+dependencies = [+ "base64ct",+ "der",+]++[[package]]+name = "sqlx"+version = "0.8.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1fefb893899429669dcdd979aff487bd78f4064e5e7907e4269081e0ef7d97dc"+dependencies = [+ "sqlx-core",+ "sqlx-macros",+ "sqlx-mysql",+ "sqlx-postgres",+ "sqlx-sqlite",+]++[[package]]+name = "sqlx-core"+version = "0.8.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ee6798b1838b6a0f69c007c133b8df5866302197e404e8b6ee8ed3e3a5e68dc6"+dependencies = [+ "base64 0.22.1",+ "bytes",+ "crc",+ "crossbeam-queue",+ "either",+ "event-listener",+ "futures-core",+ "futures-intrusive",+ "futures-io",+ "futures-util",+ "hashbrown 0.15.5",+ "hashlink 0.10.0",+ "indexmap",+ "log",+ "memchr",+ "once_cell",+ "percent-encoding",+ "serde",+ "serde_json",+ "sha2",+ "smallvec",+ "thiserror 2.0.16",+ "tokio",+ "tokio-stream",+ "tracing",+ "url",+]++[[package]]+name = "sqlx-macros"+version = "0.8.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a2d452988ccaacfbf5e0bdbc348fb91d7c8af5bee192173ac3636b5fb6e6715d"+dependencies = [+ "proc-macro2",+ "quote",+ "sqlx-core",+ "sqlx-macros-core",+ "syn",+]++[[package]]+name = "sqlx-macros-core"+version = "0.8.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "19a9c1841124ac5a61741f96e1d9e2ec77424bf323962dd894bdb93f37d5219b"+dependencies = [+ "dotenvy",+ "either",+ "heck",+ "hex",+ "once_cell",+ "proc-macro2",+ "quote",+ "serde",+ "serde_json",+ "sha2",+ "sqlx-core",+ "sqlx-mysql",+ "sqlx-postgres",+ "sqlx-sqlite",+ "syn",+ "tokio",+ "url",+]++[[package]]+name = "sqlx-mysql"+version = "0.8.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526"+dependencies = [+ "atoi",+ "base64 0.22.1",+ "bitflags",+ "byteorder",+ "bytes",+ "crc",+ "digest",+ "dotenvy",+ "either",+ "futures-channel",+ "futures-core",+ "futures-io",+ "futures-util",+ "generic-array",+ "hex",+ "hkdf",+ "hmac",+ "itoa",+ "log",+ "md-5",+ "memchr",+ "once_cell",+ "percent-encoding",+ "rand 0.8.5",+ "rsa",+ "serde",+ "sha1",+ "sha2",+ "smallvec",+ "sqlx-core",+ "stringprep",+ "thiserror 2.0.16",+ "tracing",+ "whoami",+]++[[package]]+name = "sqlx-postgres"+version = "0.8.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46"+dependencies = [+ "atoi",+ "base64 0.22.1",+ "bitflags",+ "byteorder",+ "crc",+ "dotenvy",+ "etcetera",+ "futures-channel",+ "futures-core",+ "futures-util",+ "hex",+ "hkdf",+ "hmac",+ "home",+ "itoa",+ "log",+ "md-5",+ "memchr",+ "once_cell",+ "rand 0.8.5",+ "serde",+ "serde_json",+ "sha2",+ "smallvec",+ "sqlx-core",+ "stringprep",+ "thiserror 2.0.16",+ "tracing",+ "whoami",+]++[[package]]+name = "sqlx-sqlite"+version = "0.8.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c2d12fe70b2c1b4401038055f90f151b78208de1f9f89a7dbfd41587a10c3eea"+dependencies = [+ "atoi",+ "flume",+ "futures-channel",+ "futures-core",+ "futures-executor",+ "futures-intrusive",+ "futures-util",+ "libsqlite3-sys",+ "log",+ "percent-encoding",+ "serde",+ "serde_urlencoded",+ "sqlx-core",+ "thiserror 2.0.16",+ "tracing",+ "url",+]+[[package]]name = "srp"version = "0.6.0"@@ -2421,6 +2868,17 @@ version = "1.2.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"+[[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 = "strsim"version = "0.11.1"@@ -2470,7 +2928,7 @@ version = "0.6.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b"dependencies = [- "bitflags 2.9.2",+ "bitflags","core-foundation","system-configuration-sys",]@@ -2597,6 +3055,21 @@ dependencies = ["zerovec",]+[[package]]+name = "tinyvec"+version = "1.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa"+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.47.1"@@ -2608,7 +3081,7 @@ dependencies = ["io-uring","libc","mio",- "parking_lot 0.12.4",+ "parking_lot","pin-project-lite","signal-hook-registry","slab",@@ -2648,6 +3121,17 @@ dependencies = ["tokio",]+[[package]]+name = "tokio-stream"+version = "0.1.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "eca58d7bba4a75707817a2c44174253f9236b2d5fbd055602e9d5c07c139a047"+dependencies = [+ "futures-core",+ "pin-project-lite",+ "tokio",+]+[[package]]name = "tokio-util"version = "0.7.16"@@ -2723,7 +3207,7 @@ version = "0.6.6"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"dependencies = [- "bitflags 2.9.2",+ "bitflags","bytes","futures-util","http",@@ -2753,10 +3237,23 @@ version = "0.1.41"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"dependencies = [+ "log","pin-project-lite",+ "tracing-attributes","tracing-core",]+[[package]]+name = "tracing-attributes"+version = "0.1.30"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903"+dependencies = [+ "proc-macro2",+ "quote",+ "syn",+]+[[package]]name = "tracing-core"version = "0.1.34"@@ -2784,12 +3281,33 @@ version = "0.1.7"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"+[[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.18"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"+[[package]]+name = "unicode-normalization"+version = "0.1.24"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956"+dependencies = [+ "tinyvec",+]++[[package]]+name = "unicode-properties"+version = "0.1.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0"+[[package]]name = "unicode-segmentation"version = "1.12.0"@@ -2907,6 +3425,12 @@ dependencies = ["wit-bindgen-rt",]+[[package]]+name = "wasite"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b"+[[package]]name = "wasm-bindgen"version = "0.2.100"@@ -3011,6 +3535,16 @@ dependencies = ["wasm-bindgen",]+[[package]]+name = "whoami"+version = "1.6.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5d4a4db5077702ca3015d3d02d74974948aba2ad9e12ab7df718ee64ccd7e97d"+dependencies = [+ "libredox",+ "wasite",+]+[[package]]name = "winapi"version = "0.3.9"@@ -3349,7 +3883,7 @@ version = "0.39.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"dependencies = [- "bitflags 2.9.2",+ "bitflags",][[package]]@@ -3385,7 +3919,7 @@ checksum = "8902160c4e6f2fb145dbe9d6760a75e3c9522d8bf796ed7047c85919ac7115f8"dependencies = ["arraydeque","encoding_rs",- "hashlink",+ "hashlink 0.8.4",][[package]]diff --git a/rust/Cargo.toml b/rust/Cargo.tomlindex 1151da1604..b34adacbaa 100644--- a/rust/Cargo.toml+++ b/rust/Cargo.toml@@ -32,8 +32,8 @@ srp = "0.6"num-bigint = "0.4"# Storage-sled = "0.34"-bincode = "1.3"+rusqlite = { version = "0.32", features = ["bundled", "serde_json"] }+sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite", "migrate"], optional = true }# Utilitiesthiserror = "2.0"diff --git a/rust/src/main.rs b/rust/src/main.rsindex 74bcae5f12..eb0339166d 100644--- a/rust/src/main.rs+++ b/rust/src/main.rs@@ -2,6 +2,7 @@ use clap::Parser;use ente_rs::{Result,cli::{Cli, Commands},+ storage::Storage,};#[tokio::main]@@ -11,6 +12,11 @@ async fn main() -> Result<()> {// Initialize libsodiumente_rs::crypto::init()?;++ // Initialize storage+ let config_dir = ente_rs::utils::get_cli_config_dir()?;+ let db_path = config_dir.join("ente.db");+ let _storage = Storage::new(&db_path)?;// Parse CLI argumentslet cli = Cli::parse();diff --git a/rust/src/models/error.rs b/rust/src/models/error.rsindex c41179ce71..8ba242c919 100644--- a/rust/src/models/error.rs+++ b/rust/src/models/error.rs@@ -12,7 +12,7 @@ pub enum Error {Serialization(#[from] serde_json::Error),#[error("Database error: {0}")]- Database(#[from] sled::Error),+ Database(String),#[error("Crypto error: {0}")]Crypto(String),diff --git a/rust/src/storage/account.rs b/rust/src/storage/account.rsnew file mode 100644index 0000000000..5050caaaa2--- /dev/null+++ b/rust/src/storage/account.rs@@ -0,0 +1,150 @@+#![allow(dead_code)]++use crate::{Result, models::account::{Account, App, AccountSecrets}};+use rusqlite::{Connection, params, Row, OptionalExtension};+use std::time::{SystemTime, UNIX_EPOCH};++pub struct AccountStore<'a> {+ conn: &'a Connection,+}++impl<'a> AccountStore<'a> {+ pub fn new(conn: &'a Connection) -> Self {+ Self { conn }+ }++ /// Add a new account+ pub fn add(&self, account: &Account) -> Result<i64> {+ let now = current_timestamp();++ self.conn.execute(+ "INSERT INTO accounts (email, user_id, app, export_dir, created_at, updated_at)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6)",+ params![+ account.email,+ account.user_id,+ format!("{:?}", account.app).to_lowercase(),+ account.export_dir,+ now,+ now+ ],+ )?;++ Ok(self.conn.last_insert_rowid())+ }++ /// Get an account by email and app+ pub fn get(&self, email: &str, app: App) -> Result<Option<Account>> {+ let mut stmt = self.conn.prepare(+ "SELECT id, email, user_id, app, export_dir FROM accounts+ WHERE email = ?1 AND app = ?2"+ )?;++ let account = stmt.query_row(+ params![email, format!("{:?}", app).to_lowercase()],+ |row| row_to_account(row)+ ).optional()?;++ Ok(account)+ }++ /// List all accounts+ pub fn list(&self) -> Result<Vec<Account>> {+ let mut stmt = self.conn.prepare(+ "SELECT id, email, user_id, app, export_dir FROM accounts+ ORDER BY email, app"+ )?;++ let accounts = stmt.query_map([], |row| row_to_account(row))?+ .collect::<std::result::Result<Vec<_>, _>>()?;++ Ok(accounts)+ }++ /// Update account export directory+ pub fn update_export_dir(&self, email: &str, app: App, export_dir: &str) -> Result<()> {+ let now = current_timestamp();++ self.conn.execute(+ "UPDATE accounts SET export_dir = ?1, updated_at = ?2+ WHERE email = ?3 AND app = ?4",+ params![export_dir, now, email, format!("{:?}", app).to_lowercase()],+ )?;++ Ok(())+ }++ /// Delete an account+ pub fn delete(&self, account_id: i64) -> Result<()> {+ self.conn.execute(+ "DELETE FROM accounts WHERE id = ?1",+ params![account_id],+ )?;+ Ok(())+ }++ /// Store account secrets (encrypted)+ pub fn store_secrets(&self, account_id: i64, secrets: &AccountSecrets) -> Result<()> {+ let now = current_timestamp();++ self.conn.execute(+ "INSERT OR REPLACE INTO secrets+ (account_id, token, master_key, secret_key, public_key, updated_at)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6)",+ params![+ account_id,+ &secrets.token,+ &secrets.master_key,+ &secrets.secret_key,+ &secrets.public_key,+ now+ ],+ )?;++ Ok(())+ }++ /// Get account secrets+ pub fn get_secrets(&self, account_id: i64) -> Result<Option<AccountSecrets>> {+ let mut stmt = self.conn.prepare(+ "SELECT token, master_key, secret_key, public_key FROM secrets+ WHERE account_id = ?1"+ )?;++ let secrets = stmt.query_row(params![account_id], |row| {+ Ok(AccountSecrets {+ token: row.get(0)?,+ master_key: row.get(1)?,+ secret_key: row.get(2)?,+ public_key: row.get(3)?,+ })+ }).optional()?;++ Ok(secrets)+ }+}++fn row_to_account(row: &Row) -> rusqlite::Result<Account> {+ let app_str: String = row.get(3)?;+ let app = match app_str.as_str() {+ "photos" => App::Photos,+ "locker" => App::Locker,+ "auth" => App::Auth,+ _ => App::Photos, // Default fallback+ };++ Ok(Account {+ id: row.get(0)?,+ email: row.get(1)?,+ user_id: row.get(2)?,+ app,+ export_dir: row.get(4)?,+ })+}++fn current_timestamp() -> i64 {+ SystemTime::now()+ .duration_since(UNIX_EPOCH)+ .unwrap()+ .as_secs() as i64+}\ No newline at end of filediff --git a/rust/src/storage/config.rs b/rust/src/storage/config.rsnew file mode 100644index 0000000000..4d1c80c536--- /dev/null+++ b/rust/src/storage/config.rs@@ -0,0 +1,67 @@+#![allow(dead_code)]++use crate::Result;+use rusqlite::{Connection, params, OptionalExtension};+use std::time::{SystemTime, UNIX_EPOCH};++pub struct ConfigStore<'a> {+ conn: &'a Connection,+}++impl<'a> ConfigStore<'a> {+ pub fn new(conn: &'a Connection) -> Self {+ Self { conn }+ }++ /// Set a configuration value+ pub fn set(&self, key: &str, value: &str) -> Result<()> {+ let now = SystemTime::now()+ .duration_since(UNIX_EPOCH)+ .unwrap()+ .as_secs() as i64;++ self.conn.execute(+ "INSERT OR REPLACE INTO config (key, value, updated_at)+ VALUES (?1, ?2, ?3)",+ params![key, value, now],+ )?;++ Ok(())+ }++ /// Get a configuration value+ pub fn get(&self, key: &str) -> Result<Option<String>> {+ let mut stmt = self.conn.prepare(+ "SELECT value FROM config WHERE key = ?1"+ )?;++ let value = stmt.query_row(params![key], |row| {+ row.get::<_, String>(0)+ }).optional()?;++ Ok(value)+ }++ /// Delete a configuration value+ pub fn delete(&self, key: &str) -> Result<()> {+ self.conn.execute(+ "DELETE FROM config WHERE key = ?1",+ params![key],+ )?;++ Ok(())+ }++ /// Get all configuration values+ pub fn list(&self) -> Result<Vec<(String, String)>> {+ let mut stmt = self.conn.prepare(+ "SELECT key, value FROM config ORDER BY key"+ )?;++ let configs = stmt.query_map([], |row| {+ Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?))+ })?.collect::<std::result::Result<Vec<_>, _>>()?;++ Ok(configs)+ }+}\ No newline at end of filediff --git a/rust/src/storage/mod.rs b/rust/src/storage/mod.rsindex a4cb12346c..a64b53b4c8 100644--- a/rust/src/storage/mod.rs+++ b/rust/src/storage/mod.rs@@ -1,18 +1,95 @@#![allow(dead_code)]-use crate::Result;-use sled::Db;+use crate::{Error, Result};+use rusqlite::Connection;use std::path::Path;+use serde::{Serialize, Deserialize};+pub mod schema;+pub mod account;+pub mod config;+pub mod sync;++pub use account::AccountStore;+pub use config::ConfigStore;+pub use sync::SyncStore;++/// Main storage handler that manages the SQLite databasepub struct Storage {- db: Db,+ conn: Connection,}impl Storage {+ /// Create a new storage instance with the given database pathpub fn new<P: AsRef<Path>>(path: P) -> Result<Self> {- let db = sled::open(path)?;- Ok(Self { db })+ let conn = Connection::open(path)?;++ // Enable foreign keys+ conn.execute("PRAGMA foreign_keys = ON", [])?;++ // Create tables+ schema::create_tables(&conn)?;++ Ok(Self { conn })+ }++ /// Create an in-memory database (useful for testing)+ pub fn new_in_memory() -> Result<Self> {+ let conn = Connection::open_in_memory()?;+ conn.execute("PRAGMA foreign_keys = ON", [])?;+ schema::create_tables(&conn)?;+ Ok(Self { conn })+ }++ /// Get a reference to the connection+ pub fn conn(&self) -> &Connection {+ &self.conn+ }++ /// Begin a transaction+ pub fn transaction<F, R>(&mut self, f: F) -> Result<R>+ where+ F: FnOnce(&rusqlite::Transaction) -> Result<R>,+ {+ let tx = self.conn.transaction()?;+ let result = f(&tx)?;+ tx.commit()?;+ Ok(result)+ }++ /// Get account store+ pub fn accounts(&self) -> AccountStore {+ AccountStore::new(&self.conn)+ }++ /// Get config store+ pub fn config(&self) -> ConfigStore {+ ConfigStore::new(&self.conn)}++ /// Get sync store+ pub fn sync(&self) -> SyncStore {+ SyncStore::new(&self.conn)+ }+}- // TODO: Implement storage methods+/// Helper trait for JSON serialization in SQLite+pub trait JsonValue: Serialize + for<'de> Deserialize<'de> {+ fn to_json(&self) -> Result<String> {+ Ok(serde_json::to_string(self)?)+ }++ fn from_json(json: &str) -> Result<Self> {+ Ok(serde_json::from_str(json)?)+ }}++// Implement for common types+impl<T> JsonValue for T where T: Serialize + for<'de> Deserialize<'de> {}++// Re-export rusqlite error conversion+impl From<rusqlite::Error> for Error {+ fn from(err: rusqlite::Error) -> Self {+ Error::Generic(err.to_string())+ }+}\ No newline at end of filediff --git a/rust/src/storage/schema.rs b/rust/src/storage/schema.rsnew file mode 100644index 0000000000..2e33591d53--- /dev/null+++ b/rust/src/storage/schema.rs@@ -0,0 +1,131 @@+use crate::Result;+use rusqlite::Connection;++/// Create all database tables+pub fn create_tables(conn: &Connection) -> Result<()> {+ // Accounts table+ conn.execute(+ "CREATE TABLE IF NOT EXISTS accounts (+ id INTEGER PRIMARY KEY,+ email TEXT NOT NULL,+ user_id INTEGER NOT NULL,+ app TEXT NOT NULL,+ export_dir TEXT,+ created_at INTEGER NOT NULL,+ updated_at INTEGER NOT NULL,+ UNIQUE(email, app)+ )",+ [],+ )?;++ // Secrets table (encrypted credentials)+ conn.execute(+ "CREATE TABLE IF NOT EXISTS secrets (+ account_id INTEGER PRIMARY KEY,+ token BLOB NOT NULL,+ master_key BLOB NOT NULL,+ secret_key BLOB NOT NULL,+ public_key BLOB NOT NULL,+ updated_at INTEGER NOT NULL,+ FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE+ )",+ [],+ )?;++ // Configuration table+ conn.execute(+ "CREATE TABLE IF NOT EXISTS config (+ key TEXT PRIMARY KEY,+ value TEXT NOT NULL,+ updated_at INTEGER NOT NULL+ )",+ [],+ )?;++ // Collections/Albums table+ conn.execute(+ "CREATE TABLE IF NOT EXISTS collections (+ id INTEGER PRIMARY KEY,+ account_id INTEGER NOT NULL,+ collection_id INTEGER NOT NULL,+ name TEXT NOT NULL,+ type TEXT NOT NULL,+ owner INTEGER NOT NULL,+ is_deleted INTEGER NOT NULL DEFAULT 0,+ metadata TEXT,+ updated_at INTEGER NOT NULL,+ FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE,+ UNIQUE(account_id, collection_id)+ )",+ [],+ )?;++ // Files table (for caching remote file metadata)+ conn.execute(+ "CREATE TABLE IF NOT EXISTS files (+ id INTEGER PRIMARY KEY,+ account_id INTEGER NOT NULL,+ file_id INTEGER NOT NULL,+ collection_id INTEGER NOT NULL,+ encrypted_key TEXT NOT NULL,+ key_decryption_nonce TEXT NOT NULL,+ file_info TEXT NOT NULL,+ metadata TEXT NOT NULL,+ is_deleted INTEGER NOT NULL DEFAULT 0,+ updated_at INTEGER NOT NULL,+ FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE,+ FOREIGN KEY (collection_id) REFERENCES collections(collection_id),+ UNIQUE(account_id, file_id)+ )",+ [],+ )?;++ // Album files mapping+ conn.execute(+ "CREATE TABLE IF NOT EXISTS album_files (+ id INTEGER PRIMARY KEY,+ account_id INTEGER NOT NULL,+ album_id INTEGER NOT NULL,+ file_id INTEGER NOT NULL,+ synced_locally INTEGER NOT NULL DEFAULT 0,+ created_at INTEGER NOT NULL,+ FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE,+ UNIQUE(account_id, album_id, file_id)+ )",+ [],+ )?;++ // Sync state table+ conn.execute(+ "CREATE TABLE IF NOT EXISTS sync_state (+ account_id INTEGER PRIMARY KEY,+ last_file_sync INTEGER,+ last_collection_sync INTEGER,+ last_album_sync INTEGER,+ sync_status TEXT,+ FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE+ )",+ [],+ )?;++ // Create indices for better performance+ conn.execute(+ "CREATE INDEX IF NOT EXISTS idx_files_collection+ ON files(account_id, collection_id)",+ [],+ )?;++ conn.execute(+ "CREATE INDEX IF NOT EXISTS idx_album_files_album+ ON album_files(account_id, album_id)",+ [],+ )?;++ conn.execute(+ "CREATE INDEX IF NOT EXISTS idx_collections_account+ ON collections(account_id)",+ [],+ )?;++ Ok(())+}\ No newline at end of filediff --git a/rust/src/storage/sync.rs b/rust/src/storage/sync.rsnew file mode 100644index 0000000000..92959764b6--- /dev/null+++ b/rust/src/storage/sync.rs@@ -0,0 +1,161 @@+#![allow(dead_code)]++use crate::{Result, models::{file::RemoteFile, collection::Collection}};+use rusqlite::{Connection, params, OptionalExtension};+use serde_json;++pub struct SyncStore<'a> {+ conn: &'a Connection,+}++impl<'a> SyncStore<'a> {+ pub fn new(conn: &'a Connection) -> Self {+ Self { conn }+ }++ /// Store a collection+ pub fn upsert_collection(&self, account_id: i64, collection: &Collection) -> Result<()> {+ let metadata = serde_json::to_string(&collection)?;++ self.conn.execute(+ "INSERT OR REPLACE INTO collections+ (account_id, collection_id, name, type, owner, is_deleted, metadata, updated_at)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)",+ params![+ account_id,+ collection.id,+ collection.name,+ format!("{:?}", collection.collection_type).to_lowercase(),+ collection.owner,+ collection.is_deleted as i32,+ metadata,+ collection.updated_at+ ],+ )?;++ Ok(())+ }++ /// Get all collections for an account+ pub fn get_collections(&self, account_id: i64) -> Result<Vec<Collection>> {+ let mut stmt = self.conn.prepare(+ "SELECT metadata FROM collections+ WHERE account_id = ?1 AND is_deleted = 0+ ORDER BY collection_id"+ )?;++ let collections = stmt.query_map(params![account_id], |row| {+ let metadata: String = row.get(0)?;+ Ok(serde_json::from_str::<Collection>(&metadata).unwrap())+ })?.collect::<std::result::Result<Vec<_>, _>>()?;++ Ok(collections)+ }++ /// Store a file+ pub fn upsert_file(&self, account_id: i64, file: &RemoteFile) -> Result<()> {+ let file_info = serde_json::to_string(&file.file)?;+ let metadata = serde_json::to_string(&file.metadata)?;++ self.conn.execute(+ "INSERT OR REPLACE INTO files+ (account_id, file_id, collection_id, encrypted_key, key_decryption_nonce,+ file_info, metadata, is_deleted, updated_at)+ VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",+ params![+ account_id,+ file.id,+ file.collection_id,+ file.encrypted_key,+ file.key_decryption_nonce,+ file_info,+ metadata,+ file.is_deleted as i32,+ file.updated_at+ ],+ )?;++ Ok(())+ }++ /// Get files for a collection+ pub fn get_files_by_collection(&self, account_id: i64, collection_id: i64) -> Result<Vec<RemoteFile>> {+ let mut stmt = self.conn.prepare(+ "SELECT file_id, collection_id, encrypted_key, key_decryption_nonce,+ file_info, metadata, is_deleted, updated_at+ FROM files+ WHERE account_id = ?1 AND collection_id = ?2 AND is_deleted = 0+ ORDER BY file_id"+ )?;++ let files = stmt.query_map(params![account_id, collection_id], |row| {+ let file_info: String = row.get(4)?;+ let metadata: String = row.get(5)?;++ Ok(RemoteFile {+ id: row.get(0)?,+ collection_id: row.get(1)?,+ owner_id: 0, // Will need to fetch from account+ encrypted_key: row.get(2)?,+ key_decryption_nonce: row.get(3)?,+ file: serde_json::from_str(&file_info).unwrap(),+ thumbnail: serde_json::from_str("{}").unwrap(), // Placeholder+ metadata: serde_json::from_str(&metadata).unwrap(),+ is_deleted: row.get::<_, i32>(6)? != 0,+ updated_at: row.get(7)?,+ })+ })?.collect::<std::result::Result<Vec<_>, _>>()?;++ Ok(files)+ }++ /// Update sync state+ pub fn update_sync_state(&self, account_id: i64, sync_type: &str, timestamp: i64) -> Result<()> {+ let column = match sync_type {+ "files" => "last_file_sync",+ "collections" => "last_collection_sync",+ "albums" => "last_album_sync",+ _ => return Err(crate::Error::InvalidInput("Invalid sync type".into())),+ };++ let query = format!(+ "INSERT OR REPLACE INTO sync_state (account_id, {}) VALUES (?1, ?2)+ ON CONFLICT(account_id) DO UPDATE SET {} = ?2",+ column, column+ );++ self.conn.execute(&query, params![account_id, timestamp])?;++ Ok(())+ }++ /// Get last sync timestamp+ pub fn get_last_sync(&self, account_id: i64, sync_type: &str) -> Result<Option<i64>> {+ let column = match sync_type {+ "files" => "last_file_sync",+ "collections" => "last_collection_sync",+ "albums" => "last_album_sync",+ _ => return Err(crate::Error::InvalidInput("Invalid sync type".into())),+ };++ let query = format!("SELECT {} FROM sync_state WHERE account_id = ?1", column);+ let mut stmt = self.conn.prepare(&query)?;++ let timestamp = stmt.query_row(params![account_id], |row| {+ row.get::<_, Option<i64>>(0)+ }).optional()?.flatten();++ Ok(timestamp)+ }++ /// Mark album file as synced+ pub fn mark_album_file_synced(&self, account_id: i64, album_id: i64, file_id: i64) -> Result<()> {+ self.conn.execute(+ "UPDATE album_files SET synced_locally = 1+ WHERE account_id = ?1 AND album_id = ?2 AND file_id = ?3",+ params![account_id, album_id, file_id],+ )?;++ Ok(())+ }+}\ No newline at end of file