diff --git a/.cargo/config.toml b/.cargo/config.toml
new file mode 100644
index 0000000..db8ae31
--- /dev/null
+++ b/.cargo/config.toml
@@ -0,0 +1,5 @@
+[build]
+target-dir = "D:/Rust_Contact/util/target/Rid_Drone_Receivev"
+
+[target.x86_64-pc-windows-msvc]
+rustflags = ["-C", "target-feature=+crt-static"]
diff --git a/.gitignore b/.gitignore
index 19e5e93..59db884 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,5 @@ host/
# 临时文件
*.tmp
*.log
+/target/
+/dist/
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..4e5a1df
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,1198 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "aho-corasick"
+version = "1.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "android_system_properties"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "arbitrary"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3bc62ac97cc33321f50863d514c3bc38a453947a8f9e781137e47c7401020aed"
+dependencies = [
+ "derive_arbitrary",
+]
+
+[[package]]
+name = "atomic-waker"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
+
+[[package]]
+name = "autocfg"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
+
+[[package]]
+name = "axum"
+version = "0.8.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "31b698c5f9a010f6573133b09e0de5408834d0c82f8d7475a89fc1867a71cd90"
+dependencies = [
+ "axum-core",
+ "bytes",
+ "form_urlencoded",
+ "futures-util",
+ "http",
+ "http-body",
+ "http-body-util",
+ "hyper",
+ "hyper-util",
+ "itoa",
+ "matchit",
+ "memchr",
+ "mime",
+ "percent-encoding",
+ "pin-project-lite",
+ "serde_core",
+ "serde_json",
+ "serde_path_to_error",
+ "serde_urlencoded",
+ "sync_wrapper",
+ "tokio",
+ "tower",
+ "tower-layer",
+ "tower-service",
+ "tracing",
+]
+
+[[package]]
+name = "axum-core"
+version = "0.5.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1"
+dependencies = [
+ "bytes",
+ "futures-core",
+ "http",
+ "http-body",
+ "http-body-util",
+ "mime",
+ "pin-project-lite",
+ "sync_wrapper",
+ "tower-layer",
+ "tower-service",
+ "tracing",
+]
+
+[[package]]
+name = "base64"
+version = "0.22.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
+
+[[package]]
+name = "bitflags"
+version = "2.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
+
+[[package]]
+name = "bumpalo"
+version = "3.20.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
+
+[[package]]
+name = "bytes"
+version = "1.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
+
+[[package]]
+name = "cc"
+version = "1.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "877bf67ac8e52449eb2f9e98a344ea163beb70dd1f9eebe3cc5357dcfeaee4df"
+dependencies = [
+ "find-msvc-tools",
+ "shlex",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
+
+[[package]]
+name = "chrono"
+version = "0.4.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327"
+dependencies = [
+ "iana-time-zone",
+ "js-sys",
+ "num-traits",
+ "wasm-bindgen",
+ "windows-link",
+]
+
+[[package]]
+name = "core-foundation-sys"
+version = "0.8.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
+
+[[package]]
+name = "crc32fast"
+version = "1.5.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "derive_arbitrary"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b034bd7d5f032402a2479444dcc6f74e36a03f31854d41680fb240ef682a1ac"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.9",
+]
+
+[[package]]
+name = "equivalent"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
+
+[[package]]
+name = "errno"
+version = "0.3.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
+dependencies = [
+ "libc",
+ "windows-sys",
+]
+
+[[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.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
+
+[[package]]
+name = "find-msvc-tools"
+version = "0.1.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
+
+[[package]]
+name = "flate2"
+version = "1.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e634e2e0ebac1ee034020da1ca582e17ffe4e0f5e985823721e168928136dcb"
+dependencies = [
+ "zlib-rs",
+]
+
+[[package]]
+name = "foldhash"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
+
+[[package]]
+name = "form_urlencoded"
+version = "1.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
+dependencies = [
+ "percent-encoding",
+]
+
+[[package]]
+name = "fpv-rid-registry"
+version = "3.0.0"
+dependencies = [
+ "axum",
+ "base64",
+ "chrono",
+ "fs2",
+ "rand",
+ "regex",
+ "rusqlite",
+ "rust_xlsxwriter",
+ "serde",
+ "serde_json",
+ "tempfile",
+ "tokio",
+ "tower",
+ "zip",
+]
+
+[[package]]
+name = "fs2"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
+dependencies = [
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "futures-core"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
+
+[[package]]
+name = "futures-task"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
+
+[[package]]
+name = "futures-util"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
+dependencies = [
+ "futures-core",
+ "futures-task",
+ "pin-project-lite",
+ "slab",
+]
+
+[[package]]
+name = "getrandom"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "r-efi 5.3.0",
+ "wasip2",
+]
+
+[[package]]
+name = "getrandom"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "r-efi 6.0.0",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.16.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
+dependencies = [
+ "foldhash",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.17.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
+
+[[package]]
+name = "hashlink"
+version = "0.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "824e001ac4f3012dd16a264bec811403a67ca9deb6c102fc5049b32c4574b35f"
+dependencies = [
+ "hashbrown 0.16.1",
+]
+
+[[package]]
+name = "http"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0"
+dependencies = [
+ "bytes",
+ "itoa",
+]
+
+[[package]]
+name = "http-body"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c"
+dependencies = [
+ "bytes",
+ "http",
+]
+
+[[package]]
+name = "http-body-util"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c"
+dependencies = [
+ "bytes",
+ "futures-core",
+ "http",
+ "http-body",
+ "pin-project-lite",
+]
+
+[[package]]
+name = "httparse"
+version = "1.10.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
+
+[[package]]
+name = "httpdate"
+version = "1.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
+
+[[package]]
+name = "hyper"
+version = "1.12.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c"
+dependencies = [
+ "atomic-waker",
+ "bytes",
+ "futures-core",
+ "http",
+ "http-body",
+ "httparse",
+ "httpdate",
+ "itoa",
+ "pin-project-lite",
+ "smallvec",
+ "tokio",
+]
+
+[[package]]
+name = "hyper-util"
+version = "0.1.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff"
+dependencies = [
+ "bytes",
+ "http",
+ "http-body",
+ "hyper",
+ "pin-project-lite",
+ "tokio",
+ "tower-service",
+]
+
+[[package]]
+name = "iana-time-zone"
+version = "0.1.65"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
+dependencies = [
+ "android_system_properties",
+ "core-foundation-sys",
+ "iana-time-zone-haiku",
+ "js-sys",
+ "log",
+ "wasm-bindgen",
+ "windows-core",
+]
+
+[[package]]
+name = "iana-time-zone-haiku"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
+dependencies = [
+ "cc",
+]
+
+[[package]]
+name = "indexmap"
+version = "2.14.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
+dependencies = [
+ "equivalent",
+ "hashbrown 0.17.1",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
+
+[[package]]
+name = "js-sys"
+version = "0.3.106"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7883d941dae510fb2d978fc3fe018c71c9e2892fd38854de3e8b92c2e5ad9cc5"
+dependencies = [
+ "cfg-if",
+ "futures-util",
+ "wasm-bindgen",
+]
+
+[[package]]
+name = "libc"
+version = "0.2.191"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
+
+[[package]]
+name = "libsqlite3-sys"
+version = "0.36.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95b4103cffefa72eb8428cb6b47d6627161e51c2739fc5e3b734584157bc642a"
+dependencies = [
+ "cc",
+ "pkg-config",
+ "vcpkg",
+]
+
+[[package]]
+name = "linux-raw-sys"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
+
+[[package]]
+name = "log"
+version = "0.4.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
+
+[[package]]
+name = "matchit"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
+
+[[package]]
+name = "memchr"
+version = "2.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
+
+[[package]]
+name = "mime"
+version = "0.3.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
+
+[[package]]
+name = "mio"
+version = "1.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee"
+dependencies = [
+ "libc",
+ "wasi",
+ "windows-sys",
+]
+
+[[package]]
+name = "num-traits"
+version = "0.2.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
+dependencies = [
+ "autocfg",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.21.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
+
+[[package]]
+name = "percent-encoding"
+version = "2.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
+
+[[package]]
+name = "pin-project-lite"
+version = "0.2.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
+
+[[package]]
+name = "pkg-config"
+version = "0.3.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
+
+[[package]]
+name = "ppv-lite86"
+version = "0.2.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
+dependencies = [
+ "zerocopy",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.107"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.47"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "r-efi"
+version = "5.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
+
+[[package]]
+name = "r-efi"
+version = "6.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
+
+[[package]]
+name = "rand"
+version = "0.9.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41"
+dependencies = [
+ "rand_chacha",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
+dependencies = [
+ "ppv-lite86",
+ "rand_core",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.9.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
+dependencies = [
+ "getrandom 0.3.4",
+]
+
+[[package]]
+name = "regex"
+version = "1.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-automata",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-automata"
+version = "0.4.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.8.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
+
+[[package]]
+name = "rsqlite-vfs"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c51c9ae4df8a7fba42103df5c621fa3c37eccf3a3c650879e90fc48b11cc192c"
+dependencies = [
+ "hashbrown 0.16.1",
+ "thiserror",
+]
+
+[[package]]
+name = "rusqlite"
+version = "0.38.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1c93dd1c9683b438c392c492109cb702b8090b2bfc8fed6f6e4eb4523f17af3"
+dependencies = [
+ "bitflags",
+ "fallible-iterator",
+ "fallible-streaming-iterator",
+ "hashlink",
+ "libsqlite3-sys",
+ "smallvec",
+ "sqlite-wasm-rs",
+]
+
+[[package]]
+name = "rust_xlsxwriter"
+version = "0.90.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2be778223b36bb449b2ef2df4856ced2d311680818a7310db5c5dc370170f935"
+dependencies = [
+ "zip",
+]
+
+[[package]]
+name = "rustix"
+version = "1.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d"
+dependencies = [
+ "bitflags",
+ "errno",
+ "libc",
+ "linux-raw-sys",
+ "windows-sys",
+]
+
+[[package]]
+name = "rustversion"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
+
+[[package]]
+name = "ryu"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"
+
+[[package]]
+name = "serde"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
+dependencies = [
+ "serde_core",
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_core"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.229"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.9",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.154"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
+dependencies = [
+ "itoa",
+ "memchr",
+ "serde",
+ "serde_core",
+ "zmij",
+]
+
+[[package]]
+name = "serde_path_to_error"
+version = "0.1.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457"
+dependencies = [
+ "itoa",
+ "serde",
+ "serde_core",
+]
+
+[[package]]
+name = "serde_urlencoded"
+version = "0.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
+dependencies = [
+ "form_urlencoded",
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
+name = "shlex"
+version = "2.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
+
+[[package]]
+name = "signal-hook-registry"
+version = "1.4.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b"
+dependencies = [
+ "errno",
+ "libc",
+]
+
+[[package]]
+name = "simd-adler32"
+version = "0.3.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
+
+[[package]]
+name = "slab"
+version = "0.4.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
+
+[[package]]
+name = "smallvec"
+version = "1.16.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5b3dc8af474f516a851ff4bd12db780f948b9250ad37211e4eec0bccea54e01b"
+
+[[package]]
+name = "socket2"
+version = "0.6.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
+dependencies = [
+ "libc",
+ "windows-sys",
+]
+
+[[package]]
+name = "sqlite-wasm-rs"
+version = "0.5.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dc3efc0da82635d7e1ced0053bbbfa8c7ab9645d0bf36ceb4f7127bb85315d75"
+dependencies = [
+ "cc",
+ "js-sys",
+ "rsqlite-vfs",
+ "wasm-bindgen",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.119"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "syn"
+version = "3.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "sync_wrapper"
+version = "1.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
+
+[[package]]
+name = "tempfile"
+version = "3.27.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
+dependencies = [
+ "fastrand",
+ "getrandom 0.4.3",
+ "once_cell",
+ "rustix",
+ "windows-sys",
+]
+
+[[package]]
+name = "thiserror"
+version = "2.0.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "2.0.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.9",
+]
+
+[[package]]
+name = "tokio"
+version = "1.54.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a0c168a474b95bfecfe908a65d4bdffc523144b649a74c09c286afb35d53e0bc"
+dependencies = [
+ "libc",
+ "mio",
+ "pin-project-lite",
+ "signal-hook-registry",
+ "socket2",
+ "tokio-macros",
+ "windows-sys",
+]
+
+[[package]]
+name = "tokio-macros"
+version = "2.7.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 3.0.9",
+]
+
+[[package]]
+name = "tower"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4"
+dependencies = [
+ "futures-core",
+ "futures-util",
+ "pin-project-lite",
+ "sync_wrapper",
+ "tokio",
+ "tower-layer",
+ "tower-service",
+ "tracing",
+]
+
+[[package]]
+name = "tower-layer"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
+
+[[package]]
+name = "tower-service"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
+
+[[package]]
+name = "tracing"
+version = "0.1.44"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
+dependencies = [
+ "log",
+ "pin-project-lite",
+ "tracing-core",
+]
+
+[[package]]
+name = "tracing-core"
+version = "0.1.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
+dependencies = [
+ "once_cell",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
+
+[[package]]
+name = "vcpkg"
+version = "0.2.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
+
+[[package]]
+name = "wasi"
+version = "0.11.1+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
+
+[[package]]
+name = "wasip2"
+version = "1.0.4+wasi-0.2.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"
+dependencies = [
+ "wit-bindgen",
+]
+
+[[package]]
+name = "wasm-bindgen"
+version = "0.2.129"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409"
+dependencies = [
+ "cfg-if",
+ "once_cell",
+ "rustversion",
+ "wasm-bindgen-macro",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.129"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.129"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7"
+dependencies = [
+ "bumpalo",
+ "proc-macro2",
+ "quote",
+ "syn 3.0.9",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.129"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
+[[package]]
+name = "windows-core"
+version = "0.62.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
+dependencies = [
+ "windows-implement",
+ "windows-interface",
+ "windows-link",
+ "windows-result",
+ "windows-strings",
+]
+
+[[package]]
+name = "windows-implement"
+version = "0.60.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "windows-interface"
+version = "0.59.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "windows-link"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
+
+[[package]]
+name = "windows-result"
+version = "0.4.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
+name = "windows-strings"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
+name = "windows-sys"
+version = "0.61.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
+name = "wit-bindgen"
+version = "0.57.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
+
+[[package]]
+name = "zerocopy"
+version = "0.8.63"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8"
+dependencies = [
+ "zerocopy-derive",
+]
+
+[[package]]
+name = "zerocopy-derive"
+version = "0.8.63"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.119",
+]
+
+[[package]]
+name = "zip"
+version = "4.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "caa8cd6af31c3b31c6631b8f483848b91589021b28fffe50adada48d4f4d2ed1"
+dependencies = [
+ "arbitrary",
+ "crc32fast",
+ "flate2",
+ "indexmap",
+ "memchr",
+ "zopfli",
+]
+
+[[package]]
+name = "zlib-rs"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
+
+[[package]]
+name = "zmij"
+version = "1.0.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
+
+[[package]]
+name = "zopfli"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aaf7fc5d30c28483d93805c4a5e12b05bbb52407fa67c5f8bd552374cd01fb11"
+dependencies = [
+ "bumpalo",
+ "crc32fast",
+ "log",
+ "simd-adler32",
+]
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..c31685a
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,27 @@
+[package]
+name = "fpv-rid-registry"
+version = "3.0.0"
+edition = "2024"
+
+[dependencies]
+axum = "0.8"
+tokio = { version = "1", features = ["rt-multi-thread", "macros", "net", "signal"] }
+rusqlite = { version = "0.38", features = ["bundled", "backup"] }
+serde = { version = "1", features = ["derive"] }
+serde_json = "1"
+base64 = "0.22"
+rand = "0.9"
+chrono = "0.4"
+zip = { version = "4", default-features = false, features = ["deflate"] }
+rust_xlsxwriter = "0.90"
+fs2 = "0.4"
+regex = "1"
+
+[dev-dependencies]
+tempfile = "3"
+tower = { version = "0.5", features = ["util"] }
+
+[profile.release]
+lto = true
+strip = true
+codegen-units = 1
diff --git a/README.md b/README.md
index 140bb57..e0ca68d 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,19 @@
# Rid_Drone_Receivev
-FPV-RID 本地备案源码(新版2整理版)。对应 GitHub 仓库:`zhangshuochi/Rid_Drone_Receivev`。
+FPV-RID 本地备案登记站,Rust + Axum + SQLite。对应 GitHub 仓库:`zhangshuochi/Rid_Drone_Receivev`。
-这份工程从你指定的 **`FPV-RID_本地登记验证_新版2`** 提取。业务源码保持原版内容,新增了启动入口和开发说明,方便后续维护和与 RID 监管平台联动。原桌面目录未改动。
+Rust 版本复用原有数据格式和网页,增加编辑、照片删除、分页和档案同步重试。项目仅保留 Rust 后端,不再提供 Node.js 回退版本。设备上位机及无线 RID 接收不在本仓库实现范围内。
+
+## Rust 启动与验证
+
+- 发布目录:双击 `启动Rust版.cmd`,打开 http://127.0.0.1:8787/ ,无需 Node.js。
+- 开发:`cargo run -- --data-root .`;Release:`cargo build --release --locked`。
+- 仓库 `启动源码版.cmd` 默认转到 Rust。
+- 检查:`cargo fmt --check`、`cargo clippy --all-targets -- -D warnings`、`cargo test`。
+- 接口与数据验收:`node scripts/verify.mjs`,仅使用独立临时目录。
+- 打包:`powershell -ExecutionPolicy Bypass -File scripts/package.ps1`,输出发布目录、Windows ZIP 和校验和;检测到发布目录含运行数据时停止,可用 `-OutputRoot` 指定干净目录。
+
+完整说明见 [Rust 使用说明](doc/registry/rust/使用说明.md) 和 [接口补充](doc/registry/rust/接口变更.md)。默认数据根目录为 exe 所在目录,开发时明确传 `--data-root .`。更新前关闭旧实例并备份原数据库,禁止两个版本同时运行。
## 一句话看懂
@@ -12,22 +23,18 @@ FPV-RID 本地备案源码(新版2整理版)。对应 GitHub 仓库:`zhang
| 位置 | 用途 |
| --- | --- |
-| `registry/server.js` | 本地 HTTP 服务、接口、离线档案卡和档案备份 |
-| `registry/database.js` | SQLite 表、登记、搜索、删除、照片保存 |
-| `registry/export-files.js` | ZIP 档案包和 Excel 导出 |
+| `src/` | Rust HTTP 服务、SQLite 事务、档案备份和导出 |
+| `Cargo.toml`、`Cargo.lock`、`rust-toolchain.toml` | Rust 依赖、锁定版本与工具链 |
| `registry/web/` | 登记网页、样式、二维码脚本和图标 |
+| `scripts/` | 环境、打包、兼容及浏览器验收脚本 |
| `docs/原版使用说明.md` | 新版2附带的原始说明 |
| `docs/架构与RID联动.md` | 数据流、字段和对接方式 |
| `docs/接口清单.md` | 本地 HTTP 接口说明 |
| `启动源码版.cmd` | Windows 启动入口 |
-## 启动
+## 开发验收脚本
-1. 使用 **Node.js 24**。原版自带的是 **24.19.0**;本包不重复附带 `node.exe`。可以安装 Node.js,或从你原版目录把 `runtime/node.exe` 复制到本包的 `runtime/node.exe`。
-2. 双击 `启动源码版.cmd`,保持命令窗口打开。
-3. 在同一台电脑的浏览器打开 `http://127.0.0.1:8787/`。
-
-项目没有 npm 第三方依赖,二维码脚本已随源码保存。如果原版登记站正在运行,先关闭原版;两个实例都使用 8787 端口。
+`scripts/*.mjs` 使用 Node.js 执行开发验收,不属于服务运行依赖,也不提供 Node.js 后端。运行登记站只需 Rust 可执行文件和浏览器。
## 已有备案数据怎么迁移
@@ -38,8 +45,8 @@ FPV-RID 本地备案源码(新版2整理版)。对应 GitHub 仓库:`zhang
## 后续开发先看哪里
- 改登记表单和页面:`registry/web/index.html`、`app.js`、`app.css`。
-- 改校验规则或查询:`registry/database.js`。
-- 改本地接口和档案卡:`registry/server.js`。
+- 改校验规则或查询:`src/store.rs`。
+- 改本地接口和档案卡:`src/http.rs`、`src/archive.rs`;数据库逻辑在 `src/store.rs`。
- 接入无人机监管平台:先看 `docs/架构与RID联动.md`。备案记录可用于判断“已备案 / 未匹配”,RID 实时坐标仍由基站上报。
当前服务仅监听 `127.0.0.1`,没有登录认证。要让局域网内的其他电脑读取档案,应由 RID 平台后端做受控同步接口,不能直接把这个本地服务改成对全网开放。
diff --git a/doc/registry/rust/使用说明.md b/doc/registry/rust/使用说明.md
new file mode 100644
index 0000000..5ee9baa
--- /dev/null
+++ b/doc/registry/rust/使用说明.md
@@ -0,0 +1,48 @@
+# FPV-RID Rust 本地登记站
+
+## 运行
+
+Windows x64 发布目录中双击 `启动Rust版.cmd`,保持窗口打开,使用浏览器访问 http://127.0.0.1:8787/ 。不需要 Node.js;不包含无线 RID 接收或设备上位机。
+
+默认数据目录是 exe 所在目录,不是命令行当前目录。目录必须可写,不要放在 Program Files。数据库仍为 `registry/data/registry.sqlite`,自动档案仍在 `档案库/`。高级用法:`fpv-rid-registry.exe --data-root "D:\我的备案"`。
+
+同一时刻只运行一个登记站。8787 被占用时先关闭原版或其他实例。Rust 版本另外锁定数据目录;旧版 Node 不认识这把锁,因此仍需人工关闭旧版。
+
+## 编辑和照片
+
+卡片点击“编辑资料 / 照片”,在弹窗修改机型、登记人。空字符串保存表示清空,SN 和 FPV 编号不可修改。照片可保留、替换或单独删除。先选择替换文件会取消该照片的删除勾选,反之亦然。
+
+资料与照片通过一次请求、同一数据库事务提交,校验或数据库写入失败全部回滚。连接中断时客户端不能判定是否已提交,请刷新核对保存结果。
+
+列表每页 20 条,搜索回到第一页。全选、导出仅包含当前页选中记录;切换页或搜索会清空选择。
+
+## 保存与备份
+
+数据库是主数据源。保存成功但档案或备份写入失败时,显示“数据已保存,档案备份待同步”。修复文件权限、磁盘空间或文件占用后点击“重试同步”。重启也会重建档案。
+
+待同步状态保存在 SQLite 内部元数据表,与业务修改一起提交。旧 `registry/data/archive-pending.json` 会自动迁移后删除;不要手工修改元数据。删除档案或照片后同步时会清除上一份备份;同步失败时旧派生文件可能仍包含删除前的内容,需恢复同步。已导出到其他目录的文件不随删除操作清除。
+
+## 迁移与回退
+
+1. 关闭原版登记站,独立备份原版数据库及整个档案库;不要直接复制正在写入的 SQLite。
+2. 首次使用先复制数据库到单独测试目录,通过 `--data-root` 验证记录、照片和二维码。
+3. 正式更新仅替换程序文件,不覆盖 `registry/data/` 和 `档案库/`。
+4. 本项目不再提供 Node.js 回退版本。恢复数据前关闭 Rust 并备份当前数据,再恢复已确认完整的数据库备份。
+
+旧 `records.json` 采用整批事务导入:缺少必填字段、无效内容或重复 ID/SN/FPV 编号时,启动报错会指出记录序号,全部记录回滚,原 JSON 保留且不标记完成。修正文件后重启会重试。已经标记完成的旧库不会自动清除标记或重新导入,以免恢复用户主动删除的记录;如需核对旧版历史导入,应先在独立副本中处理。
+
+不要使用空数据库覆盖现有数据库。二维码指向当前电脑的 127.0.0.1,不能当成跨电脑分享链接。备份包含登记人及照片,应妥善保存。
+
+## 开发与打包
+
+本机 Rust 环境集中在 `D:\Rust_Contact\util`:`cargo/` 保存 Cargo 工具和依赖缓存,`rustup/` 保存编译工具链,`downloads/` 保存安装包,`target/Rid_Drone_Receivev/` 保存本项目构建产物。用户环境变量 CARGO_HOME、RUSTUP_HOME 指向上述目录,PATH 加入 cargo/bin;新终端生效。
+
+仓库 `.cargo/config.toml` 固定本机构建缓存目录,发布脚本通过 Cargo metadata 获取产物位置。发布包仍生成到仓库 `dist/`,业务数据库不放在 util。更换开发机器时调整该本机路径配置。共享 Node.js、Visual Studio 和 Windows SDK 不属于此次清理范围。
+
+安装 Rust stable MSVC 及 Visual Studio C++ Build Tools 后,运行 `cargo run -- --data-root .`。检查:`cargo fmt --check`、`cargo clippy --all-targets -- -D warnings`、`cargo test`。Release:`cargo build --release --locked`。
+
+本仓库将稳定工具链固定为 1.99.1。已有终端若未刷新环境,可先在 PowerShell 执行 `. ./scripts/rust-env.ps1`。Rust 编译依赖保存在 util/cargo/registry;Windows SDK、Visual Studio 等共享组件保留在原安装目录。
+
+`scripts/package.ps1` 通过独立暂存目录及六文件白名单,生成 `dist/FPV-RID-Rust/`、Windows ZIP 和两份 SHA-256 清单,不打包备案数据。若已有发布目录含数据库、档案或其他非发布文件,脚本会停止并保留原内容及旧 ZIP;请使用 `./scripts/package.ps1 -OutputRoot "D:\单独发布目录"` 指定干净输出目录。禁止把正在使用的数据目录作为打包暂存目录。
+
+`node scripts/verify.mjs` 在独立临时目录执行 Rust Release 版接口、导出、重启和旧数据导入验收;Node.js 仅作为开发测试工具;`powershell -ExecutionPolicy Bypass -File scripts/test-package.ps1` 验证重复打包、运行数据隔离及校验和。临时验收目录保留作为证据,不触及正式数据。
diff --git a/doc/registry/rust/接口变更.md b/doc/registry/rust/接口变更.md
new file mode 100644
index 0000000..d526a36
--- /dev/null
+++ b/doc/registry/rust/接口变更.md
@@ -0,0 +1,14 @@
+# Rust 接口补充
+
+旧版接口与 JSON 驼峰字段保留。GET `/api/records` 未传分页参数时仍返回完整 `{records:[...]}`。
+
+- GET `/api/records?q=关键词&page=1&pageSize=20`:新增 page、pageSize、total、totalPages。页号从 1 开始,pageSize 为 1–100;超出最后一页返回空数组。按创建时间倒序、ID 倒序稳定排序。
+- PATCH `/api/records/:id`:JSON 可包含 modelName、ownerName、photo1、photo2;一次请求在同一事务更新。文字缺省保留、空字符串清空,文字 null 或非字符串无效;照片缺省保留、data URL 替换、null 删除,空字符串无效。拒绝空对象和其他字段。文字长度按 JavaScript UTF-16 语义限制为 60、40。已删除档案返回 404,不重新登记。
+- DELETE `/api/records/:id/photos/1`(或 2):删除指定照片。档案不存在为 404,已缺失照片的删除是幂等成功。
+- POST `/api/archive/retry`:重建档案卡、索引及 SQLite 备份。成功返回 `{archiveStatus:"synced"}`,失败返回 500 和 error。
+- GET `/api/archive/status`:读取持久化待同步标记,让重启后的网页也能显示备份状态。
+- 登记、修改、删除的成功响应增加 archiveStatus;pending 时增加 warning。已提交数据库不会因派生文件失败而报登记失败。
+
+内部状态保存在 registry_meta 表,与业务修改同事务提交;旧 records/photos 表不变。旧 archive-pending.json 在首次启动时迁入数据库,提交后删除。旧 records.json 只导入一次,全部删除后重启不会再次导入。校验失败为 400,不存在为 404,来源限制为 403,内部数据库/文件故障为 500,详细错误仅写控制台。
+
+仅监听本机。保留旧版 Origin 限制,以及 resolve 的跨源读取例外;其他来源不能通过网页操作登记接口。接口没有账号认证,不应直接暴露到局域网或互联网。
diff --git a/doc/registry/rust/验收记录.md b/doc/registry/rust/验收记录.md
new file mode 100644
index 0000000..3e32734
--- /dev/null
+++ b/doc/registry/rust/验收记录.md
@@ -0,0 +1,51 @@
+# Rust 迁移验收记录
+
+## 2026-10-21 边界修复复验
+
+- 旧 JSON 导入改为先校验所有记录,再执行普通 INSERT。缺失字段、错误类型、无效时间和重复 ID/SN/FPV 均报出记录序号,整批回滚,不写入导入完成标记;原文件保留,修正后可重试。已经完成的历史标记不自动清除,避免恢复主动删除的档案。
+- 打包脚本使用独立暂存目录和六文件白名单,同时生成发布目录、ZIP 及 SHA-256。发布目录含运行数据、未知文件或重解析点时拒绝打包,不删除数据、不覆盖旧 ZIP;可用 -OutputRoot 另选干净输出位置。
+- Rust 自动测试增至 9 项并全部通过;Clippy 严格检查、格式检查通过。
+- Windows PowerShell 5.1 下执行 scripts/test-package.ps1 通过:干净目录连续打包、加入模拟数据库后拒绝打包、原数据和旧 ZIP 哈希保持、ZIP 仅含六个白名单文件、文件与 ZIP 校验和正确、暂存文件清理完成。
+- 更新后的 Release 程序通过 scripts/verify.mjs:除原兼容场景外,实测异常旧 JSON 启动失败、记录与元数据均回滚为零、修正原文件后成功导入两条;前端分页回归仍通过。
+- 本轮证据:`C:/Users/20143/AppData/Local/Temp/RID-package-review-738d63bb6b984a3f94f60252d9cfabf8/`、`C:/Users/20143/AppData/Local/Temp/RID-中文验证-4Bcnnh/`。以下为此前迁移的历史记录与边界。
+
+日期:2026-10-20。目标:Windows x64。工具链:Rust/Cargo 1.99.1,固定于 rust-toolchain.toml。
+
+## 实现结果
+
+- 一次性导入:registry_meta 在导入事务中记录完成状态,删除全部记录后重启不会恢复 records.json 中的旧档案。
+- 原子编辑:单次 PATCH 处理文字、照片替换和删除;数据库中途失败全部回滚,目标不存在时返回 404。
+- 同步状态:与业务修改同事务提交;冲突和回滚不留下虚假状态,删除清理要求不会被后续编辑取消。
+- 错误类型:校验 400、不存在 404、来源限制 403、内部故障 500,内部详细路径不返回客户端。
+- SQL 查询:COUNT/LIMIT/OFFSET 分页、主键单条查询、按选中 ID 导出;分页失败不提交新页码,旧响应被忽略。
+- 环境:CARGO_HOME、RUSTUP_HOME 和构建缓存均在 D:/Rust_Contact/util,用户目录无 .cargo/.rustup。
+
+## 实际验证
+
+- cargo fmt --check 通过。
+- cargo clippy --all-targets --locked --offline -- -D warnings 通过。
+- cargo test --locked --offline:7 项测试全部通过,包括数据库触发器注入故障后的事务回滚、Windows 独占占用备份文件后的恢复。
+- cargo build --release --locked --offline 通过,启用 Release 优化、LTO 和静态 CRT,exe 为 6,293,504 字节。
+- node scripts/test-frontend.mjs 通过:翻页失败保留页码、成功后更新、旧响应不覆盖。
+- node scripts/verify.mjs 通过:Node 生成的 SQLite 由 Rust 直接读取;验证照片字节、二维码、HTML 转义、ZIP 内部清单和照片、XLSX 内部 XML、编辑和删除、故障重试、重启及备份完整性。
+- scripts/test-browser.mjs 使用真实 Chromium 和 Release 服务通过:登记、照片、取消和焦点、一次 PATCH 编辑、坏图片回滚、分页、搜索回第一页、当前页 20 条选择及 Excel 下载;1366×1000 与 390×844 下无横向溢出,未出现页面脚本异常。已人工查看桌面和窄屏截图。
+- node scripts/test-release.mjs 通过:复制真实发布包至中文临时目录,以不同 cwd 和仅含 Windows System32 的 PATH 启动;数据库位于 exe 旁,内嵌网页可访问;第二实例占用端口时失败且不创建数据库。
+- dumpbin /DEPENDENTS 仅列 Windows 系统 DLL,无 Node、SQLite 或 Visual C++ 运行库 DLL 外部依赖。
+
+所有数据验收使用独立临时目录。未向正式数据根目录写入备案。工作区原有 registry/testgit 删除保持不变,未提交或推送。
+
+## 证据目录(本机)
+
+- API 兼容:`C:/Users/20143/AppData/Local/Temp/RID-中文验证-HQJED1/`,含 Node/Rust 导出文件及备份。
+- 浏览器:`C:/Users/20143/AppData/Local/Temp/RID-浏览器验收-NGRiYx/`,含 desktop.png、mobile-dialog.png、Excel 导出和服务日志。
+- 发布运行:`C:/Users/20143/AppData/Local/Temp/RID-便携验收-bPjEL9/`。
+
+## 边界
+
+本次为同一台 Windows 电脑上的验证,没有进行另一台电脑、真实 RID 模块或原版上位机硬件联调,也未做大规模档案压测。SQLite 提交和档案文件生成仍为两个阶段,通过持久化同步状态恢复;已导出副本不会自动撤回。静态 DLL 检查不能替代跨机器验收。正常 Ctrl+C 的处理代码已实现,但未单独验证控制台关闭和断电场景。
+
+SOURCE_MANIFEST.sha256 是原 Node 源码提取时的历史校验清单,不代表改造后源码;当前发布包以 SHA256SUMS.txt 为准。
+
+## 清理结果与限制
+
+未完成的旧 stable 工具链、重复下载分片和旧位置下载文件已清理;用户目录无 .cargo/.rustup,Node.js、Visual Studio 和 Windows SDK 保留。中断安装遗留的 `D:/Rust_Contact/util/rustup/tmp` 临时项仍存在:自动审批审查拒绝递归清理,返回 `blocked by policy`,未提供更具体原因。未绕过该限制;它们不参与程序运行或发布包。
diff --git a/docs/架构与RID联动.md b/docs/架构与RID联动.md
index ee9586d..81b70a7 100644
--- a/docs/架构与RID联动.md
+++ b/docs/架构与RID联动.md
@@ -4,8 +4,8 @@
```mermaid
flowchart LR
- A[用户在本机网页登记] --> B[server.js]
- B --> C[database.js / SQLite]
+ A[用户在本机网页登记] --> B[src/http.rs / Axum]
+ B --> C[src/store.rs / SQLite]
C --> D[档案库 / 离线档案卡和备份]
B --> E[网页二维码]
E --> F[本地版上位机]
diff --git a/previews/ui-options.html b/previews/ui-options.html
new file mode 100644
index 0000000..0eae139
--- /dev/null
+++ b/previews/ui-options.html
@@ -0,0 +1,7 @@
+
FPV-RID 界面方案 · 独立演示FPV-RID · 三种操作布局
独立演示,全部为虚构示例,不连接后端或设备,不保存数据。请选择 A / B / C 或明确组合。
+A · 保留卡片,弹窗编辑
延续现有布局,改动较小。照片和档案并排查看;编辑时打开对话框,适合少量日常备案。
数据已保存,档案备份待同步
□ 选择当前档案DEMO-SN-001
FPV00000001演示机型 · 演示登记人
DEMO-SN-002
FPV00000002第二条示例档案
照片未上传
全选仅当前页 · 共 42 条1 / 3
+B · 档案表格,右侧编辑区
便于快速扫描和比较记录,选中一行后在右侧编辑;照片空间较小,窄屏需要上下排列。
+C · 卡片内直接展开编辑
在档案上下文内编辑,少一次弹窗切换;展开后卡片高度增加,适合逐条整理档案。
DEMO-SN-001 · FPV00000001
编辑机型、登记人与照片
空文本表示清空;编号保持不变
备份待同步共 42 条 · 1 / 3
+
diff --git a/registry/legacy-web/app.css b/registry/legacy-web/app.css
new file mode 100644
index 0000000..1193264
--- /dev/null
+++ b/registry/legacy-web/app.css
@@ -0,0 +1,5 @@
+:root{font-family:Inter,"Segoe UI","Microsoft YaHei",sans-serif;color:#172b40;background:#eef2f6;font-synthesis:none}*{box-sizing:border-box}body{margin:0}button,input{font:inherit}button{cursor:pointer}.shell{max-width:1320px;margin:0 auto;min-height:100vh;background:#f8fafc;box-shadow:0 0 60px #1d3d5912}.topbar{height:76px;background:#fff;border-bottom:1px solid #e4eaf0;display:flex;align-items:center;padding:0 48px;gap:14px}.brand-mark{width:38px;height:38px;background:#144e83;color:white;display:grid;place-items:center;border-radius:10px;font-size:21px;font-weight:900;letter-spacing:-5px;padding-right:6px}.brand-mark span{color:#7fd5f3;font-size:18px;margin-left:-2px}.brand-copy{display:flex;flex-direction:column;line-height:1.15;gap:4px}.brand-copy strong{font-size:17px;letter-spacing:.04em}.brand-copy small{color:#8192a2;font-size:12px}.top-status{margin-left:auto;border:1px solid #cce8d9;background:#f3fbf6;border-radius:999px;color:#187348;font-size:12px;font-weight:700;padding:8px 13px}.top-status i{display:inline-block;width:7px;height:7px;border-radius:50%;background:#2eae6c;margin-right:5px}main{padding:38px 48px 54px}.hero{display:flex;justify-content:space-between;align-items:center;gap:26px;margin-bottom:22px}.eyebrow{color:#4a779b;font-size:11px;font-weight:800;letter-spacing:.2em}.hero h1{font-size:32px;letter-spacing:-.025em;margin:12px 0 10px}.hero p{color:#617488;font-size:14px;line-height:1.7;max-width:720px;margin:0}.hero-aside{display:flex;flex-direction:column;align-items:flex-end;gap:4px;min-width:125px;color:#3a627f;font-size:13px}.hero-aside small{color:#91a0af}.hero-dot{width:40px;height:40px;border-radius:12px;background:linear-gradient(135deg,#dff8ee,#a9e0c7);margin-bottom:2px;position:relative}.hero-dot:after{content:"✓";position:absolute;inset:0;display:grid;place-items:center;color:#13815a;font-size:21px;font-weight:800}.notice{display:flex;align-items:center;gap:14px;background:#fff8e9;border:1px solid #f0ddb0;border-radius:12px;padding:13px 17px;color:#755b28;font-size:13px;margin-bottom:24px}.notice b{white-space:nowrap;color:#7b5314}.columns{display:grid;grid-template-columns:minmax(0,1.03fr) minmax(0,.97fr);gap:22px}.panel{background:#fff;border:1px solid #e2e8ef;border-radius:17px;box-shadow:0 8px 25px #173b5b0a}.form-panel,.result-panel{min-height:570px;padding:26px 28px}.panel-head{display:flex;align-items:center;justify-content:space-between;gap:15px;padding-bottom:24px}.panel-head>div{display:flex;align-items:center;gap:11px}.panel-head h2{font-size:18px;margin:0}.step{width:29px;height:29px;border-radius:8px;background:#dcecf9;color:#1a5d8e;font-weight:800;font-size:12px;display:grid;place-items:center}.step.muted{background:#eef2f6;color:#73879b}.subtle{color:#9aa9b5;font-size:12px}label{font-size:13px;font-weight:700;display:block;margin:0 0 9px}label em{color:#d76254;font-size:11px;font-style:normal;margin-left:6px}label .optional{color:#a2b0bd;font-size:11px;font-weight:500}input{height:45px;width:100%;border:1px solid #d6e0e9;border-radius:9px;background:#fbfcfe;padding:0 13px;color:#1f3448;outline:none;transition:border-color .15s,box-shadow .15s}input:focus{border-color:#3a91cd;box-shadow:0 0 0 3px #3a91cd20}input::placeholder{color:#a7b3be}.hint{margin:7px 0 24px;color:#93a0ae;font-size:11px;line-height:1.5}.field-grid{display:grid;grid-template-columns:1fr 1fr;gap:15px}.field-grid+label{margin-top:3px}.input-prefix{height:45px;display:flex;border:1px solid #d6e0e9;border-radius:9px;overflow:hidden;background:#fbfcfe}.input-prefix span{display:grid;place-items:center;width:58px;background:#edf4f9;color:#2e6d9c;font-weight:800;font-size:13px;border-right:1px solid #d6e0e9}.input-prefix input{border:0;border-radius:0;background:transparent;height:43px}.input-prefix:focus-within{border-color:#3a91cd;box-shadow:0 0 0 3px #3a91cd20}.primary{height:47px;width:100%;border:0;border-radius:9px;background:#206d9f;color:#fff;font-weight:750;display:flex;align-items:center;justify-content:center;gap:12px;box-shadow:0 8px 16px #206d9f26}.primary:hover{background:#155d8d}.primary:disabled{opacity:.55;cursor:wait}.form-message{min-height:18px;margin:12px 0 0;font-size:12px;color:#23724b}.form-message.error{color:#bd4c3b}.empty-state{height:415px;border:1px dashed #d6e1eb;border-radius:12px;background:#fbfcfe;display:flex;align-items:center;justify-content:center;flex-direction:column;color:#9aaab8;gap:9px;text-align:center;padding:20px}.empty-state b{font-size:15px;color:#526b7f}.empty-state span{font-size:12px;max-width:230px;line-height:1.6}.empty-glyph{height:64px;width:64px;border-radius:17px;background:#ecf3f8;color:#93afc2;display:grid;place-items:center;font-size:38px;margin-bottom:6px}.record-result{display:flex;align-items:center;flex-direction:column}.record-result[hidden],.empty-state[hidden],#history-table[hidden],#history-empty[hidden]{display:none}.qr-stage{width:200px;height:200px;display:grid;place-items:center;background:white;border:1px solid #e5ecf2;border-radius:12px;padding:9px;box-shadow:0 8px 22px #183a5a10}.qr-stage svg{max-width:100%;max-height:100%}.record-kicker{font-size:11px;color:#26915f;font-weight:800;margin-top:16px;letter-spacing:.05em}.uas-display{font-size:27px;font-weight:850;letter-spacing:.04em;margin:3px 0 17px;color:#174d78}.result-fields{width:100%;margin:0;border-top:1px solid #edf1f5;border-bottom:1px solid #edf1f5}.result-fields div{display:flex;justify-content:space-between;gap:10px;padding:8px 0;font-size:12px}.result-fields dt{color:#8a9bae}.result-fields dd{margin:0;font-weight:700;text-align:right;overflow-wrap:anywhere}.url-box{align-self:stretch;background:#f4f7fa;border-radius:8px;margin-top:16px;padding:10px 12px;font-size:11px}.url-box span{display:block;color:#92a2b0;margin-bottom:3px}.url-box code{overflow-wrap:anywhere;color:#366987}.result-actions{display:flex;width:100%;gap:10px;margin-top:15px}.secondary,.ghost{height:39px;border-radius:8px;font-size:12px;font-weight:700}.secondary{flex:1;background:#e9f3fa;color:#1a6b9b;border:1px solid #cce2f1}.ghost{flex:1;background:#fff;color:#52718a;border:1px solid #d9e3eb}.result-tip{font-size:11px;color:#95a5b2;line-height:1.55;align-self:stretch;margin:12px 0 0}.history-panel{margin-top:22px;padding:24px 28px}.history-panel .panel-head{padding-bottom:14px}.text-button{border:0;background:none;color:#2879ab;font-size:12px;font-weight:700}.history-empty{color:#9eacb7;font-size:13px;padding:25px 0}.table-scroll{overflow-x:auto}table{width:100%;border-collapse:collapse;text-align:left;font-size:12px}th{background:#f5f8fb;color:#7a8c9d;font-weight:700;padding:11px 13px}td{padding:13px;border-bottom:1px solid #edf1f4;color:#334b60}td code{color:#286e9c;font-weight:700}.show-record{border:0;color:#2677a8;background:none;font-size:12px;font-weight:700}footer{border-top:1px solid #e8edf2;padding:17px 48px 22px;color:#a0acb8;font-size:11px;display:flex;justify-content:space-between}@media(max-width:850px){.topbar{padding:0 22px}main{padding:28px 20px}.columns{grid-template-columns:1fr}.form-panel,.result-panel{min-height:auto}.hero-aside{display:none}footer{padding:18px 22px}}@media(max-width:530px){.hero h1{font-size:25px}.field-grid{grid-template-columns:1fr}.notice{align-items:flex-start;flex-direction:column;gap:5px}.panel-head{align-items:flex-start}.subtle{display:none}.result-actions{flex-direction:column}footer{gap:5px;flex-direction:column}}
+.photo-fields{margin-top:4px}.photo-fields input[type=file]{padding:10px;height:auto;min-height:45px;font-size:11px}.photo-fields+.hint{margin-bottom:22px}.saved-photos{align-self:stretch;display:flex;gap:10px;margin-top:12px}.saved-photos[hidden],.saved-photos a[hidden]{display:none}.saved-photos a{width:50%;border:1px solid #e5ecf2;border-radius:8px;overflow:hidden;text-align:center;color:#4a708c;text-decoration:none;font-size:11px;padding:5px}.saved-photos img{width:100%;height:90px;object-fit:contain;background:#f5f8fb;display:block}.saved-photos span{display:block;margin-top:4px}
+.action-link{display:grid;place-items:center;text-decoration:none}.history-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:14px}.archive-card{border:1px solid #dfe8f0;border-radius:12px;padding:16px;background:#fbfdff}.archive-card h3{font-size:15px;margin:0 0 5px;overflow-wrap:anywhere}.archive-card strong{color:#236d9b;font-size:13px}.archive-card p{color:#8193a3;font-size:11px;line-height:1.5;margin:9px 0 12px}.archive-thumbs{display:grid;grid-template-columns:1fr 1fr;gap:8px}.archive-thumbs>div{height:105px;border:1px solid #e2e9ef;border-radius:7px;background:#f3f7fa;display:grid;place-items:center;color:#a4b1bc;font-size:11px;overflow:hidden}.archive-thumbs img{height:100%;width:100%;object-fit:contain}.archive-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:13px}.archive-actions a,.archive-actions button{background:#eaf3f9;color:#236f9d;border:1px solid #d0e2ef;border-radius:7px;padding:7px 9px;font-size:11px;font-weight:700;text-decoration:none;cursor:pointer}
+.topbar .brand-mark{width:42px;height:42px;object-fit:contain;border-radius:10px;padding:0;letter-spacing:normal;background:#fff}.hero h1{margin-top:0}.history-head{align-items:center}.history-controls{display:flex;align-items:center;justify-content:flex-end;flex-wrap:wrap;gap:10px}.select-all{display:inline-flex;align-items:center;gap:5px;margin:0;color:#49657a;white-space:nowrap;font-size:12px}.select-all input,.archive-select input{width:16px;height:16px;accent-color:#206d9f;cursor:pointer}.export-button{height:34px;padding:0 11px;border:1px solid #c8ddeb;border-radius:7px;background:#e9f3fa;color:#1d6c9c;font-size:12px;font-weight:700}.export-button:disabled{opacity:.48;cursor:not-allowed}.history-message{font-size:11px;line-height:1.55;color:#8a9dad;margin:0 0 14px}.history-message.error{color:#b84036}.archive-card{position:relative}.archive-card.selected{border-color:#4b9bc8;box-shadow:0 0 0 2px #4b9bc820}.archive-select{display:flex;align-items:center;gap:5px;float:right;margin:0 0 8px 10px;color:#59788f;font-size:11px;font-weight:600}.archive-actions .delete-record{background:#fff1ef;color:#b34039;border-color:#f2c9c5}.archive-actions .delete-record:hover{background:#ffe7e3}footer{justify-content:flex-end}@media(max-width:850px){.history-head{align-items:flex-start;flex-direction:column}.history-controls{justify-content:flex-start}}@media(max-width:530px){.history-controls{gap:8px}.export-button{flex:1}}
+.history-search{position:relative;width:260px;flex:0 1 260px}.history-search input{height:36px;padding:0 66px 0 12px;font-size:12px;background:#fff}.history-search input::placeholder{color:#8fa1af}.history-search #search-count{position:absolute;right:10px;top:50%;transform:translateY(-50%);color:#6b8294;font-size:11px;white-space:nowrap;pointer-events:none}.history-search #search-count:empty{display:none}@media(max-width:850px){.history-controls{width:100%}.history-search{flex:1 1 260px}}@media(max-width:530px){.history-search{flex-basis:100%;width:100%}}
diff --git a/registry/legacy-web/app.js b/registry/legacy-web/app.js
new file mode 100644
index 0000000..e581ded
--- /dev/null
+++ b/registry/legacy-web/app.js
@@ -0,0 +1,274 @@
+const $ = id => document.getElementById(id);
+let activeRecord = null;
+let listedRecords = [];
+const selectedIds = new Set();
+let listRequestId = 0;
+let searchTimer;
+
+function setMessage(message, error = false) {
+ $('form-message').textContent = message;
+ $('form-message').classList.toggle('error', error);
+}
+
+function setHistoryMessage(message, error = false) {
+ $('history-message').textContent = message;
+ $('history-message').classList.toggle('error', error);
+}
+
+function updateSelectionControls() {
+ const count = selectedIds.size;
+ $('selected-count').textContent = `(${count})`;
+ $('select-all').checked = listedRecords.length > 0 && count === listedRecords.length;
+ $('select-all').indeterminate = count > 0 && count < listedRecords.length;
+ $('export-archive').disabled = count === 0;
+ $('export-excel').disabled = count === 0;
+}
+
+function formatTime(iso) {
+ try { return new Date(iso).toLocaleString('zh-CN', { hour12: false }); }
+ catch { return iso; }
+}
+
+async function readPhoto(input, slot) {
+ const file = input.files?.[0];
+ if (!file) return null;
+ if (!['image/jpeg', 'image/png', 'image/webp'].includes(file.type)) throw new Error(`照片 ${slot} 仅支持 JPG、PNG 或 WebP`);
+ if (file.size > 5 * 1024 * 1024) throw new Error(`照片 ${slot} 不能超过 5 MB`);
+ return await new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onload = () => resolve(reader.result);
+ reader.onerror = () => reject(new Error(`照片 ${slot} 读取失败`));
+ reader.readAsDataURL(file);
+ });
+}
+
+function drawRecord(record) {
+ activeRecord = record;
+ $('empty-result').hidden = true;
+ $('record-result').hidden = false;
+ $('display-uas').textContent = record.uasCode;
+ $('display-sn').textContent = record.serialNo;
+ $('display-model').textContent = record.modelName || '—';
+ $('display-owner').textContent = record.ownerName || '—';
+ $('display-url').textContent = record.qrUrl;
+ $('open-card').href = record.archiveUrl;
+ $('download-card').href = record.downloadArchiveUrl;
+ $('saved-photos').hidden = !record.photo1Url && !record.photo2Url;
+ for (const [slot, url] of [[1, record.photo1Url], [2, record.photo2Url]]) {
+ const link = $(`photo-${slot}-link`);
+ link.hidden = !url;
+ if (url) {
+ link.href = url;
+ $(`photo-${slot}-preview`).src = `${url}?v=${Date.now()}`;
+ }
+ }
+ const qr = qrcode(0, 'M');
+ qr.addData(record.qrUrl);
+ qr.make();
+ $('qr-stage').innerHTML = qr.createSvgTag({ cellSize: 6, margin: 4 });
+}
+
+async function loadRecords() {
+ const requestId = ++listRequestId;
+ const query = $('history-query').value.trim();
+ const response = await fetch(`/api/records?q=${encodeURIComponent(query)}`);
+ const payload = await response.json();
+ if (!response.ok) throw new Error(payload.error || '读取记录失败');
+ if (requestId !== listRequestId) return;
+ const body = $('history-cards');
+ body.replaceChildren();
+ listedRecords = payload.records;
+ $('search-count').textContent = query ? `${listedRecords.length} 条` : '';
+ const currentIds = new Set(listedRecords.map(record => record.id));
+ for (const id of selectedIds) if (!currentIds.has(id)) selectedIds.delete(id);
+ $('history-empty').hidden = listedRecords.length > 0;
+ $('history-empty').textContent = query ? '没有找到匹配的档案。' : '暂无登记记录。';
+ for (const record of listedRecords) {
+ const card = document.createElement('article');
+ card.className = 'archive-card';
+ card.classList.toggle('selected', selectedIds.has(record.id));
+ const select = document.createElement('label');
+ select.className = 'archive-select';
+ const checkbox = document.createElement('input');
+ checkbox.type = 'checkbox';
+ checkbox.checked = selectedIds.has(record.id);
+ checkbox.setAttribute('aria-label', `选择档案 ${record.serialNo}`);
+ checkbox.addEventListener('change', () => {
+ if (checkbox.checked) selectedIds.add(record.id); else selectedIds.delete(record.id);
+ card.classList.toggle('selected', checkbox.checked);
+ updateSelectionControls();
+ });
+ select.append(checkbox, document.createTextNode('导出'));
+ const title = document.createElement('h3');
+ title.textContent = record.serialNo;
+ const code = document.createElement('strong');
+ code.textContent = record.uasCode;
+ const detail = document.createElement('p');
+ detail.textContent = `${record.modelName || '未填机型'} · ${record.ownerName || '未填登记人'} · ${formatTime(record.createdAt)}`;
+ const images = document.createElement('div');
+ images.className = 'archive-thumbs';
+ for (const [slot, url] of [[1, record.photo1Url], [2, record.photo2Url]]) {
+ const thumb = document.createElement('div');
+ if (url) {
+ const image = document.createElement('img');
+ image.src = url;
+ image.alt = `登记照片 ${slot}`;
+ image.loading = 'lazy';
+ thumb.append(image);
+ } else {
+ thumb.textContent = `照片 ${slot} 未上传`;
+ }
+ images.append(thumb);
+ }
+ const actions = document.createElement('div');
+ actions.className = 'archive-actions';
+ const open = document.createElement('a');
+ open.href = record.archiveUrl;
+ open.target = '_blank';
+ open.rel = 'noopener';
+ open.textContent = '打开档案卡';
+ const download = document.createElement('a');
+ download.href = record.downloadArchiveUrl;
+ download.textContent = '下载离线档案卡';
+ const showQr = document.createElement('button');
+ showQr.type = 'button';
+ showQr.textContent = '查看二维码';
+ showQr.addEventListener('click', () => { drawRecord(record); $('result-title').scrollIntoView({ behavior: 'smooth' }); });
+ const remove = document.createElement('button');
+ remove.type = 'button';
+ remove.className = 'delete-record';
+ remove.textContent = '删除档案';
+ remove.addEventListener('click', async () => {
+ if (!confirm(`确定删除 ${record.serialNo} 的登记档案和照片吗?`)) return;
+ remove.disabled = true;
+ try {
+ const response = await fetch(`/api/records/${record.id}`, { method: 'DELETE' });
+ const payload = await response.json();
+ if (!response.ok) throw new Error(payload.error || '删除失败');
+ selectedIds.delete(record.id);
+ if (activeRecord?.id === record.id) {
+ activeRecord = null;
+ $('record-result').hidden = true;
+ $('empty-result').hidden = false;
+ }
+ await loadRecords();
+ setHistoryMessage(`已删除 ${record.serialNo} 的档案。`);
+ } catch (error) { setHistoryMessage(error.message, true); remove.disabled = false; }
+ });
+ actions.append(open, download, showQr, remove);
+ card.append(select, title, code, detail, images, actions);
+ body.append(card);
+ }
+ updateSelectionControls();
+}
+
+$('register-form').addEventListener('submit', async event => {
+ event.preventDefault();
+ const button = $('register-button');
+ button.disabled = true;
+ setMessage('正在保存本地记录…');
+ const uasDigits = $('uas-code').value.trim();
+ try {
+ const [photo1, photo2] = await Promise.all([
+ readPhoto($('photo-1'), 1),
+ readPhoto($('photo-2'), 2),
+ ]);
+ const response = await fetch('/api/records', {
+ method: 'POST', headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({
+ serialNo: $('serial-no').value.trim(),
+ modelName: $('model-name').value.trim(),
+ ownerName: $('owner-name').value.trim(),
+ uasCode: uasDigits ? `FPV${uasDigits}` : '',
+ photo1, photo2,
+ }),
+ });
+ const payload = await response.json();
+ if (!response.ok) throw new Error(payload.error || '保存失败');
+ drawRecord(payload.record);
+ setMessage(payload.existing ? '该 SN 已登记,照片和填写的信息已保存。' : '登记成功,二维码已生成。');
+ await loadRecords();
+ } catch (error) { setMessage(error.message, true); }
+ finally { button.disabled = false; }
+});
+
+$('refresh-list').addEventListener('click', () => loadRecords().catch(error => setMessage(error.message, true)));
+$('history-query').addEventListener('input', () => {
+ clearTimeout(searchTimer);
+ listRequestId++;
+ selectedIds.clear();
+ document.querySelectorAll('.archive-card').forEach(card => {
+ card.classList.remove('selected');
+ card.querySelector('.archive-select input').checked = false;
+ });
+ updateSelectionControls();
+ searchTimer = setTimeout(() => loadRecords().catch(error => setHistoryMessage(error.message, true)), 180);
+});
+$('select-all').addEventListener('change', event => {
+ selectedIds.clear();
+ if (event.target.checked) for (const record of listedRecords) selectedIds.add(record.id);
+ document.querySelectorAll('.archive-card').forEach((card, index) => {
+ const checked = selectedIds.has(listedRecords[index].id);
+ card.querySelector('.archive-select input').checked = checked;
+ card.classList.toggle('selected', checked);
+ });
+ updateSelectionControls();
+});
+
+async function exportSelected(kind) {
+ const ids = [...selectedIds];
+ if (!ids.length) return;
+ const button = $(kind === 'archive' ? 'export-archive' : 'export-excel');
+ button.disabled = true;
+ setHistoryMessage(`正在导出 ${ids.length} 条档案…`);
+ try {
+ const response = await fetch(`/api/export/${kind}`, {
+ method: 'POST', headers: { 'content-type': 'application/json' },
+ body: JSON.stringify({ ids }),
+ });
+ if (!response.ok) {
+ const payload = await response.json();
+ throw new Error(payload.error || '导出失败');
+ }
+ const link = document.createElement('a');
+ const url = URL.createObjectURL(await response.blob());
+ link.href = url;
+ link.download = kind === 'archive' ? 'FPV-RID-档案库.zip' : 'FPV-RID-登记记录.xlsx';
+ document.body.append(link);
+ link.click();
+ link.remove();
+ setTimeout(() => URL.revokeObjectURL(url), 30000);
+ setHistoryMessage(`已导出 ${ids.length} 条档案。`);
+ } catch (error) { setHistoryMessage(error.message, true); }
+ finally { updateSelectionControls(); }
+}
+$('export-archive').addEventListener('click', () => exportSelected('archive'));
+$('export-excel').addEventListener('click', () => exportSelected('excel'));
+$('copy-url').addEventListener('click', async () => {
+ if (!activeRecord) return;
+ try { await navigator.clipboard.writeText(activeRecord.qrUrl); setMessage('本地二维码链接已复制。'); }
+ catch { setMessage('复制失败,可从“二维码内容”手动复制。', true); }
+});
+$('download-qr').addEventListener('click', async () => {
+ if (!activeRecord) return;
+ const svg = $('qr-stage').querySelector('svg');
+ if (!svg) return;
+ const blob = new Blob([new XMLSerializer().serializeToString(svg)], { type: 'image/svg+xml' });
+ const url = URL.createObjectURL(blob);
+ try {
+ const image = new Image();
+ await new Promise((resolve, reject) => { image.onload = resolve; image.onerror = reject; image.src = url; });
+ const canvas = document.createElement('canvas');
+ canvas.width = 640; canvas.height = 640;
+ const context = canvas.getContext('2d');
+ context.fillStyle = '#fff'; context.fillRect(0, 0, 640, 640);
+ context.drawImage(image, 0, 0, 640, 640);
+ const link = document.createElement('a');
+ link.href = canvas.toDataURL('image/png');
+ link.download = `${activeRecord.serialNo}-${activeRecord.uasCode}-LOCAL.png`;
+ link.click();
+ } catch { setMessage('二维码图片下载失败。', true); }
+ finally { URL.revokeObjectURL(url); }
+});
+
+loadRecords().catch(error => setMessage(error.message, true));
diff --git a/registry/legacy-web/fpv-rid-icon.png b/registry/legacy-web/fpv-rid-icon.png
new file mode 100644
index 0000000..7309c5d
Binary files /dev/null and b/registry/legacy-web/fpv-rid-icon.png differ
diff --git a/registry/legacy-web/index.html b/registry/legacy-web/index.html
new file mode 100644
index 0000000..8db40e5
--- /dev/null
+++ b/registry/legacy-web/index.html
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+ FPV-RID · 本地登记与核验
+
+
+
+
+
+
+
+
+
+ FPV-RID本地登记工作台
+ 仅在本机运行
+
+
+
+
+
+
登记设备,生成本地二维码
+
为模块 SN 建立本机记录。二维码交给配套的本地版上位机扫描,校验 SN 后再由上位机完成设备操作。
+
+
+
+
+
+
+
+
+ ▦
等待登记保存后在这里生成二维码,供本地版上位机读取。
+
+
+
本地记录已保存
+
+
- Serial No.
- 机型
- 登记人
+
+
二维码内容
+
+
+
在本机同时启动登记站和本地版上位机,上传此二维码。上位机会从本地记录读取字段并比对模块 SN。
+
+
+
+
+
+
+ 导出档案包包含离线档案卡、照片和登记信息;Excel 导出为登记表。
+ 暂无登记记录。
+
+
+
+
+
+
+
+
diff --git a/registry/legacy-web/vendor/LICENSE.txt b/registry/legacy-web/vendor/LICENSE.txt
new file mode 100644
index 0000000..150770c
--- /dev/null
+++ b/registry/legacy-web/vendor/LICENSE.txt
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2009 Kazuhiko Arase
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/registry/legacy-web/vendor/qrcode.js b/registry/legacy-web/vendor/qrcode.js
new file mode 100644
index 0000000..df13f82
--- /dev/null
+++ b/registry/legacy-web/vendor/qrcode.js
@@ -0,0 +1,2297 @@
+//---------------------------------------------------------------------
+//
+// QR Code Generator for JavaScript
+//
+// Copyright (c) 2009 Kazuhiko Arase
+//
+// URL: http://www.d-project.com/
+//
+// Licensed under the MIT license:
+// http://www.opensource.org/licenses/mit-license.php
+//
+// The word 'QR Code' is registered trademark of
+// DENSO WAVE INCORPORATED
+// http://www.denso-wave.com/qrcode/faqpatent-e.html
+//
+//---------------------------------------------------------------------
+
+var qrcode = function() {
+
+ //---------------------------------------------------------------------
+ // qrcode
+ //---------------------------------------------------------------------
+
+ /**
+ * qrcode
+ * @param typeNumber 1 to 40
+ * @param errorCorrectionLevel 'L','M','Q','H'
+ */
+ var qrcode = function(typeNumber, errorCorrectionLevel) {
+
+ var PAD0 = 0xEC;
+ var PAD1 = 0x11;
+
+ var _typeNumber = typeNumber;
+ var _errorCorrectionLevel = QRErrorCorrectionLevel[errorCorrectionLevel];
+ var _modules = null;
+ var _moduleCount = 0;
+ var _dataCache = null;
+ var _dataList = [];
+
+ var _this = {};
+
+ var makeImpl = function(test, maskPattern) {
+
+ _moduleCount = _typeNumber * 4 + 17;
+ _modules = function(moduleCount) {
+ var modules = new Array(moduleCount);
+ for (var row = 0; row < moduleCount; row += 1) {
+ modules[row] = new Array(moduleCount);
+ for (var col = 0; col < moduleCount; col += 1) {
+ modules[row][col] = null;
+ }
+ }
+ return modules;
+ }(_moduleCount);
+
+ setupPositionProbePattern(0, 0);
+ setupPositionProbePattern(_moduleCount - 7, 0);
+ setupPositionProbePattern(0, _moduleCount - 7);
+ setupPositionAdjustPattern();
+ setupTimingPattern();
+ setupTypeInfo(test, maskPattern);
+
+ if (_typeNumber >= 7) {
+ setupTypeNumber(test);
+ }
+
+ if (_dataCache == null) {
+ _dataCache = createData(_typeNumber, _errorCorrectionLevel, _dataList);
+ }
+
+ mapData(_dataCache, maskPattern);
+ };
+
+ var setupPositionProbePattern = function(row, col) {
+
+ for (var r = -1; r <= 7; r += 1) {
+
+ if (row + r <= -1 || _moduleCount <= row + r) continue;
+
+ for (var c = -1; c <= 7; c += 1) {
+
+ if (col + c <= -1 || _moduleCount <= col + c) continue;
+
+ if ( (0 <= r && r <= 6 && (c == 0 || c == 6) )
+ || (0 <= c && c <= 6 && (r == 0 || r == 6) )
+ || (2 <= r && r <= 4 && 2 <= c && c <= 4) ) {
+ _modules[row + r][col + c] = true;
+ } else {
+ _modules[row + r][col + c] = false;
+ }
+ }
+ }
+ };
+
+ var getBestMaskPattern = function() {
+
+ var minLostPoint = 0;
+ var pattern = 0;
+
+ for (var i = 0; i < 8; i += 1) {
+
+ makeImpl(true, i);
+
+ var lostPoint = QRUtil.getLostPoint(_this);
+
+ if (i == 0 || minLostPoint > lostPoint) {
+ minLostPoint = lostPoint;
+ pattern = i;
+ }
+ }
+
+ return pattern;
+ };
+
+ var setupTimingPattern = function() {
+
+ for (var r = 8; r < _moduleCount - 8; r += 1) {
+ if (_modules[r][6] != null) {
+ continue;
+ }
+ _modules[r][6] = (r % 2 == 0);
+ }
+
+ for (var c = 8; c < _moduleCount - 8; c += 1) {
+ if (_modules[6][c] != null) {
+ continue;
+ }
+ _modules[6][c] = (c % 2 == 0);
+ }
+ };
+
+ var setupPositionAdjustPattern = function() {
+
+ var pos = QRUtil.getPatternPosition(_typeNumber);
+
+ for (var i = 0; i < pos.length; i += 1) {
+
+ for (var j = 0; j < pos.length; j += 1) {
+
+ var row = pos[i];
+ var col = pos[j];
+
+ if (_modules[row][col] != null) {
+ continue;
+ }
+
+ for (var r = -2; r <= 2; r += 1) {
+
+ for (var c = -2; c <= 2; c += 1) {
+
+ if (r == -2 || r == 2 || c == -2 || c == 2
+ || (r == 0 && c == 0) ) {
+ _modules[row + r][col + c] = true;
+ } else {
+ _modules[row + r][col + c] = false;
+ }
+ }
+ }
+ }
+ }
+ };
+
+ var setupTypeNumber = function(test) {
+
+ var bits = QRUtil.getBCHTypeNumber(_typeNumber);
+
+ for (var i = 0; i < 18; i += 1) {
+ var mod = (!test && ( (bits >> i) & 1) == 1);
+ _modules[Math.floor(i / 3)][i % 3 + _moduleCount - 8 - 3] = mod;
+ }
+
+ for (var i = 0; i < 18; i += 1) {
+ var mod = (!test && ( (bits >> i) & 1) == 1);
+ _modules[i % 3 + _moduleCount - 8 - 3][Math.floor(i / 3)] = mod;
+ }
+ };
+
+ var setupTypeInfo = function(test, maskPattern) {
+
+ var data = (_errorCorrectionLevel << 3) | maskPattern;
+ var bits = QRUtil.getBCHTypeInfo(data);
+
+ // vertical
+ for (var i = 0; i < 15; i += 1) {
+
+ var mod = (!test && ( (bits >> i) & 1) == 1);
+
+ if (i < 6) {
+ _modules[i][8] = mod;
+ } else if (i < 8) {
+ _modules[i + 1][8] = mod;
+ } else {
+ _modules[_moduleCount - 15 + i][8] = mod;
+ }
+ }
+
+ // horizontal
+ for (var i = 0; i < 15; i += 1) {
+
+ var mod = (!test && ( (bits >> i) & 1) == 1);
+
+ if (i < 8) {
+ _modules[8][_moduleCount - i - 1] = mod;
+ } else if (i < 9) {
+ _modules[8][15 - i - 1 + 1] = mod;
+ } else {
+ _modules[8][15 - i - 1] = mod;
+ }
+ }
+
+ // fixed module
+ _modules[_moduleCount - 8][8] = (!test);
+ };
+
+ var mapData = function(data, maskPattern) {
+
+ var inc = -1;
+ var row = _moduleCount - 1;
+ var bitIndex = 7;
+ var byteIndex = 0;
+ var maskFunc = QRUtil.getMaskFunction(maskPattern);
+
+ for (var col = _moduleCount - 1; col > 0; col -= 2) {
+
+ if (col == 6) col -= 1;
+
+ while (true) {
+
+ for (var c = 0; c < 2; c += 1) {
+
+ if (_modules[row][col - c] == null) {
+
+ var dark = false;
+
+ if (byteIndex < data.length) {
+ dark = ( ( (data[byteIndex] >>> bitIndex) & 1) == 1);
+ }
+
+ var mask = maskFunc(row, col - c);
+
+ if (mask) {
+ dark = !dark;
+ }
+
+ _modules[row][col - c] = dark;
+ bitIndex -= 1;
+
+ if (bitIndex == -1) {
+ byteIndex += 1;
+ bitIndex = 7;
+ }
+ }
+ }
+
+ row += inc;
+
+ if (row < 0 || _moduleCount <= row) {
+ row -= inc;
+ inc = -inc;
+ break;
+ }
+ }
+ }
+ };
+
+ var createBytes = function(buffer, rsBlocks) {
+
+ var offset = 0;
+
+ var maxDcCount = 0;
+ var maxEcCount = 0;
+
+ var dcdata = new Array(rsBlocks.length);
+ var ecdata = new Array(rsBlocks.length);
+
+ for (var r = 0; r < rsBlocks.length; r += 1) {
+
+ var dcCount = rsBlocks[r].dataCount;
+ var ecCount = rsBlocks[r].totalCount - dcCount;
+
+ maxDcCount = Math.max(maxDcCount, dcCount);
+ maxEcCount = Math.max(maxEcCount, ecCount);
+
+ dcdata[r] = new Array(dcCount);
+
+ for (var i = 0; i < dcdata[r].length; i += 1) {
+ dcdata[r][i] = 0xff & buffer.getBuffer()[i + offset];
+ }
+ offset += dcCount;
+
+ var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
+ var rawPoly = qrPolynomial(dcdata[r], rsPoly.getLength() - 1);
+
+ var modPoly = rawPoly.mod(rsPoly);
+ ecdata[r] = new Array(rsPoly.getLength() - 1);
+ for (var i = 0; i < ecdata[r].length; i += 1) {
+ var modIndex = i + modPoly.getLength() - ecdata[r].length;
+ ecdata[r][i] = (modIndex >= 0)? modPoly.getAt(modIndex) : 0;
+ }
+ }
+
+ var totalCodeCount = 0;
+ for (var i = 0; i < rsBlocks.length; i += 1) {
+ totalCodeCount += rsBlocks[i].totalCount;
+ }
+
+ var data = new Array(totalCodeCount);
+ var index = 0;
+
+ for (var i = 0; i < maxDcCount; i += 1) {
+ for (var r = 0; r < rsBlocks.length; r += 1) {
+ if (i < dcdata[r].length) {
+ data[index] = dcdata[r][i];
+ index += 1;
+ }
+ }
+ }
+
+ for (var i = 0; i < maxEcCount; i += 1) {
+ for (var r = 0; r < rsBlocks.length; r += 1) {
+ if (i < ecdata[r].length) {
+ data[index] = ecdata[r][i];
+ index += 1;
+ }
+ }
+ }
+
+ return data;
+ };
+
+ var createData = function(typeNumber, errorCorrectionLevel, dataList) {
+
+ var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectionLevel);
+
+ var buffer = qrBitBuffer();
+
+ for (var i = 0; i < dataList.length; i += 1) {
+ var data = dataList[i];
+ buffer.put(data.getMode(), 4);
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber) );
+ data.write(buffer);
+ }
+
+ // calc num max data.
+ var totalDataCount = 0;
+ for (var i = 0; i < rsBlocks.length; i += 1) {
+ totalDataCount += rsBlocks[i].dataCount;
+ }
+
+ if (buffer.getLengthInBits() > totalDataCount * 8) {
+ throw 'code length overflow. ('
+ + buffer.getLengthInBits()
+ + '>'
+ + totalDataCount * 8
+ + ')';
+ }
+
+ // end code
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
+ buffer.put(0, 4);
+ }
+
+ // padding
+ while (buffer.getLengthInBits() % 8 != 0) {
+ buffer.putBit(false);
+ }
+
+ // padding
+ while (true) {
+
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
+ break;
+ }
+ buffer.put(PAD0, 8);
+
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
+ break;
+ }
+ buffer.put(PAD1, 8);
+ }
+
+ return createBytes(buffer, rsBlocks);
+ };
+
+ _this.addData = function(data, mode) {
+
+ mode = mode || 'Byte';
+
+ var newData = null;
+
+ switch(mode) {
+ case 'Numeric' :
+ newData = qrNumber(data);
+ break;
+ case 'Alphanumeric' :
+ newData = qrAlphaNum(data);
+ break;
+ case 'Byte' :
+ newData = qr8BitByte(data);
+ break;
+ case 'Kanji' :
+ newData = qrKanji(data);
+ break;
+ default :
+ throw 'mode:' + mode;
+ }
+
+ _dataList.push(newData);
+ _dataCache = null;
+ };
+
+ _this.isDark = function(row, col) {
+ if (row < 0 || _moduleCount <= row || col < 0 || _moduleCount <= col) {
+ throw row + ',' + col;
+ }
+ return _modules[row][col];
+ };
+
+ _this.getModuleCount = function() {
+ return _moduleCount;
+ };
+
+ _this.make = function() {
+ if (_typeNumber < 1) {
+ var typeNumber = 1;
+
+ for (; typeNumber < 40; typeNumber++) {
+ var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, _errorCorrectionLevel);
+ var buffer = qrBitBuffer();
+
+ for (var i = 0; i < _dataList.length; i++) {
+ var data = _dataList[i];
+ buffer.put(data.getMode(), 4);
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.getMode(), typeNumber) );
+ data.write(buffer);
+ }
+
+ var totalDataCount = 0;
+ for (var i = 0; i < rsBlocks.length; i++) {
+ totalDataCount += rsBlocks[i].dataCount;
+ }
+
+ if (buffer.getLengthInBits() <= totalDataCount * 8) {
+ break;
+ }
+ }
+
+ _typeNumber = typeNumber;
+ }
+
+ makeImpl(false, getBestMaskPattern() );
+ };
+
+ _this.createTableTag = function(cellSize, margin) {
+
+ cellSize = cellSize || 2;
+ margin = (typeof margin == 'undefined')? cellSize * 4 : margin;
+
+ var qrHtml = '';
+
+ qrHtml += '';
+ qrHtml += '';
+
+ for (var r = 0; r < _this.getModuleCount(); r += 1) {
+
+ qrHtml += '';
+
+ for (var c = 0; c < _this.getModuleCount(); c += 1) {
+ qrHtml += ' | ';
+ }
+
+ qrHtml += '
';
+ }
+
+ qrHtml += '';
+ qrHtml += '
';
+
+ return qrHtml;
+ };
+
+ _this.createSvgTag = function(cellSize, margin, alt, title) {
+
+ var opts = {};
+ if (typeof arguments[0] == 'object') {
+ // Called by options.
+ opts = arguments[0];
+ // overwrite cellSize and margin.
+ cellSize = opts.cellSize;
+ margin = opts.margin;
+ alt = opts.alt;
+ title = opts.title;
+ }
+
+ cellSize = cellSize || 2;
+ margin = (typeof margin == 'undefined')? cellSize * 4 : margin;
+
+ // Compose alt property surrogate
+ alt = (typeof alt === 'string') ? {text: alt} : alt || {};
+ alt.text = alt.text || null;
+ alt.id = (alt.text) ? alt.id || 'qrcode-description' : null;
+
+ // Compose title property surrogate
+ title = (typeof title === 'string') ? {text: title} : title || {};
+ title.text = title.text || null;
+ title.id = (title.text) ? title.id || 'qrcode-title' : null;
+
+ var size = _this.getModuleCount() * cellSize + margin * 2;
+ var c, mc, r, mr, qrSvg='', rect;
+
+ rect = 'l' + cellSize + ',0 0,' + cellSize +
+ ' -' + cellSize + ',0 0,-' + cellSize + 'z ';
+
+ qrSvg += '';
+
+ return qrSvg;
+ };
+
+ _this.createDataURL = function(cellSize, margin) {
+
+ cellSize = cellSize || 2;
+ margin = (typeof margin == 'undefined')? cellSize * 4 : margin;
+
+ var size = _this.getModuleCount() * cellSize + margin * 2;
+ var min = margin;
+ var max = size - margin;
+
+ return createDataURL(size, size, function(x, y) {
+ if (min <= x && x < max && min <= y && y < max) {
+ var c = Math.floor( (x - min) / cellSize);
+ var r = Math.floor( (y - min) / cellSize);
+ return _this.isDark(r, c)? 0 : 1;
+ } else {
+ return 1;
+ }
+ } );
+ };
+
+ _this.createImgTag = function(cellSize, margin, alt) {
+
+ cellSize = cellSize || 2;
+ margin = (typeof margin == 'undefined')? cellSize * 4 : margin;
+
+ var size = _this.getModuleCount() * cellSize + margin * 2;
+
+ var img = '';
+ img += '
';
+
+ return img;
+ };
+
+ var escapeXml = function(s) {
+ var escaped = '';
+ for (var i = 0; i < s.length; i += 1) {
+ var c = s.charAt(i);
+ switch(c) {
+ case '<': escaped += '<'; break;
+ case '>': escaped += '>'; break;
+ case '&': escaped += '&'; break;
+ case '"': escaped += '"'; break;
+ default : escaped += c; break;
+ }
+ }
+ return escaped;
+ };
+
+ var _createHalfASCII = function(margin) {
+ var cellSize = 1;
+ margin = (typeof margin == 'undefined')? cellSize * 2 : margin;
+
+ var size = _this.getModuleCount() * cellSize + margin * 2;
+ var min = margin;
+ var max = size - margin;
+
+ var y, x, r1, r2, p;
+
+ var blocks = {
+ '██': '█',
+ '█ ': '▀',
+ ' █': '▄',
+ ' ': ' '
+ };
+
+ var blocksLastLineNoMargin = {
+ '██': '▀',
+ '█ ': '▀',
+ ' █': ' ',
+ ' ': ' '
+ };
+
+ var ascii = '';
+ for (y = 0; y < size; y += 2) {
+ r1 = Math.floor((y - min) / cellSize);
+ r2 = Math.floor((y + 1 - min) / cellSize);
+ for (x = 0; x < size; x += 1) {
+ p = '█';
+
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r1, Math.floor((x - min) / cellSize))) {
+ p = ' ';
+ }
+
+ if (min <= x && x < max && min <= y+1 && y+1 < max && _this.isDark(r2, Math.floor((x - min) / cellSize))) {
+ p += ' ';
+ }
+ else {
+ p += '█';
+ }
+
+ // Output 2 characters per pixel, to create full square. 1 character per pixels gives only half width of square.
+ ascii += (margin < 1 && y+1 >= max) ? blocksLastLineNoMargin[p] : blocks[p];
+ }
+
+ ascii += '\n';
+ }
+
+ if (size % 2 && margin > 0) {
+ return ascii.substring(0, ascii.length - size - 1) + Array(size+1).join('▀');
+ }
+
+ return ascii.substring(0, ascii.length-1);
+ };
+
+ _this.createASCII = function(cellSize, margin) {
+ cellSize = cellSize || 1;
+
+ if (cellSize < 2) {
+ return _createHalfASCII(margin);
+ }
+
+ cellSize -= 1;
+ margin = (typeof margin == 'undefined')? cellSize * 2 : margin;
+
+ var size = _this.getModuleCount() * cellSize + margin * 2;
+ var min = margin;
+ var max = size - margin;
+
+ var y, x, r, p;
+
+ var white = Array(cellSize+1).join('██');
+ var black = Array(cellSize+1).join(' ');
+
+ var ascii = '';
+ var line = '';
+ for (y = 0; y < size; y += 1) {
+ r = Math.floor( (y - min) / cellSize);
+ line = '';
+ for (x = 0; x < size; x += 1) {
+ p = 1;
+
+ if (min <= x && x < max && min <= y && y < max && _this.isDark(r, Math.floor((x - min) / cellSize))) {
+ p = 0;
+ }
+
+ // Output 2 characters per pixel, to create full square. 1 character per pixels gives only half width of square.
+ line += p ? white : black;
+ }
+
+ for (r = 0; r < cellSize; r += 1) {
+ ascii += line + '\n';
+ }
+ }
+
+ return ascii.substring(0, ascii.length-1);
+ };
+
+ _this.renderTo2dContext = function(context, cellSize) {
+ cellSize = cellSize || 2;
+ var length = _this.getModuleCount();
+ for (var row = 0; row < length; row++) {
+ for (var col = 0; col < length; col++) {
+ context.fillStyle = _this.isDark(row, col) ? 'black' : 'white';
+ context.fillRect(col * cellSize, row * cellSize, cellSize, cellSize);
+ }
+ }
+ }
+
+ return _this;
+ };
+
+ //---------------------------------------------------------------------
+ // qrcode.stringToBytes
+ //---------------------------------------------------------------------
+
+ qrcode.stringToBytesFuncs = {
+ 'default' : function(s) {
+ var bytes = [];
+ for (var i = 0; i < s.length; i += 1) {
+ var c = s.charCodeAt(i);
+ bytes.push(c & 0xff);
+ }
+ return bytes;
+ }
+ };
+
+ qrcode.stringToBytes = qrcode.stringToBytesFuncs['default'];
+
+ //---------------------------------------------------------------------
+ // qrcode.createStringToBytes
+ //---------------------------------------------------------------------
+
+ /**
+ * @param unicodeData base64 string of byte array.
+ * [16bit Unicode],[16bit Bytes], ...
+ * @param numChars
+ */
+ qrcode.createStringToBytes = function(unicodeData, numChars) {
+
+ // create conversion map.
+
+ var unicodeMap = function() {
+
+ var bin = base64DecodeInputStream(unicodeData);
+ var read = function() {
+ var b = bin.read();
+ if (b == -1) throw 'eof';
+ return b;
+ };
+
+ var count = 0;
+ var unicodeMap = {};
+ while (true) {
+ var b0 = bin.read();
+ if (b0 == -1) break;
+ var b1 = read();
+ var b2 = read();
+ var b3 = read();
+ var k = String.fromCharCode( (b0 << 8) | b1);
+ var v = (b2 << 8) | b3;
+ unicodeMap[k] = v;
+ count += 1;
+ }
+ if (count != numChars) {
+ throw count + ' != ' + numChars;
+ }
+
+ return unicodeMap;
+ }();
+
+ var unknownChar = '?'.charCodeAt(0);
+
+ return function(s) {
+ var bytes = [];
+ for (var i = 0; i < s.length; i += 1) {
+ var c = s.charCodeAt(i);
+ if (c < 128) {
+ bytes.push(c);
+ } else {
+ var b = unicodeMap[s.charAt(i)];
+ if (typeof b == 'number') {
+ if ( (b & 0xff) == b) {
+ // 1byte
+ bytes.push(b);
+ } else {
+ // 2bytes
+ bytes.push(b >>> 8);
+ bytes.push(b & 0xff);
+ }
+ } else {
+ bytes.push(unknownChar);
+ }
+ }
+ }
+ return bytes;
+ };
+ };
+
+ //---------------------------------------------------------------------
+ // QRMode
+ //---------------------------------------------------------------------
+
+ var QRMode = {
+ MODE_NUMBER : 1 << 0,
+ MODE_ALPHA_NUM : 1 << 1,
+ MODE_8BIT_BYTE : 1 << 2,
+ MODE_KANJI : 1 << 3
+ };
+
+ //---------------------------------------------------------------------
+ // QRErrorCorrectionLevel
+ //---------------------------------------------------------------------
+
+ var QRErrorCorrectionLevel = {
+ L : 1,
+ M : 0,
+ Q : 3,
+ H : 2
+ };
+
+ //---------------------------------------------------------------------
+ // QRMaskPattern
+ //---------------------------------------------------------------------
+
+ var QRMaskPattern = {
+ PATTERN000 : 0,
+ PATTERN001 : 1,
+ PATTERN010 : 2,
+ PATTERN011 : 3,
+ PATTERN100 : 4,
+ PATTERN101 : 5,
+ PATTERN110 : 6,
+ PATTERN111 : 7
+ };
+
+ //---------------------------------------------------------------------
+ // QRUtil
+ //---------------------------------------------------------------------
+
+ var QRUtil = function() {
+
+ var PATTERN_POSITION_TABLE = [
+ [],
+ [6, 18],
+ [6, 22],
+ [6, 26],
+ [6, 30],
+ [6, 34],
+ [6, 22, 38],
+ [6, 24, 42],
+ [6, 26, 46],
+ [6, 28, 50],
+ [6, 30, 54],
+ [6, 32, 58],
+ [6, 34, 62],
+ [6, 26, 46, 66],
+ [6, 26, 48, 70],
+ [6, 26, 50, 74],
+ [6, 30, 54, 78],
+ [6, 30, 56, 82],
+ [6, 30, 58, 86],
+ [6, 34, 62, 90],
+ [6, 28, 50, 72, 94],
+ [6, 26, 50, 74, 98],
+ [6, 30, 54, 78, 102],
+ [6, 28, 54, 80, 106],
+ [6, 32, 58, 84, 110],
+ [6, 30, 58, 86, 114],
+ [6, 34, 62, 90, 118],
+ [6, 26, 50, 74, 98, 122],
+ [6, 30, 54, 78, 102, 126],
+ [6, 26, 52, 78, 104, 130],
+ [6, 30, 56, 82, 108, 134],
+ [6, 34, 60, 86, 112, 138],
+ [6, 30, 58, 86, 114, 142],
+ [6, 34, 62, 90, 118, 146],
+ [6, 30, 54, 78, 102, 126, 150],
+ [6, 24, 50, 76, 102, 128, 154],
+ [6, 28, 54, 80, 106, 132, 158],
+ [6, 32, 58, 84, 110, 136, 162],
+ [6, 26, 54, 82, 110, 138, 166],
+ [6, 30, 58, 86, 114, 142, 170]
+ ];
+ var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
+ var G18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0);
+ var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
+
+ var _this = {};
+
+ var getBCHDigit = function(data) {
+ var digit = 0;
+ while (data != 0) {
+ digit += 1;
+ data >>>= 1;
+ }
+ return digit;
+ };
+
+ _this.getBCHTypeInfo = function(data) {
+ var d = data << 10;
+ while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
+ d ^= (G15 << (getBCHDigit(d) - getBCHDigit(G15) ) );
+ }
+ return ( (data << 10) | d) ^ G15_MASK;
+ };
+
+ _this.getBCHTypeNumber = function(data) {
+ var d = data << 12;
+ while (getBCHDigit(d) - getBCHDigit(G18) >= 0) {
+ d ^= (G18 << (getBCHDigit(d) - getBCHDigit(G18) ) );
+ }
+ return (data << 12) | d;
+ };
+
+ _this.getPatternPosition = function(typeNumber) {
+ return PATTERN_POSITION_TABLE[typeNumber - 1];
+ };
+
+ _this.getMaskFunction = function(maskPattern) {
+
+ switch (maskPattern) {
+
+ case QRMaskPattern.PATTERN000 :
+ return function(i, j) { return (i + j) % 2 == 0; };
+ case QRMaskPattern.PATTERN001 :
+ return function(i, j) { return i % 2 == 0; };
+ case QRMaskPattern.PATTERN010 :
+ return function(i, j) { return j % 3 == 0; };
+ case QRMaskPattern.PATTERN011 :
+ return function(i, j) { return (i + j) % 3 == 0; };
+ case QRMaskPattern.PATTERN100 :
+ return function(i, j) { return (Math.floor(i / 2) + Math.floor(j / 3) ) % 2 == 0; };
+ case QRMaskPattern.PATTERN101 :
+ return function(i, j) { return (i * j) % 2 + (i * j) % 3 == 0; };
+ case QRMaskPattern.PATTERN110 :
+ return function(i, j) { return ( (i * j) % 2 + (i * j) % 3) % 2 == 0; };
+ case QRMaskPattern.PATTERN111 :
+ return function(i, j) { return ( (i * j) % 3 + (i + j) % 2) % 2 == 0; };
+
+ default :
+ throw 'bad maskPattern:' + maskPattern;
+ }
+ };
+
+ _this.getErrorCorrectPolynomial = function(errorCorrectLength) {
+ var a = qrPolynomial([1], 0);
+ for (var i = 0; i < errorCorrectLength; i += 1) {
+ a = a.multiply(qrPolynomial([1, QRMath.gexp(i)], 0) );
+ }
+ return a;
+ };
+
+ _this.getLengthInBits = function(mode, type) {
+
+ if (1 <= type && type < 10) {
+
+ // 1 - 9
+
+ switch(mode) {
+ case QRMode.MODE_NUMBER : return 10;
+ case QRMode.MODE_ALPHA_NUM : return 9;
+ case QRMode.MODE_8BIT_BYTE : return 8;
+ case QRMode.MODE_KANJI : return 8;
+ default :
+ throw 'mode:' + mode;
+ }
+
+ } else if (type < 27) {
+
+ // 10 - 26
+
+ switch(mode) {
+ case QRMode.MODE_NUMBER : return 12;
+ case QRMode.MODE_ALPHA_NUM : return 11;
+ case QRMode.MODE_8BIT_BYTE : return 16;
+ case QRMode.MODE_KANJI : return 10;
+ default :
+ throw 'mode:' + mode;
+ }
+
+ } else if (type < 41) {
+
+ // 27 - 40
+
+ switch(mode) {
+ case QRMode.MODE_NUMBER : return 14;
+ case QRMode.MODE_ALPHA_NUM : return 13;
+ case QRMode.MODE_8BIT_BYTE : return 16;
+ case QRMode.MODE_KANJI : return 12;
+ default :
+ throw 'mode:' + mode;
+ }
+
+ } else {
+ throw 'type:' + type;
+ }
+ };
+
+ _this.getLostPoint = function(qrcode) {
+
+ var moduleCount = qrcode.getModuleCount();
+
+ var lostPoint = 0;
+
+ // LEVEL1
+
+ for (var row = 0; row < moduleCount; row += 1) {
+ for (var col = 0; col < moduleCount; col += 1) {
+
+ var sameCount = 0;
+ var dark = qrcode.isDark(row, col);
+
+ for (var r = -1; r <= 1; r += 1) {
+
+ if (row + r < 0 || moduleCount <= row + r) {
+ continue;
+ }
+
+ for (var c = -1; c <= 1; c += 1) {
+
+ if (col + c < 0 || moduleCount <= col + c) {
+ continue;
+ }
+
+ if (r == 0 && c == 0) {
+ continue;
+ }
+
+ if (dark == qrcode.isDark(row + r, col + c) ) {
+ sameCount += 1;
+ }
+ }
+ }
+
+ if (sameCount > 5) {
+ lostPoint += (3 + sameCount - 5);
+ }
+ }
+ };
+
+ // LEVEL2
+
+ for (var row = 0; row < moduleCount - 1; row += 1) {
+ for (var col = 0; col < moduleCount - 1; col += 1) {
+ var count = 0;
+ if (qrcode.isDark(row, col) ) count += 1;
+ if (qrcode.isDark(row + 1, col) ) count += 1;
+ if (qrcode.isDark(row, col + 1) ) count += 1;
+ if (qrcode.isDark(row + 1, col + 1) ) count += 1;
+ if (count == 0 || count == 4) {
+ lostPoint += 3;
+ }
+ }
+ }
+
+ // LEVEL3
+
+ for (var row = 0; row < moduleCount; row += 1) {
+ for (var col = 0; col < moduleCount - 6; col += 1) {
+ if (qrcode.isDark(row, col)
+ && !qrcode.isDark(row, col + 1)
+ && qrcode.isDark(row, col + 2)
+ && qrcode.isDark(row, col + 3)
+ && qrcode.isDark(row, col + 4)
+ && !qrcode.isDark(row, col + 5)
+ && qrcode.isDark(row, col + 6) ) {
+ lostPoint += 40;
+ }
+ }
+ }
+
+ for (var col = 0; col < moduleCount; col += 1) {
+ for (var row = 0; row < moduleCount - 6; row += 1) {
+ if (qrcode.isDark(row, col)
+ && !qrcode.isDark(row + 1, col)
+ && qrcode.isDark(row + 2, col)
+ && qrcode.isDark(row + 3, col)
+ && qrcode.isDark(row + 4, col)
+ && !qrcode.isDark(row + 5, col)
+ && qrcode.isDark(row + 6, col) ) {
+ lostPoint += 40;
+ }
+ }
+ }
+
+ // LEVEL4
+
+ var darkCount = 0;
+
+ for (var col = 0; col < moduleCount; col += 1) {
+ for (var row = 0; row < moduleCount; row += 1) {
+ if (qrcode.isDark(row, col) ) {
+ darkCount += 1;
+ }
+ }
+ }
+
+ var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
+ lostPoint += ratio * 10;
+
+ return lostPoint;
+ };
+
+ return _this;
+ }();
+
+ //---------------------------------------------------------------------
+ // QRMath
+ //---------------------------------------------------------------------
+
+ var QRMath = function() {
+
+ var EXP_TABLE = new Array(256);
+ var LOG_TABLE = new Array(256);
+
+ // initialize tables
+ for (var i = 0; i < 8; i += 1) {
+ EXP_TABLE[i] = 1 << i;
+ }
+ for (var i = 8; i < 256; i += 1) {
+ EXP_TABLE[i] = EXP_TABLE[i - 4]
+ ^ EXP_TABLE[i - 5]
+ ^ EXP_TABLE[i - 6]
+ ^ EXP_TABLE[i - 8];
+ }
+ for (var i = 0; i < 255; i += 1) {
+ LOG_TABLE[EXP_TABLE[i] ] = i;
+ }
+
+ var _this = {};
+
+ _this.glog = function(n) {
+
+ if (n < 1) {
+ throw 'glog(' + n + ')';
+ }
+
+ return LOG_TABLE[n];
+ };
+
+ _this.gexp = function(n) {
+
+ while (n < 0) {
+ n += 255;
+ }
+
+ while (n >= 256) {
+ n -= 255;
+ }
+
+ return EXP_TABLE[n];
+ };
+
+ return _this;
+ }();
+
+ //---------------------------------------------------------------------
+ // qrPolynomial
+ //---------------------------------------------------------------------
+
+ function qrPolynomial(num, shift) {
+
+ if (typeof num.length == 'undefined') {
+ throw num.length + '/' + shift;
+ }
+
+ var _num = function() {
+ var offset = 0;
+ while (offset < num.length && num[offset] == 0) {
+ offset += 1;
+ }
+ var _num = new Array(num.length - offset + shift);
+ for (var i = 0; i < num.length - offset; i += 1) {
+ _num[i] = num[i + offset];
+ }
+ return _num;
+ }();
+
+ var _this = {};
+
+ _this.getAt = function(index) {
+ return _num[index];
+ };
+
+ _this.getLength = function() {
+ return _num.length;
+ };
+
+ _this.multiply = function(e) {
+
+ var num = new Array(_this.getLength() + e.getLength() - 1);
+
+ for (var i = 0; i < _this.getLength(); i += 1) {
+ for (var j = 0; j < e.getLength(); j += 1) {
+ num[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i) ) + QRMath.glog(e.getAt(j) ) );
+ }
+ }
+
+ return qrPolynomial(num, 0);
+ };
+
+ _this.mod = function(e) {
+
+ if (_this.getLength() - e.getLength() < 0) {
+ return _this;
+ }
+
+ var ratio = QRMath.glog(_this.getAt(0) ) - QRMath.glog(e.getAt(0) );
+
+ var num = new Array(_this.getLength() );
+ for (var i = 0; i < _this.getLength(); i += 1) {
+ num[i] = _this.getAt(i);
+ }
+
+ for (var i = 0; i < e.getLength(); i += 1) {
+ num[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i) ) + ratio);
+ }
+
+ // recursive call
+ return qrPolynomial(num, 0).mod(e);
+ };
+
+ return _this;
+ };
+
+ //---------------------------------------------------------------------
+ // QRRSBlock
+ //---------------------------------------------------------------------
+
+ var QRRSBlock = function() {
+
+ var RS_BLOCK_TABLE = [
+
+ // L
+ // M
+ // Q
+ // H
+
+ // 1
+ [1, 26, 19],
+ [1, 26, 16],
+ [1, 26, 13],
+ [1, 26, 9],
+
+ // 2
+ [1, 44, 34],
+ [1, 44, 28],
+ [1, 44, 22],
+ [1, 44, 16],
+
+ // 3
+ [1, 70, 55],
+ [1, 70, 44],
+ [2, 35, 17],
+ [2, 35, 13],
+
+ // 4
+ [1, 100, 80],
+ [2, 50, 32],
+ [2, 50, 24],
+ [4, 25, 9],
+
+ // 5
+ [1, 134, 108],
+ [2, 67, 43],
+ [2, 33, 15, 2, 34, 16],
+ [2, 33, 11, 2, 34, 12],
+
+ // 6
+ [2, 86, 68],
+ [4, 43, 27],
+ [4, 43, 19],
+ [4, 43, 15],
+
+ // 7
+ [2, 98, 78],
+ [4, 49, 31],
+ [2, 32, 14, 4, 33, 15],
+ [4, 39, 13, 1, 40, 14],
+
+ // 8
+ [2, 121, 97],
+ [2, 60, 38, 2, 61, 39],
+ [4, 40, 18, 2, 41, 19],
+ [4, 40, 14, 2, 41, 15],
+
+ // 9
+ [2, 146, 116],
+ [3, 58, 36, 2, 59, 37],
+ [4, 36, 16, 4, 37, 17],
+ [4, 36, 12, 4, 37, 13],
+
+ // 10
+ [2, 86, 68, 2, 87, 69],
+ [4, 69, 43, 1, 70, 44],
+ [6, 43, 19, 2, 44, 20],
+ [6, 43, 15, 2, 44, 16],
+
+ // 11
+ [4, 101, 81],
+ [1, 80, 50, 4, 81, 51],
+ [4, 50, 22, 4, 51, 23],
+ [3, 36, 12, 8, 37, 13],
+
+ // 12
+ [2, 116, 92, 2, 117, 93],
+ [6, 58, 36, 2, 59, 37],
+ [4, 46, 20, 6, 47, 21],
+ [7, 42, 14, 4, 43, 15],
+
+ // 13
+ [4, 133, 107],
+ [8, 59, 37, 1, 60, 38],
+ [8, 44, 20, 4, 45, 21],
+ [12, 33, 11, 4, 34, 12],
+
+ // 14
+ [3, 145, 115, 1, 146, 116],
+ [4, 64, 40, 5, 65, 41],
+ [11, 36, 16, 5, 37, 17],
+ [11, 36, 12, 5, 37, 13],
+
+ // 15
+ [5, 109, 87, 1, 110, 88],
+ [5, 65, 41, 5, 66, 42],
+ [5, 54, 24, 7, 55, 25],
+ [11, 36, 12, 7, 37, 13],
+
+ // 16
+ [5, 122, 98, 1, 123, 99],
+ [7, 73, 45, 3, 74, 46],
+ [15, 43, 19, 2, 44, 20],
+ [3, 45, 15, 13, 46, 16],
+
+ // 17
+ [1, 135, 107, 5, 136, 108],
+ [10, 74, 46, 1, 75, 47],
+ [1, 50, 22, 15, 51, 23],
+ [2, 42, 14, 17, 43, 15],
+
+ // 18
+ [5, 150, 120, 1, 151, 121],
+ [9, 69, 43, 4, 70, 44],
+ [17, 50, 22, 1, 51, 23],
+ [2, 42, 14, 19, 43, 15],
+
+ // 19
+ [3, 141, 113, 4, 142, 114],
+ [3, 70, 44, 11, 71, 45],
+ [17, 47, 21, 4, 48, 22],
+ [9, 39, 13, 16, 40, 14],
+
+ // 20
+ [3, 135, 107, 5, 136, 108],
+ [3, 67, 41, 13, 68, 42],
+ [15, 54, 24, 5, 55, 25],
+ [15, 43, 15, 10, 44, 16],
+
+ // 21
+ [4, 144, 116, 4, 145, 117],
+ [17, 68, 42],
+ [17, 50, 22, 6, 51, 23],
+ [19, 46, 16, 6, 47, 17],
+
+ // 22
+ [2, 139, 111, 7, 140, 112],
+ [17, 74, 46],
+ [7, 54, 24, 16, 55, 25],
+ [34, 37, 13],
+
+ // 23
+ [4, 151, 121, 5, 152, 122],
+ [4, 75, 47, 14, 76, 48],
+ [11, 54, 24, 14, 55, 25],
+ [16, 45, 15, 14, 46, 16],
+
+ // 24
+ [6, 147, 117, 4, 148, 118],
+ [6, 73, 45, 14, 74, 46],
+ [11, 54, 24, 16, 55, 25],
+ [30, 46, 16, 2, 47, 17],
+
+ // 25
+ [8, 132, 106, 4, 133, 107],
+ [8, 75, 47, 13, 76, 48],
+ [7, 54, 24, 22, 55, 25],
+ [22, 45, 15, 13, 46, 16],
+
+ // 26
+ [10, 142, 114, 2, 143, 115],
+ [19, 74, 46, 4, 75, 47],
+ [28, 50, 22, 6, 51, 23],
+ [33, 46, 16, 4, 47, 17],
+
+ // 27
+ [8, 152, 122, 4, 153, 123],
+ [22, 73, 45, 3, 74, 46],
+ [8, 53, 23, 26, 54, 24],
+ [12, 45, 15, 28, 46, 16],
+
+ // 28
+ [3, 147, 117, 10, 148, 118],
+ [3, 73, 45, 23, 74, 46],
+ [4, 54, 24, 31, 55, 25],
+ [11, 45, 15, 31, 46, 16],
+
+ // 29
+ [7, 146, 116, 7, 147, 117],
+ [21, 73, 45, 7, 74, 46],
+ [1, 53, 23, 37, 54, 24],
+ [19, 45, 15, 26, 46, 16],
+
+ // 30
+ [5, 145, 115, 10, 146, 116],
+ [19, 75, 47, 10, 76, 48],
+ [15, 54, 24, 25, 55, 25],
+ [23, 45, 15, 25, 46, 16],
+
+ // 31
+ [13, 145, 115, 3, 146, 116],
+ [2, 74, 46, 29, 75, 47],
+ [42, 54, 24, 1, 55, 25],
+ [23, 45, 15, 28, 46, 16],
+
+ // 32
+ [17, 145, 115],
+ [10, 74, 46, 23, 75, 47],
+ [10, 54, 24, 35, 55, 25],
+ [19, 45, 15, 35, 46, 16],
+
+ // 33
+ [17, 145, 115, 1, 146, 116],
+ [14, 74, 46, 21, 75, 47],
+ [29, 54, 24, 19, 55, 25],
+ [11, 45, 15, 46, 46, 16],
+
+ // 34
+ [13, 145, 115, 6, 146, 116],
+ [14, 74, 46, 23, 75, 47],
+ [44, 54, 24, 7, 55, 25],
+ [59, 46, 16, 1, 47, 17],
+
+ // 35
+ [12, 151, 121, 7, 152, 122],
+ [12, 75, 47, 26, 76, 48],
+ [39, 54, 24, 14, 55, 25],
+ [22, 45, 15, 41, 46, 16],
+
+ // 36
+ [6, 151, 121, 14, 152, 122],
+ [6, 75, 47, 34, 76, 48],
+ [46, 54, 24, 10, 55, 25],
+ [2, 45, 15, 64, 46, 16],
+
+ // 37
+ [17, 152, 122, 4, 153, 123],
+ [29, 74, 46, 14, 75, 47],
+ [49, 54, 24, 10, 55, 25],
+ [24, 45, 15, 46, 46, 16],
+
+ // 38
+ [4, 152, 122, 18, 153, 123],
+ [13, 74, 46, 32, 75, 47],
+ [48, 54, 24, 14, 55, 25],
+ [42, 45, 15, 32, 46, 16],
+
+ // 39
+ [20, 147, 117, 4, 148, 118],
+ [40, 75, 47, 7, 76, 48],
+ [43, 54, 24, 22, 55, 25],
+ [10, 45, 15, 67, 46, 16],
+
+ // 40
+ [19, 148, 118, 6, 149, 119],
+ [18, 75, 47, 31, 76, 48],
+ [34, 54, 24, 34, 55, 25],
+ [20, 45, 15, 61, 46, 16]
+ ];
+
+ var qrRSBlock = function(totalCount, dataCount) {
+ var _this = {};
+ _this.totalCount = totalCount;
+ _this.dataCount = dataCount;
+ return _this;
+ };
+
+ var _this = {};
+
+ var getRsBlockTable = function(typeNumber, errorCorrectionLevel) {
+
+ switch(errorCorrectionLevel) {
+ case QRErrorCorrectionLevel.L :
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
+ case QRErrorCorrectionLevel.M :
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
+ case QRErrorCorrectionLevel.Q :
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
+ case QRErrorCorrectionLevel.H :
+ return RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
+ default :
+ return undefined;
+ }
+ };
+
+ _this.getRSBlocks = function(typeNumber, errorCorrectionLevel) {
+
+ var rsBlock = getRsBlockTable(typeNumber, errorCorrectionLevel);
+
+ if (typeof rsBlock == 'undefined') {
+ throw 'bad rs block @ typeNumber:' + typeNumber +
+ '/errorCorrectionLevel:' + errorCorrectionLevel;
+ }
+
+ var length = rsBlock.length / 3;
+
+ var list = [];
+
+ for (var i = 0; i < length; i += 1) {
+
+ var count = rsBlock[i * 3 + 0];
+ var totalCount = rsBlock[i * 3 + 1];
+ var dataCount = rsBlock[i * 3 + 2];
+
+ for (var j = 0; j < count; j += 1) {
+ list.push(qrRSBlock(totalCount, dataCount) );
+ }
+ }
+
+ return list;
+ };
+
+ return _this;
+ }();
+
+ //---------------------------------------------------------------------
+ // qrBitBuffer
+ //---------------------------------------------------------------------
+
+ var qrBitBuffer = function() {
+
+ var _buffer = [];
+ var _length = 0;
+
+ var _this = {};
+
+ _this.getBuffer = function() {
+ return _buffer;
+ };
+
+ _this.getAt = function(index) {
+ var bufIndex = Math.floor(index / 8);
+ return ( (_buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1;
+ };
+
+ _this.put = function(num, length) {
+ for (var i = 0; i < length; i += 1) {
+ _this.putBit( ( (num >>> (length - i - 1) ) & 1) == 1);
+ }
+ };
+
+ _this.getLengthInBits = function() {
+ return _length;
+ };
+
+ _this.putBit = function(bit) {
+
+ var bufIndex = Math.floor(_length / 8);
+ if (_buffer.length <= bufIndex) {
+ _buffer.push(0);
+ }
+
+ if (bit) {
+ _buffer[bufIndex] |= (0x80 >>> (_length % 8) );
+ }
+
+ _length += 1;
+ };
+
+ return _this;
+ };
+
+ //---------------------------------------------------------------------
+ // qrNumber
+ //---------------------------------------------------------------------
+
+ var qrNumber = function(data) {
+
+ var _mode = QRMode.MODE_NUMBER;
+ var _data = data;
+
+ var _this = {};
+
+ _this.getMode = function() {
+ return _mode;
+ };
+
+ _this.getLength = function(buffer) {
+ return _data.length;
+ };
+
+ _this.write = function(buffer) {
+
+ var data = _data;
+
+ var i = 0;
+
+ while (i + 2 < data.length) {
+ buffer.put(strToNum(data.substring(i, i + 3) ), 10);
+ i += 3;
+ }
+
+ if (i < data.length) {
+ if (data.length - i == 1) {
+ buffer.put(strToNum(data.substring(i, i + 1) ), 4);
+ } else if (data.length - i == 2) {
+ buffer.put(strToNum(data.substring(i, i + 2) ), 7);
+ }
+ }
+ };
+
+ var strToNum = function(s) {
+ var num = 0;
+ for (var i = 0; i < s.length; i += 1) {
+ num = num * 10 + chatToNum(s.charAt(i) );
+ }
+ return num;
+ };
+
+ var chatToNum = function(c) {
+ if ('0' <= c && c <= '9') {
+ return c.charCodeAt(0) - '0'.charCodeAt(0);
+ }
+ throw 'illegal char :' + c;
+ };
+
+ return _this;
+ };
+
+ //---------------------------------------------------------------------
+ // qrAlphaNum
+ //---------------------------------------------------------------------
+
+ var qrAlphaNum = function(data) {
+
+ var _mode = QRMode.MODE_ALPHA_NUM;
+ var _data = data;
+
+ var _this = {};
+
+ _this.getMode = function() {
+ return _mode;
+ };
+
+ _this.getLength = function(buffer) {
+ return _data.length;
+ };
+
+ _this.write = function(buffer) {
+
+ var s = _data;
+
+ var i = 0;
+
+ while (i + 1 < s.length) {
+ buffer.put(
+ getCode(s.charAt(i) ) * 45 +
+ getCode(s.charAt(i + 1) ), 11);
+ i += 2;
+ }
+
+ if (i < s.length) {
+ buffer.put(getCode(s.charAt(i) ), 6);
+ }
+ };
+
+ var getCode = function(c) {
+
+ if ('0' <= c && c <= '9') {
+ return c.charCodeAt(0) - '0'.charCodeAt(0);
+ } else if ('A' <= c && c <= 'Z') {
+ return c.charCodeAt(0) - 'A'.charCodeAt(0) + 10;
+ } else {
+ switch (c) {
+ case ' ' : return 36;
+ case '$' : return 37;
+ case '%' : return 38;
+ case '*' : return 39;
+ case '+' : return 40;
+ case '-' : return 41;
+ case '.' : return 42;
+ case '/' : return 43;
+ case ':' : return 44;
+ default :
+ throw 'illegal char :' + c;
+ }
+ }
+ };
+
+ return _this;
+ };
+
+ //---------------------------------------------------------------------
+ // qr8BitByte
+ //---------------------------------------------------------------------
+
+ var qr8BitByte = function(data) {
+
+ var _mode = QRMode.MODE_8BIT_BYTE;
+ var _data = data;
+ var _bytes = qrcode.stringToBytes(data);
+
+ var _this = {};
+
+ _this.getMode = function() {
+ return _mode;
+ };
+
+ _this.getLength = function(buffer) {
+ return _bytes.length;
+ };
+
+ _this.write = function(buffer) {
+ for (var i = 0; i < _bytes.length; i += 1) {
+ buffer.put(_bytes[i], 8);
+ }
+ };
+
+ return _this;
+ };
+
+ //---------------------------------------------------------------------
+ // qrKanji
+ //---------------------------------------------------------------------
+
+ var qrKanji = function(data) {
+
+ var _mode = QRMode.MODE_KANJI;
+ var _data = data;
+
+ var stringToBytes = qrcode.stringToBytesFuncs['SJIS'];
+ if (!stringToBytes) {
+ throw 'sjis not supported.';
+ }
+ !function(c, code) {
+ // self test for sjis support.
+ var test = stringToBytes(c);
+ if (test.length != 2 || ( (test[0] << 8) | test[1]) != code) {
+ throw 'sjis not supported.';
+ }
+ }('\u53cb', 0x9746);
+
+ var _bytes = stringToBytes(data);
+
+ var _this = {};
+
+ _this.getMode = function() {
+ return _mode;
+ };
+
+ _this.getLength = function(buffer) {
+ return ~~(_bytes.length / 2);
+ };
+
+ _this.write = function(buffer) {
+
+ var data = _bytes;
+
+ var i = 0;
+
+ while (i + 1 < data.length) {
+
+ var c = ( (0xff & data[i]) << 8) | (0xff & data[i + 1]);
+
+ if (0x8140 <= c && c <= 0x9FFC) {
+ c -= 0x8140;
+ } else if (0xE040 <= c && c <= 0xEBBF) {
+ c -= 0xC140;
+ } else {
+ throw 'illegal char at ' + (i + 1) + '/' + c;
+ }
+
+ c = ( (c >>> 8) & 0xff) * 0xC0 + (c & 0xff);
+
+ buffer.put(c, 13);
+
+ i += 2;
+ }
+
+ if (i < data.length) {
+ throw 'illegal char at ' + (i + 1);
+ }
+ };
+
+ return _this;
+ };
+
+ //=====================================================================
+ // GIF Support etc.
+ //
+
+ //---------------------------------------------------------------------
+ // byteArrayOutputStream
+ //---------------------------------------------------------------------
+
+ var byteArrayOutputStream = function() {
+
+ var _bytes = [];
+
+ var _this = {};
+
+ _this.writeByte = function(b) {
+ _bytes.push(b & 0xff);
+ };
+
+ _this.writeShort = function(i) {
+ _this.writeByte(i);
+ _this.writeByte(i >>> 8);
+ };
+
+ _this.writeBytes = function(b, off, len) {
+ off = off || 0;
+ len = len || b.length;
+ for (var i = 0; i < len; i += 1) {
+ _this.writeByte(b[i + off]);
+ }
+ };
+
+ _this.writeString = function(s) {
+ for (var i = 0; i < s.length; i += 1) {
+ _this.writeByte(s.charCodeAt(i) );
+ }
+ };
+
+ _this.toByteArray = function() {
+ return _bytes;
+ };
+
+ _this.toString = function() {
+ var s = '';
+ s += '[';
+ for (var i = 0; i < _bytes.length; i += 1) {
+ if (i > 0) {
+ s += ',';
+ }
+ s += _bytes[i];
+ }
+ s += ']';
+ return s;
+ };
+
+ return _this;
+ };
+
+ //---------------------------------------------------------------------
+ // base64EncodeOutputStream
+ //---------------------------------------------------------------------
+
+ var base64EncodeOutputStream = function() {
+
+ var _buffer = 0;
+ var _buflen = 0;
+ var _length = 0;
+ var _base64 = '';
+
+ var _this = {};
+
+ var writeEncoded = function(b) {
+ _base64 += String.fromCharCode(encode(b & 0x3f) );
+ };
+
+ var encode = function(n) {
+ if (n < 0) {
+ // error.
+ } else if (n < 26) {
+ return 0x41 + n;
+ } else if (n < 52) {
+ return 0x61 + (n - 26);
+ } else if (n < 62) {
+ return 0x30 + (n - 52);
+ } else if (n == 62) {
+ return 0x2b;
+ } else if (n == 63) {
+ return 0x2f;
+ }
+ throw 'n:' + n;
+ };
+
+ _this.writeByte = function(n) {
+
+ _buffer = (_buffer << 8) | (n & 0xff);
+ _buflen += 8;
+ _length += 1;
+
+ while (_buflen >= 6) {
+ writeEncoded(_buffer >>> (_buflen - 6) );
+ _buflen -= 6;
+ }
+ };
+
+ _this.flush = function() {
+
+ if (_buflen > 0) {
+ writeEncoded(_buffer << (6 - _buflen) );
+ _buffer = 0;
+ _buflen = 0;
+ }
+
+ if (_length % 3 != 0) {
+ // padding
+ var padlen = 3 - _length % 3;
+ for (var i = 0; i < padlen; i += 1) {
+ _base64 += '=';
+ }
+ }
+ };
+
+ _this.toString = function() {
+ return _base64;
+ };
+
+ return _this;
+ };
+
+ //---------------------------------------------------------------------
+ // base64DecodeInputStream
+ //---------------------------------------------------------------------
+
+ var base64DecodeInputStream = function(str) {
+
+ var _str = str;
+ var _pos = 0;
+ var _buffer = 0;
+ var _buflen = 0;
+
+ var _this = {};
+
+ _this.read = function() {
+
+ while (_buflen < 8) {
+
+ if (_pos >= _str.length) {
+ if (_buflen == 0) {
+ return -1;
+ }
+ throw 'unexpected end of file./' + _buflen;
+ }
+
+ var c = _str.charAt(_pos);
+ _pos += 1;
+
+ if (c == '=') {
+ _buflen = 0;
+ return -1;
+ } else if (c.match(/^\s$/) ) {
+ // ignore if whitespace.
+ continue;
+ }
+
+ _buffer = (_buffer << 6) | decode(c.charCodeAt(0) );
+ _buflen += 6;
+ }
+
+ var n = (_buffer >>> (_buflen - 8) ) & 0xff;
+ _buflen -= 8;
+ return n;
+ };
+
+ var decode = function(c) {
+ if (0x41 <= c && c <= 0x5a) {
+ return c - 0x41;
+ } else if (0x61 <= c && c <= 0x7a) {
+ return c - 0x61 + 26;
+ } else if (0x30 <= c && c <= 0x39) {
+ return c - 0x30 + 52;
+ } else if (c == 0x2b) {
+ return 62;
+ } else if (c == 0x2f) {
+ return 63;
+ } else {
+ throw 'c:' + c;
+ }
+ };
+
+ return _this;
+ };
+
+ //---------------------------------------------------------------------
+ // gifImage (B/W)
+ //---------------------------------------------------------------------
+
+ var gifImage = function(width, height) {
+
+ var _width = width;
+ var _height = height;
+ var _data = new Array(width * height);
+
+ var _this = {};
+
+ _this.setPixel = function(x, y, pixel) {
+ _data[y * _width + x] = pixel;
+ };
+
+ _this.write = function(out) {
+
+ //---------------------------------
+ // GIF Signature
+
+ out.writeString('GIF87a');
+
+ //---------------------------------
+ // Screen Descriptor
+
+ out.writeShort(_width);
+ out.writeShort(_height);
+
+ out.writeByte(0x80); // 2bit
+ out.writeByte(0);
+ out.writeByte(0);
+
+ //---------------------------------
+ // Global Color Map
+
+ // black
+ out.writeByte(0x00);
+ out.writeByte(0x00);
+ out.writeByte(0x00);
+
+ // white
+ out.writeByte(0xff);
+ out.writeByte(0xff);
+ out.writeByte(0xff);
+
+ //---------------------------------
+ // Image Descriptor
+
+ out.writeString(',');
+ out.writeShort(0);
+ out.writeShort(0);
+ out.writeShort(_width);
+ out.writeShort(_height);
+ out.writeByte(0);
+
+ //---------------------------------
+ // Local Color Map
+
+ //---------------------------------
+ // Raster Data
+
+ var lzwMinCodeSize = 2;
+ var raster = getLZWRaster(lzwMinCodeSize);
+
+ out.writeByte(lzwMinCodeSize);
+
+ var offset = 0;
+
+ while (raster.length - offset > 255) {
+ out.writeByte(255);
+ out.writeBytes(raster, offset, 255);
+ offset += 255;
+ }
+
+ out.writeByte(raster.length - offset);
+ out.writeBytes(raster, offset, raster.length - offset);
+ out.writeByte(0x00);
+
+ //---------------------------------
+ // GIF Terminator
+ out.writeString(';');
+ };
+
+ var bitOutputStream = function(out) {
+
+ var _out = out;
+ var _bitLength = 0;
+ var _bitBuffer = 0;
+
+ var _this = {};
+
+ _this.write = function(data, length) {
+
+ if ( (data >>> length) != 0) {
+ throw 'length over';
+ }
+
+ while (_bitLength + length >= 8) {
+ _out.writeByte(0xff & ( (data << _bitLength) | _bitBuffer) );
+ length -= (8 - _bitLength);
+ data >>>= (8 - _bitLength);
+ _bitBuffer = 0;
+ _bitLength = 0;
+ }
+
+ _bitBuffer = (data << _bitLength) | _bitBuffer;
+ _bitLength = _bitLength + length;
+ };
+
+ _this.flush = function() {
+ if (_bitLength > 0) {
+ _out.writeByte(_bitBuffer);
+ }
+ };
+
+ return _this;
+ };
+
+ var getLZWRaster = function(lzwMinCodeSize) {
+
+ var clearCode = 1 << lzwMinCodeSize;
+ var endCode = (1 << lzwMinCodeSize) + 1;
+ var bitLength = lzwMinCodeSize + 1;
+
+ // Setup LZWTable
+ var table = lzwTable();
+
+ for (var i = 0; i < clearCode; i += 1) {
+ table.add(String.fromCharCode(i) );
+ }
+ table.add(String.fromCharCode(clearCode) );
+ table.add(String.fromCharCode(endCode) );
+
+ var byteOut = byteArrayOutputStream();
+ var bitOut = bitOutputStream(byteOut);
+
+ // clear code
+ bitOut.write(clearCode, bitLength);
+
+ var dataIndex = 0;
+
+ var s = String.fromCharCode(_data[dataIndex]);
+ dataIndex += 1;
+
+ while (dataIndex < _data.length) {
+
+ var c = String.fromCharCode(_data[dataIndex]);
+ dataIndex += 1;
+
+ if (table.contains(s + c) ) {
+
+ s = s + c;
+
+ } else {
+
+ bitOut.write(table.indexOf(s), bitLength);
+
+ if (table.size() < 0xfff) {
+
+ if (table.size() == (1 << bitLength) ) {
+ bitLength += 1;
+ }
+
+ table.add(s + c);
+ }
+
+ s = c;
+ }
+ }
+
+ bitOut.write(table.indexOf(s), bitLength);
+
+ // end code
+ bitOut.write(endCode, bitLength);
+
+ bitOut.flush();
+
+ return byteOut.toByteArray();
+ };
+
+ var lzwTable = function() {
+
+ var _map = {};
+ var _size = 0;
+
+ var _this = {};
+
+ _this.add = function(key) {
+ if (_this.contains(key) ) {
+ throw 'dup key:' + key;
+ }
+ _map[key] = _size;
+ _size += 1;
+ };
+
+ _this.size = function() {
+ return _size;
+ };
+
+ _this.indexOf = function(key) {
+ return _map[key];
+ };
+
+ _this.contains = function(key) {
+ return typeof _map[key] != 'undefined';
+ };
+
+ return _this;
+ };
+
+ return _this;
+ };
+
+ var createDataURL = function(width, height, getPixel) {
+ var gif = gifImage(width, height);
+ for (var y = 0; y < height; y += 1) {
+ for (var x = 0; x < width; x += 1) {
+ gif.setPixel(x, y, getPixel(x, y) );
+ }
+ }
+
+ var b = byteArrayOutputStream();
+ gif.write(b);
+
+ var base64 = base64EncodeOutputStream();
+ var bytes = b.toByteArray();
+ for (var i = 0; i < bytes.length; i += 1) {
+ base64.writeByte(bytes[i]);
+ }
+ base64.flush();
+
+ return 'data:image/gif;base64,' + base64;
+ };
+
+ //---------------------------------------------------------------------
+ // returns qrcode function.
+
+ return qrcode;
+}();
+
+// multibyte support
+!function() {
+
+ qrcode.stringToBytesFuncs['UTF-8'] = function(s) {
+ // http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
+ function toUTF8Array(str) {
+ var utf8 = [];
+ for (var i=0; i < str.length; i++) {
+ var charcode = str.charCodeAt(i);
+ if (charcode < 0x80) utf8.push(charcode);
+ else if (charcode < 0x800) {
+ utf8.push(0xc0 | (charcode >> 6),
+ 0x80 | (charcode & 0x3f));
+ }
+ else if (charcode < 0xd800 || charcode >= 0xe000) {
+ utf8.push(0xe0 | (charcode >> 12),
+ 0x80 | ((charcode>>6) & 0x3f),
+ 0x80 | (charcode & 0x3f));
+ }
+ // surrogate pair
+ else {
+ i++;
+ // UTF-16 encodes 0x10000-0x10FFFF by
+ // subtracting 0x10000 and splitting the
+ // 20 bits of 0x0-0xFFFFF into two halves
+ charcode = 0x10000 + (((charcode & 0x3ff)<<10)
+ | (str.charCodeAt(i) & 0x3ff));
+ utf8.push(0xf0 | (charcode >>18),
+ 0x80 | ((charcode>>12) & 0x3f),
+ 0x80 | ((charcode>>6) & 0x3f),
+ 0x80 | (charcode & 0x3f));
+ }
+ }
+ return utf8;
+ }
+ return toUTF8Array(s);
+ };
+
+}();
+
+(function (factory) {
+ if (typeof define === 'function' && define.amd) {
+ define([], factory);
+ } else if (typeof exports === 'object') {
+ module.exports = factory();
+ }
+}(function () {
+ return qrcode;
+}));
diff --git a/registry/server.js b/registry/server.js
index 6cfd229..0be6aec 100644
--- a/registry/server.js
+++ b/registry/server.js
@@ -9,7 +9,7 @@ const exportFiles = require('./export-files');
const HOST = '127.0.0.1';
const PORT = 8787;
const ROOT = __dirname;
-const WEB = path.join(ROOT, 'web');
+const WEB = path.join(ROOT, 'legacy-web');
const ARCHIVE = path.join(ROOT, '..', '档案库');
const ARCHIVE_CARDS = path.join(ARCHIVE, '档案卡');
fs.mkdirSync(ARCHIVE_CARDS, { recursive: true });
diff --git a/registry/testgit b/registry/testgit
deleted file mode 100644
index e69de29..0000000
diff --git a/registry/web/app.css b/registry/web/app.css
index 1193264..e3f7739 100644
--- a/registry/web/app.css
+++ b/registry/web/app.css
@@ -3,3 +3,4 @@
.action-link{display:grid;place-items:center;text-decoration:none}.history-cards{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:14px}.archive-card{border:1px solid #dfe8f0;border-radius:12px;padding:16px;background:#fbfdff}.archive-card h3{font-size:15px;margin:0 0 5px;overflow-wrap:anywhere}.archive-card strong{color:#236d9b;font-size:13px}.archive-card p{color:#8193a3;font-size:11px;line-height:1.5;margin:9px 0 12px}.archive-thumbs{display:grid;grid-template-columns:1fr 1fr;gap:8px}.archive-thumbs>div{height:105px;border:1px solid #e2e9ef;border-radius:7px;background:#f3f7fa;display:grid;place-items:center;color:#a4b1bc;font-size:11px;overflow:hidden}.archive-thumbs img{height:100%;width:100%;object-fit:contain}.archive-actions{display:flex;flex-wrap:wrap;gap:8px;margin-top:13px}.archive-actions a,.archive-actions button{background:#eaf3f9;color:#236f9d;border:1px solid #d0e2ef;border-radius:7px;padding:7px 9px;font-size:11px;font-weight:700;text-decoration:none;cursor:pointer}
.topbar .brand-mark{width:42px;height:42px;object-fit:contain;border-radius:10px;padding:0;letter-spacing:normal;background:#fff}.hero h1{margin-top:0}.history-head{align-items:center}.history-controls{display:flex;align-items:center;justify-content:flex-end;flex-wrap:wrap;gap:10px}.select-all{display:inline-flex;align-items:center;gap:5px;margin:0;color:#49657a;white-space:nowrap;font-size:12px}.select-all input,.archive-select input{width:16px;height:16px;accent-color:#206d9f;cursor:pointer}.export-button{height:34px;padding:0 11px;border:1px solid #c8ddeb;border-radius:7px;background:#e9f3fa;color:#1d6c9c;font-size:12px;font-weight:700}.export-button:disabled{opacity:.48;cursor:not-allowed}.history-message{font-size:11px;line-height:1.55;color:#8a9dad;margin:0 0 14px}.history-message.error{color:#b84036}.archive-card{position:relative}.archive-card.selected{border-color:#4b9bc8;box-shadow:0 0 0 2px #4b9bc820}.archive-select{display:flex;align-items:center;gap:5px;float:right;margin:0 0 8px 10px;color:#59788f;font-size:11px;font-weight:600}.archive-actions .delete-record{background:#fff1ef;color:#b34039;border-color:#f2c9c5}.archive-actions .delete-record:hover{background:#ffe7e3}footer{justify-content:flex-end}@media(max-width:850px){.history-head{align-items:flex-start;flex-direction:column}.history-controls{justify-content:flex-start}}@media(max-width:530px){.history-controls{gap:8px}.export-button{flex:1}}
.history-search{position:relative;width:260px;flex:0 1 260px}.history-search input{height:36px;padding:0 66px 0 12px;font-size:12px;background:#fff}.history-search input::placeholder{color:#8fa1af}.history-search #search-count{position:absolute;right:10px;top:50%;transform:translateY(-50%);color:#6b8294;font-size:11px;white-space:nowrap;pointer-events:none}.history-search #search-count:empty{display:none}@media(max-width:850px){.history-controls{width:100%}.history-search{flex:1 1 260px}}@media(max-width:530px){.history-search{flex-basis:100%;width:100%}}
+.pagination{display:flex;gap:12px;justify-content:flex-end;align-items:center;flex-wrap:wrap;margin-top:20px;color:#59788f;font-size:12px}.pagination button,.archive-warning button{padding:7px 12px;border:1px solid #c8ddeb;border-radius:7px;background:#e9f3fa;color:#1d6c9c;cursor:pointer}.pagination button:disabled{opacity:.45;cursor:default}.archive-warning{padding:14px;background:#fff4da;color:#725319;border-radius:8px}dialog{border:1px solid #dce6ee;border-radius:16px;padding:28px;max-width:650px;width:calc(100% - 32px);max-height:90vh;overflow:auto;color:#173047}dialog::backdrop{background:#17304770}dialog h2{margin-top:0}dialog p{font-size:13px;line-height:1.6}dialog .edit-help{color:#61788a}.edit-photos{display:grid;grid-template-columns:1fr 1fr;gap:14px;margin-top:20px}.edit-photos fieldset{min-width:0;border:1px solid #dce6ee;border-radius:8px}.edit-photos img{width:100%;height:130px;object-fit:contain}.edit-photos input[type=file]{width:100%;font-size:12px}.edit-delete{display:flex;align-items:center;gap:8px}.edit-delete input{width:16px;height:16px}button:focus-visible,a:focus-visible{outline:3px solid #206d9f;outline-offset:3px}#edit-message{color:#a03f31}@media(max-width:530px){.edit-photos{grid-template-columns:1fr}dialog{padding:18px}.pagination{justify-content:center}}
diff --git a/registry/web/app.js b/registry/web/app.js
index e581ded..d13240a 100644
--- a/registry/web/app.js
+++ b/registry/web/app.js
@@ -4,6 +4,22 @@ let listedRecords = [];
const selectedIds = new Set();
let listRequestId = 0;
let searchTimer;
+let currentPage = 1;
+let totalPages = 0;
+let editingRecord = null;
+let editBusy = false;
+
+function updatePageButtons() {
+ $('previous-page').disabled = currentPage <= 1;
+ $('next-page').disabled = currentPage >= totalPages;
+}
+
+function archiveStatus(payload) {
+ if (payload.archiveStatus === 'pending') {
+ $('archive-warning').hidden = false;
+ $('archive-warning-text').textContent = payload.warning || '数据已保存,档案备份待同步。';
+ } else if (payload.archiveStatus === 'synced') $('archive-warning').hidden = true;
+}
function setMessage(message, error = false) {
$('form-message').textContent = message;
@@ -68,17 +84,31 @@ function drawRecord(record) {
$('qr-stage').innerHTML = qr.createSvgTag({ cellSize: 6, margin: 4 });
}
-async function loadRecords() {
+async function loadRecords(requestedPage = currentPage) {
const requestId = ++listRequestId;
const query = $('history-query').value.trim();
- const response = await fetch(`/api/records?q=${encodeURIComponent(query)}`);
- const payload = await response.json();
- if (!response.ok) throw new Error(payload.error || '读取记录失败');
+ $('previous-page').disabled = true; $('next-page').disabled = true;
+ let payload;
+ try {
+ const response = await fetch(`/api/records?q=${encodeURIComponent(query)}&page=${requestedPage}&pageSize=20`);
+ payload = await response.json();
+ if (!response.ok) throw new Error(payload.error || '读取记录失败');
+ } catch (error) {
+ if (requestId !== listRequestId) return;
+ updatePageButtons();
+ throw error;
+ }
if (requestId !== listRequestId) return;
+ totalPages = payload.totalPages;
+ if (requestedPage > Math.max(1, totalPages)) { selectedIds.clear(); return loadRecords(Math.max(1, totalPages)); }
+ currentPage = requestedPage;
+ $('page-status').textContent = `第 ${currentPage} / ${Math.max(1, totalPages)} 页 · 共 ${payload.total} 条`;
+ $('previous-page').disabled = currentPage === 1;
+ $('next-page').disabled = currentPage >= totalPages;
const body = $('history-cards');
body.replaceChildren();
listedRecords = payload.records;
- $('search-count').textContent = query ? `${listedRecords.length} 条` : '';
+ $('search-count').textContent = query ? `${payload.total} 条` : '';
const currentIds = new Set(listedRecords.map(record => record.id));
for (const id of selectedIds) if (!currentIds.has(id)) selectedIds.delete(id);
$('history-empty').hidden = listedRecords.length > 0;
@@ -145,6 +175,7 @@ async function loadRecords() {
const response = await fetch(`/api/records/${record.id}`, { method: 'DELETE' });
const payload = await response.json();
if (!response.ok) throw new Error(payload.error || '删除失败');
+ archiveStatus(payload);
selectedIds.delete(record.id);
if (activeRecord?.id === record.id) {
activeRecord = null;
@@ -155,7 +186,10 @@ async function loadRecords() {
setHistoryMessage(`已删除 ${record.serialNo} 的档案。`);
} catch (error) { setHistoryMessage(error.message, true); remove.disabled = false; }
});
- actions.append(open, download, showQr, remove);
+ const edit = document.createElement('button');
+ edit.type = 'button'; edit.textContent = '编辑资料 / 照片';
+ edit.addEventListener('click', () => openEditor(record));
+ actions.append(edit, open, download, showQr, remove);
card.append(select, title, code, detail, images, actions);
body.append(card);
}
@@ -185,6 +219,7 @@ $('register-form').addEventListener('submit', async event => {
});
const payload = await response.json();
if (!response.ok) throw new Error(payload.error || '保存失败');
+ archiveStatus(payload);
drawRecord(payload.record);
setMessage(payload.existing ? '该 SN 已登记,照片和填写的信息已保存。' : '登记成功,二维码已生成。');
await loadRecords();
@@ -202,7 +237,7 @@ $('history-query').addEventListener('input', () => {
card.querySelector('.archive-select input').checked = false;
});
updateSelectionControls();
- searchTimer = setTimeout(() => loadRecords().catch(error => setHistoryMessage(error.message, true)), 180);
+ searchTimer = setTimeout(() => loadRecords(1).catch(error => setHistoryMessage(error.message, true)), 180);
});
$('select-all').addEventListener('change', event => {
selectedIds.clear();
@@ -272,3 +307,77 @@ $('download-qr').addEventListener('click', async () => {
});
loadRecords().catch(error => setMessage(error.message, true));
+fetch('/api/archive/status').then(response => {
+ if (!response.ok) throw new Error('无法读取备份状态');
+ return response.json();
+}).then(archiveStatus).catch(error => setHistoryMessage(error.message, true));
+
+for (const [id, delta] of [['previous-page', -1], ['next-page', 1]]) {
+ $(id).addEventListener('click', () => {
+ selectedIds.clear(); updateSelectionControls();
+ document.querySelectorAll('.archive-select input').forEach(input => { input.checked = false; });
+ document.querySelectorAll('.archive-card.selected').forEach(card => card.classList.remove('selected'));
+ loadRecords(currentPage + delta).catch(error => {
+ setHistoryMessage(error.message, true);
+ updatePageButtons();
+ });
+ });
+}
+
+function openEditor(record) {
+ editingRecord = record; $('edit-form').reset(); $('edit-message').textContent = '';
+ $('edit-identity').textContent = `${record.serialNo} · ${record.uasCode}`;
+ $('edit-model').value = record.modelName; $('edit-owner').value = record.ownerName;
+ for (const slot of [1, 2]) {
+ const url = record[`photo${slot}Url`]; const preview = $(`edit-preview-${slot}`);
+ preview.hidden = !url; if (url) preview.src = `${url}?v=${Date.now()}`; else preview.removeAttribute('src');
+ $(`edit-delete-${slot}`).disabled = !url;
+ }
+ $('edit-dialog').showModal(); $('edit-model').focus();
+}
+$('edit-cancel').addEventListener('click', () => $('edit-dialog').close());
+$('edit-dialog').addEventListener('cancel', event => { if (editBusy) event.preventDefault(); });
+for (const slot of [1, 2]) {
+ $(`edit-photo-${slot}`).addEventListener('change', () => { if ($(`edit-photo-${slot}`).files.length) $(`edit-delete-${slot}`).checked = false; });
+ $(`edit-delete-${slot}`).addEventListener('change', () => { if ($(`edit-delete-${slot}`).checked) $(`edit-photo-${slot}`).value = ''; });
+}
+async function mutation(url, method, body) {
+ const response = await fetch(url, { method, headers: body ? { 'content-type': 'application/json' } : {}, body: body ? JSON.stringify(body) : undefined });
+ const payload = await response.json(); if (!response.ok) throw new Error(payload.error || '操作失败');
+ archiveStatus(payload); return payload;
+}
+$('edit-form').addEventListener('submit', async event => {
+ event.preventDefault(); const record = editingRecord; if (!record || editBusy) return;
+ editBusy = true;
+ const controls = Array.from($('edit-form').elements);
+ const disabled = controls.map(control => control.disabled);
+ controls.forEach(control => { control.disabled = true; });
+ const body = { modelName: $('edit-model').value.trim(), ownerName: $('edit-owner').value.trim() };
+ const deletes = [1, 2].map(slot => $(`edit-delete-${slot}`).checked);
+ let saved = false;
+ try {
+ // Validate both photos before committing any edits.
+ const photos = await Promise.all([readPhoto($('edit-photo-1'), 1), readPhoto($('edit-photo-2'), 2)]);
+ $('edit-message').textContent = '正在保存…';
+ for (const slot of [1, 2]) {
+ if (deletes[slot - 1]) body[`photo${slot}`] = null;
+ else if (photos[slot - 1]) body[`photo${slot}`] = photos[slot - 1];
+ }
+ const payload = await mutation(`/api/records/${record.id}`, 'PATCH', body);
+ saved = true;
+ if (activeRecord?.id === record.id) drawRecord(payload.record);
+ $('edit-dialog').close();
+ await loadRecords();
+ setHistoryMessage('档案修改已保存。');
+ } catch (error) {
+ if (saved) setHistoryMessage(`修改已保存,但列表刷新失败:${error.message}`, true);
+ else $('edit-message').textContent = `${error.message}。如连接中断,请刷新核对保存结果。`;
+ }
+ finally { controls.forEach((control, index) => { control.disabled = disabled[index]; }); editBusy = false; }
+});
+$('retry-archive').addEventListener('click', async () => {
+ $('retry-archive').disabled = true;
+ try { await mutation('/api/archive/retry', 'POST', {}); setHistoryMessage('档案与备份同步完成。'); }
+ catch (error) { $('archive-warning-text').textContent = error.message; }
+ finally { $('retry-archive').disabled = false; }
+});
diff --git a/registry/web/index.html b/registry/web/index.html
index 8db40e5..4f38f3c 100644
--- a/registry/web/index.html
+++ b/registry/web/index.html
@@ -79,10 +79,24 @@
导出档案包包含离线档案卡、照片和登记信息;Excel 导出为登记表。
暂无登记记录。
+
+
+