Skip to content

Commit

Permalink
perf: Filtering empty data in the configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ZGGSONG committed Mar 4, 2024
1 parent cbd4078 commit e8c588b
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 6 deletions.
10 changes: 9 additions & 1 deletion STranslate/ViewModels/Preference/Services/TranslatorAli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using STranslate.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -60,14 +61,20 @@ public TranslatorAli(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand Down Expand Up @@ -120,6 +127,7 @@ private void ShowEncryptInfo(string? obj)
* @return Client
* @throws Exception
*/

public static Client CreateClient(string accessKeyId, string accessKeySecret, string url)
{
if (url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -175,4 +183,4 @@ public Task TranslateAsync(object request, Action<string> OnDataReceived, Cancel
throw new NotImplementedException();
}
}
}
}
10 changes: 9 additions & 1 deletion STranslate/ViewModels/Preference/Services/TranslatorApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using STranslate.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -57,14 +58,20 @@ public TranslatorApi(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand All @@ -76,7 +83,8 @@ public TranslatorApi(
public List<IconType> Icons { get; private set; } = Enum.GetValues(typeof(IconType)).OfType<IconType>().ToList();

[JsonIgnore]
public string Tips { get; set; } = @"请求:
public string Tips { get; set; } =
@"请求:
{
""text"": ""test"",
""source_lang"": ""auto"",
Expand Down
7 changes: 7 additions & 0 deletions STranslate/ViewModels/Preference/Services/TranslatorBaidu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using STranslate.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -58,14 +59,20 @@ public TranslatorBaidu(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand Down
12 changes: 8 additions & 4 deletions STranslate/ViewModels/Preference/Services/TranslatorCaiyun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using STranslate.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -59,14 +60,20 @@ public TranslatorCaiyun(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand Down Expand Up @@ -123,10 +130,7 @@ public async Task<TranslationResult> TranslateAsync(object request, Cancellation
detect = true
};

var headers = new Dictionary<string, string>
{
{ "X-Authorization", $"token {AppKey}" },
};
var headers = new Dictionary<string, string> { { "X-Authorization", $"token {AppKey}" }, };

string resp = await HttpUtil.PostAsync(Url, JsonConvert.SerializeObject(body), null, headers, token);
if (string.IsNullOrEmpty(resp))
Expand Down
9 changes: 9 additions & 0 deletions STranslate/ViewModels/Preference/Services/TranslatorEcdict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using STranslate.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Net.Http;
Expand Down Expand Up @@ -68,14 +69,20 @@ public TranslatorEcdict(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand Down Expand Up @@ -147,6 +154,7 @@ private void ShowEncryptInfo(string? obj)
private string _dbFileSize = "";

[RelayCommand]
[property: JsonIgnore]
private async Task DownloadResource()
{
ProcessValue = 0;
Expand Down Expand Up @@ -223,6 +231,7 @@ private void ProcessDownloadedFile()
}

[RelayCommand]
[property: JsonIgnore]
private void DeleteResource()
{
try
Expand Down
7 changes: 7 additions & 0 deletions STranslate/ViewModels/Preference/Services/TranslatorGemini.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using STranslate.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -59,14 +60,20 @@ public TranslatorGemini(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using STranslate.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -58,14 +59,20 @@ public TranslatorMicrosoft(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using STranslate.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -59,14 +60,20 @@ public TranslatorNiutrans(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand Down
9 changes: 9 additions & 0 deletions STranslate/ViewModels/Preference/Services/TranslatorOpenAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using STranslate.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -59,18 +60,26 @@ public TranslatorOpenAI(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
private string _model = "gpt-3.5-turbo";

[JsonIgnore]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using STranslate.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -60,14 +61,20 @@ public TranslatorSTranslate(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using STranslate.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -62,14 +63,20 @@ public TranslatorTencent(

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _url = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _AppID = string.Empty;

[JsonIgnore]
[ObservableProperty]
[property: DefaultValue("")]
[property: JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string _appKey = string.Empty;

[JsonIgnore]
Expand Down
Loading

0 comments on commit e8c588b

Please sign in to comment.