Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nitezs committed Sep 17, 2023
1 parent 4f4a633 commit 354379b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ CLASH_TEMPLATE=clash_template.json
REQUEST_RETRY_TIMES=3
REQUEST_MAX_FILE_SIZE=1048576
CACHE_EXPIRE=300
LOG_LEVEL=info
LOG_LEVEL=info
BASE_PATH=/
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@

可以通过编辑 .env 文件来修改默认配置,docker 直接添加环境变量

| 变量名 | 说明 | 默认值 |
|-----------------------|----------------------------------------|-----------------------|
| PORT | 端口 | `8011` |
| META_TEMPLATE | meta 模板文件名 | `template_meta.yaml` |
| CLASH_TEMPLATE | clash 模板文件名 | `template_clash.yaml` |
| REQUEST_RETRY_TIMES | Get 请求重试次数 | `3` |
| REQUEST_MAX_FILE_SIZE | Get 请求订阅文件最大大小(byte) | `1048576` |
| CACHE_EXPIRE | 订阅缓存时间(秒) | `300` |
| LOG_LEVEL | 日志等级,可选值 `debug`,`info`,`warn`,`error` | `info` |
| 变量名 | 说明 | 默认值 |
|-----------------------|-----------------------------------------------------------|-----------------------|
| BASE_PATH | 程序运行子路径,例如将服务反代在 `https://example.com/sub` 则此变量值应为 `/sub` | `/` |
| PORT | 端口 | `8011` |
| META_TEMPLATE | meta 模板文件名 | `template_meta.yaml` |
| CLASH_TEMPLATE | clash 模板文件名 | `template_clash.yaml` |
| REQUEST_RETRY_TIMES | Get 请求重试次数 | `3` |
| REQUEST_MAX_FILE_SIZE | Get 请求订阅文件最大大小(byte) | `1048576` |
| CACHE_EXPIRE | 订阅缓存时间(秒) | `300` |
| LOG_LEVEL | 日志等级,可选值 `debug`,`info`,`warn`,`error` | `info` |

### API

Expand Down Expand Up @@ -63,5 +64,3 @@
[代理链接解析](./parser)还没有经过严格测试,可能会出现解析错误的情况,如果出现问题请提交 issue

## TODO

- [x] 可视化面板
5 changes: 4 additions & 1 deletion api/controller/short_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"crypto/sha256"
"encoding/hex"
"github.com/gin-gonic/gin"
"net/http"
"sub2clash/config"
"sub2clash/model"
"sub2clash/utils/database"
"sub2clash/validator"
Expand Down Expand Up @@ -46,5 +48,6 @@ func ShortLinkGetHandler(c *gin.Context) {
c.String(404, "未找到短链接")
return
}
c.Redirect(302, "../"+shortLink.Url)
uri := config.Default.BasePath + shortLink.Url
c.Redirect(http.StatusTemporaryRedirect, uri)
}
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Config struct {
RequestMaxFileSize int64
CacheExpire int64
LogLevel string
BasePath string
}

var Default *Config
Expand All @@ -27,6 +28,7 @@ func init() {
Port: 8011,
CacheExpire: 60 * 5,
LogLevel: "info",
BasePath: "/",
}
err := godotenv.Load()
if err != nil {
Expand Down Expand Up @@ -69,4 +71,10 @@ func init() {
if os.Getenv("LOG_LEVEL") != "" {
Default.LogLevel = os.Getenv("LOG_LEVEL")
}
if os.Getenv("BASE_PATH") != "" {
Default.BasePath = os.Getenv("BASE_PATH")
if Default.BasePath[len(Default.BasePath)-1] != '/' {
Default.BasePath += "/"
}
}
}

0 comments on commit 354379b

Please sign in to comment.