Skip to content

Commit 83b04a0

Browse files
committed
Fix saving system and enhance saved data
This commit includes updates to the src/index.js file. The saving system, which previously saved an empty object, has been fixed to correctly save the workspace. Additional data including the Lua code, workspace name, save date, and cc:be version are now also saved, providing more context and information in each save file.
1 parent b4600d3 commit 83b04a0

File tree

1 file changed

+63
-58
lines changed

1 file changed

+63
-58
lines changed

src/index.js

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ const loadButton = document.getElementById('loadButton');
5252

5353
const downloadWorkspace = () => {
5454
const json = {
55+
"name": fileName.value || "workspace",
5556
"version": version,
5657
"date": date,
57-
"workspace": save(ws)
58+
"workspace": save(ws),
59+
"lua": luaGenerator.workspaceToCode(ws)
5860
}
59-
const blob = new Blob([json], { type: 'application/json' });
61+
const blob = new Blob([JSON.stringify(json)], { type: 'application/json' });
6062
const url = URL.createObjectURL(blob);
6163
const a = document.createElement('a');
6264
a.href = url;
@@ -73,67 +75,70 @@ const loadWorkspace = () => {
7375
const file = input.files[0];
7476
const reader = new FileReader();
7577
reader.onload = () => {
76-
load(ws, reader.result['workspace']);
78+
const json = JSON.parse(reader.result);
79+
load(ws, json['workspace']);
80+
fileName.value = json['name'];
81+
codeDiv.innerText = json['lua'];
7782
};
7883
reader.readAsText(file);
7984
};
8085
};
8186

82-
const uploadToPastebin = () => {
83-
const code = luaGenerator.workspaceToCode(ws);
84-
const xhr = new XMLHttpRequest();
85-
xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
86-
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
87-
xhr.onreadystatechange = () => {
88-
if (xhr.readyState == 4 && xhr.status == 200) {
89-
const url = xhr.responseText;
90-
const a = document.createElement('a');
91-
a.href = url;
92-
a.target = '_blank';
93-
a.click();
94-
}
95-
};
96-
if (secret['connected'] === false) {
97-
xhr.send(`api_dev_key=${secret['api_dev_key']}&api_user_key=${secret['api_user_key']}&api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${encodeURIComponent(code)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | lua (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=lua`);
98-
} else {
99-
xhr.send(`api_dev_key=${secret['api_dev_key']}&api_option=paste&api_paste_code=${encodeURIComponent(code)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | lua (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=lua`);
100-
}
101-
}
102-
103-
const uploadWorkspaceToPastebin = () => {
104-
const workspace = save(ws);
105-
const xhr = new XMLHttpRequest();
106-
xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
107-
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
108-
xhr.onreadystatechange = () => {
109-
if (xhr.readyState == 4 && xhr.status == 200) {
110-
const url = xhr.responseText;
111-
const a = document.createElement('a');
112-
a.href = url;
113-
a.target = '_blank';
114-
a.click();
115-
}
116-
};
117-
if (secret['connected'] === false) {
118-
xhr.send(`api_dev_key=${secret['api_dev_key']}&api_user_key=${secret['api_user_key']}&api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${encodeURIComponent(workspace)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | workspace (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=json`);
119-
} else {
120-
xhr.send(`api_dev_key=${secret['api_dev_key']}&api_option=paste&api_paste_code=${encodeURIComponent(workspace)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | workspace (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=json`);
121-
}
122-
}
123-
124-
const loadWorkspaceFromPastebin = () => {
125-
const id = prompt('Enter pastebin ID');
126-
if (!id) return;
127-
const xhr = new XMLHttpRequest();
128-
xhr.open('GET', `pastebin.php?id=${id}`, true);
129-
xhr.onreadystatechange = () => {
130-
if (xhr.readyState == 4 && xhr.status == 200) {
131-
load(ws, xhr.responseText);
132-
console.log(xhr.responseText);
133-
}
134-
};
135-
xhr.send();
136-
}
87+
//const uploadToPastebin = () => {
88+
// const code = luaGenerator.workspaceToCode(ws);
89+
// const xhr = new XMLHttpRequest();
90+
// xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
91+
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
92+
// xhr.onreadystatechange = () => {
93+
// if (xhr.readyState == 4 && xhr.status == 200) {
94+
// const url = xhr.responseText;
95+
// const a = document.createElement('a');
96+
// a.href = url;
97+
// a.target = '_blank';
98+
// a.click();
99+
// }
100+
// };
101+
// if (secret['connected'] === false) {
102+
// xhr.send(`api_dev_key=${secret['api_dev_key']}&api_user_key=${secret['api_user_key']}&api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${encodeURIComponent(code)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | lua (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=lua`);
103+
// } else {
104+
// xhr.send(`api_dev_key=${secret['api_dev_key']}&api_option=paste&api_paste_code=${encodeURIComponent(code)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | lua (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=lua`);
105+
// }
106+
//}
107+
108+
//const uploadWorkspaceToPastebin = () => {
109+
// const workspace = save(ws);
110+
// const xhr = new XMLHttpRequest();
111+
// xhr.open('POST', 'https://pastebin.com/api/api_post.php', true);
112+
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
113+
// xhr.onreadystatechange = () => {
114+
// if (xhr.readyState == 4 && xhr.status == 200) {
115+
// const url = xhr.responseText;
116+
// const a = document.createElement('a');
117+
// a.href = url;
118+
// a.target = '_blank';
119+
// a.click();
120+
// }
121+
// };
122+
// if (secret['connected'] === false) {
123+
// xhr.send(`api_dev_key=${secret['api_dev_key']}&api_user_key=${secret['api_user_key']}&api_folder_key=5BbL8uf5&api_option=paste&api_paste_code=${encodeURIComponent(workspace)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | workspace (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=json`);
124+
// } else {
125+
// xhr.send(`api_dev_key=${secret['api_dev_key']}&api_option=paste&api_paste_code=${encodeURIComponent(workspace)}&api_paste_private=1&api_paste_name=${(fileName.value || 'workspace') + ' | workspace (' + Math.random().toString(36).substring(7) + ')'}&api_paste_format=json`);
126+
// }
127+
//}
128+
129+
//const loadWorkspaceFromPastebin = () => {
130+
// const id = prompt('Enter pastebin ID');
131+
// if (!id) return;
132+
// const xhr = new XMLHttpRequest();
133+
// xhr.open('GET', `pastebin.php?id=${id}`, true);
134+
// xhr.onreadystatechange = () => {
135+
// if (xhr.readyState == 4 && xhr.status == 200) {
136+
// load(ws, xhr.responseText);
137+
// console.log(xhr.responseText);
138+
// }
139+
// };
140+
// xhr.send();
141+
//}
137142

138143
//const connectToPastebin = () => {
139144
// const username = prompt('Enter pastebin username');

0 commit comments

Comments
 (0)