Update PR

* Update PR
This commit is contained in:
abraunegg 2025-09-26 09:08:37 +10:00
commit b1e86783ed
2 changed files with 1 additions and 67 deletions

View file

@ -1130,6 +1130,7 @@ class OneDriveApi {
// Obtain the Websocket Notification URL
JSONValue obtainWebSocketNotificationURL() {
addLogEntry("Request a Socket.IO Subscription Endpoint: " ~ websocketEndpoint);
return get(websocketEndpoint);
}

View file

@ -1900,70 +1900,3 @@ void displayFunctionProcessingTime(string functionName, SysTime functionStartTim
string processingTime = format("[%s] Application Function '%s' Processing Time = %.4f Seconds", strip(logKey), strip(functionName), functionDurationAsSeconds);
addLogEntry(processingTime);
}
// Convert the Graph notificationUrl into a socket.io WS endpoint:
// https://host/...?... -> wss://host/socket.io/?EIO=4&transport=websocket&...
string toSocketIoWsUrl(string notificationUrl) {
// DEBUG REMOVE LATER
addLogEntry("Input URL to toSocketIoWsUrl: " ~ notificationUrl);
// ---- scheme ----
auto iScheme = notificationUrl.countUntil("://");
if (iScheme == notificationUrl.length) return notificationUrl; // fallback (malformed input)
auto scheme = notificationUrl[0 .. iScheme];
auto rest = notificationUrl[iScheme + 3 .. $]; // after "://"
// ---- authority + path+query ----
// authority ends at first '/' or '?' (whichever comes first)
auto iSlash = rest.countUntil("/");
auto iQmark = rest.countUntil("?");
size_t cut;
if (iSlash == rest.length && iQmark == rest.length) {
cut = rest.length;
} else if (iSlash == rest.length) {
cut = iQmark;
} else if (iQmark == rest.length) {
cut = iSlash;
} else {
cut = (iSlash < iQmark) ? iSlash : iQmark;
}
auto authority = rest[0 .. cut];
auto pathQuery = rest[cut .. $]; // may be "", starts with "/" or "?"
// ---- extract original query (ignore original path; we force /socket.io/) ----
string query;
auto iq = pathQuery.countUntil("?");
if (iq != pathQuery.length) {
query = pathQuery[iq + 1 .. $]; // after '?'
} else {
query = "";
}
// ---- scheme map ----
string wsScheme = (scheme == "https") ? "wss" : (scheme == "http" ? "ws" : scheme);
// ---- keep all original params EXCEPT EIO and transport; well set them explicitly ----
string[] kept;
if (query.length) {
foreach (p; query.split("&")) {
if (p.length == 0) continue;
if (p.startsWith("EIO=")) continue;
if (p.startsWith("transport=")) continue;
kept ~= p;
}
}
// ---- final query: required first, then preserved params ----
string finalQuery = "EIO=4&transport=websocket";
if (kept.length) finalQuery ~= "&" ~ kept.join("&");
string resultURL = wsScheme ~ "://" ~ authority ~ "/socket.io/?" ~ finalQuery;
addLogEntry("Output URL from toSocketIoWsUrl: " ~ resultURL);
// ---- build final URL ----
return resultURL;
}