|
|
@@ -43,6 +43,9 @@ var gobalLocalProjectDir string |
|
|
|
|
|
|
|
var gobalSubscriptionFileChangeSwitch int =0 //订阅文件变更开关 |
|
|
|
|
|
|
|
//全局消息通知管道 |
|
|
|
var GobalMessageNotify = make(chan string,1000) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ipfsPath=os.Getenv("IPFS-PATH") |
|
|
@@ -615,7 +618,7 @@ type FileParam struct { |
|
|
|
|
|
|
|
//获取文件的历史版本管理文件最新hash值 |
|
|
|
func postGetHistoryCurrentHash(projectName, folderName, fileName, relativePath string)(string,error){ |
|
|
|
url:="http://www.lockingos.org:9003/api/pms/sdk/queryFileHistoryCurrentCid" |
|
|
|
url:=config.ServerUrl+"/api/pms/sdk/queryFileHistoryCurrentCid" |
|
|
|
contentType := "application/json" |
|
|
|
|
|
|
|
fileParam :=FileParam{ |
|
|
@@ -674,7 +677,7 @@ func postGetHistoryCurrentHash(projectName, folderName, fileName, relativePath s |
|
|
|
//更新文件记录 |
|
|
|
func postUpdateFile(projectName, folderName, relativePath, ipfsCid, fileName, historyCurrentIpfsCid, historyPreIpfsCid,userId string, fileSize int64, fileVersion int)(err error){ |
|
|
|
|
|
|
|
url:="http://www.lockingos.org:9003/api/pms/sdk/updateFile" |
|
|
|
url:=config.ServerUrl+"/api/pms/sdk/updateFile" |
|
|
|
contentType := "application/json" |
|
|
|
intUserId,_:=strconv.ParseInt(userId,10,64) |
|
|
|
|
|
|
@@ -1041,18 +1044,24 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
for actionAndModifyFilePathStr :=range config.GobalWatchChannelMap[gobalLocalProjectDir] { |
|
|
|
//log.Println(actionAndModifyFilePathStr) |
|
|
|
actionAndModifyFilePath := strings.Split(actionAndModifyFilePathStr,";") |
|
|
|
queryKey := strings.Replace(actionAndModifyFilePath[1],config.LocalWorkSpaceDir,"",1) |
|
|
|
|
|
|
|
//当前登陆用户判断 |
|
|
|
if gobalLoginUserName != strings.Split(queryKey,"\\")[0]{ |
|
|
|
log.Printf("非法用户修改%v", actionAndModifyFilePathStr) |
|
|
|
continue |
|
|
|
} |
|
|
|
|
|
|
|
if actionAndModifyFilePath[0]=="remove"{ |
|
|
|
k := strings.Replace(actionAndModifyFilePath[1],config.LocalWorkSpaceDir,"",1) |
|
|
|
queryMap,err :=etcdclient.QueryWithPrefix(k) |
|
|
|
queryMap,err :=etcdclient.QueryWithPrefix(queryKey) |
|
|
|
if len(queryMap)==0{ |
|
|
|
continue |
|
|
|
} |
|
|
|
err = etcdclient.DeleteWithPrefix(k) |
|
|
|
err = etcdclient.DeleteWithPrefix(queryKey) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
} |
|
|
|
}else if actionAndModifyFilePath[0]=="write"{ |
|
|
|
queryKey := strings.Replace(actionAndModifyFilePath[1],config.LocalWorkSpaceDir,"",1) |
|
|
|
querymap,err := etcdclient.QueryWithPrefix(queryKey) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
@@ -1072,9 +1081,7 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
log.Printf("文件变更 [ %v ] write", actionAndModifyFilePathStr) |
|
|
|
|
|
|
|
//如果非新增文件则自动post |
|
|
|
//if goabalAddFileMap[] |
|
|
|
filePath := actionAndModifyFilePath[1] |
|
|
|
//TODO |
|
|
|
|
|
|
|
//获取文件的历史版本管理文件hash |
|
|
|
fileName :=filepath.Base(filePath) |
|
|
@@ -1088,6 +1095,7 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
} |
|
|
|
historyCurrentHash,err :=postGetHistoryCurrentHash(projectName, folderName, fileName, relativePath) |
|
|
|
if err!=nil{ |
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
log.Printf("postGetHistoryCurrentHash 返回失败,%v",err.Error()) |
|
|
|
continue |
|
|
|
} |
|
|
@@ -1095,6 +1103,7 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
//自动更新文件 |
|
|
|
err =UploadCommand(nil,filePath,fileName,projectName,dir,historyCurrentHash,"",gobalLoginUserName,false) |
|
|
|
if err!=nil{ |
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
log.Printf("UploadCommand 返回失败,%v",err.Error()) |
|
|
|
//记录修改状态 |
|
|
|
newValue := oldValue[0]+";" +"1" |
|
|
@@ -1105,9 +1114,9 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
} |
|
|
|
continue |
|
|
|
} |
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新成功\n%v",fileName) |
|
|
|
|
|
|
|
}else if actionAndModifyFilePath[0]=="create"{ |
|
|
|
queryKey := strings.Replace(actionAndModifyFilePath[1],config.LocalWorkSpaceDir,"",1) |
|
|
|
querymap,err := etcdclient.QueryWithPrefix(queryKey) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
@@ -1129,7 +1138,6 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
//如果非新增文件则自动post |
|
|
|
//if goabalAddFileMap[] |
|
|
|
filePath := actionAndModifyFilePath[1] |
|
|
|
//TODO |
|
|
|
|
|
|
|
//获取文件的历史版本管理文件hash |
|
|
|
fileName :=filepath.Base(filePath) |
|
|
@@ -1143,6 +1151,7 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
} |
|
|
|
historyCurrentHash,err :=postGetHistoryCurrentHash(projectName, folderName, fileName, relativePath) |
|
|
|
if err!=nil{ |
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
log.Printf("postGetHistoryCurrentHash 返回失败,%v",err.Error()) |
|
|
|
continue |
|
|
|
} |
|
|
@@ -1150,6 +1159,7 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
//自动更新文件 |
|
|
|
err =UploadCommand(nil,filePath,fileName,projectName,dir,historyCurrentHash,"",gobalLoginUserName,false) |
|
|
|
if err!=nil{ |
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新失败\n%v",fileName) |
|
|
|
log.Printf("UploadCommand 返回失败,%v",err.Error()) |
|
|
|
//记录修改状态 |
|
|
|
newValue := oldValue[0]+";" +"1" |
|
|
@@ -1160,6 +1170,7 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
} |
|
|
|
continue |
|
|
|
} |
|
|
|
GobalMessageNotify <- fmt.Sprintf("文件更新成功\n%v",fileName) |
|
|
|
} |
|
|
|
err = sendFileListFromEtcd(keyPrefix,projectName,conn) |
|
|
|
if err != nil { |
|
|
@@ -1171,6 +1182,7 @@ func SubscriptionFileChange(conn *websocket.Conn, projectName string) error{ |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func sendFileListFromEtcd(keyPrefix,projectName string,conn *websocket.Conn) error{ |
|
|
|
dataMap,err := etcdclient.QueryWithPrefix(keyPrefix) |
|
|
|
if err != nil { |
|
|
|