소스 검색

Added get share UUID function (experimental)

tobychui 3 년 전
부모
커밋
fb22d4a6a1
1개의 변경된 파일25개의 추가작업 그리고 0개의 파일을 삭제
  1. 25 0
      mod/agi/agi.share.go

+ 25 - 0
mod/agi/agi.share.go

@@ -74,6 +74,30 @@ func (g *Gateway) injectShareFunctions(vm *otto.Otto, u *user.User) {
 		return otto.TrueValue()
 	})
 
+	vm.Set("_share_getShareUUID", func(call otto.FunctionCall) otto.Value {
+		vpath, err := call.Argument(0).ToString()
+		if err != nil {
+			log.Println("[AGI] Failed to get share UUID: filepath not given")
+			return otto.NullValue()
+		}
+
+		//Resolve the vpath to realpath
+		rpath, err := u.VirtualPathToRealPath(vpath)
+		if err != nil {
+			log.Println("[AGI] Failed to get share UUID: Unabel to resovle")
+			return otto.NullValue()
+		}
+		shareObject := g.Option.ShareManager.GetShareObjectFromRealPath(rpath)
+		if shareObject == nil {
+			log.Println("[AGI] Failed to get share UUID: File not shared")
+			return otto.NullValue()
+		}
+
+		shareUUID := shareObject.UUID
+		val, _ := otto.ToValue(shareUUID)
+		return val
+	})
+
 	vm.Set("_share_checkShareExists", func(call otto.FunctionCall) otto.Value {
 		shareUUID, err := call.Argument(0).ToString()
 		if err != nil {
@@ -108,5 +132,6 @@ func (g *Gateway) injectShareFunctions(vm *otto.Otto, u *user.User) {
 		share.removeShare = _share_removeShare;
 		share.checkShareExists = _share_checkShareExists;
 		share.fileIsShared = _share_fileIsShared;
+		share.getFileShareUUID = _share_getShareUUID;
 	`)
 }