Skip to content

Commit

Permalink
🔧 Fixed some downloading issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanMCarter committed Dec 16, 2024
1 parent 9f2cf5a commit afa9e84
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using CarterGames.Standalone.NotionData.Filters;
using UnityEditor;
using UnityEngine;

Expand Down Expand Up @@ -158,8 +160,12 @@ private static void ProcessNextAsset()

NotionApiRequestHandler.ResetRequestData();

// var requestData = new NotionRequestData(asset, databaseId, assetObject.Fp("databaseApiKey").stringValue, assetObject.Fp("sortProperties").ToSortPropertyArray(), true);
// NotionApiRequestHandler.WebRequestPostWithAuth(requestData);
var filters = (NotionFilterContainer) assetObject.GetType().BaseType!
.GetField("filters", BindingFlags.NonPublic | BindingFlags.Instance)
!.GetValue(assetObject.targetObject);

var requestData = new NotionRequestData(asset, databaseId, assetObject.Fp("databaseApiKey").stringValue, assetObject.Fp("sortProperties").ToSortPropertyArray(), filters, true);
NotionApiRequestHandler.WebRequestPostWithAuth(requestData);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,7 @@ private void OnDataReceived(NotionRequestResult data)

private void OnErrorReceived(NotionRequestError error)
{
if (error.Message.Contains("Could not find sort property"))
{
EditorUtility.DisplayDialog("Notion Data Download", $"Download failed ({error.Error}):\n{error.Message}", "Continue");
}
else
{
EditorUtility.DisplayDialog("Notion Data Download", "Download failed, please see console for errors and try again", "Continue");
}

EditorUtility.DisplayDialog("Notion Data Download", $"Download failed ({error.Error}):\n{error.Message}", "Continue");

NotionApiRequestHandler.DataReceived.Remove(OnDataReceived);
NotionApiRequestHandler.RequestError.Remove(OnErrorReceived);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static void WebRequestPostWithAuth(NotionRequestData data)
/// <param name="bodyData">The body to send with the API call.</param>
public static void WebRequestPostWithAuth(NotionRequestData data, JSONObject bodyData)
{
var request = PrepareRequest(data.Url, data.ApiKey, bodyData, data.Sorts);
var request = PrepareRequest(data.Url, data.ApiKey, bodyData, data.Sorts, data.Filter);

AsyncOperation asyncOperation = request.SendWebRequest();

Expand Down Expand Up @@ -137,6 +137,7 @@ public static void WebRequestPostWithAuth(NotionRequestData data, JSONObject bod
/// <param name="url">The url to use.</param>
/// <param name="apiKey">The api key to use.</param>
/// <param name="sorts">The sort properties to apply.</param>
/// <param name="filters">The filter to apply.</param>
/// <returns>A prepared UnityWebRequest.</returns>
private static UnityWebRequest PrepareRequest(string url, string apiKey, NotionSortProperty[] sorts = null, NotionFilterContainer filters = null)
{
Expand Down Expand Up @@ -182,10 +183,22 @@ private static UnityWebRequest PrepareRequest(string url, string apiKey, NotionS
/// <param name="apiKey">The api key to use.</param>
/// <param name="body">The body to use in the API call.</param>
/// <param name="sorts">The sort properties to apply.</param>
/// <param name="filter">The filter to apply.</param>
/// <returns>A prepared UnityWebRequest.</returns>
private static UnityWebRequest PrepareRequest(string url, string apiKey, JSONObject body, NotionSortProperty[] sorts = null)
private static UnityWebRequest PrepareRequest(string url, string apiKey, JSONObject body, NotionSortProperty[] sorts = null, NotionFilterContainer filter = null)
{
body["sorts"] = sorts.ToJsonArray();
if (sorts != null)
{
if (sorts.Length > 0)
{
body["sorts"] = sorts.ToJsonArray();
}
}

if (filter != null)
{
body["filter"] = filter.ToFilterJson();
}

var request = UnityWebRequest.Put(url, body.ToString());

Expand Down

0 comments on commit afa9e84

Please sign in to comment.