Jelajahi Sumber

Update external.agi.go

Alan Yeung 2 tahun lalu
induk
melakukan
a12188ef8f
1 mengubah file dengan 8 tambahan dan 10 penghapusan
  1. 8 10
      mod/agi/external.agi.go

+ 8 - 10
mod/agi/external.agi.go

@@ -2,7 +2,6 @@ package agi
 
 import (
 	"encoding/json"
-	"io/ioutil"
 	"log"
 	"net/http"
 	"path/filepath"
@@ -61,19 +60,18 @@ func (g *Gateway) ExtAPIHandler(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	// read the file and store it into scriptContent
-	scriptContentByte, err := ioutil.ReadFile(realPath)
-	if err != nil {
-		common.SendErrorResponse(w, "Bad file I/O")
-		return
-	}
-	scriptContent := string(scriptContentByte)
-
 	// execute!
 	start := time.Now()
-	g.ExecuteAGIScript(scriptContent, "", "", w, r, userInfo)
+	//g.ExecuteAGIScript(scriptContent, "", "", w, r, userInfo)
+	result, err := g.ExecuteAGIScriptAsUser(realPath, userInfo)
 	duration := time.Since(start)
 
+	if err != nil {
+		common.SendErrorResponse(w, err.Error())
+		return
+	}
+	common.SendTextResponse(w, result)
+
 	log.Println("[Remote AGI] IP:", r.RemoteAddr, " executed the script ", pathFromDb, "(", realPath, ")", " on behalf of", userInfo.Username, "with total duration: ", duration)
 
 }