Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions extensions/cratespro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[workspace]
members = [
"common/data_transporter",
"common/database",
"common/database/entity",
"common/model", # internal info struct,such as `crate info` `library info` `app info`
"common/repo_import", # extract repo and import data into tugraph
"common/search",
"common/tudriver", # tugraph client, deal with the quary from router
"import_tugraph",
]

resolver = "2" # use resolver of version 2

[workspace.dependencies]
# internal (项目内部依赖)
data_transporter = { path = "common/data_transporter" }
model = { path = "common/model" }
repo_import = { path = "common/repo_import" }
search = { path = "common/search" }
tudriver = { path = "common/tudriver" }
database = { path = "common/database" }
entity = { path = "common/database/entity" }
import_tugraph = {path = "import_tugraph"}

# third-party (所有第三方依赖, 按字母表排序, 均保留1个小数点)
38 changes: 38 additions & 0 deletions extensions/cratespro/common/data_transporter/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
rust_library(
name = "data_transporter",
srcs = [
"src/data_packer.rs",
"src/data_reader.rs",
"src/db.rs",
"src/handler.rs",
"src/lib.rs",
"src/transporter.rs",
"src/redis_store.rs",
],
crate_root = "src/lib.rs",
edition = "2021",
deps = [
"//project/crates-pro:model",
"//project/crates-pro:repo_import",
"//project/crates-pro:search",
"//project/crates-pro:tudriver",
"//third-party:actix-multipart",
"//third-party:actix-web",
"//third-party:async-trait",
"//third-party:chrono",
"//third-party:futures-util",
"//third-party:redis",
"//third-party:sanitize-filename",
"//third-party:semver",
"//third-party:serde",
"//third-party:serde_json",
"//third-party:tokio",
"//third-party:tokio-postgres",
"//third-party:tracing",
"//third-party:utoipa",
"//third-party:utoipa-swagger-ui",
"//third-party:uuid",
"//third-party:zip",
],
visibility = ["PUBLIC"],
)
33 changes: 33 additions & 0 deletions extensions/cratespro/common/data_transporter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "data_transporter"
version = "0.1.0"
edition = "2021"

[dependencies]
model = { workspace = true }
repo_import = { workspace = true }
search = { workspace = true }
tudriver = { workspace = true }

# third-party (第三方依赖, 不写具体版本号, 具体版本只在根目录 Cargo.toml 中出现)
actix-multipart = "0.7"
actix-web = "4.10"
async-trait = "0.1"
chrono = { version = "0.4", features = ["clock"] }
futures-util = "0.3"
redis = "0.32"
sanitize-filename = "0.6"
semver = "1.0"
serde = "1.0"
serde_json = "1.0"
tokio = { version = "1.44", features = ["full"] }
tokio-postgres = { version = "0.7", features = ["with-chrono-0_4"] }
tracing = "0.1"
utoipa = { version = "5.3", features = ["actix_extras"] }
utoipa-swagger-ui = { version = "9.0", features = ["actix-web"] }
uuid = { version = "1.16", features = [
"v4", # Lets you generate random UUIDs
"fast-rng", # Use a faster (but still sufficiently random) RNG
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
] }
zip = "=2.4.2"
28 changes: 28 additions & 0 deletions extensions/cratespro/common/data_transporter/src/data_packer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use model::tugraph_model::{Program, UProgram};

use crate::db::DBHandler;

pub struct DataPacker {
db: DBHandler,
}

impl DataPacker {
pub async fn new() -> Self {
let db = DBHandler::connect().await.unwrap();
db.clear_database().await.unwrap();
db.create_tables().await.unwrap();
Self { db }
}

pub async fn pack_into_db(
&self,
program: Program,
uprogram: UProgram,
versions: Vec<crate::VersionInfo>,
) {
self.db
.insert_program_data(program, uprogram, versions)
.await
.unwrap();
}
}
Loading