33
34 // Post the message so we can deal with large text data.
35 await fetch(`/post-message?threadId=${input.getAttribute("data-thread-id")}`, {
36 method: "post",
37 body: msgDiv.textContent,
147 return new Response(body, { headers: { "Content-Type": "text/event-stream" } });
148});
149export default app.fetch;
32 // Post the message so we can deal with large text data.
33 try {
34 await fetch(`/post-message?threadId=${input.getAttribute("data-thread-id")}`, {
35 method: "post",
36 body: msgDiv.textContent,
169});
170
171export default app.fetch;
133 return new Response(body, { headers: { "Content-Type": "text/event-stream" } });
134});
135export default app.fetch;
133 return new Response(body, { headers: { "Content-Type": "text/event-stream" } });
134});
135export default app.fetch;
133 return new Response(body, { headers: { "Content-Type": "text/event-stream" } });
134});
135export default app.fetch;
1import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
2
3const EMOJI_DATA_URL = "https://unicode.org/Public/emoji/15.1/emoji-zwj-sequences.txt";
4
5export async function getCompoundEmojis(): Promise<string[]> {
6 const data = await fetchText(EMOJI_DATA_URL);
7 let result: string[] = [];
8 const lines = data.split("\n");
12 }
13 url = "https://r.jina.ai/" + url
14 const response = await fetch(url);
15 if (!response.ok) {
16 throw new Error(`HTTP error! Status: ${response.status}`);
19 return data;
20 } catch (error) {
21 console.error('Error fetching the URL:', error);
22 return 'Error fetching the content.';
23 }
24};
129});
130
131export default app.fetch;
132
10const gitHubAPI = new GitHubAPI(GITHUB_TOKEN);
11
12async function fetchVals() {
13 const response = await valTownAPI.getAllVals();
14 return response.data;
16
17async function getExistingFiles() {
18 console.log(`Fetching existing files from repo: ${GITHUB_REPO}, branch: ${GITHUB_BRANCH}`);
19 try {
20 const response = await gitHubAPI.getRepoContent(GITHUB_REPO, "", GITHUB_BRANCH);
22 return response.map(file => file.path);
23 } catch (error) {
24 console.error(`Error fetching repo content: ${error.message}`);
25 throw error;
26 }
48 const shaResponse = await gitHubAPI.getRepoContent(GITHUB_REPO, filePath, GITHUB_BRANCH);
49 const sha = shaResponse.sha;
50 console.log(`Fetched SHA for ${filePath}: ${sha}`);
51 if (!sha) {
52 throw new Error(`Failed to fetch SHA for ${filePath}`);
53 }
54 await gitHubAPI.updateFile(GITHUB_REPO, filePath, fileContent, sha, commitMessage, GITHUB_BRANCH);
72
73async function backupVals() {
74 const vals = await fetchVals();
75 const lastBackupDates = await getLastBackupDates();
76 const allValsDetails = [];
105
106export async function runBackupIfChanged() {
107 const vals = await fetchVals();
108 const lastBackupDates = await getLastBackupDates();
109
3
4 async getRepoContent(repo: string, path: string, branch: string) {
5 const response = await fetch(`https://api.github.com/repos/${repo}/contents/${path}?ref=${branch}`, {
6 method: 'GET',
7 headers: {
11
12 if (!response.ok) {
13 throw new Error(`Error fetching repo content: ${response.statusText}`);
14 }
15
18
19 async getFileSHA(repo: string, path: string, branch: string) {
20 const response = await fetch(`https://api.github.com/repos/${repo}/contents/${path}?ref=${branch}`, {
21 method: 'GET',
22 headers: {
26
27 if (!response.ok) {
28 throw new Error(`Error fetching file SHA: ${response.statusText}`);
29 }
30
34
35 async updateFile(repo: string, path: string, content: string, sha: string, message: string, branch: string) {
36 const response = await fetch(`https://api.github.com/repos/${repo}/contents/${path}`, {
37 method: 'PUT',
38 headers: {
68
69 try {
70 const response = await fetch(`${url}?ref=${branch}`, {
71 method: 'GET',
72 headers: {
81 }
82 } catch (error) {
83 console.error(`Error fetching file SHA: ${error.message}`);
84 }
85
86 const response = await fetch(url, {
87 method: 'PUT',
88 headers: {
104
105 async getCommitHistory(repo: string, path: string, branch: string) {
106 const response = await fetch(`https://api.github.com/repos/${repo}/commits?path=${path}&sha=${branch}`, {
107 method: 'GET',
108 headers: {
112
113 if (!response.ok) {
114 throw new Error(`Error fetching commit history: ${response.statusText}`);
115 }
116
3
4 async getUserID() {
5 const response = await fetch('https://api.val.town/v1/me', {
6 method: 'GET',
7 headers: {
12
13 if (!response.ok) {
14 throw new Error(`Error fetching user details: ${response.statusText}`);
15 }
16
21 async getAllVals() {
22 const userId = await this.getUserID();
23 const response = await fetch(`https://api.val.town/v1/users/${userId}/vals`, {
24 method: 'GET',
25 headers: {
30
31 if (!response.ok) {
32 throw new Error(`Error fetching vals: ${response.statusText}`);
33 }
34