From afa9e84d58818923073e4c0cbabbe9dcf4da7af4 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 16 Dec 2024 19:41:29 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fixed=20some=20downloading=20iss?= =?UTF-8?q?ues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Auto Download All/DownloadAllHandler.cs | 10 ++++++++-- .../Inspectors/NotionDataAssetEditor.cs | 10 +--------- .../Notion Api/NotionApiRequestHandler.cs | 19 ++++++++++++++++--- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Carter Games/Notion Database To Unity/Code/Editor/Editors/Auto Download All/DownloadAllHandler.cs b/Carter Games/Notion Database To Unity/Code/Editor/Editors/Auto Download All/DownloadAllHandler.cs index c9ac1d9..39838fe 100644 --- a/Carter Games/Notion Database To Unity/Code/Editor/Editors/Auto Download All/DownloadAllHandler.cs +++ b/Carter Games/Notion Database To Unity/Code/Editor/Editors/Auto Download All/DownloadAllHandler.cs @@ -23,6 +23,8 @@ using System.Collections.Generic; using System.Linq; +using System.Reflection; +using CarterGames.Standalone.NotionData.Filters; using UnityEditor; using UnityEngine; @@ -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); } diff --git a/Carter Games/Notion Database To Unity/Code/Editor/Editors/Inspectors/NotionDataAssetEditor.cs b/Carter Games/Notion Database To Unity/Code/Editor/Editors/Inspectors/NotionDataAssetEditor.cs index 1c4ce95..21abfee 100644 --- a/Carter Games/Notion Database To Unity/Code/Editor/Editors/Inspectors/NotionDataAssetEditor.cs +++ b/Carter Games/Notion Database To Unity/Code/Editor/Editors/Inspectors/NotionDataAssetEditor.cs @@ -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); diff --git a/Carter Games/Notion Database To Unity/Code/Editor/Notion/Notion Api/NotionApiRequestHandler.cs b/Carter Games/Notion Database To Unity/Code/Editor/Notion/Notion Api/NotionApiRequestHandler.cs index 4656a41..45398b4 100644 --- a/Carter Games/Notion Database To Unity/Code/Editor/Notion/Notion Api/NotionApiRequestHandler.cs +++ b/Carter Games/Notion Database To Unity/Code/Editor/Notion/Notion Api/NotionApiRequestHandler.cs @@ -108,7 +108,7 @@ public static void WebRequestPostWithAuth(NotionRequestData data) /// The body to send with the API call. 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(); @@ -137,6 +137,7 @@ public static void WebRequestPostWithAuth(NotionRequestData data, JSONObject bod /// The url to use. /// The api key to use. /// The sort properties to apply. + /// The filter to apply. /// A prepared UnityWebRequest. private static UnityWebRequest PrepareRequest(string url, string apiKey, NotionSortProperty[] sorts = null, NotionFilterContainer filters = null) { @@ -182,10 +183,22 @@ private static UnityWebRequest PrepareRequest(string url, string apiKey, NotionS /// The api key to use. /// The body to use in the API call. /// The sort properties to apply. + /// The filter to apply. /// A prepared UnityWebRequest. - 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());