Skip to content

Commit

Permalink
fix: disable vercel cron by default
Browse files Browse the repository at this point in the history
  • Loading branch information
wayjam committed Nov 10, 2024
1 parent 68bf77c commit 30edffc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
12 changes: 11 additions & 1 deletion docs/vercel.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@

1. Vercel Blob
2. Github + jsDelivr CDN
3. 其他
3. 其他

## 定时刷新

Vercel 支持定时刷新,可以在 `vercel.json` 中配置定时刷新任务。由于 Hobby 免费版账号 Cron 次数有限,如果开启来 Pro 建议 Frok 修改。或其他定时工具通过接口触发

> 需要配置 `TV_MIXPROXY_SECRET` 环境变量
```sh
curl -X GET -H "X-TV-MIXPROXY-SECRET: <token>" https://tv-mixproxy.vercel.app/refresh_source
```
14 changes: 12 additions & 2 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
6 changes: 1 addition & 5 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@
"source": "/(.*)",
"destination": "/api/api"
}
],
"crons": [{
"path": "/refresh_source",
"schedule": "* * * * *"
}]
]
}

0 comments on commit 30edffc

Please sign in to comment.