Browse Source

Fixed file operatron window size

Toby Chui 2 năm trước cách đây
mục cha
commit
92cd783700

+ 14 - 5
mod/agi/agi.go

@@ -291,7 +291,7 @@ func (g *Gateway) ExecuteAGIScript(scriptContent string, fsh *filesystem.FileSys
 	//Detect cotent type
 	contentType := r.Header.Get("Content-type")
 	if strings.Contains(contentType, "application/json") {
-		//For shitty people who use Angular
+		//For people who use Angular
 		body, _ := io.ReadAll(r.Body)
 		fields := map[string]interface{}{}
 		json.Unmarshal(body, &fields)
@@ -338,11 +338,11 @@ func (g *Gateway) ExecuteAGIScript(scriptContent string, fsh *filesystem.FileSys
 }
 
 /*
-Execute AGI script with given user information
-scriptFile must be realpath resolved by fsa VirtualPathToRealPath function
-Pass in http.Request pointer to enable serverless GET / POST request
+	Execute AGI script with given user information
+	scriptFile must be realpath resolved by fsa VirtualPathToRealPath function
+	Pass in http.Request pointer to enable serverless GET / POST request
 */
-func (g *Gateway) ExecuteAGIScriptAsUser(fsh *filesystem.FileSystemHandler, scriptFile string, targetUser *user.User, r *http.Request) (string, error) {
+func (g *Gateway) ExecuteAGIScriptAsUser(fsh *filesystem.FileSystemHandler, scriptFile string, targetUser *user.User, w http.ResponseWriter, r *http.Request) (string, error) {
 	//Create a new vm for this request
 	vm := otto.New()
 	//Inject standard libs into the vm
@@ -397,6 +397,15 @@ func (g *Gateway) ExecuteAGIScriptAsUser(fsh *filesystem.FileSystemHandler, scri
 		return "", err
 	}
 
+	if w != nil {
+		//Serverless: Get respond header type from the vm
+		header, _ := vm.Get("HTTP_HEADER")
+		headerString, _ := header.ToString()
+		if headerString != "" {
+			w.Header().Set("Content-Type", headerString)
+		}
+	}
+
 	valueString, err := value.ToString()
 	if err != nil {
 		return "", err

+ 3 - 2
mod/agi/external.agi.go

@@ -63,14 +63,15 @@ func (g *Gateway) ExtAPIHandler(w http.ResponseWriter, r *http.Request) {
 	// execute!
 	start := time.Now()
 	//g.ExecuteAGIScript(scriptContent, "", "", w, r, userInfo)
-	result, err := g.ExecuteAGIScriptAsUser(fsh, realPath, userInfo, r)
+	result, err := g.ExecuteAGIScriptAsUser(fsh, realPath, userInfo, w, r)
 	duration := time.Since(start)
 
 	if err != nil {
 		utils.SendErrorResponse(w, err.Error())
 		return
 	}
-	utils.SendTextResponse(w, result)
+
+	w.Write([]byte(result))
 
 	log.Println("[Remote AGI] IP:", r.RemoteAddr, " executed the script ", pathFromDb, "(", realPath, ")", " on behalf of", userInfo.Username, "with total duration: ", duration)
 

+ 1 - 1
mod/time/scheduler/scheduler.go

@@ -138,7 +138,7 @@ func (a *Scheduler) createTicker(duration time.Duration) chan bool {
 								//Resolve the sript path to realpath
 								//Run the script with this user scope
 								thisJob.lastExecutionTime = time.Now().Unix()
-								resp, err := a.options.Gateway.ExecuteAGIScriptAsUser(fsh, rpath, targetUser, nil)
+								resp, err := a.options.Gateway.ExecuteAGIScriptAsUser(fsh, rpath, targetUser, nil, nil)
 								if err != nil {
 									a.cronlogError(thisJob.Name+" execution error: "+err.Error(), err)
 									thisJob.lastExecutionOutput = err.Error()

+ 1 - 1
mod/www/www.go

@@ -146,7 +146,7 @@ func (h *Handler) RouteRequest(w http.ResponseWriter, r *http.Request) {
 
 	//Execute it if it is agi file
 	if fsh.FileSystemAbstraction.FileExists(targetFilePath) && filepath.Ext(targetFilePath) == ".agi" {
-		result, err := h.Options.AgiGateway.ExecuteAGIScriptAsUser(fsh, targetFilePath, userinfo, r)
+		result, err := h.Options.AgiGateway.ExecuteAGIScriptAsUser(fsh, targetFilePath, userinfo, w, r)
 		if err != nil {
 			w.Write([]byte("500 - Internal Server Error \n" + err.Error()))
 			return

+ 1 - 1
web/Serverless/index.html

@@ -121,7 +121,7 @@
             });
 
             function openfileselector(){
-                ao_module_openFileSelector(fileLoader, "user:/", "file",false, {filter:["agi"]});
+                ao_module_openFileSelector(fileLoader, "user:/", "file",false, {filter:["agi", "js"]});
             }
 
 

+ 1 - 1
web/SystemAO/file_system/file_operation.html

@@ -831,7 +831,7 @@
             }
 
             function showPauseCancelButton(){
-                ao_module_setWindowSize(400,244);
+                ao_module_setWindowSize(400,254);
                 $("#progressbar").parent().css({
                     "margin-bottom":"1em"
                 });

+ 1 - 1
web/SystemAO/info/gomod-license.csv

@@ -69,7 +69,7 @@ golang.org/x/image,https://cs.opensource.google/go/x/image/+/e7cb9697:LICENSE,BS
 golang.org/x/net,https://cs.opensource.google/go/x/net/+/v0.2.0:LICENSE,BSD-3-Clause
 golang.org/x/oauth2,https://cs.opensource.google/go/x/oauth2/+/0ebed06d:LICENSE,BSD-3-Clause
 golang.org/x/sync/syncmap,https://cs.opensource.google/go/x/sync/+/7fc1605a:LICENSE,BSD-3-Clause
-golang.org/x/sys,https://cs.opensource.google/go/x/sys/+/v0.2.0:LICENSE,BSD-3-Clause
+golang.org/x/sys,https://cs.opensource.google/go/x/sys/+/v0.3.0:LICENSE,BSD-3-Clause
 golang.org/x/text,https://cs.opensource.google/go/x/text/+/v0.4.0:LICENSE,BSD-3-Clause
 gopkg.in/asn1-ber.v1,https://github.com/go-asn1-ber/asn1-ber/blob/f715ec2f112d/LICENSE,MIT
 gopkg.in/sourcemap.v1,https://github.com/go-sourcemap/sourcemap/blob/v1.0.5/LICENSE,BSD-2-Clause

+ 15 - 10
web/script/ao_module.js

@@ -771,16 +771,21 @@ class ao_module_codec{
 
 
 /**
-ArOZ Online Module Utils for quick deploy of ArOZ Online WebApps
-
-ao_module_utils.objectToAttr(object); //object to DOM attr
-ao_module_utils.attrToObject(attr); //DOM attr to Object
-ao_module_utils.getRandomUID(); //Get random UUID from timestamp
-ao_module_utils.getIconFromExt(ext); //Get icon tag from file extension
-
-ao_module_utils.getDropFileInfo(dropEvent); //Get the filepath and filename list from file explorer drag drop
-ao_module_utils.formatBytes(byte, decimals); //Format file byte size to human readable size
-ao_module_utils.timeConverter(unix_timestamp); //Get human readable timestamp 
+    ArOZ Online Module Utils for quick deploy of ArOZ Online WebApps
+
+    ao_module_utils.objectToAttr(object); //object to DOM attr
+    ao_module_utils.attrToObject(attr); //DOM attr to Object
+    ao_module_utils.getRandomUID(); //Get random UUID from timestamp
+    ao_module_utils.getIconFromExt(ext); //Get icon tag from file extension
+    ao_module_utils.stringToBlob(text, mimetype="text/plain") //Convert string to blob
+    ao_module_utils.blobToFile(blob, filename, mimetype="text/plain") //Convert blob to file
+    ao_module_utils.getDropFileInfo(dropEvent); //Get the filepath and filename list from file explorer drag drop
+    ao_module_utils.readFileFromFileObject(fileObject, successCallback, failedCallback=undefined) //Read file object as text
+    ao_module_utils.durationConverter(seconds) //Convert duration in seconds to Days / Hours / Minutes / Seconds
+    ao_module_utils.formatBytes(byte, decimals); //Format file byte size to human readable size
+    ao_module_utils.timeConverter(unix_timestamp); //Get human readable timestamp 
+    ao_module_utils.getWebSocketEndpoint() //Build server websocket endpoint root, e.g. wss://192.168.1.100:8080/
+    ao_module_utils.formatBytes(bytes, decimalPlace=2) //Convert and rounds bytes into KB, MB, GB or TB
 **/
 class ao_module_utils{