From 018509119ea1acbb8d2afd5b4145735a48c3f67a Mon Sep 17 00:00:00 2001 From: K97i <105120272+K97i@users.noreply.github.com> Date: Wed, 4 Nov 2026 00:16:44 +0800 Subject: [PATCH 1/3] Add upload endpoint health checks --- client/Monolith.cs | 54 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/client/Monolith.cs b/client/Monolith.cs index 3cb80c1..9a16525 100644 --- a/client/Monolith.cs +++ b/client/Monolith.cs @@ -41,6 +41,13 @@ public class Monolith public MonolithNetwork Network; public MonolithEvents Events; public string DebugLogText; + // Only entered the three domains I know exist :3 + // Sorted and ran through by priority - K97i + private static readonly string[] Domains = { + "https://spec-ify.com", + "https://specify.k97i.com", + "https://sfy.itz.sh" + }; public Monolith() { @@ -165,14 +172,49 @@ await DebugLog.LogFatalError( await DebugLog.StopDebugLog(); } + private static async Task GetViewer() + { + /* + * Simulates a POST reqeust to the upload endpoint for every domain + */ + + var client = new HttpClient(); + + foreach (var domain in Domains) + { + // If request fails... + try + { + using var request = new HttpRequestMessage(HttpMethod.Post, $"{domain}/upload.php"); + var response = await client.SendAsync(request); + + // We expect an HTTP 400 error from the endpoint complaining about the request not being `application/json` + // https://github.com/Spec-ify/specified/blob/main/upload.php#L12-L16 + if (response.StatusCode == HttpStatusCode.BadRequest) + { + // Immediately return first working domain + return domain; + } + } + + catch { + DebugLog.LogEventAsync($"{domain}'s upload endpoint is not up.", DebugLog.Region.Misc, DebugLog.EventType.WARNING); + } + } + + // Only reaches if no endpoint works + DebugLog.LogEventAsync("Upload endpoints of all default viewers are unavailable.", DebugLog.Region.Misc, DebugLog.EventType.ERROR); + return null; + } + private static async Task DoRequest(string str) { - // const string specifiedUploadDomain = "http://localhost"; - // const string specifiedUploadEndpoint = "specified/upload.php"; - const string specifiedUploadDomain = "https://spec-ify.com"; - const string specifiedUploadEndpoint = "upload.php"; + var specifiedUploadDomain = await GetViewer(); + // Default to file output when no viewers are available + if (specifiedUploadDomain == null) return null; + using var client = new HttpClient(); - using var request = new HttpRequestMessage(HttpMethod.Post, $"{specifiedUploadDomain}/{specifiedUploadEndpoint}"); + using var request = new HttpRequestMessage(HttpMethod.Post, $"{specifiedUploadDomain}/upload.php"); request.Content = new StringContent(str); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); @@ -186,7 +228,7 @@ private static async Task DoRequest(string str) await DebugLog.LogEventAsync($"Unsuccessful HTTP Response: {response.StatusCode}", DebugLog.Region.Misc, DebugLog.EventType.ERROR); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\nCould not upload. The file has been saved to specify_specs.json."); - Console.WriteLine($"Please go to {specifiedUploadDomain} to upload the file manually."); + Console.WriteLine("Please visit a Specify JSON viewer (like https://spec-ify.com) and upload the file manually."); return null; } var location = response.Headers.Location.ToString(); From cdd6e1ab71ecb5ef9b324a146e3bf24b20960426 Mon Sep 17 00:00:00 2001 From: K97i <105120272+K97i@users.noreply.github.com> Date: Wed, 4 Nov 2026 00:26:59 +0800 Subject: [PATCH 2/3] Fix github check, await errors --- client/Monolith.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/Monolith.cs b/client/Monolith.cs index 9a16525..1d88c30 100644 --- a/client/Monolith.cs +++ b/client/Monolith.cs @@ -177,9 +177,8 @@ private static async Task GetViewer() /* * Simulates a POST reqeust to the upload endpoint for every domain */ - - var client = new HttpClient(); + using var client = new HttpClient(); foreach (var domain in Domains) { // If request fails... @@ -198,12 +197,12 @@ private static async Task GetViewer() } catch { - DebugLog.LogEventAsync($"{domain}'s upload endpoint is not up.", DebugLog.Region.Misc, DebugLog.EventType.WARNING); + await DebugLog.LogEventAsync($"{domain}'s upload endpoint is not up.", DebugLog.Region.Misc, DebugLog.EventType.WARNING); } } // Only reaches if no endpoint works - DebugLog.LogEventAsync("Upload endpoints of all default viewers are unavailable.", DebugLog.Region.Misc, DebugLog.EventType.ERROR); + await DebugLog.LogEventAsync("Upload endpoints of all default viewers are unavailable.", DebugLog.Region.Misc, DebugLog.EventType.ERROR); return null; } From 61f90cd58e2e6de5288877b99b0db9c8640f08ee Mon Sep 17 00:00:00 2001 From: K97i <105120272+K97i@users.noreply.github.com> Date: Wed, 4 Nov 2026 00:57:06 +0800 Subject: [PATCH 3/3] Add non-400 edge case log --- client/Monolith.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/Monolith.cs b/client/Monolith.cs index 1d88c30..d41169f 100644 --- a/client/Monolith.cs +++ b/client/Monolith.cs @@ -194,6 +194,9 @@ private static async Task GetViewer() // Immediately return first working domain return domain; } + + // Edge case wherein it does not report 400 + await DebugLog.LogEventAsync($"{domain}'s upload endpoint does not have validity checks, assume it is not a viewer, or it is not safe.", DebugLog.Region.Misc, DebugLog.EventType.WARNING); } catch {