Refactor rc_microtransactions to use actix-web, remove rocket dependency

This commit is contained in:
NG (Graham) committed 2026-01-01 10:39:46 -05:00
1 parent 2293edec9d
commit ae091a7666
11 files changed
+160 -572

No files matched your search

+1 -6
View File
@@ -1,7 +1,2 @@
mod store;
pub fn stage() -> rocket::fairing::AdHoc {
rocket::fairing::AdHoc::on_ignite("JSON", |rocket| async {
rocket.attach(store::stage())
})
}
pub use store::robopay_store;
+93 -12
View File
@@ -1,17 +1,98 @@
use rocket::{post, routes, serde::json::{json, Value}};
use actix_web::{web::{Data, Json}, Error, post};
use serde::Serialize;
#[derive(Serialize)]
struct Response<T> {
response: T
}
#[derive(Serialize)]
struct ResponseData<T> {
data: Vec<T>
}
#[derive(Serialize)]
struct StoreBundle {
#[serde(rename = "items")]
items: Vec<StoreItem>,
#[serde(rename = "itemSku")]
item_sku: String,
#[serde(rename = "currencyCode")]
currency_code: String,
#[serde(rename = "currencyString")]
currency_string: String,
#[serde(rename = "oldCurrencyString")]
old_currency_string: String,
#[serde(rename = "priceForCheck")]
price_for_check: f32,
#[serde(rename = "oldPriceForCheck")]
old_price_for_check: f32,
#[serde(rename = "additionalValue")]
additional_value: i32,
#[serde(rename = "mostPopular")]
most_popular: bool,
#[serde(rename = "bestValue")]
best_value: bool,
#[serde(rename = "currencyType")]
currency_type: String,
#[serde(rename = "available")]
is_available: bool,
#[serde(rename = "owned")]
is_owned: bool,
}
#[derive(Serialize)]
struct StoreItem {
#[serde(rename = "itemType")]
item_type: StoreItemType,
#[serde(rename = "amount")]
amount: i32,
#[serde(rename = "data")]
data: String,
}
#[allow(dead_code)]
#[derive(Serialize)]
enum StoreItemType {
RoboPass = 0,
CosmeticCredits = 1,
Premium = 2,
PremiumForLife = 3,
Cube = 4,
Robits = 5,
Other = 6
}
type ItemResponse = Response<ResponseData<StoreBundle>>;
#[post("/robopay/store")]
pub fn robopay_store() -> Value {
pub async fn robopay_store(_cli: Data<crate::cli::CliArgs>) -> Result<Json<ItemResponse>, Error> {
// TODO authentication (Authorization header is "Robocraft {JWT token from auth}")
json!({
"response": {
"data": []
Ok(Json(Response {
response: ResponseData {
data: vec![
StoreBundle {
items: vec![
StoreItem {
item_type: StoreItemType::CosmeticCredits,
amount: 1,
data: "RE_store_item_data_01".to_owned(),
},
],
item_sku: "CosmeticCredits1".to_owned(), // SKUs can be found in RealMoneyStoreExtraData of sharedassets2.assets
currency_code: "RE_no_currency".to_owned(),
currency_string: "RE_DO_NOT_BUY_01".to_owned(),
old_currency_string: "RE_DO_NOT_BUY_OLD_01".to_owned(),
price_for_check: 42.0,
old_price_for_check: 41.0,
additional_value: 999888777,
most_popular: true,
best_value: true,
currency_type: "RE_price_type_01".to_owned(),
is_available: true,
is_owned: false,
},
]
}
})
}
pub fn stage() -> rocket::fairing::AdHoc {
rocket::fairing::AdHoc::on_ignite("Robocraft store info", |rocket| async {
rocket.mount("/", routes![robopay_store])
})
}))
}