Minor cleanup of unused playlist owner detection
This commit is contained in:
parent
7301c10aa9
commit
f9a0e1669f
@ -7,11 +7,6 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BeatSaberPlaylistsLib.Types;
|
using BeatSaberPlaylistsLib.Types;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
#if false
|
|
||||||
using BeatLeader.Utils;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using UnityEngine.Networking;
|
|
||||||
#endif
|
|
||||||
using IPALogger = IPA.Logging.Logger;
|
using IPALogger = IPA.Logging.Logger;
|
||||||
|
|
||||||
namespace Setlist
|
namespace Setlist
|
||||||
@ -242,120 +237,6 @@ namespace Setlist
|
|||||||
|
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SETLIST: Remove the entire #if false region below once we no longer need the old
|
|
||||||
// BeatLeader GET /user/playlists + login-wait verification path for reference.
|
|
||||||
|
|
||||||
#if false
|
|
||||||
private const string AuthenticationTypeName = "BeatLeader.API.Authentication";
|
|
||||||
private const string SignedInFieldName = "_signedIn";
|
|
||||||
private const float LoginWaitTimeoutSeconds = 90f;
|
|
||||||
private const int RequestTimeoutSeconds = 30;
|
|
||||||
|
|
||||||
private sealed class UserPlaylistSummary
|
|
||||||
{
|
|
||||||
[JsonProperty("guid")]
|
|
||||||
public string Guid { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private struct FetchResult
|
|
||||||
{
|
|
||||||
public HashSet<string> OwnedGuids;
|
|
||||||
public string Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator FetchOwnedGuids(Action<FetchResult> onDone)
|
|
||||||
{
|
|
||||||
var url = BLConstants.BEATLEADER_API_URL + "/user/playlists";
|
|
||||||
using (var request = UnityWebRequest.Get(url))
|
|
||||||
{
|
|
||||||
request.timeout = RequestTimeoutSeconds;
|
|
||||||
request.SetRequestHeader("User-Agent", "Setlist/" + GetAssemblyVersion());
|
|
||||||
|
|
||||||
yield return request.SendWebRequest();
|
|
||||||
|
|
||||||
if (request.result == UnityWebRequest.Result.ConnectionError)
|
|
||||||
{
|
|
||||||
onDone(new FetchResult { Failure = "network error: " + request.error });
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.result == UnityWebRequest.Result.ProtocolError)
|
|
||||||
{
|
|
||||||
onDone(new FetchResult
|
|
||||||
{
|
|
||||||
Failure = $"HTTP {request.responseCode} (cookie session not shared? "
|
|
||||||
+ "check BeatLeader login completed)",
|
|
||||||
});
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var body = request.downloadHandler != null ? request.downloadHandler.text : null;
|
|
||||||
if (string.IsNullOrEmpty(body))
|
|
||||||
{
|
|
||||||
onDone(new FetchResult { OwnedGuids = new HashSet<string>(StringComparer.OrdinalIgnoreCase) });
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
HashSet<string> set;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var summaries = JsonConvert.DeserializeObject<List<UserPlaylistSummary>>(body);
|
|
||||||
set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
if (summaries != null)
|
|
||||||
{
|
|
||||||
foreach (var s in summaries)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrEmpty(s?.Guid))
|
|
||||||
{
|
|
||||||
set.Add(s.Guid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
onDone(new FetchResult { Failure = "JSON parse failed: " + ex.Message });
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
onDone(new FetchResult { OwnedGuids = set });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static FieldInfo ResolveSignedInField(IPALogger log)
|
|
||||||
{
|
|
||||||
var beatLeaderAssembly = typeof(BLConstants).Assembly;
|
|
||||||
var authType = beatLeaderAssembly.GetType(AuthenticationTypeName);
|
|
||||||
if (authType == null)
|
|
||||||
{
|
|
||||||
log.Info($"BeatLeader assembly has no {AuthenticationTypeName} type; cannot detect login state.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var field = authType.GetField(SignedInFieldName, BindingFlags.NonPublic | BindingFlags.Static);
|
|
||||||
if (field == null)
|
|
||||||
{
|
|
||||||
log.Info($"{AuthenticationTypeName} has no static field '{SignedInFieldName}'; "
|
|
||||||
+ "BeatLeader may have changed its API.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return field;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool IsSignedIn(FieldInfo signedInField)
|
|
||||||
{
|
|
||||||
var value = signedInField.GetValue(null);
|
|
||||||
return value is bool b && b;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string GetAssemblyVersion()
|
|
||||||
{
|
|
||||||
var asm = typeof(BeatLeaderPlaylistOwnership).Assembly;
|
|
||||||
return asm.GetName().Version?.ToString() ?? "0.0.0";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
[assembly: Guid("50F53E6E-21D5-4780-8E67-273877DAA28C")]
|
[assembly: Guid("50F53E6E-21D5-4780-8E67-273877DAA28C")]
|
||||||
[assembly: AssemblyVersion("0.0.7.0")]
|
[assembly: AssemblyVersion("0.0.8.0")]
|
||||||
[assembly: AssemblyFileVersion("0.0.7.0")]
|
[assembly: AssemblyFileVersion("0.0.8.0")]
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
"id": "Setlist",
|
"id": "Setlist",
|
||||||
"name": "Setlist",
|
"name": "Setlist",
|
||||||
"author": "",
|
"author": "",
|
||||||
"version": "0.0.7",
|
"version": "0.0.8",
|
||||||
"description": "Syncs playlists with external sources.",
|
"description": "Syncs playlists with external sources.",
|
||||||
"gameVersion": "1.40.8",
|
"gameVersion": "1.40.8",
|
||||||
"dependsOn": {
|
"dependsOn": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user