Initial aishare service
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
export function validateChatGptShareUrl(raw: string): string {
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(raw);
|
||||
} catch {
|
||||
throw new Error("Enter a valid public ChatGPT share URL.");
|
||||
}
|
||||
|
||||
if (url.protocol !== "https:") {
|
||||
throw new Error("Only HTTPS ChatGPT share URLs are accepted.");
|
||||
}
|
||||
|
||||
const host = url.hostname.toLowerCase();
|
||||
const allowedHost = host === "chatgpt.com" || host === "chat.openai.com";
|
||||
if (!allowedHost || !url.pathname.startsWith("/share/")) {
|
||||
throw new Error("Only public ChatGPT share URLs under /share/ are accepted.");
|
||||
}
|
||||
|
||||
url.hash = "";
|
||||
return url.toString();
|
||||
}
|
||||
Reference in New Issue
Block a user