diff --git a/docs/vercel.md b/docs/vercel.md index d25a307..0c3224a 100644 --- a/docs/vercel.md +++ b/docs/vercel.md @@ -7,4 +7,14 @@ 1. Vercel Blob 2. Github + jsDelivr CDN -3. 其他 \ No newline at end of file +3. 其他 + +## 定时刷新 + +Vercel 支持定时刷新,可以在 `vercel.json` 中配置定时刷新任务。由于 Hobby 免费版账号 Cron 次数有限,如果开启来 Pro 建议 Frok 修改。或其他定时工具通过接口触发 + +> 需要配置 `TV_MIXPROXY_SECRET` 环境变量 + +```sh +curl -X GET -H "X-TV-MIXPROXY-SECRET: " https://tv-mixproxy.vercel.app/refresh_source +``` \ No newline at end of file diff --git a/server/handler.go b/server/handler.go index 45739a7..03ccdfa 100644 --- a/server/handler.go +++ b/server/handler.go @@ -186,8 +186,18 @@ func NewM3UMediaHandler(cfg *config.Config, sourceManager *mixer.SourceManager) func RefershSrouceHandler(cfg *config.Config, sourceManager *mixer.SourceManager) fiber.Handler { return func(c fiber.Ctx) error { - token := os.Getenv("CRON_SECRET") - if c.Get("Authorization") != "Bearer "+token { + cronSecret := os.Getenv("CRON_SECRET") + token := os.Getenv("TV_MIXPROXY_SECRET") + + pass := false + + if cronSecret != "" && c.Get("Authorization") == "Bearer "+cronSecret { + pass = true + } else if token != "" && c.Get("X-TV-MIXPROXY-SECRET") == token { + pass = true + } + + if !pass { return c.Status(fiber.StatusUnauthorized).SendString("Unauthorized") } diff --git a/vercel.json b/vercel.json index afba6d4..2fc752c 100644 --- a/vercel.json +++ b/vercel.json @@ -8,9 +8,5 @@ "source": "/(.*)", "destination": "/api/api" } - ], - "crons": [{ - "path": "/refresh_source", - "schedule": "* * * * *" - }] + ] }