fix(sync): send Gitee snippet files as JSON object
This commit is contained in:
1 parent
72880d2933
commit
968d4488a6
1 file changed
+24
-14
@@ -499,15 +499,9 @@ impl SnippetSyncClient {
|
|||||||
self.request(method, &url)?.json(&payload).send().await
|
self.request(method, &url)?.json(&payload).send().await
|
||||||
}
|
}
|
||||||
SnippetProvider::Gitee => {
|
SnippetProvider::Gitee => {
|
||||||
let files = serde_json::json!({ DEFAULT_SNIPPET_FILE_NAME: { "content": content } }).to_string();
|
let payload = gitee_snippet_payload(content);
|
||||||
self.request(method, &url)?
|
// Gitee validates `files` as a nested object; form encoding turns it into a string and is rejected.
|
||||||
.form(&[
|
self.request(method, &url)?.json(&payload).send().await
|
||||||
("files", files),
|
|
||||||
("description", "DBX configuration sync".to_string()),
|
|
||||||
("public", "false".to_string()),
|
|
||||||
])
|
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?;
|
||||||
@@ -959,6 +953,14 @@ fn snippet_response_id(value: &serde_json::Value) -> Option<String> {
|
|||||||
value.as_array()?.first()?.get("id")?.as_str().map(str::to_string)
|
value.as_array()?.first()?.get("id")?.as_str().map(str::to_string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gitee_snippet_payload(content: String) -> serde_json::Value {
|
||||||
|
serde_json::json!({
|
||||||
|
"description": "DBX configuration sync",
|
||||||
|
"public": false,
|
||||||
|
"files": { DEFAULT_SNIPPET_FILE_NAME: { "content": content } }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn snippet_file_content(
|
fn snippet_file_content(
|
||||||
value: &serde_json::Value,
|
value: &serde_json::Value,
|
||||||
file_name: &str,
|
file_name: &str,
|
||||||
@@ -1020,11 +1022,10 @@ fn parent_collection_paths(remote_path: &str) -> Vec<String> {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
apply_sync_snapshot, build_sync_snapshot, build_sync_snapshot_with_saved_secrets, decrypt_sensitive_payload,
|
apply_sync_snapshot, build_sync_snapshot, build_sync_snapshot_with_saved_secrets, decrypt_sensitive_payload,
|
||||||
encrypt_sensitive_payload, forget_webdav_sync_secrets_passphrase, normalized_remote_path,
|
encrypt_sensitive_payload, forget_webdav_sync_secrets_passphrase, gitee_snippet_payload,
|
||||||
parent_collection_paths, resolve_webdav_sync_secrets_passphrase, save_webdav_sync_secrets_preference,
|
normalized_remote_path, parent_collection_paths, resolve_webdav_sync_secrets_passphrase,
|
||||||
scrub_connection_secrets, snippet_file_content, snippet_response_id, webdav_sync_secrets_status,
|
save_webdav_sync_secrets_preference, scrub_connection_secrets, snippet_file_content, snippet_response_id,
|
||||||
ApplySnapshotOptions, ConnectionSecretSnapshot,
|
webdav_sync_secrets_status, ApplySnapshotOptions, ConnectionSecretSnapshot, SensitiveSyncPayload,
|
||||||
SensitiveSyncPayload,
|
|
||||||
};
|
};
|
||||||
use crate::connection_secrets::NACOS_AUTH_PASSWORD_KEY;
|
use crate::connection_secrets::NACOS_AUTH_PASSWORD_KEY;
|
||||||
use crate::models::connection::{
|
use crate::models::connection::{
|
||||||
@@ -1036,6 +1037,15 @@ mod tests {
|
|||||||
std::env::temp_dir().join(format!("dbx-cloud-sync-{name}-{}.db", uuid::Uuid::new_v4()))
|
std::env::temp_dir().join(format!("dbx-cloud-sync-{name}-{}.db", uuid::Uuid::new_v4()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn gitee_snippet_payload_keeps_files_as_nested_object() {
|
||||||
|
let payload = gitee_snippet_payload("snapshot".to_string());
|
||||||
|
|
||||||
|
assert_eq!(payload["files"]["dbx-sync.json"]["content"], "snapshot");
|
||||||
|
assert!(payload["files"].is_object());
|
||||||
|
assert_eq!(payload["public"], false);
|
||||||
|
}
|
||||||
|
|
||||||
fn postgres_connection(id: &str, password: &str) -> ConnectionConfig {
|
fn postgres_connection(id: &str, password: &str) -> ConnectionConfig {
|
||||||
ConnectionConfig {
|
ConnectionConfig {
|
||||||
id: id.to_string(),
|
id: id.to_string(),
|
||||||
|
|||||||
Reference in new issue
Block a user