From e346e5ba1706a883e3400cd8c73585918870f974 Mon Sep 17 00:00:00 2001 From: Bitter130 <123269179+Bitter130@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:00:13 +0200 Subject: [PATCH 1/6] Create Bitter_130 Dev Folder Just my extension stuff --- extensions/Bitter_130 | 150 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 extensions/Bitter_130 diff --git a/extensions/Bitter_130 b/extensions/Bitter_130 new file mode 100644 index 0000000000..d65ccc6f5d --- /dev/null +++ b/extensions/Bitter_130 @@ -0,0 +1,150 @@ +class ServerExtension { + constructor(runtime) { + this.runtime = runtime; + this.serverURL = 'https://snapextensions.uni-goettingen.de/handleTextfile.php'; + } + + getInfo() { + return { + id: 'serverData', + name: 'SQLSnap! Servers', + color1: '#31b3d4', + color2: '#179fc2', + blocks: [ + { + opcode: 'setServerURL', + blockType: Scratch.BlockType.COMMAND, + text: 'set server URL to [url]', + arguments: { + url: { + type: Scratch.ArgumentType.STRING, + defaultValue: this.serverURL, + }, + }, + }, + { + opcode: 'saveToServer', + blockType: Scratch.BlockType.COMMAND, + text: 'save [variableName] with content [content]', + arguments: { + variableName: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'default.txt', + }, + content: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'Hello, World!', + }, + }, + }, + { + opcode: 'loadFromServer', + blockType: Scratch.BlockType.REPORTER, + text: 'load [variableName]', + arguments: { + variableName: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'data.txt', + }, + }, + }, + { + opcode: 'fits', + blockType: Scratch.BlockType.BOOLEAN, + text: '[data] fits on server?', + arguments: { + data: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'data', + }, + }, + }, + { + opcode: 'deleteFromServer', + blockType: Scratch.BlockType.COMMAND, + text: 'delete [variableName]', + arguments: { + variableName: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'data.txt', + }, + }, + }, + ], + }; + } + + setServerURL(args, util) { + this.serverURL = args.url; + console.log(`Server URL set to: ${this.serverURL}`); // Debug line + } + + saveToServer(args, util) { + const variableName = args.variableName; + const content = args.content; + + const url = + this.serverURL + + '?type=write' + + '&content=' + + encodeURIComponent(content) + + '&filename=./textfiles/' + + encodeURIComponent(variableName); + + return fetch(url) + .then(response => response.text()) + .then(result => (result === 'ok')) + .catch(error => { + console.error('Failed to save data:', error); + return false; + }); + } + + loadFromServer(args, util) { + const variableName = args.variableName; + + const url = + this.serverURL + + '?type=read' + + '&filename=./textfiles/' + + encodeURIComponent(variableName); + + return fetch(url) + .then(response => response.text()) + .then(text => { + if (text === 'ERROR: file does not exist') { + return ''; // Return empty string or any indication that file does not exist + } else { + return text; + } + }) + .catch(error => { + console.error('Failed to load data:', error); + return "can't get data"; + }); + } + + fits(args, util) { + return args.data.length < 10001; + } + + deleteFromServer(args, util) { + const variableName = args.variableName; + + const url = + this.serverURL + + '?type=delete' + + '&filename=./textfiles/' + + encodeURIComponent(variableName); + + return fetch(url) + .then(response => response.text()) + .then(result => (result === 'ok')) + .catch(error => { + console.error('Failed to delete data:', error); + return false; + }); + } +} + +Scratch.extensions.register(new ServerExtension()); From f49be91ddd373a97cca77384c194f649439bc2b1 Mon Sep 17 00:00:00 2001 From: Bitter130 <123269179+Bitter130@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:03:46 +0200 Subject: [PATCH 2/6] Delete extensions/Bitter_130 --- extensions/Bitter_130 | 150 ------------------------------------------ 1 file changed, 150 deletions(-) delete mode 100644 extensions/Bitter_130 diff --git a/extensions/Bitter_130 b/extensions/Bitter_130 deleted file mode 100644 index d65ccc6f5d..0000000000 --- a/extensions/Bitter_130 +++ /dev/null @@ -1,150 +0,0 @@ -class ServerExtension { - constructor(runtime) { - this.runtime = runtime; - this.serverURL = 'https://snapextensions.uni-goettingen.de/handleTextfile.php'; - } - - getInfo() { - return { - id: 'serverData', - name: 'SQLSnap! Servers', - color1: '#31b3d4', - color2: '#179fc2', - blocks: [ - { - opcode: 'setServerURL', - blockType: Scratch.BlockType.COMMAND, - text: 'set server URL to [url]', - arguments: { - url: { - type: Scratch.ArgumentType.STRING, - defaultValue: this.serverURL, - }, - }, - }, - { - opcode: 'saveToServer', - blockType: Scratch.BlockType.COMMAND, - text: 'save [variableName] with content [content]', - arguments: { - variableName: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'default.txt', - }, - content: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'Hello, World!', - }, - }, - }, - { - opcode: 'loadFromServer', - blockType: Scratch.BlockType.REPORTER, - text: 'load [variableName]', - arguments: { - variableName: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'data.txt', - }, - }, - }, - { - opcode: 'fits', - blockType: Scratch.BlockType.BOOLEAN, - text: '[data] fits on server?', - arguments: { - data: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'data', - }, - }, - }, - { - opcode: 'deleteFromServer', - blockType: Scratch.BlockType.COMMAND, - text: 'delete [variableName]', - arguments: { - variableName: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'data.txt', - }, - }, - }, - ], - }; - } - - setServerURL(args, util) { - this.serverURL = args.url; - console.log(`Server URL set to: ${this.serverURL}`); // Debug line - } - - saveToServer(args, util) { - const variableName = args.variableName; - const content = args.content; - - const url = - this.serverURL + - '?type=write' + - '&content=' + - encodeURIComponent(content) + - '&filename=./textfiles/' + - encodeURIComponent(variableName); - - return fetch(url) - .then(response => response.text()) - .then(result => (result === 'ok')) - .catch(error => { - console.error('Failed to save data:', error); - return false; - }); - } - - loadFromServer(args, util) { - const variableName = args.variableName; - - const url = - this.serverURL + - '?type=read' + - '&filename=./textfiles/' + - encodeURIComponent(variableName); - - return fetch(url) - .then(response => response.text()) - .then(text => { - if (text === 'ERROR: file does not exist') { - return ''; // Return empty string or any indication that file does not exist - } else { - return text; - } - }) - .catch(error => { - console.error('Failed to load data:', error); - return "can't get data"; - }); - } - - fits(args, util) { - return args.data.length < 10001; - } - - deleteFromServer(args, util) { - const variableName = args.variableName; - - const url = - this.serverURL + - '?type=delete' + - '&filename=./textfiles/' + - encodeURIComponent(variableName); - - return fetch(url) - .then(response => response.text()) - .then(result => (result === 'ok')) - .catch(error => { - console.error('Failed to delete data:', error); - return false; - }); - } -} - -Scratch.extensions.register(new ServerExtension()); From 95de4bb603756f7b4e3d034f99919665d7b4bd99 Mon Sep 17 00:00:00 2001 From: Bitter130 <123269179+Bitter130@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:08:07 +0200 Subject: [PATCH 3/6] Create SQLSnapFileshare.js An extension used for storing files online --- extensions/Bitter_130/SQLSnapFileshare.js | 150 ++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 extensions/Bitter_130/SQLSnapFileshare.js diff --git a/extensions/Bitter_130/SQLSnapFileshare.js b/extensions/Bitter_130/SQLSnapFileshare.js new file mode 100644 index 0000000000..d65ccc6f5d --- /dev/null +++ b/extensions/Bitter_130/SQLSnapFileshare.js @@ -0,0 +1,150 @@ +class ServerExtension { + constructor(runtime) { + this.runtime = runtime; + this.serverURL = 'https://snapextensions.uni-goettingen.de/handleTextfile.php'; + } + + getInfo() { + return { + id: 'serverData', + name: 'SQLSnap! Servers', + color1: '#31b3d4', + color2: '#179fc2', + blocks: [ + { + opcode: 'setServerURL', + blockType: Scratch.BlockType.COMMAND, + text: 'set server URL to [url]', + arguments: { + url: { + type: Scratch.ArgumentType.STRING, + defaultValue: this.serverURL, + }, + }, + }, + { + opcode: 'saveToServer', + blockType: Scratch.BlockType.COMMAND, + text: 'save [variableName] with content [content]', + arguments: { + variableName: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'default.txt', + }, + content: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'Hello, World!', + }, + }, + }, + { + opcode: 'loadFromServer', + blockType: Scratch.BlockType.REPORTER, + text: 'load [variableName]', + arguments: { + variableName: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'data.txt', + }, + }, + }, + { + opcode: 'fits', + blockType: Scratch.BlockType.BOOLEAN, + text: '[data] fits on server?', + arguments: { + data: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'data', + }, + }, + }, + { + opcode: 'deleteFromServer', + blockType: Scratch.BlockType.COMMAND, + text: 'delete [variableName]', + arguments: { + variableName: { + type: Scratch.ArgumentType.STRING, + defaultValue: 'data.txt', + }, + }, + }, + ], + }; + } + + setServerURL(args, util) { + this.serverURL = args.url; + console.log(`Server URL set to: ${this.serverURL}`); // Debug line + } + + saveToServer(args, util) { + const variableName = args.variableName; + const content = args.content; + + const url = + this.serverURL + + '?type=write' + + '&content=' + + encodeURIComponent(content) + + '&filename=./textfiles/' + + encodeURIComponent(variableName); + + return fetch(url) + .then(response => response.text()) + .then(result => (result === 'ok')) + .catch(error => { + console.error('Failed to save data:', error); + return false; + }); + } + + loadFromServer(args, util) { + const variableName = args.variableName; + + const url = + this.serverURL + + '?type=read' + + '&filename=./textfiles/' + + encodeURIComponent(variableName); + + return fetch(url) + .then(response => response.text()) + .then(text => { + if (text === 'ERROR: file does not exist') { + return ''; // Return empty string or any indication that file does not exist + } else { + return text; + } + }) + .catch(error => { + console.error('Failed to load data:', error); + return "can't get data"; + }); + } + + fits(args, util) { + return args.data.length < 10001; + } + + deleteFromServer(args, util) { + const variableName = args.variableName; + + const url = + this.serverURL + + '?type=delete' + + '&filename=./textfiles/' + + encodeURIComponent(variableName); + + return fetch(url) + .then(response => response.text()) + .then(result => (result === 'ok')) + .catch(error => { + console.error('Failed to delete data:', error); + return false; + }); + } +} + +Scratch.extensions.register(new ServerExtension()); From 9d33fbb1eee2558130c477fbf9f78b51fd0c6596 Mon Sep 17 00:00:00 2001 From: Cubester Date: Mon, 15 Jul 2024 22:45:19 -0400 Subject: [PATCH 4/6] Reformat, make Unsandboxed, and Translation Functions --- extensions/Bitter_130/SQLSnapFileshare.js | 262 +++++++++++----------- 1 file changed, 136 insertions(+), 126 deletions(-) diff --git a/extensions/Bitter_130/SQLSnapFileshare.js b/extensions/Bitter_130/SQLSnapFileshare.js index d65ccc6f5d..4f06884900 100644 --- a/extensions/Bitter_130/SQLSnapFileshare.js +++ b/extensions/Bitter_130/SQLSnapFileshare.js @@ -1,150 +1,160 @@ -class ServerExtension { - constructor(runtime) { - this.runtime = runtime; - this.serverURL = 'https://snapextensions.uni-goettingen.de/handleTextfile.php'; - } +// Name: SQLSnap! Fileshare +// ID: bitter130SQLSnapFileshare +// Description: Port of the SQLSnap! Fileshare extension for cloud file share utilization. +// By: Bitter_130 + +(function (Scratch) { + "use strict"; + + class SQLSnapFileshare { + constructor() { + this.serverURL = + "https://snapextensions.uni-goettingen.de/handleTextfile.php"; + } - getInfo() { - return { - id: 'serverData', - name: 'SQLSnap! Servers', - color1: '#31b3d4', - color2: '#179fc2', - blocks: [ - { - opcode: 'setServerURL', - blockType: Scratch.BlockType.COMMAND, - text: 'set server URL to [url]', - arguments: { - url: { - type: Scratch.ArgumentType.STRING, - defaultValue: this.serverURL, + getInfo() { + return { + id: "bitter130SQLSnapFileshare", + name: "SQLSnap! " + Scratch.translate("Fileshare"), + color1: "#31b3d4", + color2: "#179fc2", + blocks: [ + { + opcode: "setServerURL", + blockType: Scratch.BlockType.COMMAND, + text: Scratch.translate("set server URL to [URL]"), + arguments: { + URL: { + type: Scratch.ArgumentType.STRING, + defaultValue: this.serverURL, + }, }, }, - }, - { - opcode: 'saveToServer', - blockType: Scratch.BlockType.COMMAND, - text: 'save [variableName] with content [content]', - arguments: { - variableName: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'default.txt', - }, - content: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'Hello, World!', + { + opcode: "saveToServer", + blockType: Scratch.BlockType.COMMAND, + text: Scratch.translate("save [FILE] with content [CONTENT]"), + arguments: { + FILE: { + type: Scratch.ArgumentType.STRING, + defaultValue: Scratch.translate("data") + ".txt", + }, + CONTENT: { + type: Scratch.ArgumentType.STRING, + defaultValue: Scratch.translate("Hello World!"), + }, }, }, - }, - { - opcode: 'loadFromServer', - blockType: Scratch.BlockType.REPORTER, - text: 'load [variableName]', - arguments: { - variableName: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'data.txt', + { + opcode: "loadFromServer", + blockType: Scratch.BlockType.REPORTER, + text: Scratch.translate("load [FILE]"), + arguments: { + FILE: { + type: Scratch.ArgumentType.STRING, + defaultValue: Scratch.translate("data") + ".txt", + }, }, }, - }, - { - opcode: 'fits', - blockType: Scratch.BlockType.BOOLEAN, - text: '[data] fits on server?', - arguments: { - data: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'data', + { + opcode: "fits", + blockType: Scratch.BlockType.BOOLEAN, + text: Scratch.translate("[DATA] fits on server?"), + arguments: { + DATA: { + type: Scratch.ArgumentType.STRING, + defaultValue: Scratch.translate("data"), + }, }, }, - }, - { - opcode: 'deleteFromServer', - blockType: Scratch.BlockType.COMMAND, - text: 'delete [variableName]', - arguments: { - variableName: { - type: Scratch.ArgumentType.STRING, - defaultValue: 'data.txt', + { + opcode: "deleteFromServer", + blockType: Scratch.BlockType.COMMAND, + text: Scratch.translate("delete [FILE]"), + arguments: { + FILE: { + type: Scratch.ArgumentType.STRING, + defaultValue: Scratch.translate("data") + ".txt", + }, }, }, - }, - ], - }; - } + ], + }; + } - setServerURL(args, util) { - this.serverURL = args.url; - console.log(`Server URL set to: ${this.serverURL}`); // Debug line - } + setServerURL(args) { + args.URL = Scratch.Cast.toString(args.URL); + this.serverURL = args.URL; + } - saveToServer(args, util) { - const variableName = args.variableName; - const content = args.content; + saveToServer(args) { + args.FILE = Scratch.Cast.toString(args.FILE); + args.CONTENT = Scratch.Cast.toString(args.CONTENT); - const url = - this.serverURL + - '?type=write' + - '&content=' + - encodeURIComponent(content) + - '&filename=./textfiles/' + - encodeURIComponent(variableName); + const url = + this.serverURL + + "?type=write" + + "&content=" + + encodeURIComponent(args.CONTENT) + + "&filename=./textfiles/" + + encodeURIComponent(args.FILE); - return fetch(url) - .then(response => response.text()) - .then(result => (result === 'ok')) - .catch(error => { - console.error('Failed to save data:', error); - return false; - }); - } + return fetch(url) + .then((response) => response.text()) + .then((result) => result === "ok") + .catch((error) => { + console.error("Failed to save data:", error); + return false; + }); + } - loadFromServer(args, util) { - const variableName = args.variableName; + loadFromServer(args) { + args.FILE = Scratch.Cast.toString(args.FILE); - const url = - this.serverURL + - '?type=read' + - '&filename=./textfiles/' + - encodeURIComponent(variableName); + const url = + this.serverURL + + "?type=read" + + "&filename=./textfiles/" + + encodeURIComponent(args.FILE); - return fetch(url) - .then(response => response.text()) - .then(text => { - if (text === 'ERROR: file does not exist') { - return ''; // Return empty string or any indication that file does not exist - } else { - return text; - } - }) - .catch(error => { - console.error('Failed to load data:', error); - return "can't get data"; - }); - } + return fetch(url) + .then((response) => response.text()) + .then((text) => { + if (text === "ERROR: file does not exist") { + return ""; // Return empty string or any indication that file does not exist + } else { + return text; + } + }) + .catch((error) => { + console.error("Failed to load data:", error); + return "can't get data"; + }); + } - fits(args, util) { - return args.data.length < 10001; - } + fits(args) { + args.DATA = Scratch.Cast.toString(args.DATA); + return args.DATA.length < 10001; + } - deleteFromServer(args, util) { - const variableName = args.variableName; + deleteFromServer(args) { + args.FILE = Scratch.Cast.toString(args.FILE); - const url = - this.serverURL + - '?type=delete' + - '&filename=./textfiles/' + - encodeURIComponent(variableName); + const url = + this.serverURL + + "?type=delete" + + "&filename=./textfiles/" + + encodeURIComponent(args.FILE); - return fetch(url) - .then(response => response.text()) - .then(result => (result === 'ok')) - .catch(error => { - console.error('Failed to delete data:', error); - return false; - }); + return fetch(url) + .then((response) => response.text()) + .then((result) => result === "ok") + .catch((error) => { + console.error("Failed to delete data:", error); + return false; + }); + } } -} -Scratch.extensions.register(new ServerExtension()); + Scratch.extensions.register(new SQLSnapFileshare()); +})(Scratch); From 4317a48e0ba15d7c257a01d9e06c7fee3da62d2e Mon Sep 17 00:00:00 2001 From: Cubester Date: Mon, 15 Jul 2024 23:21:28 -0400 Subject: [PATCH 5/6] Add `async` and make fetches `Scratch.fetch` --- extensions/Bitter_130/SQLSnapFileshare.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/extensions/Bitter_130/SQLSnapFileshare.js b/extensions/Bitter_130/SQLSnapFileshare.js index 4f06884900..db51c65413 100644 --- a/extensions/Bitter_130/SQLSnapFileshare.js +++ b/extensions/Bitter_130/SQLSnapFileshare.js @@ -87,7 +87,7 @@ this.serverURL = args.URL; } - saveToServer(args) { + async saveToServer(args) { args.FILE = Scratch.Cast.toString(args.FILE); args.CONTENT = Scratch.Cast.toString(args.CONTENT); @@ -99,7 +99,7 @@ "&filename=./textfiles/" + encodeURIComponent(args.FILE); - return fetch(url) + return Scratch.fetch(url) .then((response) => response.text()) .then((result) => result === "ok") .catch((error) => { @@ -108,7 +108,7 @@ }); } - loadFromServer(args) { + async loadFromServer(args) { args.FILE = Scratch.Cast.toString(args.FILE); const url = @@ -117,7 +117,7 @@ "&filename=./textfiles/" + encodeURIComponent(args.FILE); - return fetch(url) + return Scratch.fetch(url) .then((response) => response.text()) .then((text) => { if (text === "ERROR: file does not exist") { @@ -137,7 +137,7 @@ return args.DATA.length < 10001; } - deleteFromServer(args) { + async deleteFromServer(args) { args.FILE = Scratch.Cast.toString(args.FILE); const url = @@ -146,7 +146,7 @@ "&filename=./textfiles/" + encodeURIComponent(args.FILE); - return fetch(url) + return Scratch.fetch(url) .then((response) => response.text()) .then((result) => result === "ok") .catch((error) => { From 2679a2ffe0c8d79d8350366198b31c01a0fcaf5e Mon Sep 17 00:00:00 2001 From: Cubester Date: Mon, 15 Jul 2024 23:24:00 -0400 Subject: [PATCH 6/6] Add `await` --- extensions/Bitter_130/SQLSnapFileshare.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/Bitter_130/SQLSnapFileshare.js b/extensions/Bitter_130/SQLSnapFileshare.js index db51c65413..33034280a4 100644 --- a/extensions/Bitter_130/SQLSnapFileshare.js +++ b/extensions/Bitter_130/SQLSnapFileshare.js @@ -99,7 +99,7 @@ "&filename=./textfiles/" + encodeURIComponent(args.FILE); - return Scratch.fetch(url) + return await Scratch.fetch(url) .then((response) => response.text()) .then((result) => result === "ok") .catch((error) => { @@ -117,7 +117,7 @@ "&filename=./textfiles/" + encodeURIComponent(args.FILE); - return Scratch.fetch(url) + return await Scratch.fetch(url) .then((response) => response.text()) .then((text) => { if (text === "ERROR: file does not exist") { @@ -146,7 +146,7 @@ "&filename=./textfiles/" + encodeURIComponent(args.FILE); - return Scratch.fetch(url) + return await Scratch.fetch(url) .then((response) => response.text()) .then((result) => result === "ok") .catch((error) => {