MCPcopy Create free account
hub / github.com/ZingerLittleBee/ServerBee / seed_module

Function seed_module

crates/server/tests/widget_module_integration.rs:128–163  ·  view source on GitHub ↗
(db: &DatabaseConnection, id: &str)

Source from the content-addressed store, hash-verified

126}
127
128async fn seed_module(db: &DatabaseConnection, id: &str) {
129 let code = format!(
130 r#"/**
131 * @serverbee-widget {{
132 * "id": "{id}",
133 * "version": "1.0.0",
134 * "name": "Foo",
135 * "category": "Real-time",
136 * "sizing": {{ "defaultW": 3, "defaultH": 3, "minW": 2, "minH": 2, "strategy": "aspect-square" }},
137 * "sdkVersion": "^0.1.0"
138 * }}
139 */
140export default {{}};
141"#
142 );
143 let manifest = extract_manifest(&code).expect("manifest");
144 let sha = sha256_hex(code.as_bytes());
145
146 widget_module::ActiveModel {
147 id: Set(id.to_string()),
148 version: Set("1.0.0".into()),
149 source_type: Set(SourceType::Upload),
150 source_url: Set(None),
151 bundled_by_theme_id: Set(None),
152 manifest_json: Set(serde_json::to_string(&manifest).unwrap()),
153 code_sha256: Set(sha),
154 entry_path: Set("index.js".into()),
155 package_blob: Set(Some(code.into_bytes())),
156 installed_by: Set(None),
157 installed_at: Set(Utc::now()),
158 enabled: Set(true),
159 }
160 .insert(db)
161 .await
162 .expect("Failed to seed widget_module row");
163}
164
165fn sha256_hex(bytes: &[u8]) -> String {
166 use sha2::{Digest, Sha256};

Calls 2

extract_manifestFunction · 0.85
sha256_hexFunction · 0.85

Tested by

no test coverage detected