diff --git a/rnex-core/.sqlx/query-31e36bb378bcf8e665391d9cd2c5282fea9540a0673456d58f8142cafc330240.json b/rnex-core/.sqlx/query-31e36bb378bcf8e665391d9cd2c5282fea9540a0673456d58f8142cafc330240.json new file mode 100644 index 0000000..531ffb3 --- /dev/null +++ b/rnex-core/.sqlx/query-31e36bb378bcf8e665391d9cd2c5282fea9540a0673456d58f8142cafc330240.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE datastore.objects SET data_type=$1 WHERE data_id=$2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Int8" + ] + }, + "nullable": [] + }, + "hash": "31e36bb378bcf8e665391d9cd2c5282fea9540a0673456d58f8142cafc330240" +} diff --git a/rnex-core/.sqlx/query-433b8cbd7320b5463391b08545c09b11255b363112c3379319b9e69ed003f2eb.json b/rnex-core/.sqlx/query-433b8cbd7320b5463391b08545c09b11255b363112c3379319b9e69ed003f2eb.json new file mode 100644 index 0000000..921776d --- /dev/null +++ b/rnex-core/.sqlx/query-433b8cbd7320b5463391b08545c09b11255b363112c3379319b9e69ed003f2eb.json @@ -0,0 +1,28 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT update_password, under_review FROM datastore.objects WHERE data_id=$1 AND upload_completed=TRUE AND deleted=FALSE\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "update_password", + "type_info": "Int8" + }, + { + "ordinal": 1, + "name": "under_review", + "type_info": "Bool" + } + ], + "parameters": { + "Left": [ + "Int8" + ] + }, + "nullable": [ + false, + false + ] + }, + "hash": "433b8cbd7320b5463391b08545c09b11255b363112c3379319b9e69ed003f2eb" +} diff --git a/rnex-core/.sqlx/query-c27439038dc25c17738b4a9cc37f94f83f23239a0c37c7adbccaef571e0128da.json b/rnex-core/.sqlx/query-c27439038dc25c17738b4a9cc37f94f83f23239a0c37c7adbccaef571e0128da.json new file mode 100644 index 0000000..08ffa88 --- /dev/null +++ b/rnex-core/.sqlx/query-c27439038dc25c17738b4a9cc37f94f83f23239a0c37c7adbccaef571e0128da.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE datastore.objects SET meta_binary=$1 WHERE data_id=$2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Bytea", + "Int8" + ] + }, + "nullable": [] + }, + "hash": "c27439038dc25c17738b4a9cc37f94f83f23239a0c37c7adbccaef571e0128da" +} diff --git a/rnex-core/.sqlx/query-daac203a168b0aab9550176524d0741da291e8861fd7c6ac4838d7fe20a871f8.json b/rnex-core/.sqlx/query-daac203a168b0aab9550176524d0741da291e8861fd7c6ac4838d7fe20a871f8.json new file mode 100644 index 0000000..0790dda --- /dev/null +++ b/rnex-core/.sqlx/query-daac203a168b0aab9550176524d0741da291e8861fd7c6ac4838d7fe20a871f8.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "UPDATE datastore.objects SET period=$1 WHERE data_id=$2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Int4", + "Int8" + ] + }, + "nullable": [] + }, + "hash": "daac203a168b0aab9550176524d0741da291e8861fd7c6ac4838d7fe20a871f8" +} diff --git a/rnex-core/src/nex/datastore.rs b/rnex-core/src/nex/datastore.rs index 688ab6d..3285f23 100644 --- a/rnex-core/src/nex/datastore.rs +++ b/rnex-core/src/nex/datastore.rs @@ -1,3 +1,4 @@ +use futures::TryFutureExt; use rnex_core::nex::user::User; use rnex_core::PID; use rnex_core::executables::common::{ @@ -5,7 +6,7 @@ use rnex_core::executables::common::{ }; use rnex_core::kerberos::KerberosDateTime; use rnex_core::nex::s3presigner::S3Presigner; -use rnex_core::rmc::protocols::datastore::{BufferQueueParam, CompletePostParam, DataStoreCustomRankingResult, DataStoreGetCustomRankingByDataIDParam, DataStorePrepareGetParam, DataStoreReqGetInfo, DataStoreSearchParam, GetMetaInfo, GetMetaParam, KeyValue, Permission, PersistenceTarget, RateCustomRankingParam, RatingInfo, RatingInfoWithSlot, RatingInitParamWithSlot}; +use rnex_core::rmc::protocols::datastore::{BufferQueueParam, CompletePostParam, DataStoreChangeMetaParam, DataStoreCustomRankingResult, DataStoreGetCustomRankingByDataIDParam, DataStorePrepareGetParam, DataStoreReqGetInfo, DataStoreSearchParam, GetMetaInfo, GetMetaParam, KeyValue, Permission, PersistenceTarget, RateCustomRankingParam, RatingInfo, RatingInfoWithSlot, RatingInitParamWithSlot}; use rnex_core::rmc::protocols::datastore::{DataStore, PreparePostParam, ReqPostInfo, AttachFileParam, DataStoreRateObjectParam, DataStoreRatingTarget}; use rnex_core::rmc::response::ErrorCode; use rnex_core::rmc::structures::qbuffer::QBuffer; @@ -66,6 +67,7 @@ fn map_row_to_meta_info( } } + pub async fn check_object_availability(data_id: u64, password: u64) -> Result<(), ErrorCode> { let row = sqlx::query!( r#" @@ -658,6 +660,31 @@ async fn rate_object(dataid: u64, slot: i8, rating_value: i32, access_password: Ok(rating) } +async fn change_meta_object_check(param: &DataStoreChangeMetaParam) -> Result<(), ErrorCode> { + let row = sqlx::query!( + r#" + SELECT update_password, under_review FROM datastore.objects WHERE data_id=$1 AND upload_completed=TRUE AND deleted=FALSE + "#, + param.dataid as i64 + ) + .fetch_one(get_db()) + .await + .map_err(|e| { + log::error!("DB Error: {:?}", e); + ErrorCode::DataStore_SystemFileError + })?; + + if row.update_password != 0 && row.update_password != param.update_password as i64 { + return Err(ErrorCode::DataStore_InvalidPassword); + } + + if row.under_review { + return Err(ErrorCode::DataStore_UnderReviewing); + } + + Ok(()) +} + impl DataStore for User { async fn get_meta(&self, metaparam: GetMetaParam) -> Result { let mut meta_info = if metaparam.dataid != 0 { @@ -1260,4 +1287,59 @@ impl DataStore for User { Ok((ratings, results)) } + + async fn change_meta(&self, param: DataStoreChangeMetaParam) -> Result<(), ErrorCode> { + let object_info = get_object_info_by_data_id(param.dataid, 0).await?; + verify_object_permission(object_info.owner, self.pid, &object_info.permission).await?; + + if param.modifies_flag & 0x08 != 0 { + change_meta_object_check(¶m).await?; + + sqlx::query!( + r#"UPDATE datastore.objects SET period=$1 WHERE data_id=$2"#, + param.period as i16, + param.dataid as i64 + ) + .execute(get_db()) + .await + .map_err(|e| { + eprintln!("update error: {:?}", e); + ErrorCode::DataStore_SystemFileError + })?; + } + + if param.modifies_flag & 0x10 != 0 { + change_meta_object_check(¶m).await?; + + sqlx::query!( + r#"UPDATE datastore.objects SET meta_binary=$1 WHERE data_id=$2"#, + param.meta_binary.0, + param.dataid as i64 + ) + .execute(get_db()) + .await + .map_err(|e| { + eprintln!("update error: {:?}", e); + ErrorCode::DataStore_SystemFileError + })?; + } + + if param.modifies_flag & 0x80 != 0 { + change_meta_object_check(¶m).await?; + + sqlx::query!( + r#"UPDATE datastore.objects SET data_type=$1 WHERE data_id=$2"#, + param.data_type as i16, + param.dataid as i64 + ) + .execute(get_db()) + .await + .map_err(|e| { + eprintln!("update error: {:?}", e); + ErrorCode::DataStore_SystemFileError + })?; + } + + Ok(()) + } } diff --git a/rnex-core/src/rmc/protocols/datastore.rs b/rnex-core/src/rmc/protocols/datastore.rs index 8a0d11d..5aac7c7 100644 --- a/rnex-core/src/rmc/protocols/datastore.rs +++ b/rnex-core/src/rmc/protocols/datastore.rs @@ -235,6 +235,39 @@ pub struct DataStoreRateObjectParam { pub access_password: u64, } +#[derive(RmcSerialize, Clone, Default, Debug)] +#[rmc_struct(0)] +pub struct DataStoreChangeMetaCompareParam { + pub comparison_flag: u32, + pub name: String, + pub permission: Permission, + pub del_permission: Permission, + pub period: u16, + pub meta_binary: QBuffer, + pub tags: Vec, + pub referred_cnt: u32, + pub data_type: u16, + pub status: u8, +} + +#[derive(RmcSerialize, Clone, Default, Debug)] +#[rmc_struct(0)] +pub struct DataStoreChangeMetaParam { + pub dataid: u64, + pub modifies_flag: u32, + pub name: String, + pub permission: Permission, + pub del_permission: Permission, + pub period: u16, + pub meta_binary: QBuffer, + pub tags: Vec, + pub update_password: u64, + pub referred_cnt: u32, + pub data_type: u16, + pub status: u8, + pub compare_param: DataStoreChangeMetaCompareParam, +} + #[rmc_proto(115)] pub trait DataStore { #[method_id(8)] @@ -285,6 +318,11 @@ pub trait DataStore { &self, application_id: u32, ) -> Result, ErrorCode>; + #[method_id(38)] + async fn change_meta( + &self, + param: DataStoreChangeMetaParam + ) -> Result<(), ErrorCode>; #[method_id(40)] async fn rate_objects( &self,