v0.2.32 - Made user-settings recall resilient and backfill missing didactyl admin_pubkey/dm_protocol on republish
This commit is contained in:
+19
-14
@@ -1019,7 +1019,7 @@ static int apply_recalled_user_settings_wizard(didactyl_config_t* cfg, const cha
|
||||
|
||||
cJSON* global_llm = cJSON_GetObjectItemCaseSensitive(root, "global_llm");
|
||||
cJSON* didactyl = cJSON_GetObjectItemCaseSensitive(root, "didactyl");
|
||||
if (!global_llm || !cJSON_IsObject(global_llm) || !didactyl || !cJSON_IsObject(didactyl)) {
|
||||
if (!global_llm || !cJSON_IsObject(global_llm)) {
|
||||
cJSON_Delete(root);
|
||||
return -1;
|
||||
}
|
||||
@@ -1031,15 +1031,18 @@ static int apply_recalled_user_settings_wizard(didactyl_config_t* cfg, const cha
|
||||
cJSON* max_tokens = cJSON_GetObjectItemCaseSensitive(global_llm, "max_tokens");
|
||||
cJSON* temperature = cJSON_GetObjectItemCaseSensitive(global_llm, "temperature");
|
||||
|
||||
cJSON* admin_pubkey = cJSON_GetObjectItemCaseSensitive(didactyl, "admin_pubkey");
|
||||
cJSON* dm_protocol = cJSON_GetObjectItemCaseSensitive(didactyl, "dm_protocol");
|
||||
cJSON* max_turns = cJSON_GetObjectItemCaseSensitive(didactyl, "max_turns");
|
||||
cJSON* admin_pubkey = NULL;
|
||||
cJSON* dm_protocol = NULL;
|
||||
cJSON* max_turns = NULL;
|
||||
if (didactyl && cJSON_IsObject(didactyl)) {
|
||||
admin_pubkey = cJSON_GetObjectItemCaseSensitive(didactyl, "admin_pubkey");
|
||||
dm_protocol = cJSON_GetObjectItemCaseSensitive(didactyl, "dm_protocol");
|
||||
max_turns = cJSON_GetObjectItemCaseSensitive(didactyl, "max_turns");
|
||||
}
|
||||
|
||||
if (!api_key || !cJSON_IsString(api_key) || !api_key->valuestring || api_key->valuestring[0] == '\0' ||
|
||||
!model || !cJSON_IsString(model) || !model->valuestring || model->valuestring[0] == '\0' ||
|
||||
!base_url || !cJSON_IsString(base_url) || !base_url->valuestring || base_url->valuestring[0] == '\0' ||
|
||||
!admin_pubkey || !cJSON_IsString(admin_pubkey) || !admin_pubkey->valuestring || admin_pubkey->valuestring[0] == '\0' ||
|
||||
!dm_protocol || !cJSON_IsString(dm_protocol) || !dm_protocol->valuestring || dm_protocol->valuestring[0] == '\0') {
|
||||
!base_url || !cJSON_IsString(base_url) || !base_url->valuestring || base_url->valuestring[0] == '\0') {
|
||||
cJSON_Delete(root);
|
||||
return -1;
|
||||
}
|
||||
@@ -1060,7 +1063,7 @@ static int apply_recalled_user_settings_wizard(didactyl_config_t* cfg, const cha
|
||||
cfg->llm.temperature = temperature->valuedouble;
|
||||
}
|
||||
|
||||
{
|
||||
if (admin_pubkey && cJSON_IsString(admin_pubkey) && admin_pubkey->valuestring && admin_pubkey->valuestring[0] != '\0') {
|
||||
char decoded[65] = {0};
|
||||
if (decode_pubkey_hex_or_npub_local(admin_pubkey->valuestring, decoded) != 0) {
|
||||
cJSON_Delete(root);
|
||||
@@ -1069,12 +1072,14 @@ static int apply_recalled_user_settings_wizard(didactyl_config_t* cfg, const cha
|
||||
snprintf(cfg->admin.pubkey, sizeof(cfg->admin.pubkey), "%s", decoded);
|
||||
}
|
||||
|
||||
if (strcmp(dm_protocol->valuestring, "nip17") == 0) {
|
||||
cfg->dm_protocol = DM_PROTOCOL_NIP17;
|
||||
} else if (strcmp(dm_protocol->valuestring, "both") == 0) {
|
||||
cfg->dm_protocol = DM_PROTOCOL_BOTH;
|
||||
} else {
|
||||
cfg->dm_protocol = DM_PROTOCOL_NIP04;
|
||||
if (dm_protocol && cJSON_IsString(dm_protocol) && dm_protocol->valuestring && dm_protocol->valuestring[0] != '\0') {
|
||||
if (strcmp(dm_protocol->valuestring, "nip17") == 0) {
|
||||
cfg->dm_protocol = DM_PROTOCOL_NIP17;
|
||||
} else if (strcmp(dm_protocol->valuestring, "both") == 0) {
|
||||
cfg->dm_protocol = DM_PROTOCOL_BOTH;
|
||||
} else {
|
||||
cfg->dm_protocol = DM_PROTOCOL_NIP04;
|
||||
}
|
||||
}
|
||||
|
||||
if (max_turns && cJSON_IsNumber(max_turns)) {
|
||||
|
||||
Reference in New Issue
Block a user