diff --git a/cmd/gopcomm/yap/user_yap.html b/cmd/gopcomm/yap/user_yap.html
index 22434417..7d09eeb1 100644
--- a/cmd/gopcomm/yap/user_yap.html
+++ b/cmd/gopcomm/yap/user_yap.html
@@ -384,6 +384,11 @@
Have no data!
+
+
+ ${ item.Duration }
+
+
${ item.CreateAt.slice(0,10) }
diff --git a/internal/core/media.go b/internal/core/media.go
index f422f128..397ecec9 100644
--- a/internal/core/media.go
+++ b/internal/core/media.go
@@ -5,7 +5,9 @@ import (
"database/sql"
"encoding/base64"
"encoding/json"
+ "fmt"
"io"
+ "math"
"net/http"
"strconv"
"strings"
@@ -150,6 +152,12 @@ func (c *Community) SaveMedia(ctx context.Context, userId string, data []byte, f
c.xLog.Warn(err.Error())
return 0, err
}
+ duration, err = formatVideoDuration(duration)
+ c.xLog.Info(duration)
+ if err != nil {
+ c.xLog.Warn(err.Error())
+ return 0, err
+ }
}
// save
stem, err := c.db.Prepare(`insert into file (file_key,format,size,user_id,create_at,update_at,duration) VALUES (?,?,?,?,?,?,?)`)
@@ -167,6 +175,19 @@ func (c *Community) SaveMedia(ctx context.Context, userId string, data []byte, f
return id, err
}
+func formatVideoDuration(duration string) (string, error) {
+ seconds, err := strconv.ParseFloat(duration, 64)
+ if err != nil {
+ return "", err
+ }
+
+ minutes := math.Floor(seconds / 60)
+ secondsRemainder := int(seconds) % 60
+
+ formattedTime := fmt.Sprintf("%d:%02d", int(minutes), secondsRemainder)
+ return formattedTime, nil
+}
+
// for internal use,no need to add ctx
func (c *Community) getMediaInfo(fileKey string) (*File, error) {
r, err := c.S3Service.NewReader(context.Background(), fileKey, nil)