From ff8525ad2be97e4c8d4540a1e93b9758365900ae Mon Sep 17 00:00:00 2001 From: veypi Date: Thu, 19 Oct 2023 21:40:37 +0800 Subject: [PATCH] reform web menu and add nats url proxy --- oab/Cargo.lock | 495 +++++++++++++----- oab/Cargo.toml | 3 +- oab/cfg-demo.yml | 6 +- oab/src/api/mod.rs | 29 + oab/src/cfg.rs | 8 +- oab/src/libs/mod.rs | 2 + oab/src/libs/proxy.rs | 6 + oab/src/libs/task.rs | 101 ++++ oab/src/main.rs | 20 +- oaweb/src/assets/icon.js | 2 +- oaweb/src/boot/api/nats.ts | 19 + oaweb/src/boot/oaer.ts | 5 +- oaweb/src/cfg.ts | 15 + oaweb/src/components/EssentialLink.vue | 4 - oaweb/src/components/menu.vue | 30 -- oaweb/src/layouts/AppLayout.vue | 58 +- oaweb/src/layouts/MainLayout.vue | 2 +- oaweb/src/layouts/menu.vue | 35 ++ oaweb/src/layouts/menus.ts | 89 ++++ oaweb/src/libs/util.ts | 5 +- oaweb/src/models/index.ts | 9 - oaweb/src/pages/{AppAuth.vue => app/auth.vue} | 0 oaweb/src/pages/{AppCfg.vue => app/cfg.vue} | 0 oaweb/src/pages/{AppHome.vue => app/home.vue} | 0 oaweb/src/pages/app/oasys.vue | 79 +++ oaweb/src/pages/{AppUser.vue => app/user.vue} | 0 oaweb/src/router/routes.ts | 57 +- script/nats.cfg | 23 +- 28 files changed, 824 insertions(+), 278 deletions(-) create mode 100644 oab/src/libs/proxy.rs create mode 100644 oab/src/libs/task.rs create mode 100644 oaweb/src/boot/api/nats.ts create mode 100644 oaweb/src/cfg.ts delete mode 100644 oaweb/src/components/menu.vue create mode 100644 oaweb/src/layouts/menu.vue create mode 100644 oaweb/src/layouts/menus.ts rename oaweb/src/pages/{AppAuth.vue => app/auth.vue} (100%) rename oaweb/src/pages/{AppCfg.vue => app/cfg.vue} (100%) rename oaweb/src/pages/{AppHome.vue => app/home.vue} (100%) create mode 100644 oaweb/src/pages/app/oasys.vue rename oaweb/src/pages/{AppUser.vue => app/user.vue} (100%) diff --git a/oab/Cargo.lock b/oab/Cargo.lock index 2b5beb9..1b24754 100644 --- a/oab/Cargo.lock +++ b/oab/Cargo.lock @@ -69,7 +69,7 @@ dependencies = [ "actix-utils", "ahash 0.8.3", "base64 0.21.4", - "bitflags 2.4.0", + "bitflags 2.4.1", "brotli", "bytes", "bytestring", @@ -103,7 +103,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -141,7 +141,7 @@ dependencies = [ "parse-size", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -179,7 +179,7 @@ dependencies = [ "futures-core", "futures-util", "mio", - "socket2", + "socket2 0.5.4", "tokio", "tracing", ] @@ -240,7 +240,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "smallvec", - "socket2", + "socket2 0.5.4", "time", "url", ] @@ -254,7 +254,7 @@ dependencies = [ "actix-router", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -295,9 +295,9 @@ dependencies = [ [[package]] name = "aes-gcm" -version = "0.9.4" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" +checksum = "bc3be92e19a7ef47457b8e6f90707e12b6ac5d20c6f3866584fa3be0787d839f" dependencies = [ "aead", "aes", @@ -332,9 +332,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -446,18 +446,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -547,9 +547,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" dependencies = [ "serde", ] @@ -680,9 +680,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" @@ -925,9 +925,9 @@ dependencies = [ [[package]] name = "ctr" -version = "0.8.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" +checksum = "a232f92a03f37dd7d7dd2adc67166c77e9cd88de5b019b9a9eecfaeaf7bfd481" dependencies = [ "cipher", ] @@ -956,7 +956,7 @@ checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -980,7 +980,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -991,7 +991,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1056,10 +1056,11 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" dependencies = [ + "powerfmt", "serde", ] @@ -1178,25 +1179,14 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add4f07d43996f76ef320709726a556a9d4f965d9410d8d0271132d2f8293480" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ - "errno-dragonfly", "libc", "windows-sys", ] -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "etcetera" version = "0.8.0" @@ -1234,9 +1224,9 @@ checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6" [[package]] name = "flate2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -1259,6 +1249,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.0" @@ -1351,7 +1356,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1631,18 +1636,55 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "hyper" +version = "0.14.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2 0.4.9", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows", + "windows-core", ] [[package]] @@ -1717,7 +1759,7 @@ checksum = "ce243b1bfa62ffc028f1cc3b6034ec63d649f3031bc8a4fbbb004e1ac17d1f68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1729,6 +1771,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "ipnet" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" + [[package]] name = "itertools" version = "0.10.5" @@ -1755,9 +1803,9 @@ checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "8c37f63953c4c63420ed5fd3d6d398c719489b9f872b9fa683262f8edd363c7d" dependencies = [ "libc", ] @@ -1802,15 +1850,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.148" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libm" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "libsqlite3-sys" @@ -1825,9 +1873,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.8" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3852614a3bd9ca9804678ba6be5e3b8ce76dfc902cae004e3e0c44051b6e88db" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "local-channel" @@ -1848,9 +1896,9 @@ checksum = "e34f76eb3611940e0e7d53a9aaa4e6a3151f69541a282fd0dad5571420c53ff1" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -1930,6 +1978,24 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nkeys" version = "0.3.2" @@ -2037,9 +2103,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", "libm", @@ -2082,6 +2148,7 @@ dependencies = [ "nkeys", "proc", "rand", + "reqwest", "rust-embed", "sea-orm", "serde", @@ -2120,26 +2187,64 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "openssl" +version = "0.10.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" +dependencies = [ + "bitflags 2.4.1", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-sys" +version = "0.9.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "ordered-float" -version = "3.9.1" +version = "3.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a54938017eacd63036332b4ae5c8a49fc8c0c1d6d629893057e4f13609edd06" +checksum = "f1e1c390732d15f1d48471625cd92d154e66db2c56645e29a9cd26f4699f72dc" dependencies = [ "num-traits", ] [[package]] name = "os_str_bytes" -version = "6.5.1" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "ouroboros" @@ -2162,7 +2267,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -2189,7 +2294,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.8", + "parking_lot_core 0.9.9", ] [[package]] @@ -2208,13 +2313,13 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.3.5", + "redox_syscall 0.4.1", "smallvec", "windows-targets", ] @@ -2281,7 +2386,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -2363,6 +2468,12 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2413,9 +2524,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -2503,6 +2614,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -2516,9 +2636,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.6" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr", @@ -2528,9 +2648,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.9" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", @@ -2539,9 +2659,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.5" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rend" @@ -2552,6 +2672,44 @@ dependencies = [ "bytecheck", ] +[[package]] +name = "reqwest" +version = "0.11.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" +dependencies = [ + "base64 0.21.4", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "ring" version = "0.16.20" @@ -2657,7 +2815,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn 2.0.37", + "syn 2.0.38", "walkdir", ] @@ -2704,11 +2862,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.15" +version = "0.38.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2f9da0cbd88f9f09e7814e388301c8414c51c62aa6ce1e4b5c551d49d96e531" +checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", @@ -2831,7 +2989,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -2872,7 +3030,7 @@ dependencies = [ "proc-macro2", "quote", "sea-bae", - "syn 2.0.37", + "syn 2.0.38", "unicode-ident", ] @@ -2940,15 +3098,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.19" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] @@ -2964,13 +3122,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -3010,7 +3168,7 @@ checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -3084,9 +3242,9 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b21f559e07218024e7e9f90f96f601825397de0e25420135f7f952453fed0b" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" dependencies = [ "lazy_static", ] @@ -3155,6 +3313,16 @@ version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.4" @@ -3409,7 +3577,7 @@ dependencies = [ "atoi 2.0.0", "base64 0.21.4", "bigdecimal", - "bitflags 2.4.0", + "bitflags 2.4.1", "byteorder", "bytes", "chrono", @@ -3456,7 +3624,7 @@ dependencies = [ "atoi 2.0.0", "base64 0.21.4", "bigdecimal", - "bitflags 2.4.0", + "bitflags 2.4.1", "byteorder", "chrono", "crc 3.0.1", @@ -3559,9 +3727,9 @@ checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" [[package]] name = "subtle" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" @@ -3576,15 +3744,36 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tap" version = "1.0.1" @@ -3636,7 +3825,7 @@ checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -3651,12 +3840,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.29" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" +checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" dependencies = [ "deranged", "itoa", + "powerfmt", "serde", "time-core", "time-macros", @@ -3694,9 +3884,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.32.0" +version = "1.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" +checksum = "4f38200e3ef7995e5ef13baec2f432a6da0aa9ac495b2c0e8f3b7eec2c92d653" dependencies = [ "backtrace", "bytes", @@ -3706,7 +3896,7 @@ dependencies = [ "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.4", "tokio-macros", "windows-sys", ] @@ -3719,7 +3909,17 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", ] [[package]] @@ -3788,13 +3988,18 @@ dependencies = [ "serde", ] +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", "log", "pin-project-lite", "tracing-attributes", @@ -3814,20 +4019,20 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable", @@ -3858,6 +4063,12 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + [[package]] name = "typenum" version = "1.17.0" @@ -3908,9 +4119,9 @@ checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" [[package]] name = "universal-hash" -version = "0.4.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" dependencies = [ "generic-array", "subtle", @@ -3941,9 +4152,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" +checksum = "88ad59a7560b41a70d191093a945f0b87bc1deeda46fb237479708a1d6b6cdfc" dependencies = [ "getrandom", "md-5", @@ -3954,13 +4165,13 @@ dependencies = [ [[package]] name = "uuid-macro-internal" -version = "1.4.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e1ba1f333bd65ce3c9f27de592fcbc256dafe3af2717f56d7c87761fbaccf4" +checksum = "3d8c6bba9b149ee82950daefc9623b32bb1dacbfb1890e352f6b887bd582adaf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -3991,6 +4202,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -4018,10 +4238,22 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.87" @@ -4040,7 +4272,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4139,10 +4371,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows" -version = "0.48.0" +name = "windows-core" +version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" dependencies = [ "windows-targets", ] @@ -4213,6 +4445,16 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys", +] + [[package]] name = "wyz" version = "0.5.1" @@ -4264,11 +4506,10 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.8+zstd.1.5.5" +version = "2.0.9+zstd.1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" +checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" dependencies = [ "cc", - "libc", "pkg-config", ] diff --git a/oab/Cargo.toml b/oab/Cargo.toml index a2516b4..c3050ca 100644 --- a/oab/Cargo.toml +++ b/oab/Cargo.toml @@ -14,7 +14,7 @@ edition = "2021" [dependencies] include_dir = "*" lazy_static = "1" -serde = { version = "1", features = ["derive"] } +serde = { version = "1", features = ["derive", "rc"] } serde_json = "*" serde_yaml = "*" clap = { version = "3", features = ["derive"] } @@ -60,4 +60,5 @@ async-nats = "0.32.1" bytes = "1.5.0" nkeys = "0.3.2" tracing-appender = "0.2.2" +reqwest = "0.11.22" diff --git a/oab/cfg-demo.yml b/oab/cfg-demo.yml index 22a32ba..3e1518e 100644 --- a/oab/cfg-demo.yml +++ b/oab/cfg-demo.yml @@ -21,9 +21,9 @@ nats_sys: - UCOKXBGDAXXQOR4XUPUJ4O22HZ2A3KQN3JLCCYM3ISSKHLBZJXXQ3NLF - SUAEILQZDD2UT2ZNR6DCA44YCRKAZDYDOJRUPAUA7AOWFVGSSPFPCLXF24 info: - ws_url: http://127.0.0.1:4221 - nats_url: http://127.0.0.1:4222 - api_url: http://127.0.0.1:4001 + ws_url: 127.0.0.1:4221 + nats_url: 127.0.0.1:4222 + api_url: 127.0.0.1:4001 user_init_space: 300 diff --git a/oab/src/api/mod.rs b/oab/src/api/mod.rs index 56f12a5..ea51905 100644 --- a/oab/src/api/mod.rs +++ b/oab/src/api/mod.rs @@ -15,8 +15,13 @@ mod token; mod upload; mod user; use actix_web::web; +use tracing::info; + +use crate::{AppState, Result}; pub fn routes(cfg: &mut web::ServiceConfig) { + cfg.service(info); + cfg.service(proxynats); cfg.service(upload::save_files); cfg.service(user::get) .service(user::list) @@ -52,3 +57,27 @@ pub fn routes(cfg: &mut web::ServiceConfig) { .service(role::add) .service(role::drop); } + +#[actix_web::get("/info")] +pub async fn info(stat: web::Data) -> Result { + Ok(web::Json(stat.info.clone())) +} + +#[actix_web::get("/nats/{p:.*}")] +pub async fn proxynats( + req: actix_web::HttpRequest, + p: web::Path, +) -> Result { + let data = req.uri().query(); + let p = p.into_inner(); + let mut url = "http://127.0.0.1:8222".to_string(); + if !p.is_empty() { + url = format!("{url}/{p}") + } + if let Some(query) = data { + url = format!("{url}?{query}") + }; + info!(url); + let data = reqwest::get(url).await.unwrap().bytes().await.unwrap(); + Ok(actix_web::HttpResponse::Ok().body(data)) +} diff --git a/oab/src/cfg.rs b/oab/src/cfg.rs index 45a504d..e7c3f20 100644 --- a/oab/src/cfg.rs +++ b/oab/src/cfg.rs @@ -111,10 +111,10 @@ pub struct ApplicationConfig { #[derive(Debug, Clone, Deserialize, Serialize, Default)] pub struct InfoOpt { - nats_url: String, - ws_url: String, - api_url: String, - token: Option, + pub nats_url: String, + pub ws_url: String, + pub api_url: String, + pub token: Option, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] diff --git a/oab/src/libs/mod.rs b/oab/src/libs/mod.rs index 0f7b405..e5578f1 100644 --- a/oab/src/libs/mod.rs +++ b/oab/src/libs/mod.rs @@ -9,4 +9,6 @@ pub mod app; pub mod auth; pub mod cors; pub mod fs; +pub mod proxy; +pub mod task; pub mod user; diff --git a/oab/src/libs/proxy.rs b/oab/src/libs/proxy.rs new file mode 100644 index 0000000..a219043 --- /dev/null +++ b/oab/src/libs/proxy.rs @@ -0,0 +1,6 @@ +// +// proxy.rs +// Copyright (C) 2023 veypi +// 2023-10-19 19:31 +// Distributed under terms of the MIT license. +// diff --git a/oab/src/libs/task.rs b/oab/src/libs/task.rs new file mode 100644 index 0000000..f8c32c5 --- /dev/null +++ b/oab/src/libs/task.rs @@ -0,0 +1,101 @@ +// +// task.rs +// Copyright (C) 2023 veypi +// 2023-10-19 01:59 +// Distributed under terms of the MIT license. +// +use std::time::{Duration, Instant}; + +use futures_util::StreamExt; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; +use tracing::{info, warn}; + +#[derive(Debug, Clone, Deserialize, Serialize)] +struct sysInfo { + client: clientInfo, + id: String, + // server: String, +} +#[derive(Debug, Clone, Deserialize, Serialize)] +struct clientInfo { + id: i64, + acc: String, + name: String, + host: String, +} +pub fn start_nats_online(client: async_nats::client::Client) { + let db: Arc>> = Arc::new(Mutex::new(HashMap::new())); + { + let db = db.clone(); + let client = client.clone(); + tokio::spawn(async move { + let mut sub = client + .subscribe("$SYS.ACCOUNT.*.CONNECT".to_string()) + .await + .unwrap(); + while let Some(msg) = sub.next().await { + let s = String::from_utf8(msg.payload.to_vec()).unwrap(); + info!("{}", s); + let inf: sysInfo = serde_json::from_slice(&msg.payload.to_vec()).unwrap(); + info!("add {} {}", inf.client.id, inf.client.name); + let mut db = db.lock().unwrap(); + db.insert(inf.client.id, inf.client); + } + }); + } + { + let db = db.clone(); + let client = client.clone(); + tokio::spawn(async move { + let mut sub = client + .subscribe("$SYS.ACCOUNT.*.DISCONNECT".to_string()) + .await + .unwrap(); + while let Some(msg) = sub.next().await { + // let s = String::from_utf8(msg.payload.to_vec()).unwrap(); + let inf: sysInfo = serde_json::from_slice(&msg.payload.to_vec()).unwrap(); + info!("remove {} {}", inf.client.id, inf.client.name); + let mut db = db.lock().unwrap(); + db.remove(&inf.client.id); + } + }); + }; + tokio::spawn(async move { + let mut sub = client.subscribe("sys.online".to_string()).await.unwrap(); + while let Some(msg) = sub.next().await { + // // let s = String::from_utf8(msg.payload.to_vec()).unwrap(); + // let inf: sysInfo = serde_json::from_slice(&msg.payload.to_vec()).unwrap(); + // info!("remove {} {}", inf.client.id, inf.client.name); + // let mut db = db.lock().unwrap(); + // db.remove(&inf.client.id); + if let Some(t) = msg.reply { + let d = { + let tmp = db.lock().unwrap(); + let payload: Vec = tmp.iter().map(|(_, c)| c.clone()).collect(); + serde_json::to_string(&payload).unwrap() + }; + match client.publish(t, d.into()).await { + Ok(_) => {} + Err(e) => { + warn!("{}", e); + } + }; + } + } + }); +} + +pub fn start_demo() { + tokio::spawn(async move { + let mut interval = tokio::time::interval(Duration::from_secs(5)); + interval.tick().await; + let start = Instant::now(); + println!("time:{:?}", start); + loop { + interval.tick().await; + println!("time:{:?}", start.elapsed()); + } + }); +} diff --git a/oab/src/main.rs b/oab/src/main.rs index 188b817..f853d9e 100644 --- a/oab/src/main.rs +++ b/oab/src/main.rs @@ -30,7 +30,7 @@ async fn main() -> Result<()> { let mut data = AppState::new(&cli); if data.debug { std::env::set_var("RUST_LOG", "debug"); - std::env::set_var("RUST_BACKTRACE", "1"); + std::env::set_var("RUST_BACKTRACE", "full"); } let _log = init_log(&data); if cli.handle_service(data.clone())? { @@ -50,19 +50,21 @@ async fn main() -> Result<()> { data.connect().await?; data.connect_sqlx()?; web(data).await?; - info!("1"); - info!("12"); Ok(()) } async fn web(data: AppState) -> Result<()> { let client = match async_nats::ConnectOptions::new() - .nkey(data.nats_sys[1].clone()) - .connect("127.0.0.1:4222") + .nkey(data.nats_usr[1].clone()) + .connect(data.info.nats_url.clone()) .await { Ok(r) => r, - Err(e) => return Err(oab::Error::Unknown), + Err(e) => { + info!("{}", e); + return Err(oab::Error::Unknown); + } }; + libs::task::start_nats_online(client.clone()); client .publish("msg".to_string(), Bytes::from("asd")) .await @@ -94,7 +96,6 @@ async fn web(data: AppState) -> Result<()> { app.wrap(logger) .wrap(middleware::Compress::default()) .app_data(web::Data::new(data.clone())) - .service(info) .service(fs::Files::new("/media", data.media_path.clone()).show_files_listing()) .service( web::scope("api") @@ -169,8 +170,3 @@ async fn index(p: web::Path) -> impl Responder { .body(Asset::get("index.html").unwrap().data.into_owned()), } } - -#[get("/info")] -pub async fn info(stat: web::Data) -> Result { - Ok(web::Json(stat.info.clone())) -} diff --git a/oaweb/src/assets/icon.js b/oaweb/src/assets/icon.js index be2ce60..d7eb001 100644 --- a/oaweb/src/assets/icon.js +++ b/oaweb/src/assets/icon.js @@ -1 +1 @@ -window._iconfont_svg_string_3335115='',function(l){var c=(c=document.getElementsByTagName("script"))[c.length-1],h=c.getAttribute("data-injectcss"),c=c.getAttribute("data-disable-injectsvg");if(!c){var t,a,o,i,e,v=function(c,h){h.parentNode.insertBefore(c,h)};if(h&&!l.__iconfont__svg__cssinject__){l.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(c){console&&console.log(c)}}t=function(){var c,h=document.createElement("div");h.innerHTML=l._iconfont_svg_string_3335115,(h=h.getElementsByTagName("svg")[0])&&(h.setAttribute("aria-hidden","true"),h.style.position="absolute",h.style.width=0,h.style.height=0,h.style.overflow="hidden",h=h,(c=document.body).firstChild?v(h,c.firstChild):c.appendChild(h))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(t,0):(a=function(){document.removeEventListener("DOMContentLoaded",a,!1),t()},document.addEventListener("DOMContentLoaded",a,!1)):document.attachEvent&&(o=t,i=l.document,e=!1,s(),i.onreadystatechange=function(){"complete"==i.readyState&&(i.onreadystatechange=null,d())})}function d(){e||(e=!0,o())}function s(){try{i.documentElement.doScroll("left")}catch(c){return void setTimeout(s,50)}d()}}(window); \ No newline at end of file +window._iconfont_svg_string_3335115='',function(l){var c=(c=document.getElementsByTagName("script"))[c.length-1],h=c.getAttribute("data-injectcss"),c=c.getAttribute("data-disable-injectsvg");if(!c){var t,a,o,i,v,e=function(c,h){h.parentNode.insertBefore(c,h)};if(h&&!l.__iconfont__svg__cssinject__){l.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(c){console&&console.log(c)}}t=function(){var c,h=document.createElement("div");h.innerHTML=l._iconfont_svg_string_3335115,(h=h.getElementsByTagName("svg")[0])&&(h.setAttribute("aria-hidden","true"),h.style.position="absolute",h.style.width=0,h.style.height=0,h.style.overflow="hidden",h=h,(c=document.body).firstChild?e(h,c.firstChild):c.appendChild(h))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(t,0):(a=function(){document.removeEventListener("DOMContentLoaded",a,!1),t()},document.addEventListener("DOMContentLoaded",a,!1)):document.attachEvent&&(o=t,i=l.document,v=!1,s(),i.onreadystatechange=function(){"complete"==i.readyState&&(i.onreadystatechange=null,d())})}function d(){v||(v=!0,o())}function s(){try{i.documentElement.doScroll("left")}catch(c){return void setTimeout(s,50)}d()}}(window); \ No newline at end of file diff --git a/oaweb/src/boot/api/nats.ts b/oaweb/src/boot/api/nats.ts new file mode 100644 index 0000000..3ea4c08 --- /dev/null +++ b/oaweb/src/boot/api/nats.ts @@ -0,0 +1,19 @@ +/* + * nats.ts + * Copyright (C) 2023 veypi + * 2023-10-19 21:36 + * Distributed under terms of the MIT license. + */ + + +import ajax from './axios' + +export default { + local: './nats/', + general() { + return ajax.get(this.local + 'varz') + }, + conns() { + return ajax.get(this.local + 'connz', { subs: true }) + }, +} diff --git a/oaweb/src/boot/oaer.ts b/oaweb/src/boot/oaer.ts index 7e7fbcd..6edcfcf 100644 --- a/oaweb/src/boot/oaer.ts +++ b/oaweb/src/boot/oaer.ts @@ -9,13 +9,14 @@ // import '@veypi/oaer' import oaer from '@veypi/oaer' import '@veypi/oaer/dist/index.css' +import cfg from 'src/cfg' import bus from 'src/libs/bus' import util from 'src/libs/util' oaer.set({ token: util.getToken(), - host: 'http://' + window.location.host, - uuid: 'FR9P5t8debxc11aFF', + host: cfg.host, + uuid: cfg.id, }) bus.on('token', (t: any) => { diff --git a/oaweb/src/cfg.ts b/oaweb/src/cfg.ts new file mode 100644 index 0000000..47642f3 --- /dev/null +++ b/oaweb/src/cfg.ts @@ -0,0 +1,15 @@ +/* + * cfg.ts + * Copyright (C) 2023 veypi + * 2023-10-18 22:03 + * Distributed under terms of the MIT license. + */ + + +const cfg = { + host: 'http://' + window.location.host, + id: 'FR9P5t8debxc11aFF', +} + +export default cfg + diff --git a/oaweb/src/components/EssentialLink.vue b/oaweb/src/components/EssentialLink.vue index 2e3f964..c27cd87 100644 --- a/oaweb/src/components/EssentialLink.vue +++ b/oaweb/src/components/EssentialLink.vue @@ -1,12 +1,8 @@ diff --git a/oaweb/src/components/menu.vue b/oaweb/src/components/menu.vue deleted file mode 100644 index 2528e43..0000000 --- a/oaweb/src/components/menu.vue +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - diff --git a/oaweb/src/layouts/AppLayout.vue b/oaweb/src/layouts/AppLayout.vue index 8da473b..0f6b07e 100644 --- a/oaweb/src/layouts/AppLayout.vue +++ b/oaweb/src/layouts/AppLayout.vue @@ -24,13 +24,12 @@ diff --git a/oaweb/src/layouts/MainLayout.vue b/oaweb/src/layouts/MainLayout.vue index 4f9328e..2747afb 100644 --- a/oaweb/src/layouts/MainLayout.vue +++ b/oaweb/src/layouts/MainLayout.vue @@ -56,7 +56,7 @@ + + + diff --git a/oaweb/src/layouts/menus.ts b/oaweb/src/layouts/menus.ts new file mode 100644 index 0000000..eea2e6f --- /dev/null +++ b/oaweb/src/layouts/menus.ts @@ -0,0 +1,89 @@ +/* + * menu.ts + * Copyright (C) 2023 veypi + * 2023-10-18 22:58 + * Distributed under terms of the MIT license. + */ + +import { Dict } from 'src/models'; +import { ref } from 'vue'; +import { RouteLocationRaw } from 'vue-router'; +import cfg from 'src/cfg' + +export interface MenuLink { + title: string; + caption?: string; + to?: RouteLocationRaw; + link?: string; + icon?: string; + router?: any; +} + +const tmp_router = (title: string, icon: string, path: string, com: + string) => { + let name = 'app.' + path + return { + title: title, + icon: icon, + name: name, + to: { name: name, params: { id: '' } }, + router: { + path: path, + name: name, + component: () => import('../pages/app/' + com + '.vue') + }, + } +} +let uniqueLinks: { [key: string]: [MenuLink] } = { + [cfg.id]: [tmp_router('系统信息', 'v-data-view', 'oasys', 'oasys')] +} + +const defaultLinks: MenuLink[] = [ + { + title: '应用中心', + caption: '', + icon: 'v-apps', + to: { name: 'home' } + }, + { + title: '文件管理', + caption: '', + icon: 'v-folder', + to: { name: 'fs' } + }, + { + title: '账号设置', + icon: 'v-user', + to: { name: 'user' } + }, + { + title: '文档中心', + icon: 'v-file-exception', + to: { name: 'doc' } + }, + { + title: '设置', + caption: '', + icon: 'v-setting', + to: { name: 'settings' } + }, +] + +const items = ref(defaultLinks) + +const load_default = () => { + items.value = defaultLinks +} + + +const appLinks = ref([ + tmp_router('', 'v-home', 'home', 'home'), + tmp_router('用户管理', 'v-team', 'user', 'user'), + tmp_router('权限管理', 'v-key', 'auth', 'auth'), + tmp_router('应用设置', 'v-setting', 'cfg', 'cfg'), + tmp_router('test', 'v-key', 'test', '../IndexPage'), +] as MenuLink[]) + + +export default { items, load_default, appLinks, uniqueLinks } + diff --git a/oaweb/src/libs/util.ts b/oaweb/src/libs/util.ts index 6a001b5..81eb13e 100644 --- a/oaweb/src/libs/util.ts +++ b/oaweb/src/libs/util.ts @@ -8,7 +8,10 @@ function padLeftZero(str: string): string { const util = { datetostr(d: string) { - let r = new Date(d + 'z') + if (!d.endsWith('Z')) { + d = d + 'Z' + } + let r = new Date(d) let delta = (new Date().getTime() - r.getTime()) / 1000 if (delta < 0) { } else if (delta < 60) { diff --git a/oaweb/src/models/index.ts b/oaweb/src/models/index.ts index 7406da4..00d8262 100644 --- a/oaweb/src/models/index.ts +++ b/oaweb/src/models/index.ts @@ -5,7 +5,6 @@ * @description:index */ -import { RouteLocationRaw } from 'vue-router'; import { AccessLevel } from './auth'; export { type Auths, type modelsSimpleAuth, NewAuths, R, AccessLevel, LevelOptions } from './auth' @@ -56,14 +55,6 @@ export interface DocGroup { items?: DocItem[] } -export interface MenuLink { - title: string; - caption?: string; - to?: RouteLocationRaw; - link?: string; - icon?: string; -} - export interface modelsBread { Index: number Name: string diff --git a/oaweb/src/pages/AppAuth.vue b/oaweb/src/pages/app/auth.vue similarity index 100% rename from oaweb/src/pages/AppAuth.vue rename to oaweb/src/pages/app/auth.vue diff --git a/oaweb/src/pages/AppCfg.vue b/oaweb/src/pages/app/cfg.vue similarity index 100% rename from oaweb/src/pages/AppCfg.vue rename to oaweb/src/pages/app/cfg.vue diff --git a/oaweb/src/pages/AppHome.vue b/oaweb/src/pages/app/home.vue similarity index 100% rename from oaweb/src/pages/AppHome.vue rename to oaweb/src/pages/app/home.vue diff --git a/oaweb/src/pages/app/oasys.vue b/oaweb/src/pages/app/oasys.vue new file mode 100644 index 0000000..b337e8e --- /dev/null +++ b/oaweb/src/pages/app/oasys.vue @@ -0,0 +1,79 @@ + + + + + + + diff --git a/oaweb/src/pages/AppUser.vue b/oaweb/src/pages/app/user.vue similarity index 100% rename from oaweb/src/pages/AppUser.vue rename to oaweb/src/pages/app/user.vue diff --git a/oaweb/src/router/routes.ts b/oaweb/src/router/routes.ts index 4a9f108..6571c04 100644 --- a/oaweb/src/router/routes.ts +++ b/oaweb/src/router/routes.ts @@ -1,5 +1,6 @@ import { Auths } from 'src/models/auth'; import { RouteRecordRaw } from 'vue-router'; +import menus from 'src/layouts/menus' declare module 'vue-router' { interface RouteMeta { @@ -17,58 +18,48 @@ function loadcomponents(path: string, name: string, main: string) { return { path: path, name: name, - components: { - default: () => import("../pages/" + main + ".vue"), - } + component: () => import("../pages/" + main + ".vue"), } } const routes: RouteRecordRaw[] = [ { path: '/', - component: () => import('../layouts/MainLayout.vue'), + component: () => import('src/layouts/MainLayout.vue'), meta: { requiresAuth: true, }, redirect: 'home', children: [ - loadcomponents('home', 'home', 'IndexPage'), - loadcomponents('user', 'user', 'user'), - loadcomponents('fs', 'fs', 'fs'), - loadcomponents('doc', 'doc', 'doc'), - loadcomponents('doc/:typ/:url(.*)', 'doc_item', 'docItem'), - loadcomponents('settings', 'settings', 'settings'), { path: 'app/:id', + name: 'app', component: () => import("../layouts/AppLayout.vue"), redirect: { name: 'app.home' }, children: [ - loadcomponents('home', 'app.home', 'AppHome'), - loadcomponents('user', 'app.user', 'AppUser'), - loadcomponents('auth', 'app.auth', 'AppAuth'), - loadcomponents('settings', 'app.settings', 'AppCfg'), ] - } + }, + loadcomponents('home', 'home', 'IndexPage'), + loadcomponents('user', 'user', 'user'), + loadcomponents('fs', 'fs', 'fs'), + loadcomponents('doc', 'doc', 'doc'), + loadcomponents('doc/:typ/:url(.*)', 'doc_item', 'docItem'), + loadcomponents('settings', 'settings', 'settings'), ], }, - { - path: '/login/:uuid?', - name: 'login', - component: () => import('../pages/login.vue'), - }, - { - path: '/register/:uuid?', - name: 'register', - component: () => import('../pages/register.vue'), - }, - - - // Always leave this as last one, - // but you can also remove it - { - path: '/:catchAll(.*)*', - component: () => import('../pages/404.vue'), - }, + loadcomponents('/login/:uuid?', 'login', 'login'), + loadcomponents('/register/:uuid?', 'register', 'register'), + loadcomponents('/:catchAll(.*)*', '404', '404') ]; +for (let i of menus.appLinks.value) { + // @ts-ignore + routes[0].children[0].children.push(i.router) +} +for (let i in menus.uniqueLinks) { + for (let j of menus.uniqueLinks[i]) { + // @ts-ignore + routes[0].children[0].children.push(j.router) + } +} export default routes; diff --git a/script/nats.cfg b/script/nats.cfg index 2380a5b..194a3a2 100644 --- a/script/nats.cfg +++ b/script/nats.cfg @@ -17,13 +17,15 @@ accounts: { usrs: { users: [ { nkey: UCXFAAVMCPTATZUZX6H24YF6FI3NKPQBPLM6BNN2EDFPNSUUEZPNFKEL}, + { user: cli, password: cli}, ], exports: [ - {stream: pub.>}, - {service: psrv.>}, + # {stream: node.>}, + # {service: node.>}, ], imports: [ - {stream: {account: SYS, subject: usr.>}, prefix: a}, + {stream: {account: SYS, subject: >}}, + {service: {account: SYS, subject: >}}, ], }, nodes: { @@ -31,20 +33,21 @@ accounts: { { nkey: UAU6HPAHVIQWODQ365HMSHGZPSXJHR35T6ACURR3STGXFZNWXFNG5EA6}, ], exports: [ - {stream: pub.>}, - {service: psrv.>}, + # {stream: >}, + # {service: >}, + ], + imports: [ + # {stream: {account: usrs, subject: node.>}, prefix: 'usr'}, + # {service: {account: usrs, subject: >}}, ], }, SYS: { users: [ { nkey: UCOKXBGDAXXQOR4XUPUJ4O22HZ2A3KQN3JLCCYM3ISSKHLBZJXXQ3NLF}, - { user: cli, password: cli}, ], exports: [ - {stream: usr.>}, - {stream: node.>}, - {service: usr.>}, - {service: node.>}, + {stream: >}, + {service: >}, ], }, }