74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
controllerAudio "media/controller/audio"
|
|
controllerVideo "media/controller/video"
|
|
serviceSetup "media/service/setup"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
_ "gitea.com/red-future/common/consul"
|
|
"gitea.com/red-future/common/http"
|
|
"gitea.com/red-future/common/jaeger"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
defer jaeger.ShutDown(ctx)
|
|
|
|
loc, err := time.LoadLocation("Asia/Shanghai")
|
|
if err == nil {
|
|
time.Local = loc
|
|
}
|
|
os.Setenv("TZ", "Asia/Shanghai")
|
|
|
|
serviceSetup.EnsureDependencies(ctx)
|
|
|
|
// 清理旧 temp 文件(防止异常中断残留)
|
|
cleanupTempDir(ctx)
|
|
|
|
// 文件上传路由(在 RouteRegister 启动服务器之前注册)
|
|
http.Httpserver.BindHandler("/audio/transcribe", controllerAudio.AudioExtract.TranscribeHandler)
|
|
http.Httpserver.BindHandler("/video/concat", controllerVideo.Concat.ConcatVideosHandler)
|
|
|
|
// 启动服务器(无需 g.Meta 自动注册)
|
|
http.RouteRegister(nil)
|
|
|
|
port := g.Cfg().MustGet(ctx, "server.address", ":3001").String()
|
|
g.Log().Info(ctx, "============================================")
|
|
g.Log().Infof(ctx, "服务启动: http://localhost%s", port)
|
|
g.Log().Infof(ctx, " POST %s/audio/transcribe - 语音转文字+分镜分析(文件上传,参数名 files)", port)
|
|
g.Log().Infof(ctx, " POST %s/video/concat - 视频拼接(文件上传,参数名 files,至少2个视频)", port)
|
|
g.Log().Info(ctx, "============================================")
|
|
|
|
select {}
|
|
}
|
|
|
|
// cleanupTempDir 清理临时文件目录,防止旧运行残留
|
|
func cleanupTempDir(ctx context.Context) {
|
|
tempDir := g.Cfg().MustGet(ctx, "ffmpeg.temp_dir", "resource/temp").String()
|
|
if tempDir == "" {
|
|
tempDir = "resource/temp"
|
|
}
|
|
if !filepath.IsAbs(tempDir) {
|
|
absDir, err := filepath.Abs(tempDir)
|
|
if err != nil {
|
|
return
|
|
}
|
|
tempDir = absDir
|
|
}
|
|
|
|
entries, err := os.ReadDir(tempDir)
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, entry := range entries {
|
|
fullPath := filepath.Join(tempDir, entry.Name())
|
|
os.RemoveAll(fullPath)
|
|
}
|
|
g.Log().Infof(ctx, "临时目录已清理: %s", tempDir)
|
|
}
|