瀏覽代碼

Added template for Memo module

tobychui 3 年之前
父節點
當前提交
075b811d2a

+ 14 - 0
web/Memo/backend/dbattack_test.js

@@ -0,0 +1,14 @@
+console.log("Try to attack auth database");
+
+//Try to reate an user admin with password "admin"
+var x = writeDBItem("auth","admin","c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec")
+
+//Should return false
+console.log(x)
+
+var y = dropDBTable("auth");
+
+//Should return false
+console.log(y)
+
+sendResp("Attack Test Done");

+ 19 - 0
web/Memo/backend/dblist.js

@@ -0,0 +1,19 @@
+console.log("Testing Database Listing API");
+if (newDBTableIfNotExists("testdb")){
+	writeDBItem("testdb","One","Hello World")
+	writeDBItem("testdb","Two","This is a text message")
+	writeDBItem("testdb","Three","For listing")
+	writeDBItem("testdb","Four","123456")
+	writeDBItem("testdb","Five","You can also put JSON string here")
+	
+	//Try to list db table
+	var entries = listDBTable("testdb");
+	sendJSONResp(JSON.stringify(entries));
+	//Drop the table after testing
+	dropDBTable("testdb");
+	console.log("Testdb table dropped");
+
+	
+}else{
+	sendResp("Failed creating new db");
+}

+ 18 - 0
web/Memo/backend/dbtest.js

@@ -0,0 +1,18 @@
+console.log("Testing Database API");
+if (newDBTableIfNotExists("testdb")){
+	if (writeDBItem("testdb","message","Hello World")){
+		//Test suceed. Set Response message to the message
+		sendResp("Database access return value: " + readDBItem("testdb","message"));
+		//Delete the entry
+		
+		console.log("Delete entry:" + deleteDBItem("testdb","message"))
+		//Drop the table after testing
+		dropDBTable("testdb");
+		console.log("Testdb table dropped");
+	}else{
+		sendResp("Failed to write to db");
+	}
+	
+}else{
+	sendResp("Failed creating new db");
+}

+ 2 - 0
web/Memo/backend/error.js

@@ -0,0 +1,2 @@
+console.log("This will raise an error");
+notExistsFunction("test");

+ 32 - 0
web/Memo/backend/execpkg.js

@@ -0,0 +1,32 @@
+//Use ffmpeg to convert a file named test.mp4 on desktop
+console.log("Demo for converting a test.mp4 on Desktop to test.mp3");
+var srcVirtual = "user:/Desktop/test.mp4";
+
+//Helper function to get the filepath.Dir of the realpath
+function dir(filepath){
+	filepath = filepath.split("/");
+	filepath.pop();
+	return filepath.join("/");
+}
+
+//Require ffmpeg package
+if (requirepkg("ffmpeg",true)){
+	//Package required. Get the real path of the file
+	var srcReal = decodeVirtualPath(srcVirtual);
+	srcReal = srcReal.split("\\").join("/");
+	console.log("File real path: " + srcReal);
+	
+	//Generate the destination filepath (real)
+	var destReal = dir(srcReal) + "/test.mp3";
+	console.log("Output file path: " + destReal);
+	
+	//Convert the real path to the designed path
+	//If you want to include filepath with space, you must use " instead of '
+	var results = execpkg("ffmpeg",'-i "' + srcReal + '" "' + destReal + '"');
+	
+	//Send the CMD output as text to response
+	sendResp(results);
+}else{
+	sendResp("Failed to require package ffmpeg");
+}
+

+ 4 - 0
web/Memo/backend/filelib.aglob.js

@@ -0,0 +1,4 @@
+console.log("Testing File Glob");
+requirelib("filelib");
+var fileList = filelib.aglob("user:/Desktop/*.mp4");
+sendJSONResp(JSON.stringify(fileList));

+ 9 - 0
web/Memo/backend/filelib.file.js

@@ -0,0 +1,9 @@
+console.log("File Read Write Test");
+requirelib("filelib");
+if (filelib.writeFile("user:/Desktop/test.txt","Hello World! This is a testing message to write")){
+	//Write file succeed.
+	var fileContent = filelib.readFile("user:/Desktop/test.txt");
+	sendResp("File content: " + fileContent);
+}else{
+	SendResp("Failed to write file");
+}

+ 7 - 0
web/Memo/backend/filelib.fileExists.js

@@ -0,0 +1,7 @@
+console.log("Check if file exists");
+requirelib("filelib");
+if (filelib.fileExists("user:/Desktop/test.txt")){
+	sendResp("File Exists");
+}else{
+	sendResp("File Not Exists");
+}

+ 24 - 0
web/Memo/backend/filelib.filesize.js

@@ -0,0 +1,24 @@
+console.log('Testing get filesize');
+requirelib("filelib");
+//Help function for converting byte to human readable format
+function bytesToSize(bytes) {
+   var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
+   if (bytes == 0) return '0 Byte';
+   var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
+   return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
+}
+
+
+//Get all the files filesize on desktop
+var fileList = filelib.glob("user:/Desktop/*.*");
+var results = [];
+for (var i =0; i < fileList.length; i++){
+	var filename = fileList[i].split("/").pop();
+	var fileSize = filelib.filesize(fileList[i]);
+	results.push({
+		filename: filename,
+		filesize: bytesToSize(fileSize)
+	});
+	
+}
+sendJSONResp(JSON.stringify(results));

+ 4 - 0
web/Memo/backend/filelib.glob.js

@@ -0,0 +1,4 @@
+console.log("Testing File Glob");
+requirelib("filelib");
+var fileList = filelib.glob("user:/Desktop/*.mp3");
+sendJSONResp(JSON.stringify(fileList));

+ 7 - 0
web/Memo/backend/filelib.md5.js

@@ -0,0 +1,7 @@
+var loaded = requirelib("filelib");
+if (!loaded) {
+    console.log("Failed to load lib imagelib, terminated.");
+}
+
+sendJSONResp(JSON.stringify(filelib.md5("user:/Desktop/test.jpeg")))
+    //will return md5 hash or false

+ 17 - 0
web/Memo/backend/filelib.mkdir.js

@@ -0,0 +1,17 @@
+//This script will create a folder on your desktop named "Hello World"
+console.log("Create Folder Test");
+var srcPath = "user:/Desktop/Hello World";
+
+//Require the image library
+var loaded = requirelib("filelib");
+if (loaded) {
+    //Library loaded. Call to the functions
+    var success = filelib.mkdir(srcPath);
+	if (success){
+		sendResp("OK")
+	}else{
+		sendResp("Failed to resize image");
+	}
+} else {
+    console.log("Failed to load lib: filelib");
+}

+ 4 - 0
web/Memo/backend/filelib.readDir.js

@@ -0,0 +1,4 @@
+console.log("ListDir Testing");
+requirelib("filelib");
+//This function only shows all directory within this dir
+sendJSONResp(JSON.stringify(filelib.readdir("user:/Desktop/*")))

+ 2 - 0
web/Memo/backend/getLoadedModules.js

@@ -0,0 +1,2 @@
+console.log("List all loaded modules and its launch info");
+sendJSONResp(JSON.stringify(LOADED_MODULES));

+ 16 - 0
web/Memo/backend/getParamters.js

@@ -0,0 +1,16 @@
+console.log("Get argument test");
+sendJSONResp(JSON.stringify([foo,bar]));
+/*
+//The following paramters can be passed in using POST paramters as follow
+function testRunScript(){
+	var script = "Dummy/backend/getParamters.js";
+	$.ajax({
+		url: "../system/ajgi/interface?script=" + script,
+		data: {foo: "Hello", bar: "World"},
+		method: "POST",
+		success: function(data){
+			console.log(data);
+		}
+	})
+}
+*/

+ 12 - 0
web/Memo/backend/getStorageDevices.js

@@ -0,0 +1,12 @@
+//This script demonstrate the iteration over storage devices
+console.log("Storage Device Setting List");
+var html = "";
+for (var i = 0; i < LOADED_STORAGES.length; i++){
+	var thisStorage = LOADED_STORAGES[i];
+	html = html + "Name=" + thisStorage.Name + "<br>UUID=" + thisStorage.Uuid + "<br>Path=" + thisStorage.Path + "<br><br>";
+}
+
+//Set Response header to html
+HTTP_HEADER = "text/html; charset=utf-8";
+//Send Response
+sendResp(html);

+ 13 - 0
web/Memo/backend/imagelib.imageDimension.js

@@ -0,0 +1,13 @@
+console.log("Image Properties Access Test");
+//To test this, put a test.jpg on your desktop
+var imagePath = "user:/Desktop/test.jpeg";
+
+//Require the image library
+var loaded = requirelib("imagelib");
+if (loaded) {
+    //Library loaded. Call to the functions
+    var dimension = imagelib.getImageDimension(imagePath);
+    sendJSONResp(JSON.stringify(dimension));
+} else {
+    console.log("Failed to load lib: imagelib");
+}

+ 18 - 0
web/Memo/backend/imagelib.imageResize.js

@@ -0,0 +1,18 @@
+console.log("Image Resizing Test");
+//To test this, put a test.jpg on your desktop
+var srcPath = "user:/Desktop/test.jpg";
+var destPath = "user:/Desktop/output.jpg";
+
+//Require the image library
+var loaded = requirelib("imagelib");
+if (loaded) {
+    //Library loaded. Call to the functions
+    var success = imagelib.resizeImage(srcPath, destPath, 200, 0);
+	if (success){
+		sendResp("OK")
+	}else{
+		sendResp("Failed to resize image");
+	}
+} else {
+    console.log("Failed to load lib: imagelib");
+}

+ 13 - 0
web/Memo/backend/jsonPost.js

@@ -0,0 +1,13 @@
+//For those shitty persons who use appplication/json instead of x-www-encoded
+//POST_data is constant and won't change
+sendJSONResp(JSON.stringify(POST_data));
+/*
+$.ajax({
+    type: 'POST',
+    url: '/form/',
+    data: '{"name":"jonas"}', // or JSON.stringify ({name: 'jonas'}),
+    success: function(data) { alert('data: ' + data); },
+    contentType: "application/json",
+    dataType: 'json'
+});
+*/

+ 1 - 0
web/Memo/backend/modulelist.js

@@ -0,0 +1 @@
+sendJSONResp(JSON.stringify(LOADED_MODULES));

+ 7 - 0
web/Memo/backend/permission.js

@@ -0,0 +1,7 @@
+console.log("User Permission Checking");
+var permissionGroup = getUserPermissionGroup();
+if (userIsAdmin() == true){
+	sendResp("This user is admin with group = " + permissionGroup);
+}else{
+	sendResp("This user not admin with group = " + permissionGroup);
+}

+ 4 - 0
web/Memo/backend/require_pkg.js

@@ -0,0 +1,4 @@
+requirepkg("ffmpeg",true)
+sendResp("FFMPEG installed");
+
+

+ 6 - 0
web/Memo/backend/require_pkg_windows.js

@@ -0,0 +1,6 @@
+//Run this on windows, you can switch the package name to something exist
+//In your PATH environment varaibles
+requirepkg("asdasd",true)
+sendResp("You should see not found in Windows %PATH% error on terminal log");
+
+

+ 5 - 0
web/Memo/backend/vpath_test.js

@@ -0,0 +1,5 @@
+console.log("Testing Multiline Javascript");
+function getVirtualPath(path){
+	return decodeVirtualPath(path);
+}
+sendJSONResp(JSON.stringify(getVirtualPath("user:/Desktop").split("/")));

二進制
web/Memo/img/baseline_login_black_48dp.png


二進制
web/Memo/img/function_icon.png


二進制
web/Memo/img/function_icon.psd


二進制
web/Memo/img/small_icon.png


二進制
web/Memo/img/small_icon.psd


+ 85 - 0
web/Memo/index.html

@@ -0,0 +1,85 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta name="apple-mobile-web-app-capable" content="yes" />
+        <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
+        <meta charset="UTF-8">
+        <meta name="theme-color" content="#4b75ff">
+        <link rel="stylesheet" href="../script/semantic/semantic.min.css">
+        <script src="../script/jquery.min.js"></script>
+        <script src="../script/ao_module.js"></script>
+        <script src="../script/semantic/semantic.min.js"></script>
+        <title>Dummy</title>
+        <style>
+            body{
+                background-color:white;
+            }
+        </style>
+    </head>
+    <body>
+        <br><br>
+        <div class="ui container">
+            <h3>This is a Dummy Testing Module</h3>
+            <p>Received drag-in filelist (if any)</p>
+            <span id="flist"></span>
+            <div class="ui divider"></div>
+            <p>Try open an IME and type something</p>
+            <input class="ui fluid input" val="Test"></input>
+            <br>
+            <textarea></textarea>
+            <br>
+            <button class="ui blue button" onClick="pinWindow();">Pin Window</button>
+            <button class="ui blue button" onClick="unpinWindow();">Unpin Window</button>
+            <button class="ui primary button" onclick="openfileselector();">Open File Selector New Mode</button>
+            <button class="ui negative button" onClick="ao_module_close();">Close Window</button>
+        </div>
+        <script>
+            var flist = ao_module_loadInputFiles();
+            if (flist == null){
+                $("#flist").text("No input file");
+            }else{
+                for (var i =0; i < flist.length; i++){
+                    $("#flist").append(flist[i].filename + " / " + flist[i].filepath + "<br>");
+                }
+            }
+
+            function openfileselector(){
+                ao_module_openFileSelector(fileLoader, "user:/Desktop/",type="new",true, {
+                    defaultName: "New File.txt"
+                })
+            }
+
+            //Test to pin this window to topmost
+            function pinWindow(){
+                ao_module_setTopMost();
+            }
+
+            function unpinWindow(){
+                ao_module_unsetTopMost();
+            }
+
+            function fileLoader(filedata){
+                if (filedata.length == 0){
+                    $("#flist").text("No file selected");
+                    return;
+                }
+                $("#flist").html("");
+                for (var i =0; i < filedata.length; i++){
+                    $("#flist").append(filedata[i].filename + " / " + filedata[i].filepath + "<br>");
+                }
+            }
+
+            function testRunScript(){
+                var script = "Dummy/backend/getParamters.js";
+                $.ajax({
+                    url: "../system/ajgi/interface?script=" + script,
+                    data: {foo: "Hello", bar: "World"},
+                    method: "POST",
+                    success: function(data){
+                        console.log(data);
+                    }
+                })
+            }
+        </script>
+    </body>
+</html>

+ 23 - 0
web/Memo/init.agi

@@ -0,0 +1,23 @@
+/*
+	Memo Apps
+
+	A simple memo marking app for ArozOS
+*/
+
+
+//Define the launchInfo for the module
+var moduleLaunchInfo = {
+    Name: "Memo",
+	Desc: "A simple Memo App for ArozOS",
+	Group: "Office",
+	IconPath: "Memo/img/small_icon.png",
+	Version: "0.1.0",
+	StartDir: "Memo/index.html",
+	SupportFW: true,
+	LaunchFWDir: "Memo/index.html",
+	SupportEmb: false,
+	InitFWSize: [475, 700]
+}
+
+//Register the module
+registerModule(JSON.stringify(moduleLaunchInfo));