Skip to content
27 changes: 21 additions & 6 deletions Editor/Resources/Builder/BuilderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,8 @@ public IEnumerator Json<T>(string url, Action<T> callback)
yield return uwr.SendWebRequest();
if (uwr.result != UnityWebRequest.Result.Success)
{
throw new System.Exception(uwr.error);
string errorMsg = $"HTTP/{uwr.responseCode}: {uwr.error}";
throw new System.Exception(errorMsg);
}
else
{
Expand All @@ -1218,7 +1219,8 @@ public IEnumerator Json<T>(string url, T postData, Action<string> callback, Dict
if (uwr.result != UnityWebRequest.Result.Success)
{
Debug.LogError(url + ":" + JsonUtility.ToJson(postData));
throw new System.Exception(uwr.error);
string errorMsg = $"HTTP/{uwr.responseCode}: {uwr.error}";
throw new System.Exception(errorMsg);
}
else
{
Expand Down Expand Up @@ -1323,15 +1325,28 @@ private IEnumerator UploadAvatar(Action callback)
{
status.AddStatus("Posted avatar successfully.");
Debug.Log("Posted avatar successfully.");
callback();
selectedExistingAvatar = av;
SetupExistingAvatars();
EditorCoroutineUtility.StartCoroutine(sq.AttachAvatar((slot) =>
{
status.AddStatus("Avatar attached successfully.");
Debug.Log("Avatar attached successfully.");
callback();
EditorCoroutineUtility.StartCoroutine(sq.SelectAvatar(() => { }, Debug.LogException, slot.UserAvatarId), this);
Debug.Log("Avatar attached successfully.");
if (slot == null)
{
status.AddStatus("Failed to select avatar: attach response was empty.");
Debug.LogError("Failed to select avatar: attach response was empty.");
callback();
return;
}
EditorCoroutineUtility.StartCoroutine(sq.SelectAvatar(() =>
{
callback();
}, e =>
{
status.AddStatus("Failed to select avatar: " + e);
Debug.LogError("Failed to select avatar: " + e);
callback();
}, slot.UserAvatarId), this);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}, e =>
{
status.AddStatus("Failed to attach avatar: " + e);
Expand Down
27 changes: 24 additions & 3 deletions Editor/Resources/Builder/SideQuest/SqEditorAppApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -95,7 +95,7 @@ public IEnumerator UpdateAvatar(Action<SqEditorAvatar> OnCompleted, Action<Excep
yield return JsonPost<SqEditorAvatar>($"/v2/avatars/{avatarId}", new SqEditorAvatar() { HighId = highId, LowId = lowId, PreviewImage = screenshotId, Public = ispublic, Version = 2, Name = name}, (av) =>
{
OnCompleted?.Invoke(av);
}, OnError, true, false, "PATCH");
}, OnError, true, false, "PUT");
}
public IEnumerator GetAvatars(Action<List<SqEditorAvatar>> OnCompleted, Action<Exception> OnError)
{
Expand Down Expand Up @@ -126,7 +126,7 @@ public IEnumerator SelectAvatar(Action OnCompleted, Action<Exception> OnError, l
yield return JsonPost<SqAvatarSlot>($"/v2/users/me/avatars/{userAvatarId}", new SqAvatarSlotSelect() { IsSelected = true}, (u) =>
{
OnCompleted?.Invoke();
}, OnError, true, false,"PATCH");
}, OnError, true, false);
}
/// <summary>
/// Get a list of the currently logged in sidequest user's achievements
Expand Down Expand Up @@ -533,6 +533,7 @@ private async Task<long> UploadFileWithRetryAsync(string url, byte[] data, strin
using (var request = new HttpRequestMessage(HttpMethod.Put, url))
{
request.Content = content;
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(GetMimeType(name));

// Set timeout for this specific request
using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5)))
Expand Down Expand Up @@ -891,6 +892,26 @@ private void LoadData()
}
}

private string GetMimeType(string fileName)
{
var ext = Path.GetExtension(fileName)?.ToLower();
switch (ext)
{
case ".html": return "text/html";
case ".js": return "application/javascript";
case ".glb": return "model/gltf-binary";
case ".gltf": return "model/gltf+json";
case ".png": return "image/png";
case ".jpg":
case ".jpeg": return "image/jpeg";
case ".gif": return "image/gif";
case ".zip": return "application/zip";
case ".json": return "application/json";
case ".txt": return "text/plain";
default: return "application/octet-stream";
}
}

private void SaveData()
{
File.WriteAllText(Config.DataFile, JsonConvert.SerializeObject(Data));
Expand Down
5 changes: 4 additions & 1 deletion Editor/Resources/Builder/SideQuest/SqEditorModels.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -492,6 +492,9 @@ public class SqAvatarSlot

[JsonProperty("is_selected")]
public bool IsSelected { get; set; }

[JsonProperty("is_public", NullValueHandling = NullValueHandling.Ignore)]
public bool? IsPublic { get; set; }
}

public class SqAvatarSlotSelect
Expand Down