2export async function importFile(path: string) {
3 const url = new URL(path, import.meta.url);
4 const res = await fetch(url, { redirect: "follow" });
5 if (!res.ok) return null;
6 return await res.text();
20
21 try {
22 const response = await fetch("/chat", {
23 method: "POST",
24 headers: { "Content-Type": "application/json" },
57
58 useEffect(() => {
59 fetchState();
60 }, []);
61
62 /**
63 * Fetches the current state from the server
64 */
65 const fetchState = async () => {
66 setIsLoading(true);
67 setError(null);
68 try {
69 const response = await fetch("/api/state");
70 if (!response.ok) throw new Error("Failed to fetch state");
71 const data = await response.json();
72 setState(data);
86 setError(null);
87 try {
88 const response = await fetch("/api/state", {
89 method: "POST",
90 headers: { "Content-Type": "application/json" },
92 });
93 if (!response.ok) throw new Error("Failed to update state");
94 await fetchState();
95 } catch (err) {
96 setError(err.message);
546 if (webhookUrl) {
547 try {
548 await fetch(webhookUrl, {
549 method: "POST",
550 headers: { "Content-Type": "application/json" },
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
62
63 useEffect(() => {
64 const fetchYCCompanies = async () => {
65 const storedCompanies = localStorage.getItem("ycCompanies");
66 if (storedCompanies) {
69 setDebugInfo(prevInfo => prevInfo + `\nLoaded ${companies.length} companies from localStorage`);
70 } else {
71 const response = await fetch("/companies.json");
72 const companies = await response.json();
73 setYcCompanies(companies);
74 localStorage.setItem("ycCompanies", JSON.stringify(companies));
75 setDebugInfo(prevInfo =>
76 prevInfo + `\nFetched ${companies.length} companies from server and stored in localStorage`
77 );
78 }
79 };
80 fetchYCCompanies();
81 }, []);
82
226
227export default async function server(request: Request): Promise<Response> {
228 const companies = await fetch("https://stevekrouse-yc_database.web.val.run").then(res => res.json());
229 const url = new URL(request.url);
230 if (url.pathname === "/companies.json") {
51
52 useEffect(() => {
53 fetchState();
54 }, []);
55
56 /**
57 * Fetches the current state from the server
58 */
59 const fetchState = async () => {
60 setIsLoading(true);
61 setError(null);
62 try {
63 const response = await fetch("/api/state");
64 if (!response.ok) throw new Error("Failed to fetch state");
65 const data = await response.json();
66 setState(data);
80 setError(null);
81 try {
82 const response = await fetch("/api/state", {
83 method: "POST",
84 headers: { "Content-Type": "application/json" },
86 });
87 if (!response.ok) throw new Error("Failed to update state");
88 await fetchState();
89 } catch (err) {
90 setError(err.message);
565 if (webhookUrl) {
566 try {
567 await fetch(webhookUrl, {
568 method: "POST",
569 headers: { "Content-Type": "application/json" },
192// https://discord.com/developers/docs/topics/rate-limits
193async function sendWithRateLimit(url: string, init: RequestInit): Promise<Response> {
194 const resp = await fetch(url + "?wait=true", init);
195 if (resp.status === 429) {
196 const retryAfter = resp.headers.get("Retry-After");
7countPath(app);
8
9export default app.fetch;