176 lines
5.8 KiB
Go
176 lines
5.8 KiB
Go
// Code generated by gowebx, DO AVOID EDIT.
|
|
package api
|
|
|
|
import (
|
|
"easyaudioencode/internal/conf"
|
|
"easyaudioencode/internal/core/audioencode"
|
|
"easyaudioencode/internal/core/host"
|
|
"easyaudioencode/internal/core/media"
|
|
"easyaudioencode/internal/core/transcode"
|
|
"fmt"
|
|
"git.lnton.com/lnton/pkg/reason"
|
|
"git.lnton.com/lnton/pkg/web"
|
|
"github.com/gin-gonic/gin"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type Loger interface {
|
|
RecordLog(remark string) gin.HandlerFunc
|
|
}
|
|
type AudioEncodeAPI struct {
|
|
core *audioencode.Core
|
|
meidaCore *media.Core
|
|
transcodeCore *transcode.Core
|
|
cfg *conf.Bootstrap
|
|
HostCore *host.Core
|
|
}
|
|
|
|
func NewAudioEncodeAPI(core *audioencode.Core, meidaCore *media.Core, transcodeCore *transcode.Core, HostCore *host.Core, cfg *conf.Bootstrap) AudioEncodeAPI {
|
|
return AudioEncodeAPI{core: core, meidaCore: meidaCore, transcodeCore: transcodeCore, HostCore: HostCore, cfg: cfg}
|
|
}
|
|
|
|
func RegisterAudioEncode(g gin.IRouter, api AudioEncodeAPI, handler ...gin.HandlerFunc) {
|
|
{
|
|
|
|
group := g.Group("/api/audioencode", handler...)
|
|
group.GET("", web.WarpH(api.findAudioEncode))
|
|
group.GET("/:id", web.WarpH(api.getAudioEncode))
|
|
group.PUT("/:id", web.WarpH(api.editAudioEncode))
|
|
//group.POST("", web.WarpH(api.addAudioEncode))
|
|
group.DELETE("/:id", web.WarpH(api.delAudioEncode))
|
|
|
|
group.POST("/upload", web.WarpH(api.uploadAudioHandler))
|
|
group.GET("/:id/start", web.WarpH(api.getStart))
|
|
group.GET("/:id/stop", web.WarpH(api.getStop))
|
|
group.GET("/:id/snap", web.WarpH(api.getSnap))
|
|
|
|
}
|
|
}
|
|
|
|
// >>> pulltopushServer >>>>>>>>>>>>>>>>>>>>
|
|
|
|
func (a AudioEncodeAPI) getStart(c *gin.Context, _ *struct{}) (any, error) {
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
|
_, err := a.core.GetAudioEncode(c.Request.Context(), ID)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find audioencode [%d] err [%s]`, ID, err.Error()))
|
|
}
|
|
//err = a.sourceCore.StartStream(info.ID)
|
|
//if err != nil {
|
|
// return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`StartStream [%d] err [%s]`, ID, err.Error()))
|
|
//}
|
|
err = a.core.AudioEncodeEnable(true, ID)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`AudioEncodeEnable [%d] err [%s]`, ID, err.Error()))
|
|
}
|
|
return gin.H{"data": "OK!"}, err
|
|
}
|
|
|
|
func (a AudioEncodeAPI) getStop(c *gin.Context, _ *struct{}) (any, error) {
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
|
_, err := a.core.GetAudioEncode(c.Request.Context(), ID)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find audioencode [%d] err [%s]`, ID, err.Error()))
|
|
}
|
|
//err = a.sourceCore.StopStream(info.ID)
|
|
//if err != nil {
|
|
// return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`StopStream [%d] err [%s]`, ID, err.Error()))
|
|
//}
|
|
err = a.core.AudioEncodeEnable(false, ID)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`AudioEncodeEnable [%d] err [%s]`, ID, err.Error()))
|
|
}
|
|
return gin.H{"data": "OK!"}, err
|
|
}
|
|
|
|
func (a AudioEncodeAPI) getSnap(c *gin.Context, _ *struct{}) (any, error) {
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
|
_, err := a.core.GetAudioEncode(c.Request.Context(), ID)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find audioencode [%d] err [%s]`, ID, err.Error()))
|
|
}
|
|
//_ = a.sourceCore.SnapStream(info.ID)
|
|
time.Sleep(200 * time.Microsecond)
|
|
return gin.H{"data": fmt.Sprintf("/snap_%d.jpg", ID)}, err
|
|
}
|
|
|
|
func (a AudioEncodeAPI) findAudioEncode(c *gin.Context, in *audioencode.FindAudioEncodeInput) (any, error) {
|
|
items, total, err := a.core.FindAudioEncode(c.Request.Context(), in)
|
|
rows := make([]map[string]interface{}, 0)
|
|
|
|
for _, item := range items {
|
|
//row := structs.Map(item)
|
|
row := make(map[string]interface{})
|
|
|
|
row["name"] = item.Name
|
|
row["file_name"] = item.FileName
|
|
row["size"] = item.Size
|
|
row["id"] = item.ID
|
|
row["mode"] = item.Mode
|
|
row["source_url"] = item.SourceUrl
|
|
row["created_at"] = item.CreatedAt
|
|
row["updated_at"] = item.UpdatedAt
|
|
row["encode_status"] = item.EncodeStatus
|
|
row["des"] = item.Des
|
|
rows = append(rows, row)
|
|
}
|
|
|
|
return gin.H{"items": rows, "total": total}, err
|
|
}
|
|
|
|
func (a AudioEncodeAPI) getAudioEncode(c *gin.Context, _ *struct{}) (any, error) {
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
|
item, err := a.core.GetAudioEncode(c.Request.Context(), ID)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find audioencode [%d] err [%s]`, ID, err.Error()))
|
|
}
|
|
row := make(map[string]interface{})
|
|
|
|
row["name"] = item.Name
|
|
row["file_name"] = item.FileName
|
|
row["size"] = item.Size
|
|
row["id"] = item.ID
|
|
row["mode"] = item.Mode
|
|
row["source_url"] = item.SourceUrl
|
|
row["created_at"] = item.CreatedAt
|
|
row["updated_at"] = item.UpdatedAt
|
|
row["encode_status"] = item.EncodeStatus
|
|
|
|
row["des"] = item.Des
|
|
return gin.H{"data": row}, err
|
|
}
|
|
|
|
func (a AudioEncodeAPI) editAudioEncode(c *gin.Context, in *audioencode.EditAudioEncodeInput) (any, error) {
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
|
_, err := a.core.GetAudioEncode(c.Request.Context(), ID)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`find audioencode [%d] err [%s]`, ID, err.Error()))
|
|
}
|
|
|
|
_, err = a.core.EditAudioEncode(c.Request.Context(), in, ID)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`edit audioencode err [%s]`, err.Error()))
|
|
}
|
|
return gin.H{"data": "OK!"}, err
|
|
}
|
|
|
|
func (a AudioEncodeAPI) addAudioEncode(c *gin.Context, in *audioencode.AddAudioEncodeInput) (any, error) {
|
|
|
|
_, err := a.core.AddAudioEncode(c.Request.Context(), in)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`add audioencode err [%s]`, err.Error()))
|
|
}
|
|
|
|
return gin.H{"data": "OK!"}, err
|
|
}
|
|
|
|
func (a AudioEncodeAPI) delAudioEncode(c *gin.Context, _ *struct{}) (any, error) {
|
|
ID, _ := strconv.Atoi(c.Param("id"))
|
|
_, err := a.core.DelAudioEncode(c.Request.Context(), ID)
|
|
if err != nil {
|
|
return nil, reason.ErrServer.SetMsg(fmt.Sprintf(`del audioencode [%d] err [%s]`, ID, err.Error()))
|
|
}
|
|
return gin.H{"data": "OK!"}, err
|
|
}
|