This commit is contained in:
jebbs 2022-10-17 11:13:26 +08:00
parent 2da163d59b
commit 917a33a190
8 changed files with 160 additions and 1 deletions

View File

@ -24,6 +24,7 @@ sing-box uses JSON for configuration files.
| `inbounds` | [Inbound](./inbound) | | `inbounds` | [Inbound](./inbound) |
| `outbounds` | [Outbound](./outbound) | | `outbounds` | [Outbound](./outbound) |
| `route` | [Route](./route) | | `route` | [Route](./route) |
| `services` | [Services](./services) |
| `experimental` | [Experimental](./experimental) | | `experimental` | [Experimental](./experimental) |
### Check ### Check

View File

@ -24,6 +24,7 @@ sing-box 使用 JSON 作为配置文件格式。
| `inbounds` | [入站](./inbound) | | `inbounds` | [入站](./inbound) |
| `outbounds` | [出站](./outbound) | | `outbounds` | [出站](./outbound) |
| `route` | [路由](./route) | | `route` | [路由](./route) |
| `services` | [服务](./services) |
| `experimental` | [实验性](./experimental) | | `experimental` | [实验性](./experimental) |
### 检查 ### 检查

View File

@ -0,0 +1,24 @@
# Outbound
### Structure
```json
{
"services": [
{
"type": "",
"tag": ""
}
]
}
```
### Fields
| Type | Format |
| -------------- | ------------------------------ |
| `subscription` | [Subscription](./subscription) |
#### tag
The tag of the service.

View File

@ -0,0 +1,24 @@
# 服务
### 结构
```json
{
"services": [
{
"type": "",
"tag": ""
}
]
}
```
### 字段
| 类型 | 格式 |
| -------------- | ------------------------------ |
| `subscription` | [Subscription](./subscription) |
#### tag
服务的标签。

View File

@ -0,0 +1,52 @@
# Subscription
### Structure
```json
{
"type": "subscription",
"tag": "all.sub",
"interval": "1h",
"providers": [
{
"tag": "provider1",
"url": "https://url.to/subscription",
"exclude": "",
"include": ""
}
]
}
```
### Fields
#### interval
Refresh interval of the subscription. The minimum value is `1m`, the default value is `1h`.
#### providers
List of subscription providers.
#### providers.tag
==Required==
Tag of the subscription provider.
Suppose we have `node1` from the subscription provider, the tag of the outbound will be `all.sub.provider1.node1`.
#### providers.url
==Required==
URL of the subscription provider.
#### providers.exclude
Regular expression to exclude nodes. The priority of the exclude expression is higher than the include expression.
#### providers.include
Regular expression to include nodes.

View File

@ -0,0 +1,52 @@
# 订阅
### 结构
```json
{
"type": "subscription",
"tag": "all.sub",
"interval": "1h",
"providers": [
{
"tag": "provider1",
"url": "https://url.to/subscription",
"exclude": "",
"include": ""
}
]
}
```
### 字段
#### interval
刷新订阅的时间间隔。最小值为 `1m`,默认值为 `1h`
#### providers
订阅源列表。
#### providers.tag
==必填==
订阅源的标签。
所设订阅源中有一个节点 `node1`,则该节点导入后的标签为 `all.sub.provider1.node1`
#### providers.url
==必填==
订阅源的 URL。
#### providers.exclude
排除节点的正则表达式。排除表达式的优先级高于包含表达式。
#### providers.include
包含节点的正则表达式。

View File

@ -9,7 +9,7 @@ type SubscriptionServiceOptions struct {
} }
type SubscriptionProviderOptions struct { type SubscriptionProviderOptions struct {
Tag string `json:"tag,omitempty"` Tag string `json:"tag"`
URL string `json:"url"` URL string `json:"url"`
Exclude string `json:"exclude,omitempty"` Exclude string `json:"exclude,omitempty"`
Include string `json:"include,omitempty"` Include string `json:"include,omitempty"`

View File

@ -91,7 +91,12 @@ func NewSubscription(ctx context.Context, router adapter.Router, logger log.Cont
}) })
} }
interval := time.Duration(options.SubscriptionOptions.Interval) interval := time.Duration(options.SubscriptionOptions.Interval)
if interval <= 0 {
// default to 1 hour
interval = time.Hour
}
if interval < time.Minute { if interval < time.Minute {
// minimum interval is 1 minute
interval = time.Minute interval = time.Minute
} }