Skip to content

Commit

Permalink
VNDB API HTTPS Changes: LogIn and ChangeVote
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltanar committed Apr 5, 2024
1 parent 18fc02b commit 434003c
Show file tree
Hide file tree
Showing 10 changed files with 843 additions and 714 deletions.
253 changes: 127 additions & 126 deletions Happy Reader/View/Tabs/SettingsTab.xaml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Happy Reader/View/Tabs/SettingsTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ private void LogInWithDetails(object sender, RoutedEventArgs e)
{
var password = LoadPassword();
var response = Conn.Login(password != null
? new VndbConnection.LoginCredentials(ClientName, ClientVersion, CSettings.Username, password)
: new VndbConnection.LoginCredentials(ClientName, ClientVersion), false);
? new VndbConnection.LoginCredentials(ClientName, ClientVersion, CSettings.Username, password, CSettings.ApiToken)
: new VndbConnection.LoginCredentials(ClientName, ClientVersion, null, null, CSettings.ApiToken), false);
LoginResponseBlock.Text = response;
}

Expand Down
8 changes: 4 additions & 4 deletions Happy Reader/ViewModel/DatabaseViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected void ChangeConnectionStatus(VndbConnection.APIStatus status)
{
Dispatcher.CurrentDispatcher.Invoke(() =>
{
if (status != VndbConnection.APIStatus.Ready) VndbConnectionStatus = $@"{status} ({StaticHelpers.Conn.ActiveQuery.ActionName})";
if (status != VndbConnection.APIStatus.Ready) VndbConnectionStatus = $@"{status} ({StaticHelpers.Conn.ActiveQuery?.ActionName})";
switch (status)
{
case VndbConnection.APIStatus.Ready:
Expand All @@ -152,13 +152,13 @@ protected void ChangeConnectionStatus(VndbConnection.APIStatus status)
VndbConnectionBackground = Theme.VndbConnectionReadyBackground;
break;
case VndbConnection.APIStatus.Busy:
StaticHelpers.Logger.Verbose($"{StaticHelpers.Conn.ActiveQuery.ActionName} Started");
StaticHelpers.Logger.Verbose($"{StaticHelpers.Conn.ActiveQuery?.ActionName} Started");
VndbConnectionForeground = Theme.VndbConnectionBusyForeground;
VndbConnectionBackground = Theme.VndbConnectionBusyBackground;
break;
case VndbConnection.APIStatus.Throttled:
StaticHelpers.Logger.Verbose($"{StaticHelpers.Conn.ActiveQuery.ActionName} Throttled");
VndbConnectionStatus = $@"{status} ({StaticHelpers.Conn.ActiveQuery.ActionName})";
StaticHelpers.Logger.Verbose($"{StaticHelpers.Conn.ActiveQuery?.ActionName} Throttled");
VndbConnectionStatus = $@"{status} ({StaticHelpers.Conn.ActiveQuery?.ActionName})";
VndbConnectionForeground = Theme.VndbConnectionThrottledForeground;
VndbConnectionBackground = Theme.VndbConnectionThrottledBackground;
break;
Expand Down
4 changes: 2 additions & 2 deletions Happy Reader/ViewModel/VNTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ await Task.Run(() =>
StaticHelpers.Conn = new VndbConnection(SetReplyText, MainViewModel.VndbAdvancedAction, AskForNonSsl, ChangeConnectionStatus);
var password = StaticHelpers.LoadPassword();
StaticHelpers.Conn.Login(password != null
? new VndbConnection.LoginCredentials(StaticHelpers.ClientName, StaticHelpers.ClientVersion, CSettings.Username, password)
: new VndbConnection.LoginCredentials(StaticHelpers.ClientName, StaticHelpers.ClientVersion), false);
? new VndbConnection.LoginCredentials(StaticHelpers.ClientName, StaticHelpers.ClientVersion, CSettings.Username, password, CSettings.ApiToken)
: new VndbConnection.LoginCredentials(StaticHelpers.ClientName, StaticHelpers.ClientVersion, null, null, CSettings.ApiToken), false);
});
MainViewModel.StatusText = "Loading VN List...";
SelectedFilterIndex = 0;
Expand Down
9 changes: 9 additions & 0 deletions HappySearchObjectClasses/API Objects/AuthInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// ReSharper disable once CheckNamespace
namespace Happy_Apps_Core.API_Objects;

public struct AuthInfo
{
public string Id { get; set; }
public string UserName { get; set; }
public string[] Permissions { get; set; }
}
39 changes: 39 additions & 0 deletions HappySearchObjectClasses/API Objects/UList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;

namespace Happy_Apps_Core.API_Objects;

public struct UList
{
private static JsonSerializerSettings _serializerSettings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };
public string User { get; set; }
public string Fields { get; set; }
public object[] Filters { get; set; }
public string Sort { get; set; }
public bool Reverse { get; set; }
public int Results { get; set; }

public string GetAsJson()
{
return JsonConvert.SerializeObject(this, _serializerSettings);
}
}

public struct UListPatch
{
private static JsonSerializerSettings _serializerSettings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int[] Labels_Unset { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int[] Labels_Set { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Include, PropertyName = "vote")]
public int? Vote { get; set; }


public string GetAsJson(bool includeVote)
{
//use JsonProperty values if we want to include vote when null (for removing vote), else, ignore all null values.
return JsonConvert.SerializeObject(this, includeVote ? null :_serializerSettings);
}
}
25 changes: 20 additions & 5 deletions HappySearchObjectClasses/CoreSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class CoreSettings : SettingsJsonFile
private string _imageFolderPath = Path.Combine(StaticHelpers.StoredDataFolder, "vndb-img\\");
private ImageSyncMode _imageSync = ImageSyncMode.None;
private string _secondaryTitleLanguage = "en";
private string _apiToken;

/// <summary>
/// Username of user.
Expand Down Expand Up @@ -40,12 +41,26 @@ public int UserID
_userID = value;
if (Loaded) Save();
}
}
}

/// <summary>
/// Date of last time that tag/trait dump files were downloaded.
/// </summary>
public DateTime DumpfileDate
/// <summary>
/// API Token for VNDB User
/// </summary>
public string ApiToken
{
get => _apiToken;
set
{
if (_apiToken == value) return;
_apiToken = value;
if (Loaded) Save();
}
}

/// <summary>
/// Date of last time that tag/trait dump files were downloaded.
/// </summary>
public DateTime DumpfileDate
{
get => _dumpfileDate;
set
Expand Down
2 changes: 2 additions & 0 deletions HappySearchObjectClasses/Happy_Apps_Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="API Objects\AuthInfo.cs" />
<Compile Include="API Objects\SubLevel\AnimeItem.cs" />
<Compile Include="API Objects\SubLevel\CharacterItem.cs" />
<Compile Include="API Objects\SubLevel\RelationsItem.cs" />
<Compile Include="API Objects\SubLevel\ScreenItem.cs" />
<Compile Include="API Objects\UList.cs" />
<Compile Include="DataAccess\DACollection.cs" />
<Compile Include="DataAccess\DAListCollection.cs" />
<Compile Include="DataAccess\IDataItem.cs" />
Expand Down
Loading

0 comments on commit 434003c

Please sign in to comment.