|
|
@@ -1,6 +1,8 @@
|
|
|
package action
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
+ "os"
|
|
|
"pbx-api-gin/internal/app/stc/active"
|
|
|
"pbx-api-gin/internal/app/stc/priority"
|
|
|
alstatus "pbx-api-gin/internal/app/stc/sendstatus"
|
|
|
@@ -54,20 +56,48 @@ func HandleAMI(event map[string]string) {
|
|
|
case "UserEvent": // RCD filename; PA;CPA; CabCab
|
|
|
lfshook.NewLogger().Infof("========event:%s File:%s", event["Event"], event["FILENAME"])
|
|
|
|
|
|
- if event["UserEvent"] == "SetRecordFile" { //get record file name
|
|
|
+ if event["UserEvent"] == "SetRecordFile" { //Get record file name
|
|
|
//延时一下1秒;
|
|
|
- time.Sleep(time.Second)
|
|
|
- //检测录音文件是否存在;
|
|
|
+ //time.Sleep(time.Second)
|
|
|
+
|
|
|
+ //检测录音文件是否存在;最多检测5次,每次间隔1秒
|
|
|
+ var fileExists bool
|
|
|
+ for i := 0; i < 5; i++ {
|
|
|
+ if _, err := os.Stat(event["FILENAME"]); err == nil {
|
|
|
+ fileExists = true
|
|
|
+ lfshook.NewLogger().Infof("File found: %s", event["FILENAME"])
|
|
|
+ break
|
|
|
+ } else if os.IsNotExist(err) {
|
|
|
+ lfshook.NewLogger().Infof("File not found (attempt %d): %s", i+1, event["FILENAME"])
|
|
|
+ } else {
|
|
|
+ lfshook.NewLogger().Errorf("Error checking file: %v", err)
|
|
|
+ }
|
|
|
+ time.Sleep(time.Second) // 等待1秒
|
|
|
+ }
|
|
|
+
|
|
|
+ if !fileExists {
|
|
|
+ lfshook.NewLogger().Errorf("File not found after 5 attempts: %s", event["FILENAME"])
|
|
|
+ // 可选:发送错误通知或跳过后续处理
|
|
|
+ break
|
|
|
+ }
|
|
|
|
|
|
//检测录音文件是否超过3min;
|
|
|
+ duration, err := utils.GetDuration(event["FILENAME"])
|
|
|
+ if err != nil {
|
|
|
+ lfshook.NewLogger().Errorf("Get duration err: %+v", err)
|
|
|
+ }
|
|
|
|
|
|
//如果超过则切割
|
|
|
+ if duration > 180 {
|
|
|
|
|
|
- //执行加密操作
|
|
|
+ }
|
|
|
|
|
|
- //切割之后推送生成的文件名;
|
|
|
+ //执行加密操作
|
|
|
+ DstFile := fmt.Sprintf("%s.bin", event["FILENAME"])
|
|
|
+ utils.AudioFileEncode(DstFile, event["FILENAME"])
|
|
|
|
|
|
- alstatus.SendRecordFile(event["FILENAME"], event["RecordType"])
|
|
|
+ //切割&加密之后推送生成的文件名;
|
|
|
+ alstatus.SendRecordFile(DstFile, event["RecordType"])
|
|
|
|
|
|
} else if event["UserEvent"] == "CallType" && (event["Type"] == "PA" || event["Type"] == "CPA") { //PA start; check manual PA priority
|
|
|
//PA & CPA interrupt others
|