mirror of
				https://github.com/bestnite/sub2clash.git
				synced 2025-11-04 04:40:36 +00:00 
			
		
		
		
	Compare commits
	
		
			14 Commits
		
	
	
		
			v0.0.13-be
			...
			v1.1.0-rc.
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						516657f849
	
				 | 
					
					
						|||
| 
						
						
							
						
						800c5ff7f1
	
				 | 
					
					
						|||
| 
						
						
							
						
						892fa7ce41
	
				 | 
					
					
						|||
| 
						
						
							
						
						007093ac48
	
				 | 
					
					
						|||
| 
						
						
							
						
						ed479b7efa
	
				 | 
					
					
						|||
| 
						
						
							
						
						dac4760289
	
				 | 
					
					
						|||
| 
						
						
							
						
						86b74f30e7
	
				 | 
					
					
						|||
| 
						
						
							
						
						1e8a79c2d2
	
				 | 
					
					
						|||
| 
						
						
							
						
						be656cca57
	
				 | 
					
					
						|||
| 
						
						
							
						
						23a85f573b
	
				 | 
					
					
						|||
| 
						
						
							
						
						fce75baed4
	
				 | 
					
					
						|||
| f5686561f9 | |||
| 83c24170a0 | |||
| 80d91efca4 | 
							
								
								
									
										6
									
								
								.github/workflows/docker.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.github/workflows/docker.yml
									
									
									
									
										vendored
									
									
								
							@@ -45,11 +45,13 @@ jobs:
 | 
				
			|||||||
          password: ${{ secrets.GITHUB_TOKEN }}
 | 
					          password: ${{ secrets.GITHUB_TOKEN }}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Build and push
 | 
					      - name: Build and push
 | 
				
			||||||
        uses: docker/build-push-action@v5
 | 
					        uses: docker/build-push-action@v6
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          build-args: |
 | 
					          build-args: |
 | 
				
			||||||
            "version=${{ github.ref_name }}"
 | 
					            "version=${{ github.ref_name }}"
 | 
				
			||||||
          push: true
 | 
					          push: true
 | 
				
			||||||
          tags: ${{ steps.meta.outputs.tags }}
 | 
					          tags: ${{ steps.meta.outputs.tags }}
 | 
				
			||||||
          labels: ${{ steps.meta.outputs.labels }}
 | 
					          labels: ${{ steps.meta.outputs.labels }}
 | 
				
			||||||
          platforms: linux/amd64,linux/arm64,linux/arm/v7
 | 
					          platforms: linux/amd64,linux/arm64
 | 
				
			||||||
 | 
					          file: Containerfile
 | 
				
			||||||
 | 
					          
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										16
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							@@ -13,13 +13,23 @@ jobs:
 | 
				
			|||||||
    runs-on: ubuntu-latest
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
      - name: Checkout
 | 
					      - name: Checkout
 | 
				
			||||||
        uses: actions/checkout@v4
 | 
					        uses: actions/checkout@v5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Set up Go
 | 
					      - name: Set up Go
 | 
				
			||||||
        uses: actions/setup-go@v4
 | 
					        uses: actions/setup-go@v5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: Install UPX
 | 
				
			||||||
 | 
					        uses: crazy-max/ghaction-upx@v3
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          install-only: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      - name: setup node
 | 
				
			||||||
 | 
					        uses: actions/setup-node@v6
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          node-version: "latest"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Run GoReleaser
 | 
					      - name: Run GoReleaser
 | 
				
			||||||
        uses: goreleaser/goreleaser-action@v5
 | 
					        uses: goreleaser/goreleaser-action@v6
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          distribution: goreleaser
 | 
					          distribution: goreleaser
 | 
				
			||||||
          version: latest
 | 
					          version: latest
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,11 +1,9 @@
 | 
				
			|||||||
.idea
 | 
					.idea
 | 
				
			||||||
.vscode
 | 
					 | 
				
			||||||
dist
 | 
					dist
 | 
				
			||||||
subs
 | 
					subs
 | 
				
			||||||
logs
 | 
					logs
 | 
				
			||||||
data
 | 
					data
 | 
				
			||||||
.env
 | 
					.env
 | 
				
			||||||
.vscode/settings.json
 | 
					 | 
				
			||||||
config.yaml
 | 
					config.yaml
 | 
				
			||||||
config.yml
 | 
					config.yml
 | 
				
			||||||
config.json
 | 
					config.json
 | 
				
			||||||
@@ -1,27 +1,26 @@
 | 
				
			|||||||
 | 
					version: 2
 | 
				
			||||||
project_name: sub2clash
 | 
					project_name: sub2clash
 | 
				
			||||||
 | 
					before:
 | 
				
			||||||
 | 
					  hooks:
 | 
				
			||||||
 | 
					    - bash ./build-frontend.sh {{ .Version }}
 | 
				
			||||||
builds:
 | 
					builds:
 | 
				
			||||||
  - env:
 | 
					  - env:
 | 
				
			||||||
      - CGO_ENABLED=0
 | 
					      - CGO_ENABLED=0
 | 
				
			||||||
    goos:
 | 
					    goos:
 | 
				
			||||||
      - windows
 | 
					 | 
				
			||||||
      - linux
 | 
					      - linux
 | 
				
			||||||
 | 
					      - windows
 | 
				
			||||||
      - darwin
 | 
					      - darwin
 | 
				
			||||||
    goarch:
 | 
					    goarch:
 | 
				
			||||||
      - amd64
 | 
					      - amd64
 | 
				
			||||||
      - arm64
 | 
					      - arm64
 | 
				
			||||||
      - arm
 | 
					 | 
				
			||||||
      - "386"
 | 
					 | 
				
			||||||
    goarm:
 | 
					 | 
				
			||||||
      - "6"
 | 
					 | 
				
			||||||
      - "7"
 | 
					 | 
				
			||||||
    ldflags:
 | 
					    ldflags:
 | 
				
			||||||
      - -s -w -X sub2clash/constant.Version={{ .Version }}
 | 
					      - -s -w -X github.com/bestnite/sub2clash/constant.Version={{ .Version }}
 | 
				
			||||||
    flags:
 | 
					    flags:
 | 
				
			||||||
      - -trimpath
 | 
					      - -trimpath
 | 
				
			||||||
archives:
 | 
					archives:
 | 
				
			||||||
  - format: tar.gz
 | 
					  - formats: ["tar.gz"]
 | 
				
			||||||
    format_overrides:
 | 
					    format_overrides:
 | 
				
			||||||
      - format: zip
 | 
					      - formats: ["zip"]
 | 
				
			||||||
        goos: windows
 | 
					        goos: windows
 | 
				
			||||||
    wrap_in_directory: true
 | 
					    wrap_in_directory: true
 | 
				
			||||||
    files:
 | 
					    files:
 | 
				
			||||||
@@ -30,3 +29,19 @@ archives:
 | 
				
			|||||||
      - templates
 | 
					      - templates
 | 
				
			||||||
release:
 | 
					release:
 | 
				
			||||||
  draft: true
 | 
					  draft: true
 | 
				
			||||||
 | 
					# upx:
 | 
				
			||||||
 | 
					#   - enabled: true
 | 
				
			||||||
 | 
					#     compress: best
 | 
				
			||||||
 | 
					nfpms:
 | 
				
			||||||
 | 
					  - id: sub2clash
 | 
				
			||||||
 | 
					    homepage: https://github.com/bestnite/sub2clash
 | 
				
			||||||
 | 
					    maintainer: Nite <admin@nite07.com>
 | 
				
			||||||
 | 
					    license: "MIT"
 | 
				
			||||||
 | 
					    formats:
 | 
				
			||||||
 | 
					      - apk
 | 
				
			||||||
 | 
					      - deb
 | 
				
			||||||
 | 
					      - rpm
 | 
				
			||||||
 | 
					      - termux.deb
 | 
				
			||||||
 | 
					      - archlinux
 | 
				
			||||||
 | 
					    provides:
 | 
				
			||||||
 | 
					      - sub2clash
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										14
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "version": "0.2.0",
 | 
				
			||||||
 | 
					  "configurations": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "name": "debug",
 | 
				
			||||||
 | 
					      "type": "go",
 | 
				
			||||||
 | 
					      "request": "launch",
 | 
				
			||||||
 | 
					      "mode": "auto",
 | 
				
			||||||
 | 
					      "program": "${workspaceFolder}",
 | 
				
			||||||
 | 
					      "args": [],
 | 
				
			||||||
 | 
					      "preLaunchTask": "build frontend"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										21
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								.vscode/tasks.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "version": "2.0.0",
 | 
				
			||||||
 | 
					    "tasks": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            "label": "build frontend",
 | 
				
			||||||
 | 
					            "type": "shell",
 | 
				
			||||||
 | 
					            "command": "npm",
 | 
				
			||||||
 | 
					            "args": [
 | 
				
			||||||
 | 
					                "run",
 | 
				
			||||||
 | 
					                "build"
 | 
				
			||||||
 | 
					            ],
 | 
				
			||||||
 | 
					            "group": {
 | 
				
			||||||
 | 
					                "kind": "build",
 | 
				
			||||||
 | 
					                "isDefault": true
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            "options": {
 | 
				
			||||||
 | 
					                "cwd": "${workspaceFolder}/server/frontend"
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										47
									
								
								API.md
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								API.md
									
									
									
									
									
								
							@@ -1,47 +0,0 @@
 | 
				
			|||||||
# `GET /clash`, `GET /meta`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
获取 Clash/Clash.Meta 配置链接
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Query 参数   | 类型   | 是否必须                 | 默认值    | 说明                                                                                                                                                                                                                                      |
 | 
					 | 
				
			||||||
| ------------ | ------ | ------------------------ | --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
 | 
					 | 
				
			||||||
| sub          | string | sub/proxy 至少有一项存在 | -         | 订阅链接,可以在链接结尾加上`#名称`,来给订阅中的节点加上统一前缀(可以输入多个,用 `,` 分隔)                                                                                                                                            |
 | 
					 | 
				
			||||||
| proxy        | string | sub/proxy 至少有一项存在 | -         | 节点分享链接(可以输入多个,用 `,` 分隔)                                                                                                                                                                                                 |
 | 
					 | 
				
			||||||
| refresh      | bool   | 否                       | `false`   | 强制刷新配置(默认缓存 5 分钟)                                                                                                                                                                                                           |
 | 
					 | 
				
			||||||
| template     | string | 否                       | -         | 外部模板链接或内部模板名称                                                                                                                                                                                                                |
 | 
					 | 
				
			||||||
| ruleProvider | string | 否                       | -         | 格式 `[Behavior,Url,Group,Prepend,Name],[Behavior,Url,Group,Prepend,Name]...`,其中 `Group` 是该规则集使用的策略组名,`Prepend` 为 bool 类型,如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部(会调整到 MATCH 规则之前) |
 | 
					 | 
				
			||||||
| rule         | string | 否                       | -         | 格式 `[Rule,Prepend],[Rule,Prepend]...`,其中 `Prepend` 为 bool 类型,如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部(会调整到 MATCH 规则之前)                                                                         |
 | 
					 | 
				
			||||||
| autoTest     | bool   | 否                       | `false`   | 国家策略组是否自动测速                                                                                                                                                                                                                    |
 | 
					 | 
				
			||||||
| lazy         | bool   | 否                       | `false`   | 自动测速是否启用 lazy                                                                                                                                                                                                                     |
 | 
					 | 
				
			||||||
| sort         | string | 否                       | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc`                                                                                                                                                                   |
 | 
					 | 
				
			||||||
| replace      | string | 否                       | -         | 通过正则表达式重命名节点,格式 `[<ReplaceKey>,<ReplaceTo>],[<ReplaceKey>,<ReplaceTo>]...`                                                                                                                                                 |
 | 
					 | 
				
			||||||
| remove       | string | 否                       | -         | 通过正则表达式删除节点                                                                                                                                                                                                                    |
 | 
					 | 
				
			||||||
| nodeList     | bool   | 否                       | `false`   | 只输出节点                                                                                                                                                                                                                                |
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# `POST /short`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
获取短链,Content-Type 为 `application/json`
 | 
					 | 
				
			||||||
具体参考使用可以参考 [api\templates\index.html](api/static/index.html)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Body 参数 | 类型   | 是否必须 | 默认值 | 说明                      |
 | 
					 | 
				
			||||||
| --------- | ------ | -------- | ------ | ------------------------- |
 | 
					 | 
				
			||||||
| url       | string | 是       | -      | 需要转换的 Query 参数部分 |
 | 
					 | 
				
			||||||
| password  | string | 否       | -      | 短链密码                  |
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# `GET /s/:hash`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
短链跳转
 | 
					 | 
				
			||||||
`hash` 为动态路由参数,可以通过 `/short` 接口获取
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Query 参数 | 类型   | 是否必须 | 默认值 | 说明     |
 | 
					 | 
				
			||||||
| ---------- | ------ | -------- | ------ | -------- |
 | 
					 | 
				
			||||||
| password   | string | 否       | -      | 短链密码 |
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# `PUT /short`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
更新短链,Content-Type 为 `application/json`
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| Body 参数 | 类型   | 是否必须 | 默认值 | 说明                      |
 | 
					 | 
				
			||||||
| --------- | ------ | -------- | ------ | ------------------------- |
 | 
					 | 
				
			||||||
| url       | string | 是       | -      | 需要转换的 Query 参数部分 |
 | 
					 | 
				
			||||||
| password  | string | 否       | -      | 短链密码                  |
 | 
					 | 
				
			||||||
| hash      | string | 是       | -      | 短链 hash                 |
 | 
					 | 
				
			||||||
							
								
								
									
										21
									
								
								Containerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								Containerfile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					FROM node:latest AS frontend_builder
 | 
				
			||||||
 | 
					WORKDIR /app/server/frontend
 | 
				
			||||||
 | 
					COPY server/frontend/package*.json ./
 | 
				
			||||||
 | 
					RUN npm install
 | 
				
			||||||
 | 
					COPY server/frontend .
 | 
				
			||||||
 | 
					ARG version
 | 
				
			||||||
 | 
					ENV VITE_APP_VERSION=${version}
 | 
				
			||||||
 | 
					RUN npm run build
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					FROM golang:1.25 AS builder
 | 
				
			||||||
 | 
					WORKDIR /app
 | 
				
			||||||
 | 
					COPY . .
 | 
				
			||||||
 | 
					COPY --from=frontend_builder /app/server/frontend/dist /app/server/frontend/dist
 | 
				
			||||||
 | 
					RUN go mod download
 | 
				
			||||||
 | 
					ARG version
 | 
				
			||||||
 | 
					RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X github.com/bestnite/sub2clash/constant.Version=${version}" -o sub2clash .
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					FROM alpine:latest
 | 
				
			||||||
 | 
					WORKDIR /app
 | 
				
			||||||
 | 
					COPY --from=builder /app/sub2clash /app/sub2clash
 | 
				
			||||||
 | 
					ENTRYPOINT ["/app/sub2clash"]
 | 
				
			||||||
							
								
								
									
										12
									
								
								Dockerfile
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								Dockerfile
									
									
									
									
									
								
							@@ -1,12 +0,0 @@
 | 
				
			|||||||
FROM golang:1.21-alpine as builder
 | 
					 | 
				
			||||||
LABEL authors="nite07"
 | 
					 | 
				
			||||||
WORKDIR /app
 | 
					 | 
				
			||||||
COPY . .
 | 
					 | 
				
			||||||
RUN go mod download
 | 
					 | 
				
			||||||
ARG version
 | 
					 | 
				
			||||||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w -X github.com/bestnite/sub2clash/constant.Version=${version}" -o sub2clash .
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
FROM alpine:latest
 | 
					 | 
				
			||||||
WORKDIR /app
 | 
					 | 
				
			||||||
COPY --from=builder /app/sub2clash /app/sub2clash
 | 
					 | 
				
			||||||
ENTRYPOINT ["/app/sub2clash"]
 | 
					 | 
				
			||||||
							
								
								
									
										46
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								README.md
									
									
									
									
									
								
							@@ -59,7 +59,51 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
### API
 | 
					### API
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[API 文档](./API.md)
 | 
					#### `GET /convert/:config`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					获取 Clash/Clash.Meta 配置链接
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Path 参数 | 类型   | 说明                                           |
 | 
				
			||||||
 | 
					| --------- | ------ | ---------------------------------------------- |
 | 
				
			||||||
 | 
					| config    | string | Base64 URL Safe 编码后的 JSON 字符串,格式如下 |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					##### `config` JSON 结构
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| Query 参数         | 类型              | 是否必须                 | 默认值    | 说明                                                                                                     |
 | 
				
			||||||
 | 
					| ------------------ | ----------------- | ------------------------ | --------- | -------------------------------------------------------------------------------------------------------- |
 | 
				
			||||||
 | 
					| clashType          | int               | 是                       | 1         | 配置文件类型 (1: Clash, 2: Clash.Meta)                                                                   |
 | 
				
			||||||
 | 
					| subscriptions      | []string          | sub/proxy 至少有一项存在 | -         | 订阅链接(v2ray 或 clash 格式),可以在链接结尾加上`#名称`,来给订阅中的节点加上统一前缀(可以输入多个) |
 | 
				
			||||||
 | 
					| proxies            | []string          | sub/proxy 至少有一项存在 | -         | 节点分享链接(可以输入多个)                                                                             |
 | 
				
			||||||
 | 
					| refresh            | bool              | 否                       | `false`   | 强制刷新配置(默认缓存 5 分钟)                                                                          |
 | 
				
			||||||
 | 
					| template           | string            | 否                       | -         | 外部模板链接或内部模板名称                                                                               |
 | 
				
			||||||
 | 
					| ruleProviders      | []RuleProvider    | 否                       | -         | 规则                                                                                                     |
 | 
				
			||||||
 | 
					| rules              | []Rule            | 否                       | -         | 规则                                                                                                     |
 | 
				
			||||||
 | 
					| autoTest           | bool              | 否                       | `false`   | 国家策略组是否自动测速                                                                                   |
 | 
				
			||||||
 | 
					| lazy               | bool              | 否                       | `false`   | 自动测速是否启用 lazy                                                                                    |
 | 
				
			||||||
 | 
					| sort               | string            | 否                       | `nameasc` | 国家策略组排序策略,可选值 `nameasc`、`namedesc`、`sizeasc`、`sizedesc`                                  |
 | 
				
			||||||
 | 
					| replace            | map[string]string | 否                       | -         | 通过正则表达式重命名节点                                                                                 |
 | 
				
			||||||
 | 
					| remove             | string            | 否                       | -         | 通过正则表达式删除节点                                                                                   |
 | 
				
			||||||
 | 
					| nodeList           | bool              | 否                       | `false`   | 只输出节点                                                                                               |
 | 
				
			||||||
 | 
					| ignoreCountryGroup | bool              | 否                       | `false`   | 是否忽略国家分组                                                                                         |
 | 
				
			||||||
 | 
					| userAgent          | string            | 否                       | -         | 订阅 user-agent                                                                                          |
 | 
				
			||||||
 | 
					| useUDP             | bool              | 否                       | `false`   | 是否使用 UDP                                                                                             |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					###### `RuleProvider` 结构
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| 字段     | 类型   | 说明                                                             |
 | 
				
			||||||
 | 
					| -------- | ------ | ---------------------------------------------------------------- |
 | 
				
			||||||
 | 
					| behavior | string | rule-set 的 behavior                                             |
 | 
				
			||||||
 | 
					| url      | string | rule-set 的 url                                                  |
 | 
				
			||||||
 | 
					| group    | string | 该规则集使用的策略组名                                           |
 | 
				
			||||||
 | 
					| prepend  | bool   | 如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部 |
 | 
				
			||||||
 | 
					| name     | string | 该 rule-provider 的名称,不能重复                                |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					###### `Rule` 结构
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					| 字段    | 类型   | 说明                                                             |
 | 
				
			||||||
 | 
					| ------- | ------ | ---------------------------------------------------------------- |
 | 
				
			||||||
 | 
					| rule    | string | 规则                                                             |
 | 
				
			||||||
 | 
					| prepend | bool   | 如果为 `true` 规则将被添加到规则列表顶部,否则添加到规则列表底部 |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### 模板
 | 
					### 模板
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								build-frontend.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								build-frontend.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					#!/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export VITE_APP_VERSION=$1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cd server/frontend
 | 
				
			||||||
 | 
					npm install
 | 
				
			||||||
 | 
					npm run build
 | 
				
			||||||
@@ -1,72 +1,77 @@
 | 
				
			|||||||
package database
 | 
					package database
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/json"
 | 
						"context"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/bestnite/sub2clash/common"
 | 
						"github.com/bestnite/sub2clash/common"
 | 
				
			||||||
	"github.com/bestnite/sub2clash/model"
 | 
						"github.com/bestnite/sub2clash/model"
 | 
				
			||||||
 | 
						"github.com/glebarez/sqlite"
 | 
				
			||||||
	"go.etcd.io/bbolt"
 | 
						"gorm.io/gorm"
 | 
				
			||||||
 | 
						"gorm.io/gorm/logger"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var DB *bbolt.DB
 | 
					type Database struct {
 | 
				
			||||||
 | 
						db *gorm.DB
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func ConnectDB() error {
 | 
					func ConnectDB() (*Database, error) {
 | 
				
			||||||
	path := filepath.Join("data", "sub2clash.db")
 | 
						path := filepath.Join("data", "sub2clash.db")
 | 
				
			||||||
 | 
						if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
 | 
				
			||||||
	db, err := bbolt.Open(path, 0600, nil)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return common.NewDatabaseConnectError(err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	DB = db
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return db.Update(func(tx *bbolt.Tx) error {
 | 
					 | 
				
			||||||
		_, err := tx.CreateBucketIfNotExists([]byte("ShortLinks"))
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return common.NewDatabaseConnectError(err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func FindShortLinkByHash(hash string) (*model.ShortLink, error) {
 | 
					 | 
				
			||||||
	var shortLink model.ShortLink
 | 
					 | 
				
			||||||
	err := DB.View(func(tx *bbolt.Tx) error {
 | 
					 | 
				
			||||||
		b := tx.Bucket([]byte("ShortLinks"))
 | 
					 | 
				
			||||||
		v := b.Get([]byte(hash))
 | 
					 | 
				
			||||||
		if v == nil {
 | 
					 | 
				
			||||||
			return common.NewRecordNotFoundError("ShortLink", hash)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return json.Unmarshal(v, &shortLink)
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return &shortLink, nil
 | 
						db, err := gorm.Open(sqlite.Open(path), &gorm.Config{
 | 
				
			||||||
 | 
							Logger: logger.Discard,
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, common.NewDatabaseConnectError(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SaveShortLink(shortLink *model.ShortLink) error {
 | 
						if err = db.AutoMigrate(&model.ShortLink{}); err != nil {
 | 
				
			||||||
	return DB.Update(func(tx *bbolt.Tx) error {
 | 
							return nil, err
 | 
				
			||||||
		b := tx.Bucket([]byte("ShortLinks"))
 | 
						}
 | 
				
			||||||
		encoded, err := json.Marshal(shortLink)
 | 
					
 | 
				
			||||||
		if err != nil {
 | 
						return &Database{
 | 
				
			||||||
 | 
							db: db,
 | 
				
			||||||
 | 
						}, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *Database) FindShortLinkByID(id string) (model.ShortLink, error) {
 | 
				
			||||||
 | 
						ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
 | 
				
			||||||
 | 
						defer cancel()
 | 
				
			||||||
 | 
						return gorm.G[model.ShortLink](d.db).Where("id = ?", id).First(ctx)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *Database) CreateShortLink(shortLink *model.ShortLink) error {
 | 
				
			||||||
 | 
						ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
 | 
				
			||||||
 | 
						defer cancel()
 | 
				
			||||||
 | 
						return gorm.G[model.ShortLink](d.db).Create(ctx, shortLink)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *Database) UpdataShortLink(id string, name string, value any) error {
 | 
				
			||||||
 | 
						ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
 | 
				
			||||||
 | 
						defer cancel()
 | 
				
			||||||
 | 
						_, err := gorm.G[model.ShortLink](d.db).Where("id = ?", id).Update(ctx, name, value)
 | 
				
			||||||
	return err
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		return b.Put([]byte(shortLink.Hash), encoded)
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
func CheckShortLinkHashExists(hash string) (bool, error) {
 | 
					func (d *Database) CheckShortLinkIDExists(id string) (bool, error) {
 | 
				
			||||||
	exists := false
 | 
						_, err := d.FindShortLinkByID(id)
 | 
				
			||||||
	err := DB.View(func(tx *bbolt.Tx) error {
 | 
					 | 
				
			||||||
		b := tx.Bucket([]byte("ShortLinks"))
 | 
					 | 
				
			||||||
		v := b.Get([]byte(hash))
 | 
					 | 
				
			||||||
		exists = v != nil
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	})
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
							if errors.Is(err, gorm.ErrRecordNotFound) {
 | 
				
			||||||
 | 
								return false, nil
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return false, err
 | 
							return false, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return exists, nil
 | 
						return true, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (d *Database) DeleteShortLink(id string) error {
 | 
				
			||||||
 | 
						ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
 | 
				
			||||||
 | 
						defer cancel()
 | 
				
			||||||
 | 
						_, err := gorm.G[model.ShortLink](d.db).Where("id = ?", id).Delete(ctx)
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -133,8 +133,8 @@ func NewTemplateLoadError(template string, cause error) *CommonError {
 | 
				
			|||||||
	return NewError(ErrTemplateLoad, fmt.Sprintf("failed to load template: %s", template), cause)
 | 
						return NewError(ErrTemplateLoad, fmt.Sprintf("failed to load template: %s", template), cause)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewTemplateParseError(cause error) *CommonError {
 | 
					func NewTemplateParseError(data []byte, cause error) *CommonError {
 | 
				
			||||||
	return NewError(ErrTemplateParse, "failed to parse template", cause)
 | 
						return NewError(ErrTemplateParse, fmt.Sprintf("failed to parse template: %s", data), cause)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Subscription errors
 | 
					// Subscription errors
 | 
				
			||||||
@@ -142,8 +142,8 @@ func NewSubscriptionLoadError(url string, cause error) *CommonError {
 | 
				
			|||||||
	return NewError(ErrSubscriptionLoad, fmt.Sprintf("failed to load subscription: %s", url), cause)
 | 
						return NewError(ErrSubscriptionLoad, fmt.Sprintf("failed to load subscription: %s", url), cause)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewSubscriptionParseError(cause error) *CommonError {
 | 
					func NewSubscriptionParseError(data []byte, cause error) *CommonError {
 | 
				
			||||||
	return NewError(ErrSubscriptionParse, "failed to parse subscription", cause)
 | 
						return NewError(ErrSubscriptionParse, fmt.Sprintf("failed to parse subscription: %s", string(data)), cause)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Regex errors
 | 
					// Regex errors
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ import (
 | 
				
			|||||||
	"github.com/bestnite/sub2clash/model"
 | 
						"github.com/bestnite/sub2clash/model"
 | 
				
			||||||
	P "github.com/bestnite/sub2clash/model/proxy"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
	"github.com/bestnite/sub2clash/parser"
 | 
						"github.com/bestnite/sub2clash/parser"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
	"go.uber.org/zap"
 | 
						"go.uber.org/zap"
 | 
				
			||||||
	"gopkg.in/yaml.v3"
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -92,7 +93,7 @@ func FetchSubscriptionFromAPI(url string, userAgent string, retryTimes int) ([]b
 | 
				
			|||||||
	return data, nil
 | 
						return data, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func BuildSub(clashType model.ClashType, query model.SubConfig, template string, cacheExpire int64, retryTimes int) (
 | 
					func BuildSub(clashType model.ClashType, query model.ConvertConfig, template string, cacheExpire int64, retryTimes int) (
 | 
				
			||||||
	*model.Subscription, error,
 | 
						*model.Subscription, error,
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
	var temp = &model.Subscription{}
 | 
						var temp = &model.Subscription{}
 | 
				
			||||||
@@ -128,22 +129,22 @@ func BuildSub(clashType model.ClashType, query model.SubConfig, template string,
 | 
				
			|||||||
	err = yaml.Unmarshal(templateBytes, &temp)
 | 
						err = yaml.Unmarshal(templateBytes, &temp)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logger.Logger.Debug("parse template failed", zap.Error(err))
 | 
							logger.Logger.Debug("parse template failed", zap.Error(err))
 | 
				
			||||||
		return nil, NewTemplateParseError(err)
 | 
							return nil, NewTemplateParseError(templateBytes, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	var proxyList []P.Proxy
 | 
						var proxyList []P.Proxy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i := range query.Subs {
 | 
						for i := range query.Subs {
 | 
				
			||||||
		data, err := LoadSubscription(query.Subs[i], query.Refresh, query.UserAgent, cacheExpire, retryTimes)
 | 
							data, err := LoadSubscription(query.Subs[i], query.Refresh, query.UserAgent, cacheExpire, retryTimes)
 | 
				
			||||||
		subName := ""
 | 
					 | 
				
			||||||
		if strings.Contains(query.Subs[i], "#") {
 | 
					 | 
				
			||||||
			subName = query.Subs[i][strings.LastIndex(query.Subs[i], "#")+1:]
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			logger.Logger.Debug(
 | 
								logger.Logger.Debug(
 | 
				
			||||||
				"load subscription failed", zap.String("url", query.Subs[i]), zap.Error(err),
 | 
									"load subscription failed", zap.String("url", query.Subs[i]), zap.Error(err),
 | 
				
			||||||
			)
 | 
								)
 | 
				
			||||||
			return nil, NewSubscriptionLoadError(query.Subs[i], err)
 | 
								return nil, NewSubscriptionLoadError(query.Subs[i], err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							subName := ""
 | 
				
			||||||
 | 
							if strings.Contains(query.Subs[i], "#") {
 | 
				
			||||||
 | 
								subName = query.Subs[i][strings.LastIndex(query.Subs[i], "#")+1:]
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		err = yaml.Unmarshal(data, &sub)
 | 
							err = yaml.Unmarshal(data, &sub)
 | 
				
			||||||
		var newProxies []P.Proxy
 | 
							var newProxies []P.Proxy
 | 
				
			||||||
@@ -160,14 +161,14 @@ func BuildSub(clashType model.ClashType, query model.SubConfig, template string,
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
				newProxies = p
 | 
									newProxies = p
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				base64, err := parser.DecodeBase64(string(data))
 | 
									base64, err := utils.DecodeBase64(string(data), false)
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					logger.Logger.Debug(
 | 
										logger.Logger.Debug(
 | 
				
			||||||
						"parse subscription failed", zap.String("url", query.Subs[i]),
 | 
											"parse subscription failed", zap.String("url", query.Subs[i]),
 | 
				
			||||||
						zap.String("data", string(data)),
 | 
											zap.String("data", string(data)),
 | 
				
			||||||
						zap.Error(err),
 | 
											zap.Error(err),
 | 
				
			||||||
					)
 | 
										)
 | 
				
			||||||
					return nil, NewSubscriptionParseError(err)
 | 
										return nil, NewSubscriptionParseError(data, err)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				p, err := parser.ParseProxies(parser.ParseConfig{UseUDP: query.UseUDP}, strings.Split(base64, "\n")...)
 | 
									p, err := parser.ParseProxies(parser.ParseConfig{UseUDP: query.UseUDP}, strings.Split(base64, "\n")...)
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
@@ -186,7 +187,7 @@ func BuildSub(clashType model.ClashType, query model.SubConfig, template string,
 | 
				
			|||||||
		proxyList = append(proxyList, newProxies...)
 | 
							proxyList = append(proxyList, newProxies...)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(query.Proxy) != 0 {
 | 
						if len(query.Proxies) != 0 {
 | 
				
			||||||
		p, err := parser.ParseProxies(parser.ParseConfig{UseUDP: query.UseUDP}, query.Proxies...)
 | 
							p, err := parser.ParseProxies(parser.ParseConfig{UseUDP: query.UseUDP}, query.Proxies...)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
@@ -236,22 +237,17 @@ func BuildSub(clashType model.ClashType, query model.SubConfig, template string,
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 替换
 | 
						// 替换
 | 
				
			||||||
	if len(query.ReplaceKeys) != 0 {
 | 
						if len(query.Replace) != 0 {
 | 
				
			||||||
		replaceRegs := make([]*regexp.Regexp, 0, len(query.ReplaceKeys))
 | 
							for k, v := range query.Replace {
 | 
				
			||||||
		for _, v := range query.ReplaceKeys {
 | 
								replaceReg, err := regexp.Compile(k)
 | 
				
			||||||
			replaceReg, err := regexp.Compile(v)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				logger.Logger.Debug("replace regexp compile failed", zap.Error(err))
 | 
									logger.Logger.Debug("replace regexp compile failed", zap.Error(err))
 | 
				
			||||||
				return nil, NewRegexInvalidError("replace", err)
 | 
									return nil, NewRegexInvalidError("replace", err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			replaceRegs = append(replaceRegs, replaceReg)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
			for i := range proxyList {
 | 
								for i := range proxyList {
 | 
				
			||||||
 | 
									if replaceReg.MatchString(proxyList[i].Name) {
 | 
				
			||||||
			for j, v := range replaceRegs {
 | 
										proxyList[i].Name = replaceReg.ReplaceAllString(
 | 
				
			||||||
				if v.MatchString(proxyList[i].Name) {
 | 
											proxyList[i].Name, v,
 | 
				
			||||||
					proxyList[i].Name = v.ReplaceAllString(
 | 
					 | 
				
			||||||
						proxyList[i].Name, query.ReplaceTo[j],
 | 
					 | 
				
			||||||
					)
 | 
										)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -276,6 +272,7 @@ func BuildSub(clashType model.ClashType, query model.SubConfig, template string,
 | 
				
			|||||||
	var t = &model.Subscription{}
 | 
						var t = &model.Subscription{}
 | 
				
			||||||
	AddProxy(t, query.AutoTest, query.Lazy, clashType, proxyList...)
 | 
						AddProxy(t, query.AutoTest, query.Lazy, clashType, proxyList...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 排序
 | 
				
			||||||
	switch query.Sort {
 | 
						switch query.Sort {
 | 
				
			||||||
	case "sizeasc":
 | 
						case "sizeasc":
 | 
				
			||||||
		sort.Sort(model.ProxyGroupsSortBySize(t.ProxyGroup))
 | 
							sort.Sort(model.ProxyGroupsSortBySize(t.ProxyGroup))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,11 +3,27 @@ package common
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
 | 
						"path/filepath"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func LoadTemplate(templatePath string) ([]byte, error) {
 | 
					const templatesDir = "templates"
 | 
				
			||||||
	if _, err := os.Stat(templatePath); err == nil {
 | 
					
 | 
				
			||||||
		file, err := os.Open(templatePath)
 | 
					// LoadTemplate 只读取运行目录下的 templates 目录,防止其他文件内容泄漏
 | 
				
			||||||
 | 
					func LoadTemplate(templateName string) ([]byte, error) {
 | 
				
			||||||
 | 
						// 清理路径,防止目录遍历攻击
 | 
				
			||||||
 | 
						cleanTemplateName := filepath.Clean(templateName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 检查是否尝试访问父目录
 | 
				
			||||||
 | 
						if strings.HasPrefix(cleanTemplateName, "..") || strings.Contains(cleanTemplateName, string(filepath.Separator)+".."+string(filepath.Separator)) {
 | 
				
			||||||
 | 
							return nil, NewFileNotFoundError(templateName) // 拒绝包含父目录的路径
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 构建完整路径,确保只从 templates 目录读取
 | 
				
			||||||
 | 
						fullPath := filepath.Join(templatesDir, cleanTemplateName)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if _, err := os.Stat(fullPath); err == nil {
 | 
				
			||||||
 | 
							file, err := os.Open(fullPath)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return nil, err
 | 
								return nil, err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -22,5 +38,5 @@ func LoadTemplate(templatePath string) ([]byte, error) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		return result, nil
 | 
							return result, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return nil, NewFileNotFoundError(templatePath)
 | 
						return nil, NewFileNotFoundError(templateName)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										33
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								go.mod
									
									
									
									
									
								
							@@ -1,18 +1,17 @@
 | 
				
			|||||||
module github.com/bestnite/sub2clash
 | 
					module github.com/bestnite/sub2clash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
go 1.21.0
 | 
					go 1.25
 | 
				
			||||||
 | 
					 | 
				
			||||||
toolchain go1.24.3
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
require (
 | 
					require (
 | 
				
			||||||
	github.com/gin-gonic/gin v1.10.1
 | 
						github.com/gin-gonic/gin v1.10.1
 | 
				
			||||||
 | 
						github.com/glebarez/sqlite v1.11.0
 | 
				
			||||||
	github.com/metacubex/mihomo v1.19.10
 | 
						github.com/metacubex/mihomo v1.19.10
 | 
				
			||||||
	github.com/spf13/viper v1.20.1
 | 
						github.com/spf13/viper v1.20.1
 | 
				
			||||||
	go.etcd.io/bbolt v1.3.9
 | 
					 | 
				
			||||||
	go.uber.org/zap v1.27.0
 | 
						go.uber.org/zap v1.27.0
 | 
				
			||||||
	golang.org/x/text v0.22.0
 | 
						golang.org/x/text v0.30.0
 | 
				
			||||||
	gopkg.in/natefinch/lumberjack.v2 v2.2.1
 | 
						gopkg.in/natefinch/lumberjack.v2 v2.2.1
 | 
				
			||||||
	gopkg.in/yaml.v3 v3.0.1
 | 
						gopkg.in/yaml.v3 v3.0.1
 | 
				
			||||||
 | 
						gorm.io/gorm v1.31.0
 | 
				
			||||||
	resty.dev/v3 v3.0.0-beta.3
 | 
						resty.dev/v3 v3.0.0-beta.3
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -30,6 +29,7 @@ require (
 | 
				
			|||||||
	github.com/cloudwego/iasm v0.2.0 // indirect
 | 
						github.com/cloudwego/iasm v0.2.0 // indirect
 | 
				
			||||||
	github.com/coreos/go-iptables v0.8.0 // indirect
 | 
						github.com/coreos/go-iptables v0.8.0 // indirect
 | 
				
			||||||
	github.com/dlclark/regexp2 v1.11.5 // indirect
 | 
						github.com/dlclark/regexp2 v1.11.5 // indirect
 | 
				
			||||||
 | 
						github.com/dustin/go-humanize v1.0.1 // indirect
 | 
				
			||||||
	github.com/ebitengine/purego v0.8.3 // indirect
 | 
						github.com/ebitengine/purego v0.8.3 // indirect
 | 
				
			||||||
	github.com/enfein/mieru/v3 v3.13.0 // indirect
 | 
						github.com/enfein/mieru/v3 v3.13.0 // indirect
 | 
				
			||||||
	github.com/ericlagergren/aegis v0.0.0-20250325060835-cd0defd64358 // indirect
 | 
						github.com/ericlagergren/aegis v0.0.0-20250325060835-cd0defd64358 // indirect
 | 
				
			||||||
@@ -40,6 +40,7 @@ require (
 | 
				
			|||||||
	github.com/gabriel-vasile/mimetype v1.4.3 // indirect
 | 
						github.com/gabriel-vasile/mimetype v1.4.3 // indirect
 | 
				
			||||||
	github.com/gaukas/godicttls v0.0.4 // indirect
 | 
						github.com/gaukas/godicttls v0.0.4 // indirect
 | 
				
			||||||
	github.com/gin-contrib/sse v0.1.0 // indirect
 | 
						github.com/gin-contrib/sse v0.1.0 // indirect
 | 
				
			||||||
 | 
						github.com/glebarez/go-sqlite v1.21.2 // indirect
 | 
				
			||||||
	github.com/go-ole/go-ole v1.3.0 // indirect
 | 
						github.com/go-ole/go-ole v1.3.0 // indirect
 | 
				
			||||||
	github.com/go-playground/locales v0.14.1 // indirect
 | 
						github.com/go-playground/locales v0.14.1 // indirect
 | 
				
			||||||
	github.com/go-playground/universal-translator v0.18.1 // indirect
 | 
						github.com/go-playground/universal-translator v0.18.1 // indirect
 | 
				
			||||||
@@ -53,9 +54,12 @@ require (
 | 
				
			|||||||
	github.com/gofrs/uuid/v5 v5.3.2 // indirect
 | 
						github.com/gofrs/uuid/v5 v5.3.2 // indirect
 | 
				
			||||||
	github.com/google/btree v1.1.3 // indirect
 | 
						github.com/google/btree v1.1.3 // indirect
 | 
				
			||||||
	github.com/google/go-cmp v0.6.0 // indirect
 | 
						github.com/google/go-cmp v0.6.0 // indirect
 | 
				
			||||||
	github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
 | 
						github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 // indirect
 | 
				
			||||||
 | 
						github.com/google/uuid v1.6.0 // indirect
 | 
				
			||||||
	github.com/hashicorp/yamux v0.1.2 // indirect
 | 
						github.com/hashicorp/yamux v0.1.2 // indirect
 | 
				
			||||||
	github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905 // indirect
 | 
						github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905 // indirect
 | 
				
			||||||
 | 
						github.com/jinzhu/inflection v1.0.0 // indirect
 | 
				
			||||||
 | 
						github.com/jinzhu/now v1.1.5 // indirect
 | 
				
			||||||
	github.com/josharian/native v1.1.0 // indirect
 | 
						github.com/josharian/native v1.1.0 // indirect
 | 
				
			||||||
	github.com/json-iterator/go v1.1.12 // indirect
 | 
						github.com/json-iterator/go v1.1.12 // indirect
 | 
				
			||||||
	github.com/klauspost/compress v1.17.9 // indirect
 | 
						github.com/klauspost/compress v1.17.9 // indirect
 | 
				
			||||||
@@ -103,6 +107,7 @@ require (
 | 
				
			|||||||
	github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
 | 
						github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
 | 
				
			||||||
	github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
 | 
						github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
 | 
				
			||||||
	github.com/quic-go/qpack v0.4.0 // indirect
 | 
						github.com/quic-go/qpack v0.4.0 // indirect
 | 
				
			||||||
 | 
						github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
 | 
				
			||||||
	github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a // indirect
 | 
						github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a // indirect
 | 
				
			||||||
	github.com/sagikazarmark/locafero v0.7.0 // indirect
 | 
						github.com/sagikazarmark/locafero v0.7.0 // indirect
 | 
				
			||||||
	github.com/samber/lo v1.50.0 // indirect
 | 
						github.com/samber/lo v1.50.0 // indirect
 | 
				
			||||||
@@ -132,14 +137,18 @@ require (
 | 
				
			|||||||
	go.uber.org/multierr v1.11.0 // indirect
 | 
						go.uber.org/multierr v1.11.0 // indirect
 | 
				
			||||||
	go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
 | 
						go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
 | 
				
			||||||
	golang.org/x/arch v0.8.0 // indirect
 | 
						golang.org/x/arch v0.8.0 // indirect
 | 
				
			||||||
	golang.org/x/crypto v0.33.0 // indirect
 | 
						golang.org/x/crypto v0.42.0 // indirect
 | 
				
			||||||
	golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
 | 
						golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
 | 
				
			||||||
	golang.org/x/mod v0.20.0 // indirect
 | 
						golang.org/x/mod v0.28.0 // indirect
 | 
				
			||||||
	golang.org/x/net v0.35.0 // indirect
 | 
						golang.org/x/net v0.44.0 // indirect
 | 
				
			||||||
	golang.org/x/sync v0.11.0 // indirect
 | 
						golang.org/x/sync v0.17.0 // indirect
 | 
				
			||||||
	golang.org/x/sys v0.30.0 // indirect
 | 
						golang.org/x/sys v0.36.0 // indirect
 | 
				
			||||||
	golang.org/x/time v0.8.0 // indirect
 | 
						golang.org/x/time v0.8.0 // indirect
 | 
				
			||||||
	golang.org/x/tools v0.24.0 // indirect
 | 
						golang.org/x/tools v0.37.0 // indirect
 | 
				
			||||||
	google.golang.org/protobuf v1.36.1 // indirect
 | 
						google.golang.org/protobuf v1.36.1 // indirect
 | 
				
			||||||
	lukechampine.com/blake3 v1.3.0 // indirect
 | 
						lukechampine.com/blake3 v1.3.0 // indirect
 | 
				
			||||||
 | 
						modernc.org/libc v1.22.5 // indirect
 | 
				
			||||||
 | 
						modernc.org/mathutil v1.5.0 // indirect
 | 
				
			||||||
 | 
						modernc.org/memory v1.5.0 // indirect
 | 
				
			||||||
 | 
						modernc.org/sqlite v1.23.1 // indirect
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										68
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								go.sum
									
									
									
									
									
								
							@@ -19,9 +19,6 @@ github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc
 | 
				
			|||||||
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
 | 
					github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
 | 
				
			||||||
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
 | 
					github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
 | 
				
			||||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
 | 
					github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
 | 
				
			||||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
 | 
					 | 
				
			||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
 | 
					 | 
				
			||||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
 | 
					 | 
				
			||||||
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
 | 
					github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
 | 
				
			||||||
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
 | 
					github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
 | 
				
			||||||
github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
 | 
					github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y=
 | 
				
			||||||
@@ -35,6 +32,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
 | 
				
			|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
					github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 | 
				
			||||||
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
 | 
					github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
 | 
				
			||||||
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
 | 
					github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
 | 
				
			||||||
 | 
					github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
 | 
				
			||||||
 | 
					github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
 | 
				
			||||||
github.com/ebitengine/purego v0.8.3 h1:K+0AjQp63JEZTEMZiwsI9g0+hAMNohwUOtY0RPGexmc=
 | 
					github.com/ebitengine/purego v0.8.3 h1:K+0AjQp63JEZTEMZiwsI9g0+hAMNohwUOtY0RPGexmc=
 | 
				
			||||||
github.com/ebitengine/purego v0.8.3/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
 | 
					github.com/ebitengine/purego v0.8.3/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
 | 
				
			||||||
github.com/enfein/mieru/v3 v3.13.0 h1:eGyxLGkb+lut9ebmx+BGwLJ5UMbEc/wGIYO0AXEKy98=
 | 
					github.com/enfein/mieru/v3 v3.13.0 h1:eGyxLGkb+lut9ebmx+BGwLJ5UMbEc/wGIYO0AXEKy98=
 | 
				
			||||||
@@ -61,6 +60,10 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
 | 
				
			|||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 | 
					github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
 | 
				
			||||||
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
 | 
					github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
 | 
				
			||||||
github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
 | 
					github.com/gin-gonic/gin v1.10.1/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y=
 | 
				
			||||||
 | 
					github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
 | 
				
			||||||
 | 
					github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
 | 
				
			||||||
 | 
					github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw=
 | 
				
			||||||
 | 
					github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ=
 | 
				
			||||||
github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=
 | 
					github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=
 | 
				
			||||||
github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
 | 
					github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
 | 
				
			||||||
github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
 | 
					github.com/go-chi/render v1.0.3 h1:AsXqd2a1/INaIfUSKq3G5uA8weYx20FOsM7uSoCyyt4=
 | 
				
			||||||
@@ -101,15 +104,20 @@ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
 | 
				
			|||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
 | 
					github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
 | 
				
			||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 | 
					github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 | 
				
			||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 | 
					github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 | 
				
			||||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
 | 
					github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
 | 
				
			||||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
 | 
					github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
 | 
				
			||||||
github.com/google/tink/go v1.6.1 h1:t7JHqO8Ath2w2ig5vjwQYJzhGEZymedQc90lQXUBa4I=
 | 
					github.com/google/tink/go v1.6.1 h1:t7JHqO8Ath2w2ig5vjwQYJzhGEZymedQc90lQXUBa4I=
 | 
				
			||||||
github.com/google/tink/go v1.6.1/go.mod h1:IGW53kTgag+st5yPhKKwJ6u2l+SSp5/v9XF7spovjlY=
 | 
					github.com/google/tink/go v1.6.1/go.mod h1:IGW53kTgag+st5yPhKKwJ6u2l+SSp5/v9XF7spovjlY=
 | 
				
			||||||
 | 
					github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
 | 
				
			||||||
 | 
					github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 | 
				
			||||||
github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
 | 
					github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
 | 
				
			||||||
github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
 | 
					github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
 | 
				
			||||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
 | 
					 | 
				
			||||||
github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905 h1:q3OEI9RaN/wwcx+qgGo6ZaoJkCiDYe/gjDLfq7lQQF4=
 | 
					github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905 h1:q3OEI9RaN/wwcx+qgGo6ZaoJkCiDYe/gjDLfq7lQQF4=
 | 
				
			||||||
github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905/go.mod h1:VvGYjkZoJyKqlmT1yzakUs4mfKMNB0XdODP0+rdml6k=
 | 
					github.com/insomniacslk/dhcp v0.0.0-20250109001534-8abf58130905/go.mod h1:VvGYjkZoJyKqlmT1yzakUs4mfKMNB0XdODP0+rdml6k=
 | 
				
			||||||
 | 
					github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 | 
				
			||||||
 | 
					github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 | 
				
			||||||
 | 
					github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
 | 
				
			||||||
 | 
					github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
 | 
				
			||||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
 | 
					github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
 | 
				
			||||||
github.com/josharian/native v1.0.1-0.20221213033349-c1e37c09b531/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
 | 
					github.com/josharian/native v1.0.1-0.20221213033349-c1e37c09b531/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
 | 
				
			||||||
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
 | 
					github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
 | 
				
			||||||
@@ -226,6 +234,9 @@ github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++
 | 
				
			|||||||
github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
 | 
					github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
 | 
				
			||||||
github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
 | 
					github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
 | 
				
			||||||
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
 | 
					github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
 | 
				
			||||||
 | 
					github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
 | 
				
			||||||
 | 
					github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
 | 
				
			||||||
 | 
					github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
 | 
				
			||||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
 | 
					github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
 | 
				
			||||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
 | 
					github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
 | 
				
			||||||
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a h1:ObwtHN2VpqE0ZNjr6sGeT00J8uU7JF4cNUdb44/Duis=
 | 
					github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a h1:ObwtHN2VpqE0ZNjr6sGeT00J8uU7JF4cNUdb44/Duis=
 | 
				
			||||||
@@ -297,8 +308,6 @@ gitlab.com/go-extension/aes-ccm v0.0.0-20230221065045-e58665ef23c7 h1:UNrDfkQqiE
 | 
				
			|||||||
gitlab.com/go-extension/aes-ccm v0.0.0-20230221065045-e58665ef23c7/go.mod h1:E+rxHvJG9H6PUdzq9NRG6csuLN3XUx98BfGOVWNYnXs=
 | 
					gitlab.com/go-extension/aes-ccm v0.0.0-20230221065045-e58665ef23c7/go.mod h1:E+rxHvJG9H6PUdzq9NRG6csuLN3XUx98BfGOVWNYnXs=
 | 
				
			||||||
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec h1:FpfFs4EhNehiVfzQttTuxanPIT43FtkkCFypIod8LHo=
 | 
					gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec h1:FpfFs4EhNehiVfzQttTuxanPIT43FtkkCFypIod8LHo=
 | 
				
			||||||
gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec/go.mod h1:BZ1RAoRPbCxum9Grlv5aeksu2H8BiKehBYooU2LFiOQ=
 | 
					gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec/go.mod h1:BZ1RAoRPbCxum9Grlv5aeksu2H8BiKehBYooU2LFiOQ=
 | 
				
			||||||
go.etcd.io/bbolt v1.3.9 h1:8x7aARPEXiXbHmtUwAIv7eV2fQFHrLLavdiJ3uzJXoI=
 | 
					 | 
				
			||||||
go.etcd.io/bbolt v1.3.9/go.mod h1:zaO32+Ti0PK1ivdPtgMESzuzL2VPoIG1PCQNvOdo/dE=
 | 
					 | 
				
			||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 | 
					go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
 | 
				
			||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
 | 
					go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
 | 
				
			||||||
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
 | 
					go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
 | 
				
			||||||
@@ -314,27 +323,26 @@ golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
 | 
				
			|||||||
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
 | 
					golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 | 
					golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 | 
				
			||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 | 
					golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 | 
				
			||||||
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
 | 
					golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=
 | 
				
			||||||
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
 | 
					golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=
 | 
				
			||||||
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
 | 
					golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk=
 | 
				
			||||||
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
 | 
					golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
 | 
				
			||||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
 | 
					golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
 | 
				
			||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
 | 
					golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
 | 
				
			||||||
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
 | 
					golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
 | 
				
			||||||
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
 | 
					golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
 | 
				
			||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 | 
					golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 | 
				
			||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 | 
					golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 | 
				
			||||||
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
 | 
					golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
 | 
				
			||||||
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
 | 
					golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
 | 
				
			||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
					golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 | 
				
			||||||
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
 | 
					golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
 | 
				
			||||||
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
 | 
					golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 | 
					golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					 | 
				
			||||||
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
					golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 | 
				
			||||||
golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.0.0-20220622161953-175b2fd9d664/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
@@ -344,18 +352,18 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			|||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
					golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 | 
				
			||||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
					golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
				
			||||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
 | 
					golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
 | 
				
			||||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 | 
					golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
 | 
				
			||||||
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
 | 
					golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ=
 | 
				
			||||||
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
 | 
					golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
 | 
				
			||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 | 
					golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 | 
				
			||||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
 | 
					golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
 | 
				
			||||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
 | 
					golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
 | 
				
			||||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
 | 
					golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
 | 
				
			||||||
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
 | 
					golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
 | 
				
			||||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
 | 
					golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
 | 
				
			||||||
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
 | 
					golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
 | 
				
			||||||
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
 | 
					golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
 | 
				
			||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
					golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
				
			||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
					golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 | 
				
			||||||
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
 | 
					google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
 | 
				
			||||||
@@ -368,8 +376,18 @@ gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYs
 | 
				
			|||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
					gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
 | 
				
			||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
					gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
 | 
				
			||||||
 | 
					gorm.io/gorm v1.31.0 h1:0VlycGreVhK7RF/Bwt51Fk8v0xLiiiFdbGDPIZQ7mJY=
 | 
				
			||||||
 | 
					gorm.io/gorm v1.31.0/go.mod h1:XyQVbO2k6YkOis7C2437jSit3SsDK72s7n7rsSHd+Gs=
 | 
				
			||||||
lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE=
 | 
					lukechampine.com/blake3 v1.3.0 h1:sJ3XhFINmHSrYCgl958hscfIa3bw8x4DqMP3u1YvoYE=
 | 
				
			||||||
lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
 | 
					lukechampine.com/blake3 v1.3.0/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
 | 
				
			||||||
 | 
					modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
 | 
				
			||||||
 | 
					modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
 | 
				
			||||||
 | 
					modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
 | 
				
			||||||
 | 
					modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
 | 
				
			||||||
 | 
					modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
 | 
				
			||||||
 | 
					modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
 | 
				
			||||||
 | 
					modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
 | 
				
			||||||
 | 
					modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
 | 
				
			||||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
 | 
					nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
 | 
				
			||||||
resty.dev/v3 v3.0.0-beta.3 h1:3kEwzEgCnnS6Ob4Emlk94t+I/gClyoah7SnNi67lt+E=
 | 
					resty.dev/v3 v3.0.0-beta.3 h1:3kEwzEgCnnS6Ob4Emlk94t+I/gClyoah7SnNi67lt+E=
 | 
				
			||||||
resty.dev/v3 v3.0.0-beta.3/go.mod h1:OgkqiPvTDtOuV4MGZuUDhwOpkY8enjOsjjMzeOHefy4=
 | 
					resty.dev/v3 v3.0.0-beta.3/go.mod h1:OgkqiPvTDtOuV4MGZuUDhwOpkY8enjOsjjMzeOHefy4=
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.go
									
									
									
									
									
								
							@@ -5,7 +5,6 @@ import (
 | 
				
			|||||||
	"io"
 | 
						"io"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/bestnite/sub2clash/common"
 | 
						"github.com/bestnite/sub2clash/common"
 | 
				
			||||||
	"github.com/bestnite/sub2clash/common/database"
 | 
					 | 
				
			||||||
	"github.com/bestnite/sub2clash/config"
 | 
						"github.com/bestnite/sub2clash/config"
 | 
				
			||||||
	"github.com/bestnite/sub2clash/logger"
 | 
						"github.com/bestnite/sub2clash/logger"
 | 
				
			||||||
	"github.com/bestnite/sub2clash/server"
 | 
						"github.com/bestnite/sub2clash/server"
 | 
				
			||||||
@@ -29,10 +28,6 @@ func init() {
 | 
				
			|||||||
		logger.Logger.Panic("load config failed", zap.Error(err))
 | 
							logger.Logger.Panic("load config failed", zap.Error(err))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = database.ConnectDB()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		logger.Logger.Panic("database connect failed", zap.Error(err))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	logger.Logger.Info("database connect success")
 | 
						logger.Logger.Info("database connect success")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,11 +13,12 @@ func GetSupportProxyTypes(clashType ClashType) map[string]bool {
 | 
				
			|||||||
	supportProxyTypes := make(map[string]bool)
 | 
						supportProxyTypes := make(map[string]bool)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, parser := range parser.GetAllParsers() {
 | 
						for _, parser := range parser.GetAllParsers() {
 | 
				
			||||||
		if clashType == Clash {
 | 
							switch clashType {
 | 
				
			||||||
 | 
							case Clash:
 | 
				
			||||||
			if parser.SupportClash() {
 | 
								if parser.SupportClash() {
 | 
				
			||||||
				supportProxyTypes[parser.GetType()] = true
 | 
									supportProxyTypes[parser.GetType()] = true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		} else if clashType == ClashMeta {
 | 
							case ClashMeta:
 | 
				
			||||||
			if parser.SupportMeta() {
 | 
								if parser.SupportMeta() {
 | 
				
			||||||
				supportProxyTypes[parser.GetType()] = true
 | 
									supportProxyTypes[parser.GetType()] = true
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										92
									
								
								model/convert_config.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								model/convert_config.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,92 @@
 | 
				
			|||||||
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"net/url"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type ConvertConfig struct {
 | 
				
			||||||
 | 
						ClashType           ClashType            `json:"clashType" binding:"required"`
 | 
				
			||||||
 | 
						Subs                []string             `json:"subscriptions" binding:""`
 | 
				
			||||||
 | 
						Proxies             []string             `json:"proxies" binding:""`
 | 
				
			||||||
 | 
						Refresh             bool                 `json:"refresh" binding:""`
 | 
				
			||||||
 | 
						Template            string               `json:"template" binding:""`
 | 
				
			||||||
 | 
						RuleProviders       []RuleProviderStruct `json:"ruleProviders" binding:""`
 | 
				
			||||||
 | 
						Rules               []RuleStruct         `json:"rules" binding:""`
 | 
				
			||||||
 | 
						AutoTest            bool                 `json:"autoTest" binding:""`
 | 
				
			||||||
 | 
						Lazy                bool                 `json:"lazy" binding:""`
 | 
				
			||||||
 | 
						Sort                string               `json:"sort" binding:""`
 | 
				
			||||||
 | 
						Remove              string               `json:"remove" binding:""`
 | 
				
			||||||
 | 
						Replace             map[string]string    `json:"replace" binding:""`
 | 
				
			||||||
 | 
						NodeListMode        bool                 `json:"nodeList" binding:""`
 | 
				
			||||||
 | 
						IgnoreCountryGrooup bool                 `json:"ignoreCountryGroup" binding:""`
 | 
				
			||||||
 | 
						UserAgent           string               `json:"userAgent" binding:""`
 | 
				
			||||||
 | 
						UseUDP              bool                 `json:"useUDP" binding:""`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RuleProviderStruct struct {
 | 
				
			||||||
 | 
						Behavior string `json:"behavior" binding:""`
 | 
				
			||||||
 | 
						Url      string `json:"url" binding:""`
 | 
				
			||||||
 | 
						Group    string `json:"group" binding:""`
 | 
				
			||||||
 | 
						Prepend  bool   `json:"prepend" binding:""`
 | 
				
			||||||
 | 
						Name     string `json:"name" binding:""`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type RuleStruct struct {
 | 
				
			||||||
 | 
						Rule    string `json:"rule" binding:""`
 | 
				
			||||||
 | 
						Prepend bool   `json:"prepend" binding:""`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ParseConvertQuery(c *gin.Context) (ConvertConfig, error) {
 | 
				
			||||||
 | 
						config := c.Param("config")
 | 
				
			||||||
 | 
						queryBytes, err := utils.DecodeBase64(config, true)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ConvertConfig{}, errors.New("参数错误: " + err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var query ConvertConfig
 | 
				
			||||||
 | 
						err = json.Unmarshal([]byte(queryBytes), &query)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return ConvertConfig{}, errors.New("参数错误: " + err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(query.Subs) == 0 && len(query.Proxies) == 0 {
 | 
				
			||||||
 | 
							return ConvertConfig{}, errors.New("参数错误: sub 和 proxy 不能同时为空")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(query.Subs) > 0 {
 | 
				
			||||||
 | 
							for i := range query.Subs {
 | 
				
			||||||
 | 
								if !strings.HasPrefix(query.Subs[i], "http") {
 | 
				
			||||||
 | 
									return ConvertConfig{}, errors.New("参数错误: sub 格式错误")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if _, err := url.ParseRequestURI(query.Subs[i]); err != nil {
 | 
				
			||||||
 | 
									return ConvertConfig{}, errors.New("参数错误: " + err.Error())
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							query.Subs = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if query.Template != "" {
 | 
				
			||||||
 | 
							if strings.HasPrefix(query.Template, "http") {
 | 
				
			||||||
 | 
								uri, err := url.ParseRequestURI(query.Template)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return ConvertConfig{}, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								query.Template = uri.String()
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(query.RuleProviders) > 0 {
 | 
				
			||||||
 | 
							names := make(map[string]bool)
 | 
				
			||||||
 | 
							for _, ruleProvider := range query.RuleProviders {
 | 
				
			||||||
 | 
								if _, ok := names[ruleProvider.Name]; ok {
 | 
				
			||||||
 | 
									return ConvertConfig{}, errors.New("参数错误: Rule-Provider 名称重复")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								names[ruleProvider.Name] = true
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							query.RuleProviders = nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return query, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -3,7 +3,7 @@ package proxy
 | 
				
			|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/anytls.go
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/anytls.go
 | 
				
			||||||
type Anytls struct {
 | 
					type Anytls struct {
 | 
				
			||||||
	Server                   string      `yaml:"server"`
 | 
						Server                   string      `yaml:"server"`
 | 
				
			||||||
	Port                     int        `yaml:"port"`
 | 
						Port                     IntOrString `yaml:"port"`
 | 
				
			||||||
	Password                 string      `yaml:"password"`
 | 
						Password                 string      `yaml:"password"`
 | 
				
			||||||
	ALPN                     []string    `yaml:"alpn,omitempty"`
 | 
						ALPN                     []string    `yaml:"alpn,omitempty"`
 | 
				
			||||||
	SNI                      string      `yaml:"sni,omitempty"`
 | 
						SNI                      string      `yaml:"sni,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package proxy
 | 
				
			|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria.go
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria.go
 | 
				
			||||||
type Hysteria struct {
 | 
					type Hysteria struct {
 | 
				
			||||||
	Server              string      `yaml:"server"`
 | 
						Server              string      `yaml:"server"`
 | 
				
			||||||
	Port                int        `yaml:"port,omitempty"`
 | 
						Port                IntOrString `yaml:"port,omitempty"`
 | 
				
			||||||
	Ports               string      `yaml:"ports,omitempty"`
 | 
						Ports               string      `yaml:"ports,omitempty"`
 | 
				
			||||||
	Protocol            string      `yaml:"protocol,omitempty"`
 | 
						Protocol            string      `yaml:"protocol,omitempty"`
 | 
				
			||||||
	ObfsProtocol        string      `yaml:"obfs-protocol,omitempty"` // compatible with Stash
 | 
						ObfsProtocol        string      `yaml:"obfs-protocol,omitempty"` // compatible with Stash
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package proxy
 | 
				
			|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria2.go
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/hysteria2.go
 | 
				
			||||||
type Hysteria2 struct {
 | 
					type Hysteria2 struct {
 | 
				
			||||||
	Server         string      `yaml:"server"`
 | 
						Server         string      `yaml:"server"`
 | 
				
			||||||
	Port           int        `yaml:"port,omitempty"`
 | 
						Port           IntOrString `yaml:"port,omitempty"`
 | 
				
			||||||
	Ports          string      `yaml:"ports,omitempty"`
 | 
						Ports          string      `yaml:"ports,omitempty"`
 | 
				
			||||||
	HopInterval    int         `yaml:"hop-interval,omitempty"`
 | 
						HopInterval    int         `yaml:"hop-interval,omitempty"`
 | 
				
			||||||
	Up             string      `yaml:"up,omitempty"`
 | 
						Up             string      `yaml:"up,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,10 +2,31 @@ package proxy
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
 | 
						"strconv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"gopkg.in/yaml.v3"
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type IntOrString int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (i *IntOrString) UnmarshalYAML(value *yaml.Node) error {
 | 
				
			||||||
 | 
						intVal := 0
 | 
				
			||||||
 | 
						err := yaml.Unmarshal([]byte(value.Value), &intVal)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							*i = IntOrString(intVal)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						strVal := ""
 | 
				
			||||||
 | 
						err = yaml.Unmarshal([]byte(value.Value), &strVal)
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							_int, err := strconv.ParseInt(strVal, 10, 64)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								*i = IntOrString(_int)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type HTTPOptions struct {
 | 
					type HTTPOptions struct {
 | 
				
			||||||
	Method  string              `yaml:"method,omitempty"`
 | 
						Method  string              `yaml:"method,omitempty"`
 | 
				
			||||||
	Path    []string            `yaml:"path,omitempty"`
 | 
						Path    []string            `yaml:"path,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package proxy
 | 
				
			|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocks.go
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocks.go
 | 
				
			||||||
type ShadowSocks struct {
 | 
					type ShadowSocks struct {
 | 
				
			||||||
	Server            string         `yaml:"server"`
 | 
						Server            string         `yaml:"server"`
 | 
				
			||||||
	Port              int            `yaml:"port"`
 | 
						Port              IntOrString    `yaml:"port"`
 | 
				
			||||||
	Password          string         `yaml:"password"`
 | 
						Password          string         `yaml:"password"`
 | 
				
			||||||
	Cipher            string         `yaml:"cipher"`
 | 
						Cipher            string         `yaml:"cipher"`
 | 
				
			||||||
	UDP               bool           `yaml:"udp,omitempty"`
 | 
						UDP               bool           `yaml:"udp,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package proxy
 | 
				
			|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocksr.go
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/shadowsocksr.go
 | 
				
			||||||
type ShadowSocksR struct {
 | 
					type ShadowSocksR struct {
 | 
				
			||||||
	Server        string      `yaml:"server"`
 | 
						Server        string      `yaml:"server"`
 | 
				
			||||||
	Port          int    `yaml:"port"`
 | 
						Port          IntOrString `yaml:"port"`
 | 
				
			||||||
	Password      string      `yaml:"password"`
 | 
						Password      string      `yaml:"password"`
 | 
				
			||||||
	Cipher        string      `yaml:"cipher"`
 | 
						Cipher        string      `yaml:"cipher"`
 | 
				
			||||||
	Obfs          string      `yaml:"obfs"`
 | 
						Obfs          string      `yaml:"obfs"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package proxy
 | 
				
			|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/socks5.go
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/socks5.go
 | 
				
			||||||
type Socks struct {
 | 
					type Socks struct {
 | 
				
			||||||
	Server         string      `yaml:"server"`
 | 
						Server         string      `yaml:"server"`
 | 
				
			||||||
	Port           int    `yaml:"port"`
 | 
						Port           IntOrString `yaml:"port"`
 | 
				
			||||||
	UserName       string      `yaml:"username,omitempty"`
 | 
						UserName       string      `yaml:"username,omitempty"`
 | 
				
			||||||
	Password       string      `yaml:"password,omitempty"`
 | 
						Password       string      `yaml:"password,omitempty"`
 | 
				
			||||||
	TLS            bool        `yaml:"tls,omitempty"`
 | 
						TLS            bool        `yaml:"tls,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package proxy
 | 
				
			|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/trojan.go
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/trojan.go
 | 
				
			||||||
type Trojan struct {
 | 
					type Trojan struct {
 | 
				
			||||||
	Server            string         `yaml:"server"`
 | 
						Server            string         `yaml:"server"`
 | 
				
			||||||
	Port              int            `yaml:"port"`
 | 
						Port              IntOrString    `yaml:"port"`
 | 
				
			||||||
	Password          string         `yaml:"password"`
 | 
						Password          string         `yaml:"password"`
 | 
				
			||||||
	ALPN              []string       `yaml:"alpn,omitempty"`
 | 
						ALPN              []string       `yaml:"alpn,omitempty"`
 | 
				
			||||||
	SNI               string         `yaml:"sni,omitempty"`
 | 
						SNI               string         `yaml:"sni,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package proxy
 | 
				
			|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vless.go
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vless.go
 | 
				
			||||||
type Vless struct {
 | 
					type Vless struct {
 | 
				
			||||||
	Server            string            `yaml:"server"`
 | 
						Server            string            `yaml:"server"`
 | 
				
			||||||
	Port              int               `yaml:"port"`
 | 
						Port              IntOrString       `yaml:"port"`
 | 
				
			||||||
	UUID              string            `yaml:"uuid"`
 | 
						UUID              string            `yaml:"uuid"`
 | 
				
			||||||
	Flow              string            `yaml:"flow,omitempty"`
 | 
						Flow              string            `yaml:"flow,omitempty"`
 | 
				
			||||||
	TLS               bool              `yaml:"tls,omitempty"`
 | 
						TLS               bool              `yaml:"tls,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,9 +3,9 @@ package proxy
 | 
				
			|||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vmess.go
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/adapter/outbound/vmess.go
 | 
				
			||||||
type Vmess struct {
 | 
					type Vmess struct {
 | 
				
			||||||
	Server              string         `yaml:"server"`
 | 
						Server              string         `yaml:"server"`
 | 
				
			||||||
	Port                int            `yaml:"port"`
 | 
						Port                IntOrString    `yaml:"port"`
 | 
				
			||||||
	UUID                string         `yaml:"uuid"`
 | 
						UUID                string         `yaml:"uuid"`
 | 
				
			||||||
	AlterID             int            `yaml:"alterId"`
 | 
						AlterID             IntOrString    `yaml:"alterId"`
 | 
				
			||||||
	Cipher              string         `yaml:"cipher"`
 | 
						Cipher              string         `yaml:"cipher"`
 | 
				
			||||||
	UDP                 bool           `yaml:"udp,omitempty"`
 | 
						UDP                 bool           `yaml:"udp,omitempty"`
 | 
				
			||||||
	Network             string         `yaml:"network,omitempty"`
 | 
						Network             string         `yaml:"network,omitempty"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
package model
 | 
					package model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ShortLink struct {
 | 
					type ShortLink struct {
 | 
				
			||||||
	Hash            string
 | 
						ID              string        `gorm:"unique"`
 | 
				
			||||||
	Url             string
 | 
						Config          ConvertConfig `gorm:"serializer:json"`
 | 
				
			||||||
	Password        string
 | 
						Password        string
 | 
				
			||||||
	LastRequestTime int64
 | 
						LastRequestTime int64
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,159 +0,0 @@
 | 
				
			|||||||
package model
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import (
 | 
					 | 
				
			||||||
	"crypto/sha256"
 | 
					 | 
				
			||||||
	"encoding/hex"
 | 
					 | 
				
			||||||
	"errors"
 | 
					 | 
				
			||||||
	"net/url"
 | 
					 | 
				
			||||||
	"regexp"
 | 
					 | 
				
			||||||
	"strings"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type SubConfig struct {
 | 
					 | 
				
			||||||
	Sub                 string               `form:"sub" binding:""`
 | 
					 | 
				
			||||||
	Subs                []string             `form:"-" binding:""`
 | 
					 | 
				
			||||||
	Proxy               string               `form:"proxy" binding:""`
 | 
					 | 
				
			||||||
	Proxies             []string             `form:"-" binding:""`
 | 
					 | 
				
			||||||
	Refresh             bool                 `form:"refresh,default=false" binding:""`
 | 
					 | 
				
			||||||
	Template            string               `form:"template" binding:""`
 | 
					 | 
				
			||||||
	RuleProvider        string               `form:"ruleProvider" binding:""`
 | 
					 | 
				
			||||||
	RuleProviders       []RuleProviderStruct `form:"-" binding:""`
 | 
					 | 
				
			||||||
	Rule                string               `form:"rule" binding:""`
 | 
					 | 
				
			||||||
	Rules               []RuleStruct         `form:"-" binding:""`
 | 
					 | 
				
			||||||
	AutoTest            bool                 `form:"autoTest,default=false" binding:""`
 | 
					 | 
				
			||||||
	Lazy                bool                 `form:"lazy,default=false" binding:""`
 | 
					 | 
				
			||||||
	Sort                string               `form:"sort" binding:""`
 | 
					 | 
				
			||||||
	Remove              string               `form:"remove" binding:""`
 | 
					 | 
				
			||||||
	Replace             string               `form:"replace" binding:""`
 | 
					 | 
				
			||||||
	ReplaceKeys         []string             `form:"-" binding:""`
 | 
					 | 
				
			||||||
	ReplaceTo           []string             `form:"-" binding:""`
 | 
					 | 
				
			||||||
	NodeListMode        bool                 `form:"nodeList,default=false" binding:""`
 | 
					 | 
				
			||||||
	IgnoreCountryGrooup bool                 `form:"ignoreCountryGroup,default=false" binding:""`
 | 
					 | 
				
			||||||
	UserAgent           string               `form:"userAgent" binding:""`
 | 
					 | 
				
			||||||
	UseUDP              bool                 `form:"useUDP,default=false" binding:""`
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RuleProviderStruct struct {
 | 
					 | 
				
			||||||
	Behavior string
 | 
					 | 
				
			||||||
	Url      string
 | 
					 | 
				
			||||||
	Group    string
 | 
					 | 
				
			||||||
	Prepend  bool
 | 
					 | 
				
			||||||
	Name     string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type RuleStruct struct {
 | 
					 | 
				
			||||||
	Rule    string
 | 
					 | 
				
			||||||
	Prepend bool
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func ParseSubQuery(c *gin.Context) (SubConfig, error) {
 | 
					 | 
				
			||||||
	var query SubConfig
 | 
					 | 
				
			||||||
	if err := c.ShouldBind(&query); err != nil {
 | 
					 | 
				
			||||||
		return SubConfig{}, errors.New("参数错误: " + err.Error())
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Sub == "" && query.Proxy == "" {
 | 
					 | 
				
			||||||
		return SubConfig{}, errors.New("参数错误: sub 和 proxy 不能同时为空")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Sub != "" {
 | 
					 | 
				
			||||||
		query.Subs = strings.Split(query.Sub, ",")
 | 
					 | 
				
			||||||
		for i := range query.Subs {
 | 
					 | 
				
			||||||
			if !strings.HasPrefix(query.Subs[i], "http") {
 | 
					 | 
				
			||||||
				return SubConfig{}, errors.New("参数错误: sub 格式错误")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			if _, err := url.ParseRequestURI(query.Subs[i]); err != nil {
 | 
					 | 
				
			||||||
				return SubConfig{}, errors.New("参数错误: " + err.Error())
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		query.Subs = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Proxy != "" {
 | 
					 | 
				
			||||||
		query.Proxies = strings.Split(query.Proxy, ",")
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		query.Proxies = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Template != "" {
 | 
					 | 
				
			||||||
		if strings.HasPrefix(query.Template, "http") {
 | 
					 | 
				
			||||||
			uri, err := url.ParseRequestURI(query.Template)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return SubConfig{}, err
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			query.Template = uri.String()
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.RuleProvider != "" {
 | 
					 | 
				
			||||||
		reg := regexp.MustCompile(`\[(.*?)\]`)
 | 
					 | 
				
			||||||
		ruleProviders := reg.FindAllStringSubmatch(query.RuleProvider, -1)
 | 
					 | 
				
			||||||
		for i := range ruleProviders {
 | 
					 | 
				
			||||||
			length := len(ruleProviders)
 | 
					 | 
				
			||||||
			parts := strings.Split(ruleProviders[length-i-1][1], ",")
 | 
					 | 
				
			||||||
			if len(parts) < 4 {
 | 
					 | 
				
			||||||
				return SubConfig{}, errors.New("参数错误: ruleProvider 格式错误")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			u := parts[1]
 | 
					 | 
				
			||||||
			uri, err := url.ParseRequestURI(u)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return SubConfig{}, errors.New("参数错误: " + err.Error())
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			u = uri.String()
 | 
					 | 
				
			||||||
			if len(parts) == 4 {
 | 
					 | 
				
			||||||
				hash := sha256.Sum224([]byte(u))
 | 
					 | 
				
			||||||
				parts = append(parts, hex.EncodeToString(hash[:]))
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			query.RuleProviders = append(
 | 
					 | 
				
			||||||
				query.RuleProviders, RuleProviderStruct{
 | 
					 | 
				
			||||||
					Behavior: parts[0],
 | 
					 | 
				
			||||||
					Url:      u,
 | 
					 | 
				
			||||||
					Group:    parts[2],
 | 
					 | 
				
			||||||
					Prepend:  parts[3] == "true",
 | 
					 | 
				
			||||||
					Name:     parts[4],
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		names := make(map[string]bool)
 | 
					 | 
				
			||||||
		for _, ruleProvider := range query.RuleProviders {
 | 
					 | 
				
			||||||
			if _, ok := names[ruleProvider.Name]; ok {
 | 
					 | 
				
			||||||
				return SubConfig{}, errors.New("参数错误: Rule-Provider 名称重复")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			names[ruleProvider.Name] = true
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		query.RuleProviders = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if query.Rule != "" {
 | 
					 | 
				
			||||||
		reg := regexp.MustCompile(`\[(.*?)\]`)
 | 
					 | 
				
			||||||
		rules := reg.FindAllStringSubmatch(query.Rule, -1)
 | 
					 | 
				
			||||||
		for i := range rules {
 | 
					 | 
				
			||||||
			length := len(rules)
 | 
					 | 
				
			||||||
			r := rules[length-1-i][1]
 | 
					 | 
				
			||||||
			strings.LastIndex(r, ",")
 | 
					 | 
				
			||||||
			parts := [2]string{}
 | 
					 | 
				
			||||||
			parts[0] = r[:strings.LastIndex(r, ",")]
 | 
					 | 
				
			||||||
			parts[1] = r[strings.LastIndex(r, ",")+1:]
 | 
					 | 
				
			||||||
			query.Rules = append(
 | 
					 | 
				
			||||||
				query.Rules, RuleStruct{
 | 
					 | 
				
			||||||
					Rule:    parts[0],
 | 
					 | 
				
			||||||
					Prepend: parts[1] == "true",
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		query.Rules = nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if strings.TrimSpace(query.Replace) != "" {
 | 
					 | 
				
			||||||
		reg := regexp.MustCompile(`\[<(.*?)>,<(.*?)>\]`)
 | 
					 | 
				
			||||||
		replaces := reg.FindAllStringSubmatch(query.Replace, -1)
 | 
					 | 
				
			||||||
		for i := range replaces {
 | 
					 | 
				
			||||||
			length := len(replaces[i])
 | 
					 | 
				
			||||||
			if length != 3 {
 | 
					 | 
				
			||||||
				return SubConfig{}, errors.New("参数错误: replace 格式错误")
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			query.ReplaceKeys = append(query.ReplaceKeys, replaces[i][1])
 | 
					 | 
				
			||||||
			query.ReplaceTo = append(query.ReplaceTo, replaces[i][2])
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return query, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -14,11 +14,11 @@ type NodeList struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// https://github.com/MetaCubeX/mihomo/blob/Meta/config/config.go RawConfig
 | 
					// https://github.com/MetaCubeX/mihomo/blob/Meta/config/config.go RawConfig
 | 
				
			||||||
type Subscription struct {
 | 
					type Subscription struct {
 | 
				
			||||||
	Port                    int            `yaml:"port,omitempty" json:"port"`
 | 
						Port                    proxy.IntOrString `yaml:"port,omitempty" json:"port"`
 | 
				
			||||||
	SocksPort               int            `yaml:"socks-port,omitempty" json:"socks-port"`
 | 
						SocksPort               proxy.IntOrString `yaml:"socks-port,omitempty" json:"socks-port"`
 | 
				
			||||||
	RedirPort               int            `yaml:"redir-port,omitempty" json:"redir-port"`
 | 
						RedirPort               proxy.IntOrString `yaml:"redir-port,omitempty" json:"redir-port"`
 | 
				
			||||||
	TProxyPort              int            `yaml:"tproxy-port,omitempty" json:"tproxy-port"`
 | 
						TProxyPort              proxy.IntOrString `yaml:"tproxy-port,omitempty" json:"tproxy-port"`
 | 
				
			||||||
	MixedPort               int            `yaml:"mixed-port,omitempty" json:"mixed-port"`
 | 
						MixedPort               proxy.IntOrString `yaml:"mixed-port,omitempty" json:"mixed-port"`
 | 
				
			||||||
	ShadowSocksConfig       string            `yaml:"ss-config,omitempty" json:"ss-config"`
 | 
						ShadowSocksConfig       string            `yaml:"ss-config,omitempty" json:"ss-config"`
 | 
				
			||||||
	VmessConfig             string            `yaml:"vmess-config,omitempty" json:"vmess-config"`
 | 
						VmessConfig             string            `yaml:"vmess-config,omitempty" json:"vmess-config"`
 | 
				
			||||||
	InboundTfo              bool              `yaml:"inbound-tfo,omitempty" json:"inbound-tfo"`
 | 
						InboundTfo              bool              `yaml:"inbound-tfo,omitempty" json:"inbound-tfo"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,7 +68,7 @@ func (p *AnytlsParser) Parse(config ParseConfig, proxy string) (P.Proxy, error)
 | 
				
			|||||||
		Name: remarks,
 | 
							Name: remarks,
 | 
				
			||||||
		Anytls: P.Anytls{
 | 
							Anytls: P.Anytls{
 | 
				
			||||||
			Server:         server,
 | 
								Server:         server,
 | 
				
			||||||
			Port:           port,
 | 
								Port:           P.IntOrString(port),
 | 
				
			||||||
			Password:       password,
 | 
								Password:       password,
 | 
				
			||||||
			SNI:            sni,
 | 
								SNI:            sni,
 | 
				
			||||||
			SkipCertVerify: insecureBool,
 | 
								SkipCertVerify: insecureBool,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,13 +1,13 @@
 | 
				
			|||||||
package parser
 | 
					package parser
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"encoding/base64"
 | 
					 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"unicode/utf8"
 | 
						"unicode/utf8"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	P "github.com/bestnite/sub2clash/model/proxy"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func hasPrefix(proxy string, prefixes []string) bool {
 | 
					func hasPrefix(proxy string, prefixes []string) bool {
 | 
				
			||||||
@@ -49,7 +49,7 @@ func isLikelyBase64(s string) bool {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	decoded, err := DecodeBase64(s)
 | 
						decoded, err := utils.DecodeBase64(s, true)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return false
 | 
							return false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -60,23 +60,6 @@ func isLikelyBase64(s string) bool {
 | 
				
			|||||||
	return true
 | 
						return true
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func DecodeBase64(s string) (string, error) {
 | 
					 | 
				
			||||||
	s = strings.TrimSpace(s)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if strings.Contains(s, "-") || strings.Contains(s, "_") {
 | 
					 | 
				
			||||||
		s = strings.ReplaceAll(s, "-", "+")
 | 
					 | 
				
			||||||
		s = strings.ReplaceAll(s, "_", "/")
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(s)%4 != 0 {
 | 
					 | 
				
			||||||
		s += strings.Repeat("=", 4-len(s)%4)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	decodeStr, err := base64.StdEncoding.DecodeString(s)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return "", err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return string(decodeStr), nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type ParseConfig struct {
 | 
					type ParseConfig struct {
 | 
				
			||||||
	UseUDP bool
 | 
						UseUDP bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -76,7 +76,7 @@ func (p *HysteriaParser) Parse(config ParseConfig, proxy string) (P.Proxy, error
 | 
				
			|||||||
		Name: remarks,
 | 
							Name: remarks,
 | 
				
			||||||
		Hysteria: P.Hysteria{
 | 
							Hysteria: P.Hysteria{
 | 
				
			||||||
			Server:         server,
 | 
								Server:         server,
 | 
				
			||||||
			Port:           port,
 | 
								Port:           P.IntOrString(port),
 | 
				
			||||||
			Up:             upmbps,
 | 
								Up:             upmbps,
 | 
				
			||||||
			Down:           downmbps,
 | 
								Down:           downmbps,
 | 
				
			||||||
			Auth:           auth,
 | 
								Auth:           auth,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,7 +68,7 @@ func (p *Hysteria2Parser) Parse(config ParseConfig, proxy string) (P.Proxy, erro
 | 
				
			|||||||
		Name: remarks,
 | 
							Name: remarks,
 | 
				
			||||||
		Hysteria2: P.Hysteria2{
 | 
							Hysteria2: P.Hysteria2{
 | 
				
			||||||
			Server:         server,
 | 
								Server:         server,
 | 
				
			||||||
			Port:           port,
 | 
								Port:           P.IntOrString(port),
 | 
				
			||||||
			Password:       password,
 | 
								Password:       password,
 | 
				
			||||||
			Obfs:           obfs,
 | 
								Obfs:           obfs,
 | 
				
			||||||
			ObfsPassword:   obfsPassword,
 | 
								ObfsPassword:   obfsPassword,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	P "github.com/bestnite/sub2clash/model/proxy"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ShadowsocksParser Shadowsocks协议解析器
 | 
					// ShadowsocksParser Shadowsocks协议解析器
 | 
				
			||||||
@@ -43,7 +44,7 @@ func (p *ShadowsocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, er
 | 
				
			|||||||
				break
 | 
									break
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		d, err := DecodeBase64(s[0])
 | 
							d, err := utils.DecodeBase64(s[0], true)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -76,7 +77,7 @@ func (p *ShadowsocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, er
 | 
				
			|||||||
	password, hasPassword := link.User.Password()
 | 
						password, hasPassword := link.User.Password()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !hasPassword && isLikelyBase64(method) {
 | 
						if !hasPassword && isLikelyBase64(method) {
 | 
				
			||||||
		decodedStr, err := DecodeBase64(method)
 | 
							decodedStr, err := utils.DecodeBase64(method, true)
 | 
				
			||||||
		if err == nil {
 | 
							if err == nil {
 | 
				
			||||||
			methodAndPass := strings.SplitN(decodedStr, ":", 2)
 | 
								methodAndPass := strings.SplitN(decodedStr, ":", 2)
 | 
				
			||||||
			if len(methodAndPass) == 2 {
 | 
								if len(methodAndPass) == 2 {
 | 
				
			||||||
@@ -88,7 +89,7 @@ func (p *ShadowsocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, er
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if password != "" && isLikelyBase64(password) {
 | 
						if password != "" && isLikelyBase64(password) {
 | 
				
			||||||
		password, err = DecodeBase64(password)
 | 
							password, err = utils.DecodeBase64(password, true)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -107,7 +108,7 @@ func (p *ShadowsocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, er
 | 
				
			|||||||
			Cipher:   method,
 | 
								Cipher:   method,
 | 
				
			||||||
			Password: password,
 | 
								Password: password,
 | 
				
			||||||
			Server:   server,
 | 
								Server:   server,
 | 
				
			||||||
			Port:     port,
 | 
								Port:     P.IntOrString(port),
 | 
				
			||||||
			UDP:      config.UseUDP,
 | 
								UDP:      config.UseUDP,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	P "github.com/bestnite/sub2clash/model/proxy"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ShadowsocksRParser struct{}
 | 
					type ShadowsocksRParser struct{}
 | 
				
			||||||
@@ -39,7 +40,7 @@ func (p *ShadowsocksRParser) Parse(config ParseConfig, proxy string) (P.Proxy, e
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	proxy, err := DecodeBase64(proxy)
 | 
						proxy, err := utils.DecodeBase64(proxy, true)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidBase64, err.Error())
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidBase64, err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -55,7 +56,7 @@ func (p *ShadowsocksRParser) Parse(config ParseConfig, proxy string) (P.Proxy, e
 | 
				
			|||||||
	protocol := parts[2]
 | 
						protocol := parts[2]
 | 
				
			||||||
	method := parts[3]
 | 
						method := parts[3]
 | 
				
			||||||
	obfs := parts[4]
 | 
						obfs := parts[4]
 | 
				
			||||||
	password, err := DecodeBase64(parts[5])
 | 
						password, err := utils.DecodeBase64(parts[5], true)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidStruct, err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -73,13 +74,13 @@ func (p *ShadowsocksRParser) Parse(config ParseConfig, proxy string) (P.Proxy, e
 | 
				
			|||||||
			return P.Proxy{}, fmt.Errorf("%w: %s", ErrCannotParseParams, err.Error())
 | 
								return P.Proxy{}, fmt.Errorf("%w: %s", ErrCannotParseParams, err.Error())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if params.Get("obfsparam") != "" {
 | 
							if params.Get("obfsparam") != "" {
 | 
				
			||||||
			obfsParam, err = DecodeBase64(params.Get("obfsparam"))
 | 
								obfsParam, err = utils.DecodeBase64(params.Get("obfsparam"), true)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if params.Get("protoparam") != "" {
 | 
							if params.Get("protoparam") != "" {
 | 
				
			||||||
			protoParam, err = DecodeBase64(params.Get("protoparam"))
 | 
								protoParam, err = utils.DecodeBase64(params.Get("protoparam"), true)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if params.Get("remarks") != "" {
 | 
							if params.Get("remarks") != "" {
 | 
				
			||||||
			remarks, err = DecodeBase64(params.Get("remarks"))
 | 
								remarks, err = utils.DecodeBase64(params.Get("remarks"), true)
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			remarks = server + ":" + strconv.Itoa(port)
 | 
								remarks = server + ":" + strconv.Itoa(port)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -93,7 +94,7 @@ func (p *ShadowsocksRParser) Parse(config ParseConfig, proxy string) (P.Proxy, e
 | 
				
			|||||||
		Name: remarks,
 | 
							Name: remarks,
 | 
				
			||||||
		ShadowSocksR: P.ShadowSocksR{
 | 
							ShadowSocksR: P.ShadowSocksR{
 | 
				
			||||||
			Server:        server,
 | 
								Server:        server,
 | 
				
			||||||
			Port:          port,
 | 
								Port:          P.IntOrString(port),
 | 
				
			||||||
			Protocol:      protocol,
 | 
								Protocol:      protocol,
 | 
				
			||||||
			Cipher:        method,
 | 
								Cipher:        method,
 | 
				
			||||||
			Obfs:          obfs,
 | 
								Obfs:          obfs,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,7 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	P "github.com/bestnite/sub2clash/model/proxy"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type SocksParser struct{}
 | 
					type SocksParser struct{}
 | 
				
			||||||
@@ -59,7 +60,7 @@ func (p *SocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			|||||||
	password, hasPassword := link.User.Password()
 | 
						password, hasPassword := link.User.Password()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if !hasPassword && isLikelyBase64(username) {
 | 
						if !hasPassword && isLikelyBase64(username) {
 | 
				
			||||||
		decodedStr, err := DecodeBase64(username)
 | 
							decodedStr, err := utils.DecodeBase64(username, true)
 | 
				
			||||||
		if err == nil {
 | 
							if err == nil {
 | 
				
			||||||
			usernameAndPassword := strings.SplitN(decodedStr, ":", 2)
 | 
								usernameAndPassword := strings.SplitN(decodedStr, ":", 2)
 | 
				
			||||||
			if len(usernameAndPassword) == 2 {
 | 
								if len(usernameAndPassword) == 2 {
 | 
				
			||||||
@@ -78,7 +79,7 @@ func (p *SocksParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			|||||||
		Name: remarks,
 | 
							Name: remarks,
 | 
				
			||||||
		Socks: P.Socks{
 | 
							Socks: P.Socks{
 | 
				
			||||||
			Server:   server,
 | 
								Server:   server,
 | 
				
			||||||
			Port:     port,
 | 
								Port:     P.IntOrString(port),
 | 
				
			||||||
			UserName: username,
 | 
								UserName: username,
 | 
				
			||||||
			Password: password,
 | 
								Password: password,
 | 
				
			||||||
			TLS:      tls == "true",
 | 
								TLS:      tls == "true",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,7 +63,7 @@ func (p *TrojanParser) Parse(config ParseConfig, proxy string) (P.Proxy, error)
 | 
				
			|||||||
	insecureBool := insecure == "1"
 | 
						insecureBool := insecure == "1"
 | 
				
			||||||
	result := P.Trojan{
 | 
						result := P.Trojan{
 | 
				
			||||||
		Server:         server,
 | 
							Server:         server,
 | 
				
			||||||
		Port:           port,
 | 
							Port:           P.IntOrString(port),
 | 
				
			||||||
		Password:       password,
 | 
							Password:       password,
 | 
				
			||||||
		Network:        network,
 | 
							Network:        network,
 | 
				
			||||||
		UDP:            udp == "true",
 | 
							UDP:            udp == "true",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,7 +66,7 @@ func (p *VlessParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	result := P.Vless{
 | 
						result := P.Vless{
 | 
				
			||||||
		Server:         server,
 | 
							Server:         server,
 | 
				
			||||||
		Port:           port,
 | 
							Port:           P.IntOrString(port),
 | 
				
			||||||
		UUID:           uuid,
 | 
							UUID:           uuid,
 | 
				
			||||||
		Flow:           flow,
 | 
							Flow:           flow,
 | 
				
			||||||
		UDP:            udp == "true",
 | 
							UDP:            udp == "true",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ import (
 | 
				
			|||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	P "github.com/bestnite/sub2clash/model/proxy"
 | 
						P "github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/utils"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type VmessJson struct {
 | 
					type VmessJson struct {
 | 
				
			||||||
@@ -57,7 +58,7 @@ func (p *VmessParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			|||||||
			break
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	base64, err := DecodeBase64(proxy)
 | 
						base64, err := utils.DecodeBase64(proxy, true)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidBase64, err.Error())
 | 
							return P.Proxy{}, fmt.Errorf("%w: %s", ErrInvalidBase64, err.Error())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -108,9 +109,9 @@ func (p *VmessParser) Parse(config ParseConfig, proxy string) (P.Proxy, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	result := P.Vmess{
 | 
						result := P.Vmess{
 | 
				
			||||||
		Server:  vmess.Add,
 | 
							Server:  vmess.Add,
 | 
				
			||||||
		Port:    port,
 | 
							Port:    P.IntOrString(port),
 | 
				
			||||||
		UUID:    vmess.Id,
 | 
							UUID:    vmess.Id,
 | 
				
			||||||
		AlterID: aid,
 | 
							AlterID: P.IntOrString(aid),
 | 
				
			||||||
		Cipher:  vmess.Scy,
 | 
							Cipher:  vmess.Scy,
 | 
				
			||||||
		UDP:     config.UseUDP,
 | 
							UDP:     config.UseUDP,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								server/frontend/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								server/frontend/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					# Logs
 | 
				
			||||||
 | 
					logs
 | 
				
			||||||
 | 
					*.log
 | 
				
			||||||
 | 
					npm-debug.log*
 | 
				
			||||||
 | 
					yarn-debug.log*
 | 
				
			||||||
 | 
					yarn-error.log*
 | 
				
			||||||
 | 
					pnpm-debug.log*
 | 
				
			||||||
 | 
					lerna-debug.log*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					node_modules
 | 
				
			||||||
 | 
					dist
 | 
				
			||||||
 | 
					dist-ssr
 | 
				
			||||||
 | 
					*.local
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Editor directories and files
 | 
				
			||||||
 | 
					.vscode/*
 | 
				
			||||||
 | 
					!.vscode/extensions.json
 | 
				
			||||||
 | 
					.idea
 | 
				
			||||||
 | 
					.DS_Store
 | 
				
			||||||
 | 
					*.suo
 | 
				
			||||||
 | 
					*.ntvs*
 | 
				
			||||||
 | 
					*.njsproj
 | 
				
			||||||
 | 
					*.sln
 | 
				
			||||||
 | 
					*.sw?
 | 
				
			||||||
							
								
								
									
										17
									
								
								server/frontend/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								server/frontend/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
				
			|||||||
 | 
					<!doctype html>
 | 
				
			||||||
 | 
					<html lang="zh-CN" data-theme="light">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					  <meta charset="UTF-8" />
 | 
				
			||||||
 | 
					  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
				
			||||||
 | 
					  <title>sub2clash</title>
 | 
				
			||||||
 | 
					  <link rel="stylesheet" href="./src/index.css" />
 | 
				
			||||||
 | 
					  <script type="module" src="/src/app.ts"></script>
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					  <sub2clash-app>
 | 
				
			||||||
 | 
					  </sub2clash-app>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										2030
									
								
								server/frontend/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										2030
									
								
								server/frontend/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										22
									
								
								server/frontend/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								server/frontend/package.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "name": "sub2clash-frontend",
 | 
				
			||||||
 | 
					  "private": true,
 | 
				
			||||||
 | 
					  "version": "0.0.0",
 | 
				
			||||||
 | 
					  "type": "module",
 | 
				
			||||||
 | 
					  "scripts": {
 | 
				
			||||||
 | 
					    "dev": "vite",
 | 
				
			||||||
 | 
					    "build": "tsc && vite build",
 | 
				
			||||||
 | 
					    "preview": "vite preview"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "@tailwindcss/vite": "^4.1.14",
 | 
				
			||||||
 | 
					    "axios": "^1.12.2",
 | 
				
			||||||
 | 
					    "daisyui": "^5.3.7",
 | 
				
			||||||
 | 
					    "lit": "^3.3.1",
 | 
				
			||||||
 | 
					    "tailwindcss": "^4.1.14"
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "devDependencies": {
 | 
				
			||||||
 | 
					    "typescript": "~5.9.3",
 | 
				
			||||||
 | 
					    "vite": "^7.1.7"
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										677
									
								
								server/frontend/src/app.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										677
									
								
								server/frontend/src/app.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,677 @@
 | 
				
			|||||||
 | 
					import { LitElement, html, unsafeCSS } from "lit";
 | 
				
			||||||
 | 
					import { customElement, query, state } from "lit/decorators.js";
 | 
				
			||||||
 | 
					import globalStyles from "./index.css?inline";
 | 
				
			||||||
 | 
					import { type Config, type Rule, type RuleProvider } from "./interface.js";
 | 
				
			||||||
 | 
					import axios, { AxiosError } from "axios";
 | 
				
			||||||
 | 
					import { base64EncodeUnicode, base64decodeUnicode } from "./utils.js";
 | 
				
			||||||
 | 
					import "./components/rule-provider-input.js";
 | 
				
			||||||
 | 
					import "./components/rule-input.js";
 | 
				
			||||||
 | 
					import "./components/rename-input.js";
 | 
				
			||||||
 | 
					import "./components/short-link-input-group.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@customElement("sub2clash-app")
 | 
				
			||||||
 | 
					export class Sub2clashApp extends LitElement {
 | 
				
			||||||
 | 
					  static styles = [unsafeCSS(globalStyles)];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private _config: Config = {
 | 
				
			||||||
 | 
					    clashType: 2,
 | 
				
			||||||
 | 
					    subscriptions: [],
 | 
				
			||||||
 | 
					    proxies: [],
 | 
				
			||||||
 | 
					    refresh: false,
 | 
				
			||||||
 | 
					    autoTest: false,
 | 
				
			||||||
 | 
					    lazy: false,
 | 
				
			||||||
 | 
					    ignoreCountryGroup: false,
 | 
				
			||||||
 | 
					    useUDP: false,
 | 
				
			||||||
 | 
					    template: "",
 | 
				
			||||||
 | 
					    sort: "nameasc",
 | 
				
			||||||
 | 
					    remove: "",
 | 
				
			||||||
 | 
					    nodeList: false,
 | 
				
			||||||
 | 
					    ruleProviders: [],
 | 
				
			||||||
 | 
					    replace: undefined,
 | 
				
			||||||
 | 
					    rules: [],
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  set config(value: Config) {
 | 
				
			||||||
 | 
					    console.log(JSON.stringify(value));
 | 
				
			||||||
 | 
					    if (
 | 
				
			||||||
 | 
					      (value.subscriptions == null || value.subscriptions.length == 0) &&
 | 
				
			||||||
 | 
					      (value.proxies == null || value.proxies.length == 0)
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
 | 
					      this.configUrl = "";
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const oldValue = this._config;
 | 
				
			||||||
 | 
					    this.configUrl = `${
 | 
				
			||||||
 | 
					      window.location.origin
 | 
				
			||||||
 | 
					    }${window.location.pathname.replace(
 | 
				
			||||||
 | 
					      /\/$/,
 | 
				
			||||||
 | 
					      ""
 | 
				
			||||||
 | 
					    )}/convert/${base64EncodeUnicode(JSON.stringify(value))
 | 
				
			||||||
 | 
					      .replace(/\+/g, "-")
 | 
				
			||||||
 | 
					      .replace(/\//g, "_")}`;
 | 
				
			||||||
 | 
					    this._config = value;
 | 
				
			||||||
 | 
					    this.requestUpdate("config", oldValue);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  get config(): Config {
 | 
				
			||||||
 | 
					    return this._config;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state({
 | 
				
			||||||
 | 
					    hasChanged(value: boolean) {
 | 
				
			||||||
 | 
					      localStorage.setItem("theme", value ? "dark" : "light");
 | 
				
			||||||
 | 
					      document
 | 
				
			||||||
 | 
					        .querySelector("html")
 | 
				
			||||||
 | 
					        ?.setAttribute("data-theme", value ? "dark" : "light");
 | 
				
			||||||
 | 
					      return true;
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					  darkTheme: boolean = this.initTheme();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  initTheme(): boolean {
 | 
				
			||||||
 | 
					    const savedTheme = localStorage.getItem("theme");
 | 
				
			||||||
 | 
					    if (savedTheme != null) {
 | 
				
			||||||
 | 
					      return savedTheme === "dark" ? true : false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const prefersDark = window.matchMedia(
 | 
				
			||||||
 | 
					      "(prefers-color-scheme: dark)"
 | 
				
			||||||
 | 
					    ).matches;
 | 
				
			||||||
 | 
					    return prefersDark;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  reverseUrl: string = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  dialogMessage: string = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  dialogTitle: string = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @query("dialog#my_modal")
 | 
				
			||||||
 | 
					  dialog!: HTMLDialogElement;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  showDialog(title: string, message: string): void {
 | 
				
			||||||
 | 
					    if (title.trim() === "") {
 | 
				
			||||||
 | 
					      title = "警告";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    this.dialogTitle = title;
 | 
				
			||||||
 | 
					    this.dialogMessage = message;
 | 
				
			||||||
 | 
					    this.dialog.showModal();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  configUrl: string = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  shortLinkID: string = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  shortLinkPasswd: string = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  async copyToClipboard(content: string, e: HTMLButtonElement) {
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      await navigator.clipboard.writeText(content);
 | 
				
			||||||
 | 
					      let text = e.textContent;
 | 
				
			||||||
 | 
					      e.addEventListener("mouseout", function () {
 | 
				
			||||||
 | 
					        e.textContent = text;
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					      e.textContent = "复制成功";
 | 
				
			||||||
 | 
					    } catch (err) {
 | 
				
			||||||
 | 
					      console.error("复制到剪贴板失败:", err);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  generateShortLink() {
 | 
				
			||||||
 | 
					    if (this.configUrl === "") {
 | 
				
			||||||
 | 
					      this.showDialog("", "还未填写配置");
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    axios
 | 
				
			||||||
 | 
					      .post(
 | 
				
			||||||
 | 
					        "./short",
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          config: this.config,
 | 
				
			||||||
 | 
					          password: this.shortLinkPasswd,
 | 
				
			||||||
 | 
					          id: this.shortLinkID,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          headers: {
 | 
				
			||||||
 | 
					            "Content-Type": "application/json",
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					      .then((response) => {
 | 
				
			||||||
 | 
					        // 设置返回的短链ID和密码
 | 
				
			||||||
 | 
					        this.shortLinkID = response.data.id;
 | 
				
			||||||
 | 
					        this.shortLinkPasswd = response.data.password;
 | 
				
			||||||
 | 
					        this.showDialog("成功", "生成短链成功");
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					      .catch((error) => {
 | 
				
			||||||
 | 
					        if (error.response && error.response.data) {
 | 
				
			||||||
 | 
					          this.showDialog("", "生成短链失败:" + error.response.data);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          this.showDialog("", "生成短链失败");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  updateShortLink() {
 | 
				
			||||||
 | 
					    if (this.shortLinkID.trim() === "") {
 | 
				
			||||||
 | 
					      this.showDialog("", "请输入ID");
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (this.shortLinkPasswd.trim() === "") {
 | 
				
			||||||
 | 
					      this.showDialog("", "请输入密码");
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (this.configUrl === "") {
 | 
				
			||||||
 | 
					      this.showDialog("", "还未填写配置");
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    axios
 | 
				
			||||||
 | 
					      .put(
 | 
				
			||||||
 | 
					        "./short",
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          id: this.shortLinkID,
 | 
				
			||||||
 | 
					          config: this.config,
 | 
				
			||||||
 | 
					          password: this.shortLinkPasswd,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          headers: {
 | 
				
			||||||
 | 
					            "Content-Type": "application/json",
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					      .then(() => {
 | 
				
			||||||
 | 
					        this.showDialog("成功", "更新短链成功");
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					      .catch((error) => {
 | 
				
			||||||
 | 
					        if (error.response && error.response.status === 401) {
 | 
				
			||||||
 | 
					          this.showDialog("", "短链不存在或密码错误");
 | 
				
			||||||
 | 
					        } else if (error.response && error.response.data) {
 | 
				
			||||||
 | 
					          this.showDialog("", "更新短链失败:" + error.response.data);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          this.showDialog("", "更新短链失败");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  deleteShortLink() {
 | 
				
			||||||
 | 
					    if (this.shortLinkID.trim() === "") {
 | 
				
			||||||
 | 
					      this.showDialog("", "请输入ID");
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (this.shortLinkPasswd.trim() === "") {
 | 
				
			||||||
 | 
					      this.showDialog("", "请输入密码");
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const params = new URLSearchParams();
 | 
				
			||||||
 | 
					    params.append("password", this.shortLinkPasswd);
 | 
				
			||||||
 | 
					    axios
 | 
				
			||||||
 | 
					      .delete(`./short/${this.shortLinkID}?${params.toString()}`, {
 | 
				
			||||||
 | 
					        headers: {
 | 
				
			||||||
 | 
					          "Content-Type": "application/json",
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					      .then(() => {
 | 
				
			||||||
 | 
					        this.showDialog("成功", "删除短链成功");
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					      .catch((error) => {
 | 
				
			||||||
 | 
					        if (error.response && error.response.status === 401) {
 | 
				
			||||||
 | 
					          this.showDialog("", "短链不存在或密码错误");
 | 
				
			||||||
 | 
					        } else if (error.response && error.response.data) {
 | 
				
			||||||
 | 
					          this.showDialog("", "删除短链失败:" + error.response.data);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          this.showDialog("", "删除短链失败");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  getRawConfigFromShortLink() {
 | 
				
			||||||
 | 
					    const s = this.reverseUrl.split("/s/");
 | 
				
			||||||
 | 
					    if (s.length != 2) {
 | 
				
			||||||
 | 
					      this.showDialog("", "解析失败");
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    axios
 | 
				
			||||||
 | 
					      .get(`./short/${s[1]}`)
 | 
				
			||||||
 | 
					      .then((resp) => {
 | 
				
			||||||
 | 
					        this.config = resp.data;
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					      .catch((err: AxiosError) => {
 | 
				
			||||||
 | 
					        if (err.response && err.response.status == 401) {
 | 
				
			||||||
 | 
					          this.showDialog("", "短链不存在或密码错误");
 | 
				
			||||||
 | 
					        } else if (err.response && err.response.data) {
 | 
				
			||||||
 | 
					          this.showDialog("", "获取配置失败:" + err.response.data);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          this.showDialog("", "获取配置失败");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  parseConfig() {
 | 
				
			||||||
 | 
					    if (this.reverseUrl.trim() === "") {
 | 
				
			||||||
 | 
					      this.showDialog("", "无法解析,链接为空");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (this.reverseUrl.indexOf("/s/") != -1) {
 | 
				
			||||||
 | 
					      this.getRawConfigFromShortLink();
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let url = new URL(this.reverseUrl);
 | 
				
			||||||
 | 
					    const pathSections = url.pathname.split("/");
 | 
				
			||||||
 | 
					    if (pathSections.length < 2) {
 | 
				
			||||||
 | 
					      this.showDialog("", "无法解析,链接格式错误");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (pathSections[pathSections.length - 2] == "convert") {
 | 
				
			||||||
 | 
					      let base64Data = pathSections[pathSections.length - 1];
 | 
				
			||||||
 | 
					      base64Data = base64Data.replace(/-/g, "+").replace(/_/g, "/");
 | 
				
			||||||
 | 
					      try {
 | 
				
			||||||
 | 
					        const configData = base64decodeUnicode(base64Data);
 | 
				
			||||||
 | 
					        this.config = JSON.parse(configData) as Config;
 | 
				
			||||||
 | 
					      } catch (e: any) {
 | 
				
			||||||
 | 
					        this.showDialog("", "无法解析 Base64,配置格式错误");
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      this.showDialog("", "无法解析,链接格式错误");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  render() {
 | 
				
			||||||
 | 
					    return html`
 | 
				
			||||||
 | 
					      <dialog id="my_modal" class="modal">
 | 
				
			||||||
 | 
					        <div class="modal-box">
 | 
				
			||||||
 | 
					          <h3 class="text-lg font-bold">${this.dialogTitle}</h3>
 | 
				
			||||||
 | 
					          <p class="py-4">${this.dialogMessage}</p>
 | 
				
			||||||
 | 
					          <div class="modal-action">
 | 
				
			||||||
 | 
					            <form method="dialog">
 | 
				
			||||||
 | 
					              <button class="btn">关闭</button>
 | 
				
			||||||
 | 
					            </form>
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					      </dialog>
 | 
				
			||||||
 | 
					      <div class="max-w-4xl mx-auto p-4 flex flex-col items-center">
 | 
				
			||||||
 | 
					        <form class="w-full max-w-2xl bg-base-100">
 | 
				
			||||||
 | 
					          <fieldset class="fieldset mb-6">
 | 
				
			||||||
 | 
					            <div class="flex flex-row justify-between items-center my-6">
 | 
				
			||||||
 | 
					              <legend
 | 
				
			||||||
 | 
					                class="fieldset-legend text-2xl font-semibold inline-block m-0 p-0">
 | 
				
			||||||
 | 
					                sub2clash
 | 
				
			||||||
 | 
					              </legend>
 | 
				
			||||||
 | 
					              <label class="swap swap-rotate h-7 w-7">
 | 
				
			||||||
 | 
					                <!-- this hidden checkbox controls the state -->
 | 
				
			||||||
 | 
					                <input
 | 
				
			||||||
 | 
					                  type="checkbox"
 | 
				
			||||||
 | 
					                  class="theme-controller"
 | 
				
			||||||
 | 
					                  .checked="${!this.darkTheme}"
 | 
				
			||||||
 | 
					                  @change="${() => (this.darkTheme = !this.darkTheme)}" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <!-- sun icon -->
 | 
				
			||||||
 | 
					                <svg
 | 
				
			||||||
 | 
					                  class="swap-off h-7 w-7 fill-current"
 | 
				
			||||||
 | 
					                  xmlns="http://www.w3.org/2000/svg"
 | 
				
			||||||
 | 
					                  viewBox="0 0 24 24">
 | 
				
			||||||
 | 
					                  <path
 | 
				
			||||||
 | 
					                    d="M5.64,17l-.71.71a1,1,0,0,0,0,1.41,1,1,0,0,0,1.41,0l.71-.71A1,1,0,0,0,5.64,17ZM5,12a1,1,0,0,0-1-1H3a1,1,0,0,0,0,2H4A1,1,0,0,0,5,12Zm7-7a1,1,0,0,0,1-1V3a1,1,0,0,0-2,0V4A1,1,0,0,0,12,5ZM5.64,7.05a1,1,0,0,0,.7.29,1,1,0,0,0,.71-.29,1,1,0,0,0,0-1.41l-.71-.71A1,1,0,0,0,4.93,6.34Zm12,.29a1,1,0,0,0,.7-.29l.71-.71a1,1,0,1,0-1.41-1.41L17,5.64a1,1,0,0,0,0,1.41A1,1,0,0,0,17.66,7.34ZM21,11H20a1,1,0,0,0,0,2h1a1,1,0,0,0,0-2Zm-9,8a1,1,0,0,0-1,1v1a1,1,0,0,0,2,0V20A1,1,0,0,0,12,19ZM18.36,17A1,1,0,0,0,17,18.36l.71.71a1,1,0,0,0,1.41,0,1,1,0,0,0,0-1.41ZM12,6.5A5.5,5.5,0,1,0,17.5,12,5.51,5.51,0,0,0,12,6.5Zm0,9A3.5,3.5,0,1,1,15.5,12,3.5,3.5,0,0,1,12,15.5Z" />
 | 
				
			||||||
 | 
					                </svg>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                <!-- moon icon -->
 | 
				
			||||||
 | 
					                <svg
 | 
				
			||||||
 | 
					                  class="swap-on h-7 w-7 fill-current"
 | 
				
			||||||
 | 
					                  xmlns="http://www.w3.org/2000/svg"
 | 
				
			||||||
 | 
					                  viewBox="0 0 24 24">
 | 
				
			||||||
 | 
					                  <path
 | 
				
			||||||
 | 
					                    d="M21.64,13a1,1,0,0,0-1.05-.14,8.05,8.05,0,0,1-3.37.73A8.15,8.15,0,0,1,9.08,5.49a8.59,8.59,0,0,1,.25-2A1,1,0,0,0,8,2.36,10.14,10.14,0,1,0,22,14.05,1,1,0,0,0,21.64,13Zm-9.5,6.69A8.14,8.14,0,0,1,7.08,5.22v.27A10.15,10.15,0,0,0,17.22,15.63a9.79,9.79,0,0,0,2.1-.22A8.11,8.11,0,0,1,12.14,19.73Z" />
 | 
				
			||||||
 | 
					                </svg>
 | 
				
			||||||
 | 
					              </label>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- Input URL -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-5">
 | 
				
			||||||
 | 
					              <label class="label mb-1 pl-1">解析链接</label>
 | 
				
			||||||
 | 
					              <div class="join w-full">
 | 
				
			||||||
 | 
					                <input
 | 
				
			||||||
 | 
					                  class="input input-bordered w-full join-item"
 | 
				
			||||||
 | 
					                  type="text"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.reverseUrl = (e.target as HTMLInputElement).value;
 | 
				
			||||||
 | 
					                  }}"
 | 
				
			||||||
 | 
					                  placeholder="通过生成的链接重新填写下方设置" />
 | 
				
			||||||
 | 
					                <button
 | 
				
			||||||
 | 
					                  class="btn btn-primary join-item"
 | 
				
			||||||
 | 
					                  @click="${this.parseConfig}"
 | 
				
			||||||
 | 
					                  type="button">
 | 
				
			||||||
 | 
					                  解析
 | 
				
			||||||
 | 
					                </button>
 | 
				
			||||||
 | 
					              </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- API Endpoint -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label mb-1 pl-1" for="endpoint">客户端类型</label>
 | 
				
			||||||
 | 
					              <select
 | 
				
			||||||
 | 
					                class="select select-bordered w-full"
 | 
				
			||||||
 | 
					                name="endpoint"
 | 
				
			||||||
 | 
					                .value="${this.config.clashType == 1 ? "1" : "2"}"
 | 
				
			||||||
 | 
					                @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                  this.config = {
 | 
				
			||||||
 | 
					                    ...this.config,
 | 
				
			||||||
 | 
					                    clashType: Number((e.target as HTMLInputElement).value),
 | 
				
			||||||
 | 
					                  };
 | 
				
			||||||
 | 
					                }}">
 | 
				
			||||||
 | 
					                <option value="1">Clash</option>
 | 
				
			||||||
 | 
					                <option value="2" selected>Clash.Meta</option>
 | 
				
			||||||
 | 
					              </select>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- Template -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label mb-1 pl-1" for="template">模板链接</label>
 | 
				
			||||||
 | 
					              <input
 | 
				
			||||||
 | 
					                class="input input-bordered w-full"
 | 
				
			||||||
 | 
					                name="template"
 | 
				
			||||||
 | 
					                placeholder="输入模板链接"
 | 
				
			||||||
 | 
					                type="text"
 | 
				
			||||||
 | 
					                .value="${this.config.template ?? ""}"
 | 
				
			||||||
 | 
					                @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                  this.config = {
 | 
				
			||||||
 | 
					                    ...this.config,
 | 
				
			||||||
 | 
					                    template: (e.target as HTMLInputElement).value,
 | 
				
			||||||
 | 
					                  };
 | 
				
			||||||
 | 
					                }}" />
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- Subscription Link -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label mb-1 pl-1" for="sub">订阅链接</label>
 | 
				
			||||||
 | 
					              <div>
 | 
				
			||||||
 | 
					                <textarea
 | 
				
			||||||
 | 
					                  class="textarea textarea-bordered h-24 w-full"
 | 
				
			||||||
 | 
					                  name="sub"
 | 
				
			||||||
 | 
					                  placeholder="每行输入一个订阅链接"
 | 
				
			||||||
 | 
					                  .value="${this.config.subscriptions
 | 
				
			||||||
 | 
					                    ? this.config.subscriptions.join("\n")
 | 
				
			||||||
 | 
					                    : ""}"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.config = {
 | 
				
			||||||
 | 
					                      ...this.config,
 | 
				
			||||||
 | 
					                      subscriptions: (e.target as HTMLInputElement).value
 | 
				
			||||||
 | 
					                        .split("\n")
 | 
				
			||||||
 | 
					                        .filter((e) => e.trim() !== ""),
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                  }}"></textarea>
 | 
				
			||||||
 | 
					              </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- Proxy Link -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label mb-1 pl-1" for="proxy">节点分享链接</label>
 | 
				
			||||||
 | 
					              <div>
 | 
				
			||||||
 | 
					                <textarea
 | 
				
			||||||
 | 
					                  class="textarea textarea-bordered h-24 w-full"
 | 
				
			||||||
 | 
					                  name="proxy"
 | 
				
			||||||
 | 
					                  placeholder="每行输入一个节点分享链接"
 | 
				
			||||||
 | 
					                  .value="${this.config.proxies
 | 
				
			||||||
 | 
					                    ? this.config.proxies.join("\n")
 | 
				
			||||||
 | 
					                    : ""}"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.config = {
 | 
				
			||||||
 | 
					                      ...this.config,
 | 
				
			||||||
 | 
					                      proxies: (e.target as HTMLInputElement).value
 | 
				
			||||||
 | 
					                        .split("\n")
 | 
				
			||||||
 | 
					                        .filter((e) => e.trim() !== ""),
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                  }}"></textarea>
 | 
				
			||||||
 | 
					              </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- User Agent -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label mb-1 pl-1" for="user-agent">UA 标识</label>
 | 
				
			||||||
 | 
					              <div>
 | 
				
			||||||
 | 
					                <textarea
 | 
				
			||||||
 | 
					                  class="textarea textarea-bordered h-20 w-full"
 | 
				
			||||||
 | 
					                  name="user-agent"
 | 
				
			||||||
 | 
					                  placeholder="用于获取订阅的 http 请求中的 User-Agent 标识"
 | 
				
			||||||
 | 
					                  .value="${this.config.userAgent ?? ""}"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.config = {
 | 
				
			||||||
 | 
					                      ...this.config,
 | 
				
			||||||
 | 
					                      userAgent: (e.target as HTMLInputElement).value,
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                  }}"></textarea>
 | 
				
			||||||
 | 
					              </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- Sort -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label mb-1 pl-1" for="sort">
 | 
				
			||||||
 | 
					                国家策略组排序规则
 | 
				
			||||||
 | 
					              </label>
 | 
				
			||||||
 | 
					              <select
 | 
				
			||||||
 | 
					                class="select select-bordered w-full"
 | 
				
			||||||
 | 
					                name="sort"
 | 
				
			||||||
 | 
					                .value="${this.config.sort ?? "nameasc"}"
 | 
				
			||||||
 | 
					                @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                  this.config = {
 | 
				
			||||||
 | 
					                    ...this.config,
 | 
				
			||||||
 | 
					                    sort: (e.target as HTMLInputElement).value,
 | 
				
			||||||
 | 
					                  };
 | 
				
			||||||
 | 
					                }}">
 | 
				
			||||||
 | 
					                <option value="nameasc">名称(升序)</option>
 | 
				
			||||||
 | 
					                <option value="namedesc">名称(降序)</option>
 | 
				
			||||||
 | 
					                <option value="sizeasc">节点数量(升序)</option>
 | 
				
			||||||
 | 
					                <option value="sizedesc">节点数量(降序)</option>
 | 
				
			||||||
 | 
					              </select>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- Remove -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label mb-1 pl-1" for="remove">
 | 
				
			||||||
 | 
					                <span class="label-text">排除节点</span>
 | 
				
			||||||
 | 
					              </label>
 | 
				
			||||||
 | 
					              <input
 | 
				
			||||||
 | 
					                class="input input-bordered w-full"
 | 
				
			||||||
 | 
					                type="text"
 | 
				
			||||||
 | 
					                name="remove"
 | 
				
			||||||
 | 
					                placeholder="正则表达式"
 | 
				
			||||||
 | 
					                .value="${this.config.remove ?? ""}"
 | 
				
			||||||
 | 
					                @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                  this.config = {
 | 
				
			||||||
 | 
					                    ...this.config,
 | 
				
			||||||
 | 
					                    remove: (e.target as HTMLInputElement).value,
 | 
				
			||||||
 | 
					                  };
 | 
				
			||||||
 | 
					                }}" />
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- Checkboxes -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label cursor-pointer">
 | 
				
			||||||
 | 
					                <input
 | 
				
			||||||
 | 
					                  type="checkbox"
 | 
				
			||||||
 | 
					                  name="refresh"
 | 
				
			||||||
 | 
					                  class="checkbox"
 | 
				
			||||||
 | 
					                  .checked="${this.config.refresh ?? false}"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.config = {
 | 
				
			||||||
 | 
					                      ...this.config,
 | 
				
			||||||
 | 
					                      refresh: (e.target as HTMLInputElement).checked,
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                  }}" />
 | 
				
			||||||
 | 
					                强制重新获取订阅
 | 
				
			||||||
 | 
					              </label>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label cursor-pointer">
 | 
				
			||||||
 | 
					                <input
 | 
				
			||||||
 | 
					                  type="checkbox"
 | 
				
			||||||
 | 
					                  name="nodeList"
 | 
				
			||||||
 | 
					                  class="checkbox"
 | 
				
			||||||
 | 
					                  .checked="${this.config.nodeList ?? false}"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.config = {
 | 
				
			||||||
 | 
					                      ...this.config,
 | 
				
			||||||
 | 
					                      nodeList: (e.target as HTMLInputElement).checked,
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                  }}" />
 | 
				
			||||||
 | 
					                输出为 Node List
 | 
				
			||||||
 | 
					              </label>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label cursor-pointer">
 | 
				
			||||||
 | 
					                <input
 | 
				
			||||||
 | 
					                  type="checkbox"
 | 
				
			||||||
 | 
					                  name="autoTest"
 | 
				
			||||||
 | 
					                  class="checkbox"
 | 
				
			||||||
 | 
					                  .checked="${this.config.autoTest ?? false}"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.config = {
 | 
				
			||||||
 | 
					                      ...this.config,
 | 
				
			||||||
 | 
					                      autoTest: (e.target as HTMLInputElement).checked,
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                  }}" />
 | 
				
			||||||
 | 
					                国家策略组自动测速
 | 
				
			||||||
 | 
					              </label>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label cursor-pointer">
 | 
				
			||||||
 | 
					                <input
 | 
				
			||||||
 | 
					                  type="checkbox"
 | 
				
			||||||
 | 
					                  name="lazy"
 | 
				
			||||||
 | 
					                  class="checkbox"
 | 
				
			||||||
 | 
					                  .checked="${this.config.lazy ?? false}"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.config = {
 | 
				
			||||||
 | 
					                      ...this.config,
 | 
				
			||||||
 | 
					                      lazy: (e.target as HTMLInputElement).checked,
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                  }}" />
 | 
				
			||||||
 | 
					                自动测速启用 lazy 模式
 | 
				
			||||||
 | 
					              </label>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="form-control mb-3">
 | 
				
			||||||
 | 
					              <label class="label cursor-pointer">
 | 
				
			||||||
 | 
					                <input
 | 
				
			||||||
 | 
					                  type="checkbox"
 | 
				
			||||||
 | 
					                  name="igcg"
 | 
				
			||||||
 | 
					                  class="checkbox"
 | 
				
			||||||
 | 
					                  .checked="${this.config.ignoreCountryGroup ?? false}"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.config = {
 | 
				
			||||||
 | 
					                      ...this.config,
 | 
				
			||||||
 | 
					                      ignoreCountryGroup: (e.target as HTMLInputElement)
 | 
				
			||||||
 | 
					                        .checked,
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                  }}" />
 | 
				
			||||||
 | 
					                不输出国家策略组
 | 
				
			||||||
 | 
					              </label>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            <div class="form-control mb-5">
 | 
				
			||||||
 | 
					              <label class="label cursor-pointer">
 | 
				
			||||||
 | 
					                <input
 | 
				
			||||||
 | 
					                  type="checkbox"
 | 
				
			||||||
 | 
					                  name="useUDP"
 | 
				
			||||||
 | 
					                  class="checkbox"
 | 
				
			||||||
 | 
					                  .checked="${this.config.useUDP ?? false}"
 | 
				
			||||||
 | 
					                  @change="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.config = {
 | 
				
			||||||
 | 
					                      ...this.config,
 | 
				
			||||||
 | 
					                      useUDP: (e.target as HTMLInputElement).checked,
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					                  }}" />
 | 
				
			||||||
 | 
					                使用 UDP
 | 
				
			||||||
 | 
					              </label>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <rule-provider-input
 | 
				
			||||||
 | 
					              @change="${(e: CustomEvent<Array<RuleProvider>>) => {
 | 
				
			||||||
 | 
					                this.config = {
 | 
				
			||||||
 | 
					                  ...this.config,
 | 
				
			||||||
 | 
					                  ruleProviders: e.detail,
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					              }}"></rule-provider-input>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <rule-input
 | 
				
			||||||
 | 
					              @change="${(e: CustomEvent<Array<Rule>>) => {
 | 
				
			||||||
 | 
					                this.config = {
 | 
				
			||||||
 | 
					                  ...this.config,
 | 
				
			||||||
 | 
					                  rules: e.detail,
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					              }}"></rule-input>
 | 
				
			||||||
 | 
					            <rename-input
 | 
				
			||||||
 | 
					              @change="${(e: CustomEvent<{ [key: string]: string }>) => {
 | 
				
			||||||
 | 
					                this.config = {
 | 
				
			||||||
 | 
					                  ...this.config,
 | 
				
			||||||
 | 
					                  replace: e.detail,
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					              }}"></rename-input>
 | 
				
			||||||
 | 
					          </fieldset>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          <fieldset class="fieldset mb-8">
 | 
				
			||||||
 | 
					            <legend class="fieldset-legend text-2xl font-semibold mb-4">
 | 
				
			||||||
 | 
					              输出配置
 | 
				
			||||||
 | 
					            </legend>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <!-- Display the API Link -->
 | 
				
			||||||
 | 
					            <div class="form-control mb-5">
 | 
				
			||||||
 | 
					              <div class="join w-full mb-2">
 | 
				
			||||||
 | 
					                <input
 | 
				
			||||||
 | 
					                  class="input input-bordered w-full join-item cursor-not-allowed"
 | 
				
			||||||
 | 
					                  type="text"
 | 
				
			||||||
 | 
					                  placeholder="链接"
 | 
				
			||||||
 | 
					                  .value="${this.configUrl}"
 | 
				
			||||||
 | 
					                  readonly />
 | 
				
			||||||
 | 
					                <button
 | 
				
			||||||
 | 
					                  class="btn btn-primary join-item"
 | 
				
			||||||
 | 
					                  @click="${(e: Event) => {
 | 
				
			||||||
 | 
					                    this.copyToClipboard(
 | 
				
			||||||
 | 
					                      this.configUrl,
 | 
				
			||||||
 | 
					                      e.target as HTMLButtonElement
 | 
				
			||||||
 | 
					                    );
 | 
				
			||||||
 | 
					                  }}"
 | 
				
			||||||
 | 
					                  type="button">
 | 
				
			||||||
 | 
					                  复制链接
 | 
				
			||||||
 | 
					                </button>
 | 
				
			||||||
 | 
					              </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <short-link-input-group
 | 
				
			||||||
 | 
					              .id="${this.shortLinkID}"
 | 
				
			||||||
 | 
					              .passwd="${this.shortLinkPasswd}"
 | 
				
			||||||
 | 
					              @id-change="${(e: Event) => {
 | 
				
			||||||
 | 
					                this.shortLinkID = (e.target as HTMLInputElement).value;
 | 
				
			||||||
 | 
					              }}"
 | 
				
			||||||
 | 
					              @passwd-change="${(e: Event) => {
 | 
				
			||||||
 | 
					                this.shortLinkPasswd = (e.target as HTMLInputElement).value;
 | 
				
			||||||
 | 
					              }}"
 | 
				
			||||||
 | 
					              @generate-btn-click="${this.generateShortLink}"
 | 
				
			||||||
 | 
					              @update-btn-click="${this.updateShortLink}"
 | 
				
			||||||
 | 
					              @delete-btn-click="${this.deleteShortLink}">
 | 
				
			||||||
 | 
					            </short-link-input-group>
 | 
				
			||||||
 | 
					          </fieldset>
 | 
				
			||||||
 | 
					        </form>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <footer class="footer footer-horizontal footer-center mb-8">
 | 
				
			||||||
 | 
					        <aside>
 | 
				
			||||||
 | 
					          <p>
 | 
				
			||||||
 | 
					            Powered by
 | 
				
			||||||
 | 
					            <a class="link" href="https://github.com/bestnite/sub2clash"
 | 
				
			||||||
 | 
					              >sub2clash</a
 | 
				
			||||||
 | 
					            >
 | 
				
			||||||
 | 
					          </p>
 | 
				
			||||||
 | 
					          <p>Version: ${import.meta.env.VITE_APP_VERSION ?? "dev"}</p>
 | 
				
			||||||
 | 
					        </aside>
 | 
				
			||||||
 | 
					      </footer>
 | 
				
			||||||
 | 
					    `;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare global {
 | 
				
			||||||
 | 
					  interface HTMLElementTagNameMap {
 | 
				
			||||||
 | 
					    "sub2clash-app": Sub2clashApp;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										101
									
								
								server/frontend/src/components/rename-input.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								server/frontend/src/components/rename-input.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,101 @@
 | 
				
			|||||||
 | 
					import { LitElement, html, unsafeCSS } from "lit";
 | 
				
			||||||
 | 
					import { customElement, state } from "lit/decorators.js";
 | 
				
			||||||
 | 
					import globalStyles from "../index.css?inline";
 | 
				
			||||||
 | 
					import type { Rename } from "../interface";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@customElement("rename-input")
 | 
				
			||||||
 | 
					export class RenameInput extends LitElement {
 | 
				
			||||||
 | 
					  static styles = [unsafeCSS(globalStyles)];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  private _replaceArray: Array<Rename> = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  set replaceArray(value: Array<Rename>) {
 | 
				
			||||||
 | 
					    this._replaceArray = value;
 | 
				
			||||||
 | 
					    let updatedReplaceMap: { [key: string]: string } = {};
 | 
				
			||||||
 | 
					    value.forEach((e) => {
 | 
				
			||||||
 | 
					      updatedReplaceMap[e.old] = e.new;
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    this.dispatchEvent(
 | 
				
			||||||
 | 
					      new CustomEvent("change", {
 | 
				
			||||||
 | 
					        detail: updatedReplaceMap,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  get replaceArray(): Array<Rename> {
 | 
				
			||||||
 | 
					    return this._replaceArray;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  render() {
 | 
				
			||||||
 | 
					    return html`<!-- Rename -->
 | 
				
			||||||
 | 
					      <div class="form-control mb-3">
 | 
				
			||||||
 | 
					        <label class="label mb-1 pl-1">
 | 
				
			||||||
 | 
					          <span class="label-text">节点名称替换</span>
 | 
				
			||||||
 | 
					          <button
 | 
				
			||||||
 | 
					            class="btn btn-primary btn-xs"
 | 
				
			||||||
 | 
					            type="button"
 | 
				
			||||||
 | 
					            @click="${() => {
 | 
				
			||||||
 | 
					              let updatedReplaceArray = [...this.replaceArray];
 | 
				
			||||||
 | 
					              updatedReplaceArray.push({ old: "", new: "" });
 | 
				
			||||||
 | 
					              this.replaceArray = updatedReplaceArray;
 | 
				
			||||||
 | 
					            }}">
 | 
				
			||||||
 | 
					            +
 | 
				
			||||||
 | 
					          </button>
 | 
				
			||||||
 | 
					        </label>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <div class="mb-3">
 | 
				
			||||||
 | 
					        ${this.replaceArray.map((_, i) => this.RenameTemplate(i))}
 | 
				
			||||||
 | 
					      </div>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  RenameTemplate(index: number) {
 | 
				
			||||||
 | 
					    const replaceItem = this.replaceArray[index];
 | 
				
			||||||
 | 
					    return html`<div class="join mb-1">
 | 
				
			||||||
 | 
					      <input
 | 
				
			||||||
 | 
					        class="input join-item"
 | 
				
			||||||
 | 
					        placeholder="旧名称 (正则表达式)"
 | 
				
			||||||
 | 
					        .value="${replaceItem?.old ?? ""}"
 | 
				
			||||||
 | 
					        @change="${(e: Event) => {
 | 
				
			||||||
 | 
					          const target = e.target as HTMLInputElement;
 | 
				
			||||||
 | 
					          let updatedReplaceArray = [...this.replaceArray];
 | 
				
			||||||
 | 
					          updatedReplaceArray[index] = {
 | 
				
			||||||
 | 
					            ...updatedReplaceArray[index],
 | 
				
			||||||
 | 
					            old: target.value,
 | 
				
			||||||
 | 
					          };
 | 
				
			||||||
 | 
					          this.replaceArray = updatedReplaceArray;
 | 
				
			||||||
 | 
					        }}" />
 | 
				
			||||||
 | 
					      <input
 | 
				
			||||||
 | 
					        class="input join-item"
 | 
				
			||||||
 | 
					        placeholder="新名称"
 | 
				
			||||||
 | 
					        .value="${replaceItem?.new ?? ""}"
 | 
				
			||||||
 | 
					        @change="${(e: Event) => {
 | 
				
			||||||
 | 
					          const target = e.target as HTMLInputElement;
 | 
				
			||||||
 | 
					          let updatedReplaceArray = [...this.replaceArray];
 | 
				
			||||||
 | 
					          updatedReplaceArray[index] = {
 | 
				
			||||||
 | 
					            ...updatedReplaceArray[index],
 | 
				
			||||||
 | 
					            new: target.value,
 | 
				
			||||||
 | 
					          };
 | 
				
			||||||
 | 
					          this.replaceArray = updatedReplaceArray;
 | 
				
			||||||
 | 
					        }}" />
 | 
				
			||||||
 | 
					      <button
 | 
				
			||||||
 | 
					        class="btn join-item bg-error"
 | 
				
			||||||
 | 
					        type="button"
 | 
				
			||||||
 | 
					        @click="${() => {
 | 
				
			||||||
 | 
					          let updatedReplaceArray = this.replaceArray.filter(
 | 
				
			||||||
 | 
					            (_, i) => i !== index
 | 
				
			||||||
 | 
					          );
 | 
				
			||||||
 | 
					          this.replaceArray = updatedReplaceArray;
 | 
				
			||||||
 | 
					        }}">
 | 
				
			||||||
 | 
					        删除
 | 
				
			||||||
 | 
					      </button>
 | 
				
			||||||
 | 
					    </div>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare global {
 | 
				
			||||||
 | 
					  interface HTMLElementTagNameMap {
 | 
				
			||||||
 | 
					    "rename-input": RenameInput;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										92
									
								
								server/frontend/src/components/rule-input.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								server/frontend/src/components/rule-input.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,92 @@
 | 
				
			|||||||
 | 
					import { LitElement, html, unsafeCSS } from "lit";
 | 
				
			||||||
 | 
					import { customElement, state } from "lit/decorators.js";
 | 
				
			||||||
 | 
					import type { Rule } from "../interface";
 | 
				
			||||||
 | 
					import globalStyles from "../index.css?inline";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@customElement("rule-input")
 | 
				
			||||||
 | 
					export class RuleInput extends LitElement {
 | 
				
			||||||
 | 
					  static styles = [unsafeCSS(globalStyles)];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _rules: Array<Rule> = [];
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  set rules(value: Array<Rule>) {
 | 
				
			||||||
 | 
					    this.dispatchEvent(
 | 
				
			||||||
 | 
					      new CustomEvent("change", {
 | 
				
			||||||
 | 
					        detail: value,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    this._rules = value;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  get rules() {
 | 
				
			||||||
 | 
					    return this._rules;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  render() {
 | 
				
			||||||
 | 
					    return html`<!-- Rule -->
 | 
				
			||||||
 | 
					      <div class="form-control mb-3">
 | 
				
			||||||
 | 
					        <label class="label mb-1 pl-1">
 | 
				
			||||||
 | 
					          <span class="label-text">规则</span>
 | 
				
			||||||
 | 
					          <button
 | 
				
			||||||
 | 
					            class="btn btn-primary btn-xs"
 | 
				
			||||||
 | 
					            type="button"
 | 
				
			||||||
 | 
					            @click="${() => {
 | 
				
			||||||
 | 
					              let updatedRules = this.rules ? [...this.rules] : [];
 | 
				
			||||||
 | 
					              updatedRules?.push({
 | 
				
			||||||
 | 
					                rule: "",
 | 
				
			||||||
 | 
					                prepend: false,
 | 
				
			||||||
 | 
					              });
 | 
				
			||||||
 | 
					              this.rules = updatedRules;
 | 
				
			||||||
 | 
					            }}">
 | 
				
			||||||
 | 
					            +
 | 
				
			||||||
 | 
					          </button>
 | 
				
			||||||
 | 
					        </label>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <div class="mb-3">
 | 
				
			||||||
 | 
					        ${this.rules?.map((_, i) => this.RuleTemplate(i))}
 | 
				
			||||||
 | 
					      </div>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  RuleTemplate(index: number) {
 | 
				
			||||||
 | 
					    return html`<div class="join mb-1">
 | 
				
			||||||
 | 
					      <input
 | 
				
			||||||
 | 
					        class="input join-item"
 | 
				
			||||||
 | 
					        placeholder="规则"
 | 
				
			||||||
 | 
					        .value="${this.rules![index].rule}"
 | 
				
			||||||
 | 
					        @change="${(e: Event) => {
 | 
				
			||||||
 | 
					          const target = e.target as HTMLInputElement;
 | 
				
			||||||
 | 
					          let updatedRules = this.rules;
 | 
				
			||||||
 | 
					          updatedRules![index].rule = target.value;
 | 
				
			||||||
 | 
					          this.rules = updatedRules;
 | 
				
			||||||
 | 
					        }}" />
 | 
				
			||||||
 | 
					      <div class="tooltip" data-tip="是否置于规则列表最前">
 | 
				
			||||||
 | 
					        <select
 | 
				
			||||||
 | 
					          class="select join-item w-fit"
 | 
				
			||||||
 | 
					          .value="${String(this.rules![index].prepend)}"
 | 
				
			||||||
 | 
					          @change="${(e: Event) => {
 | 
				
			||||||
 | 
					            const target = e.target as HTMLInputElement;
 | 
				
			||||||
 | 
					            let updatedRules = this.rules;
 | 
				
			||||||
 | 
					            updatedRules![index].prepend = Boolean(target.value);
 | 
				
			||||||
 | 
					            this.rules = updatedRules;
 | 
				
			||||||
 | 
					          }}">
 | 
				
			||||||
 | 
					          <option value="true">是</option>
 | 
				
			||||||
 | 
					          <option value="false" selected>否</option>
 | 
				
			||||||
 | 
					        </select>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					      <button
 | 
				
			||||||
 | 
					        class="btn join-item bg-error"
 | 
				
			||||||
 | 
					        type="button"
 | 
				
			||||||
 | 
					        @click="${() => {
 | 
				
			||||||
 | 
					          let updatedRules = this.rules?.filter((_, i) => i !== index);
 | 
				
			||||||
 | 
					          this.rules = updatedRules;
 | 
				
			||||||
 | 
					        }}">
 | 
				
			||||||
 | 
					        删除
 | 
				
			||||||
 | 
					      </button>
 | 
				
			||||||
 | 
					    </div>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare global {
 | 
				
			||||||
 | 
					  interface HTMLElementTagNameMap {
 | 
				
			||||||
 | 
					    "rule-input": RuleInput;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										143
									
								
								server/frontend/src/components/rule-provider-input.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								server/frontend/src/components/rule-provider-input.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,143 @@
 | 
				
			|||||||
 | 
					import { LitElement, html, unsafeCSS } from "lit";
 | 
				
			||||||
 | 
					import { customElement, state } from "lit/decorators.js";
 | 
				
			||||||
 | 
					import type { RuleProvider } from "../interface";
 | 
				
			||||||
 | 
					import globalStyles from "../index.css?inline";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@customElement("rule-provider-input")
 | 
				
			||||||
 | 
					export class RuleProviderInput extends LitElement {
 | 
				
			||||||
 | 
					  static styles = [unsafeCSS(globalStyles)];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _ruleProviders: Array<RuleProvider> = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @state()
 | 
				
			||||||
 | 
					  set ruleProviders(value) {
 | 
				
			||||||
 | 
					    this.dispatchEvent(
 | 
				
			||||||
 | 
					      new CustomEvent("change", {
 | 
				
			||||||
 | 
					        detail: value,
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					    this._ruleProviders = value;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  get ruleProviders() {
 | 
				
			||||||
 | 
					    return this._ruleProviders;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  RuleProviderTemplate(index: number) {
 | 
				
			||||||
 | 
					    return html`
 | 
				
			||||||
 | 
					      <div class="join mb-1">
 | 
				
			||||||
 | 
					        <div class="tooltip" data-tip="不能重复">
 | 
				
			||||||
 | 
					          <input
 | 
				
			||||||
 | 
					            class="input join-item"
 | 
				
			||||||
 | 
					            placeholder="名称"
 | 
				
			||||||
 | 
					            .value="${this.ruleProviders![index].name}"
 | 
				
			||||||
 | 
					            @change="${(e: Event) => {
 | 
				
			||||||
 | 
					              const target = e.target as HTMLInputElement;
 | 
				
			||||||
 | 
					              let updatedRuleProviders = this.ruleProviders;
 | 
				
			||||||
 | 
					              updatedRuleProviders![index].name = target.value;
 | 
				
			||||||
 | 
					              this.ruleProviders = updatedRuleProviders;
 | 
				
			||||||
 | 
					            }}" />
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <div class="tooltip" data-tip="类型">
 | 
				
			||||||
 | 
					          <select
 | 
				
			||||||
 | 
					            class="select join-item w-fit"
 | 
				
			||||||
 | 
					            .value="${this.ruleProviders![index].behavior}"
 | 
				
			||||||
 | 
					            @change="${(e: Event) => {
 | 
				
			||||||
 | 
					              const target = e.target as HTMLInputElement;
 | 
				
			||||||
 | 
					              let updatedRuleProviders = this.ruleProviders;
 | 
				
			||||||
 | 
					              updatedRuleProviders![index].behavior = target.value;
 | 
				
			||||||
 | 
					              this.ruleProviders = updatedRuleProviders;
 | 
				
			||||||
 | 
					            }}">
 | 
				
			||||||
 | 
					            <option value="classical" selected>classical</option>
 | 
				
			||||||
 | 
					            <option value="domain">domain</option>
 | 
				
			||||||
 | 
					            <option value="ipcidr">ipcidr</option>
 | 
				
			||||||
 | 
					          </select>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <div>
 | 
				
			||||||
 | 
					          <input
 | 
				
			||||||
 | 
					            class="input join-item"
 | 
				
			||||||
 | 
					            placeholder="Url"
 | 
				
			||||||
 | 
					            .value="${this.ruleProviders![index].url}"
 | 
				
			||||||
 | 
					            @change="${(e: Event) => {
 | 
				
			||||||
 | 
					              const target = e.target as HTMLInputElement;
 | 
				
			||||||
 | 
					              let updatedRuleProviders = this.ruleProviders;
 | 
				
			||||||
 | 
					              updatedRuleProviders![index].url = target.value;
 | 
				
			||||||
 | 
					              this.ruleProviders = updatedRuleProviders;
 | 
				
			||||||
 | 
					            }}" />
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <input
 | 
				
			||||||
 | 
					          class="input join-item"
 | 
				
			||||||
 | 
					          placeholder="出站策略组"
 | 
				
			||||||
 | 
					          .value="${this.ruleProviders![index].group}"
 | 
				
			||||||
 | 
					          @change="${(e: Event) => {
 | 
				
			||||||
 | 
					            const target = e.target as HTMLInputElement;
 | 
				
			||||||
 | 
					            let updatedRuleProviders = this.ruleProviders;
 | 
				
			||||||
 | 
					            updatedRuleProviders![index].group = target.value;
 | 
				
			||||||
 | 
					            this.ruleProviders = updatedRuleProviders;
 | 
				
			||||||
 | 
					          }}" />
 | 
				
			||||||
 | 
					        <div class="tooltip" data-tip="是否置于规则列表最前">
 | 
				
			||||||
 | 
					          <select
 | 
				
			||||||
 | 
					            class="select join-item w-fit"
 | 
				
			||||||
 | 
					            .value="${String(this.ruleProviders![index].prepend)}"
 | 
				
			||||||
 | 
					            @change="${(e: Event) => {
 | 
				
			||||||
 | 
					              const target = e.target as HTMLInputElement;
 | 
				
			||||||
 | 
					              let updatedRuleProviders = this.ruleProviders;
 | 
				
			||||||
 | 
					              updatedRuleProviders![index].prepend = Boolean(target.value);
 | 
				
			||||||
 | 
					              this.ruleProviders = updatedRuleProviders;
 | 
				
			||||||
 | 
					            }}">
 | 
				
			||||||
 | 
					            <option value="true">是</option>
 | 
				
			||||||
 | 
					            <option value="false" selected>否</option>
 | 
				
			||||||
 | 
					          </select>
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <button
 | 
				
			||||||
 | 
					          class="btn join-item bg-error"
 | 
				
			||||||
 | 
					          type="button"
 | 
				
			||||||
 | 
					          @click="${() => {
 | 
				
			||||||
 | 
					            let updatedRuleProviders = this.ruleProviders?.filter(
 | 
				
			||||||
 | 
					              (_, i) => i !== index
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					            this.ruleProviders = updatedRuleProviders;
 | 
				
			||||||
 | 
					          }}">
 | 
				
			||||||
 | 
					          删除
 | 
				
			||||||
 | 
					        </button>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    `;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  render() {
 | 
				
			||||||
 | 
					    return html` <!-- Rule Provider -->
 | 
				
			||||||
 | 
					      <div class="form-control mb-3">
 | 
				
			||||||
 | 
					        <label class="label mb-1 pl-1">
 | 
				
			||||||
 | 
					          <span class="label-text">Rule Provider</span>
 | 
				
			||||||
 | 
					          <button
 | 
				
			||||||
 | 
					            class="btn btn-primary btn-xs"
 | 
				
			||||||
 | 
					            type="button"
 | 
				
			||||||
 | 
					            @click="${() => {
 | 
				
			||||||
 | 
					              let updatedRuleProviders = this.ruleProviders
 | 
				
			||||||
 | 
					                ? [...this.ruleProviders]
 | 
				
			||||||
 | 
					                : [];
 | 
				
			||||||
 | 
					              updatedRuleProviders.push({
 | 
				
			||||||
 | 
					                behavior: "classical",
 | 
				
			||||||
 | 
					                url: "",
 | 
				
			||||||
 | 
					                name: "",
 | 
				
			||||||
 | 
					                prepend: false,
 | 
				
			||||||
 | 
					                group: "",
 | 
				
			||||||
 | 
					              });
 | 
				
			||||||
 | 
					              this.ruleProviders = updatedRuleProviders;
 | 
				
			||||||
 | 
					            }}">
 | 
				
			||||||
 | 
					            +
 | 
				
			||||||
 | 
					          </button>
 | 
				
			||||||
 | 
					        </label>
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <div class="mb-3">
 | 
				
			||||||
 | 
					        ${this.ruleProviders?.map((_, i) => this.RuleProviderTemplate(i))}
 | 
				
			||||||
 | 
					      </div>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare global {
 | 
				
			||||||
 | 
					  interface HTMLElementTagNameMap {
 | 
				
			||||||
 | 
					    "rule-provider-input": RuleProviderInput;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										180
									
								
								server/frontend/src/components/short-link-input-group.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										180
									
								
								server/frontend/src/components/short-link-input-group.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,180 @@
 | 
				
			|||||||
 | 
					import { html, LitElement, unsafeCSS } from "lit";
 | 
				
			||||||
 | 
					import { customElement, property } from "lit/decorators.js";
 | 
				
			||||||
 | 
					import globalStyles from "../index.css?inline";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@customElement("short-link-input-group")
 | 
				
			||||||
 | 
					export class ShortLinkInputGroup extends LitElement {
 | 
				
			||||||
 | 
					  static styles = unsafeCSS(globalStyles);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @property()
 | 
				
			||||||
 | 
					  id: string = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @property({ type: Number })
 | 
				
			||||||
 | 
					  _screenSizeLevel: number = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @property()
 | 
				
			||||||
 | 
					  passwd: string = "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  connectedCallback() {
 | 
				
			||||||
 | 
					    super.connectedCallback();
 | 
				
			||||||
 | 
					    window.addEventListener("resize", this._checkScreenSize);
 | 
				
			||||||
 | 
					    this._checkScreenSize(); // Initial check
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  disconnectedCallback() {
 | 
				
			||||||
 | 
					    window.removeEventListener("resize", this._checkScreenSize);
 | 
				
			||||||
 | 
					    super.disconnectedCallback();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  _checkScreenSize = () => {
 | 
				
			||||||
 | 
					    const width = window.innerWidth;
 | 
				
			||||||
 | 
					    if (width < 365) {
 | 
				
			||||||
 | 
					      this._screenSizeLevel = 0; // sm
 | 
				
			||||||
 | 
					    } else if (width < 640) {
 | 
				
			||||||
 | 
					      this._screenSizeLevel = 1; // md
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      this._screenSizeLevel = 2; // other
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  async copyToClipboard(content: string, e: HTMLButtonElement) {
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      await navigator.clipboard.writeText(content);
 | 
				
			||||||
 | 
					      let text = e.textContent;
 | 
				
			||||||
 | 
					      e.addEventListener("mouseout", function () {
 | 
				
			||||||
 | 
					        e.textContent = text;
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					      e.textContent = "复制成功";
 | 
				
			||||||
 | 
					    } catch (err) {
 | 
				
			||||||
 | 
					      console.error("复制到剪贴板失败:", err);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  idInputTemplate() {
 | 
				
			||||||
 | 
					    return html`<input
 | 
				
			||||||
 | 
					      class="input input-bordered w-1/2 join-item"
 | 
				
			||||||
 | 
					      type="text"
 | 
				
			||||||
 | 
					      placeholder="ID(可选)"
 | 
				
			||||||
 | 
					      .value="${this.id}"
 | 
				
			||||||
 | 
					      @change="${(e: Event) => {
 | 
				
			||||||
 | 
					        this.id = (e.target as HTMLInputElement).value;
 | 
				
			||||||
 | 
					        this.dispatchEvent(
 | 
				
			||||||
 | 
					          new CustomEvent("id-change", {
 | 
				
			||||||
 | 
					            detail: this.id,
 | 
				
			||||||
 | 
					          })
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      }}" />`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  passwdInputTemplate() {
 | 
				
			||||||
 | 
					    return html`<input
 | 
				
			||||||
 | 
					      class="input input-bordered w-1/2 join-item"
 | 
				
			||||||
 | 
					      type="text"
 | 
				
			||||||
 | 
					      placeholder="密码"
 | 
				
			||||||
 | 
					      .value="${this.passwd}"
 | 
				
			||||||
 | 
					      @change="${(e: Event) => {
 | 
				
			||||||
 | 
					        this.passwd = (e.target as HTMLInputElement).value;
 | 
				
			||||||
 | 
					        this.dispatchEvent(
 | 
				
			||||||
 | 
					          new CustomEvent("passwd-change", {
 | 
				
			||||||
 | 
					            detail: this.passwd,
 | 
				
			||||||
 | 
					          })
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      }}" />`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  generateBtnTemplate(extraClass: string = "") {
 | 
				
			||||||
 | 
					    return html`<button
 | 
				
			||||||
 | 
					      class="btn btn-primary join-item ${extraClass}"
 | 
				
			||||||
 | 
					      type="button"
 | 
				
			||||||
 | 
					      @click="${(e: Event) => {
 | 
				
			||||||
 | 
					        this.dispatchEvent(
 | 
				
			||||||
 | 
					          new CustomEvent("generate-btn-click", { detail: e })
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      }}">
 | 
				
			||||||
 | 
					      生成短链
 | 
				
			||||||
 | 
					    </button>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  updateBtnTemplate(extraClass: string = "") {
 | 
				
			||||||
 | 
					    return html`<button
 | 
				
			||||||
 | 
					      class="btn btn-primary join-item ${extraClass}"
 | 
				
			||||||
 | 
					      @click="${(e: Event) => {
 | 
				
			||||||
 | 
					        this.dispatchEvent(new CustomEvent("update-btn-click", { detail: e }));
 | 
				
			||||||
 | 
					      }}"
 | 
				
			||||||
 | 
					      type="button">
 | 
				
			||||||
 | 
					      更新短链
 | 
				
			||||||
 | 
					    </button>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  deleteBtnTemplate(extraClass: string = "") {
 | 
				
			||||||
 | 
					    return html`<button
 | 
				
			||||||
 | 
					      class="btn btn-primary join-item ${extraClass}"
 | 
				
			||||||
 | 
					      @click="${(e: Event) => {
 | 
				
			||||||
 | 
					        this.dispatchEvent(new CustomEvent("delete-btn-click", { detail: e }));
 | 
				
			||||||
 | 
					      }}"
 | 
				
			||||||
 | 
					      type="button">
 | 
				
			||||||
 | 
					      删除短链
 | 
				
			||||||
 | 
					    </button>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  copyBtnTemplate(extraClass: string = "") {
 | 
				
			||||||
 | 
					    return html`<button
 | 
				
			||||||
 | 
					      class="btn btn-primary join-item ${extraClass}"
 | 
				
			||||||
 | 
					      type="button"
 | 
				
			||||||
 | 
					      @click="${(e: Event) => {
 | 
				
			||||||
 | 
					        this.copyToClipboard(
 | 
				
			||||||
 | 
					          `${window.location.origin}${window.location.pathname}s/${this.id}?password=${this.passwd}`,
 | 
				
			||||||
 | 
					          e.target as HTMLButtonElement
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					      }}">
 | 
				
			||||||
 | 
					      复制短链
 | 
				
			||||||
 | 
					    </button>`;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  render() {
 | 
				
			||||||
 | 
					    const sm = html`<div class="form-control mb-2">
 | 
				
			||||||
 | 
					      <div class="join w-full mb-1">
 | 
				
			||||||
 | 
					        ${this.idInputTemplate()} ${this.passwdInputTemplate()}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					      <div class="join w-full mb-1">
 | 
				
			||||||
 | 
					        ${this.generateBtnTemplate("w-1/2")} ${this.updateBtnTemplate("w-1/2")}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					      <div class="join w-full">
 | 
				
			||||||
 | 
					        ${this.deleteBtnTemplate("w-1/2")} ${this.copyBtnTemplate("w-1/2")}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const md = html`<div class="form-control mb-2">
 | 
				
			||||||
 | 
					      <div class="join w-full mb-1">
 | 
				
			||||||
 | 
					        ${this.idInputTemplate()} ${this.passwdInputTemplate()}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					      <div class="join w-full">
 | 
				
			||||||
 | 
					        ${this.generateBtnTemplate("w-1/4")} ${this.updateBtnTemplate("w-1/4")}
 | 
				
			||||||
 | 
					        ${this.deleteBtnTemplate("w-1/4")} ${this.copyBtnTemplate("w-1/4")}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const other = html`<div class="form-control mb-2">
 | 
				
			||||||
 | 
					      <div class="join w-full">
 | 
				
			||||||
 | 
					        ${this.idInputTemplate()} ${this.passwdInputTemplate()}
 | 
				
			||||||
 | 
					        ${this.generateBtnTemplate()} ${this.updateBtnTemplate()}
 | 
				
			||||||
 | 
					        ${this.deleteBtnTemplate()} ${this.copyBtnTemplate()}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    switch (this._screenSizeLevel) {
 | 
				
			||||||
 | 
					      case 0:
 | 
				
			||||||
 | 
					        return sm;
 | 
				
			||||||
 | 
					      case 1:
 | 
				
			||||||
 | 
					        return md;
 | 
				
			||||||
 | 
					      default:
 | 
				
			||||||
 | 
					        return other;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					declare global {
 | 
				
			||||||
 | 
					  interface HTMLElementTagNameMap {
 | 
				
			||||||
 | 
					    "short-link-input-group": ShortLinkInputGroup;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										72
									
								
								server/frontend/src/index.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								server/frontend/src/index.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,72 @@
 | 
				
			|||||||
 | 
					@import "tailwindcss";
 | 
				
			||||||
 | 
					@plugin "daisyui";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@plugin "daisyui/theme" {
 | 
				
			||||||
 | 
					  name: "light";
 | 
				
			||||||
 | 
					  default: false;
 | 
				
			||||||
 | 
					  prefersdark: false;
 | 
				
			||||||
 | 
					  color-scheme: "light";
 | 
				
			||||||
 | 
					  --color-base-100: oklch(98% 0.001 106.423);
 | 
				
			||||||
 | 
					  --color-base-200: oklch(97% 0.001 106.424);
 | 
				
			||||||
 | 
					  --color-base-300: oklch(92% 0.003 48.717);
 | 
				
			||||||
 | 
					  --color-base-content: oklch(21% 0.006 56.043);
 | 
				
			||||||
 | 
					  --color-primary: oklch(54% 0.281 293.009);
 | 
				
			||||||
 | 
					  --color-primary-content: oklch(96% 0.016 293.756);
 | 
				
			||||||
 | 
					  --color-secondary: oklch(57% 0.245 27.325);
 | 
				
			||||||
 | 
					  --color-secondary-content: oklch(97% 0.013 17.38);
 | 
				
			||||||
 | 
					  --color-accent: oklch(59% 0.249 0.584);
 | 
				
			||||||
 | 
					  --color-accent-content: oklch(97% 0.014 343.198);
 | 
				
			||||||
 | 
					  --color-neutral: oklch(14% 0.004 49.25);
 | 
				
			||||||
 | 
					  --color-neutral-content: oklch(98% 0.001 106.423);
 | 
				
			||||||
 | 
					  --color-info: oklch(78% 0.154 211.53);
 | 
				
			||||||
 | 
					  --color-info-content: oklch(30% 0.056 229.695);
 | 
				
			||||||
 | 
					  --color-success: oklch(79% 0.209 151.711);
 | 
				
			||||||
 | 
					  --color-success-content: oklch(26% 0.065 152.934);
 | 
				
			||||||
 | 
					  --color-warning: oklch(82% 0.189 84.429);
 | 
				
			||||||
 | 
					  --color-warning-content: oklch(27% 0.077 45.635);
 | 
				
			||||||
 | 
					  --color-error: oklch(71% 0.194 13.428);
 | 
				
			||||||
 | 
					  --color-error-content: oklch(27% 0.105 12.094);
 | 
				
			||||||
 | 
					  --radius-selector: 1rem;
 | 
				
			||||||
 | 
					  --radius-field: 1rem;
 | 
				
			||||||
 | 
					  --radius-box: 1rem;
 | 
				
			||||||
 | 
					  --size-selector: 0.25rem;
 | 
				
			||||||
 | 
					  --size-field: 0.25rem;
 | 
				
			||||||
 | 
					  --border: 1.5px;
 | 
				
			||||||
 | 
					  --depth: 0;
 | 
				
			||||||
 | 
					  --noise: 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@plugin "daisyui/theme" {
 | 
				
			||||||
 | 
					  name: "dark";
 | 
				
			||||||
 | 
					  default: true;
 | 
				
			||||||
 | 
					  prefersdark: true;
 | 
				
			||||||
 | 
					  color-scheme: "dark";
 | 
				
			||||||
 | 
					  --color-base-100: oklch(21% 0.006 285.885);
 | 
				
			||||||
 | 
					  --color-base-200: oklch(21% 0.006 285.885);
 | 
				
			||||||
 | 
					  --color-base-300: oklch(27% 0.006 286.033);
 | 
				
			||||||
 | 
					  --color-base-content: oklch(96% 0.001 286.375);
 | 
				
			||||||
 | 
					  --color-primary: oklch(55% 0.288 302.321);
 | 
				
			||||||
 | 
					  --color-primary-content: oklch(97% 0.014 308.299);
 | 
				
			||||||
 | 
					  --color-secondary: oklch(44% 0.03 256.802);
 | 
				
			||||||
 | 
					  --color-secondary-content: oklch(98% 0.002 247.839);
 | 
				
			||||||
 | 
					  --color-accent: oklch(59% 0.249 0.584);
 | 
				
			||||||
 | 
					  --color-accent-content: oklch(97% 0.014 343.198);
 | 
				
			||||||
 | 
					  --color-neutral: oklch(37% 0.013 285.805);
 | 
				
			||||||
 | 
					  --color-neutral-content: oklch(98% 0 0);
 | 
				
			||||||
 | 
					  --color-info: oklch(54% 0.245 262.881);
 | 
				
			||||||
 | 
					  --color-info-content: oklch(97% 0.014 254.604);
 | 
				
			||||||
 | 
					  --color-success: oklch(64% 0.2 131.684);
 | 
				
			||||||
 | 
					  --color-success-content: oklch(98% 0.031 120.757);
 | 
				
			||||||
 | 
					  --color-warning: oklch(66% 0.179 58.318);
 | 
				
			||||||
 | 
					  --color-warning-content: oklch(98% 0.022 95.277);
 | 
				
			||||||
 | 
					  --color-error: oklch(58% 0.253 17.585);
 | 
				
			||||||
 | 
					  --color-error-content: oklch(96% 0.015 12.422);
 | 
				
			||||||
 | 
					  --radius-selector: 1rem;
 | 
				
			||||||
 | 
					  --radius-field: 1rem;
 | 
				
			||||||
 | 
					  --radius-box: 1rem;
 | 
				
			||||||
 | 
					  --size-selector: 0.25rem;
 | 
				
			||||||
 | 
					  --size-field: 0.25rem;
 | 
				
			||||||
 | 
					  --border: 1px;
 | 
				
			||||||
 | 
					  --depth: 0;
 | 
				
			||||||
 | 
					  --noise: 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										36
									
								
								server/frontend/src/interface.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								server/frontend/src/interface.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					export interface RuleProvider {
 | 
				
			||||||
 | 
					  behavior: string;
 | 
				
			||||||
 | 
					  url: string;
 | 
				
			||||||
 | 
					  group: string;
 | 
				
			||||||
 | 
					  prepend: boolean;
 | 
				
			||||||
 | 
					  name: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface Rule {
 | 
				
			||||||
 | 
					  rule: string;
 | 
				
			||||||
 | 
					  prepend: boolean;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface Rename {
 | 
				
			||||||
 | 
					  old: string;
 | 
				
			||||||
 | 
					  new: string;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface Config {
 | 
				
			||||||
 | 
					  clashType: number;
 | 
				
			||||||
 | 
					  subscriptions?: string[];
 | 
				
			||||||
 | 
					  proxies?: string[];
 | 
				
			||||||
 | 
					  userAgent?: string;
 | 
				
			||||||
 | 
					  refresh?: boolean;
 | 
				
			||||||
 | 
					  autoTest?: boolean;
 | 
				
			||||||
 | 
					  lazy?: boolean;
 | 
				
			||||||
 | 
					  nodeList?: boolean;
 | 
				
			||||||
 | 
					  ignoreCountryGroup?: boolean;
 | 
				
			||||||
 | 
					  useUDP?: boolean;
 | 
				
			||||||
 | 
					  template?: string;
 | 
				
			||||||
 | 
					  ruleProviders?: RuleProvider[];
 | 
				
			||||||
 | 
					  rules?: Rule[];
 | 
				
			||||||
 | 
					  sort?: string;
 | 
				
			||||||
 | 
					  remove?: string;
 | 
				
			||||||
 | 
					  replace?: { [key: string]: string };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								server/frontend/src/utils.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								server/frontend/src/utils.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					export function base64EncodeUnicode(str: string) {
 | 
				
			||||||
 | 
					  const bytes = new TextEncoder().encode(str);
 | 
				
			||||||
 | 
					  let binary = "";
 | 
				
			||||||
 | 
					  bytes.forEach((b) => (binary += String.fromCharCode(b)));
 | 
				
			||||||
 | 
					  return btoa(binary);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function base64decodeUnicode(str: string) {
 | 
				
			||||||
 | 
					  const binaryString = atob(str);
 | 
				
			||||||
 | 
					  const bytes = new Uint8Array(binaryString.length);
 | 
				
			||||||
 | 
					  for (let i = 0; i < binaryString.length; i++) {
 | 
				
			||||||
 | 
					    bytes[i] = binaryString.charCodeAt(i);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return new TextDecoder().decode(bytes);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										31
									
								
								server/frontend/tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								server/frontend/tsconfig.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "compilerOptions": {
 | 
				
			||||||
 | 
					    "target": "ES2022",
 | 
				
			||||||
 | 
					    "experimentalDecorators": true,
 | 
				
			||||||
 | 
					    "useDefineForClassFields": false,
 | 
				
			||||||
 | 
					    "module": "ESNext",
 | 
				
			||||||
 | 
					    "lib": [
 | 
				
			||||||
 | 
					      "ES2022",
 | 
				
			||||||
 | 
					      "DOM",
 | 
				
			||||||
 | 
					      "DOM.Iterable"
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "types": [
 | 
				
			||||||
 | 
					      "vite/client"
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "skipLibCheck": true,
 | 
				
			||||||
 | 
					    "moduleResolution": "bundler",
 | 
				
			||||||
 | 
					    "allowImportingTsExtensions": true,
 | 
				
			||||||
 | 
					    "verbatimModuleSyntax": true,
 | 
				
			||||||
 | 
					    "moduleDetection": "force",
 | 
				
			||||||
 | 
					    "noEmit": true,
 | 
				
			||||||
 | 
					    "strict": true,
 | 
				
			||||||
 | 
					    "noUnusedLocals": true,
 | 
				
			||||||
 | 
					    "noUnusedParameters": true,
 | 
				
			||||||
 | 
					    "erasableSyntaxOnly": true,
 | 
				
			||||||
 | 
					    "noFallthroughCasesInSwitch": true,
 | 
				
			||||||
 | 
					    "noUncheckedSideEffectImports": true
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  "include": [
 | 
				
			||||||
 | 
					    "src"
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										6
									
								
								server/frontend/vite.config.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								server/frontend/vite.config.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					import { defineConfig } from "vite";
 | 
				
			||||||
 | 
					import tailwindcss from "@tailwindcss/vite";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default defineConfig({
 | 
				
			||||||
 | 
					  plugins: [tailwindcss()],
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
@@ -6,20 +6,28 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"github.com/bestnite/sub2clash/common"
 | 
						"github.com/bestnite/sub2clash/common"
 | 
				
			||||||
	"github.com/bestnite/sub2clash/config"
 | 
						"github.com/bestnite/sub2clash/config"
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model"
 | 
				
			||||||
	M "github.com/bestnite/sub2clash/model"
 | 
						M "github.com/bestnite/sub2clash/model"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
	"gopkg.in/yaml.v3"
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SubHandler(model M.ClashType, template string) func(c *gin.Context) {
 | 
					func ConvertHandler() func(c *gin.Context) {
 | 
				
			||||||
	return func(c *gin.Context) {
 | 
						return func(c *gin.Context) {
 | 
				
			||||||
		query, err := M.ParseSubQuery(c)
 | 
							query, err := M.ParseConvertQuery(c)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			c.String(http.StatusBadRequest, err.Error())
 | 
								c.String(http.StatusBadRequest, err.Error())
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		sub, err := common.BuildSub(model, query, template, config.GlobalConfig.CacheExpire, config.GlobalConfig.RequestRetryTimes)
 | 
							template := ""
 | 
				
			||||||
 | 
							switch query.ClashType {
 | 
				
			||||||
 | 
							case model.Clash:
 | 
				
			||||||
 | 
								template = config.GlobalConfig.ClashTemplate
 | 
				
			||||||
 | 
							case model.ClashMeta:
 | 
				
			||||||
 | 
								template = config.GlobalConfig.MetaTemplate
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							sub, err := common.BuildSub(query.ClashType, query, template, config.GlobalConfig.CacheExpire, config.GlobalConfig.RequestRetryTimes)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			c.String(http.StatusInternalServerError, err.Error())
 | 
								c.String(http.StatusInternalServerError, err.Error())
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
@@ -1,9 +1,10 @@
 | 
				
			|||||||
package handler
 | 
					package handler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
						"encoding/json"
 | 
				
			||||||
	"io"
 | 
						"log"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -11,60 +12,64 @@ import (
 | 
				
			|||||||
	"github.com/bestnite/sub2clash/common/database"
 | 
						"github.com/bestnite/sub2clash/common/database"
 | 
				
			||||||
	"github.com/bestnite/sub2clash/config"
 | 
						"github.com/bestnite/sub2clash/config"
 | 
				
			||||||
	"github.com/bestnite/sub2clash/model"
 | 
						"github.com/bestnite/sub2clash/model"
 | 
				
			||||||
 | 
						M "github.com/bestnite/sub2clash/model"
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type shortLinkGenRequset struct {
 | 
					type shortLinkGenRequset struct {
 | 
				
			||||||
	Url      string `form:"url" binding:"required"`
 | 
						Config   model.ConvertConfig `form:"config" binding:"required"`
 | 
				
			||||||
	Password string              `form:"password"`
 | 
						Password string              `form:"password"`
 | 
				
			||||||
	CustomID string `form:"customId"`
 | 
						ID       string              `form:"id"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type shortLinkUpdateRequest struct {
 | 
					type shortLinkUpdateRequest struct {
 | 
				
			||||||
	Hash     string `form:"hash" binding:"required"`
 | 
						Config   model.ConvertConfig `form:"config" binding:"required"`
 | 
				
			||||||
	Url      string `form:"url" binding:"required"`
 | 
					 | 
				
			||||||
	Password string              `form:"password" binding:"required"`
 | 
						Password string              `form:"password" binding:"required"`
 | 
				
			||||||
 | 
						ID       string              `form:"id" binding:"required"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func respondWithError(c *gin.Context, code int, message string) {
 | 
					var DB *database.Database
 | 
				
			||||||
	c.String(code, message)
 | 
					
 | 
				
			||||||
	c.Abort()
 | 
					func init() {
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						DB, err = database.ConnectDB()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							log.Printf("failed to connect to database: %v", err)
 | 
				
			||||||
 | 
							os.Exit(1)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GenerateLinkHandler(c *gin.Context) {
 | 
					func GenerateLinkHandler(c *gin.Context) {
 | 
				
			||||||
	var params shortLinkGenRequset
 | 
						var params shortLinkGenRequset
 | 
				
			||||||
	if err := c.ShouldBind(¶ms); err != nil {
 | 
						if err := c.ShouldBind(¶ms); err != nil {
 | 
				
			||||||
		respondWithError(c, http.StatusBadRequest, "参数错误: "+err.Error())
 | 
							c.String(http.StatusBadRequest, "参数错误: "+err.Error())
 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if strings.TrimSpace(params.Url) == "" {
 | 
					 | 
				
			||||||
		respondWithError(c, http.StatusBadRequest, "URL 不能为空")
 | 
					 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var hash string
 | 
						var id string
 | 
				
			||||||
	var password string
 | 
						var password string
 | 
				
			||||||
	var err error
 | 
						var err error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if params.CustomID != "" {
 | 
						if params.ID != "" {
 | 
				
			||||||
		// 检查自定义ID是否已存在
 | 
							// 检查自定义ID是否已存在
 | 
				
			||||||
		exists, err := database.CheckShortLinkHashExists(params.CustomID)
 | 
							exists, err := DB.CheckShortLinkIDExists(params.ID)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
								c.String(http.StatusInternalServerError, "数据库错误")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if exists {
 | 
							if exists {
 | 
				
			||||||
			respondWithError(c, http.StatusBadRequest, "短链已存在")
 | 
								c.String(http.StatusBadRequest, "短链已存在")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		hash = params.CustomID
 | 
							id = params.ID
 | 
				
			||||||
		password = params.Password
 | 
							password = params.Password
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		// 自动生成短链ID和密码
 | 
							// 自动生成短链ID和密码
 | 
				
			||||||
		hash, err = generateUniqueHash(config.GlobalConfig.ShortLinkLength)
 | 
							id, err = generateUniqueHash(config.GlobalConfig.ShortLinkLength)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			respondWithError(c, http.StatusInternalServerError, "生成短链接失败")
 | 
								c.String(http.StatusInternalServerError, "生成短链失败")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if params.Password == "" {
 | 
							if params.Password == "" {
 | 
				
			||||||
@@ -75,19 +80,19 @@ func GenerateLinkHandler(c *gin.Context) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	shortLink := model.ShortLink{
 | 
						shortLink := model.ShortLink{
 | 
				
			||||||
		Hash:     hash,
 | 
							ID:       id,
 | 
				
			||||||
		Url:      params.Url,
 | 
							Config:   params.Config,
 | 
				
			||||||
		Password: password,
 | 
							Password: password,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := database.SaveShortLink(&shortLink); err != nil {
 | 
						if err := DB.CreateShortLink(&shortLink); err != nil {
 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
							c.String(http.StatusInternalServerError, "数据库错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 返回生成的短链ID和密码
 | 
						// 返回生成的短链ID和密码
 | 
				
			||||||
	response := map[string]string{
 | 
						response := map[string]string{
 | 
				
			||||||
		"hash":     hash,
 | 
							"id":       id,
 | 
				
			||||||
		"password": password,
 | 
							"password": password,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	c.JSON(http.StatusOK, response)
 | 
						c.JSON(http.StatusOK, response)
 | 
				
			||||||
@@ -96,7 +101,7 @@ func GenerateLinkHandler(c *gin.Context) {
 | 
				
			|||||||
func generateUniqueHash(length int) (string, error) {
 | 
					func generateUniqueHash(length int) (string, error) {
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		hash := common.RandomString(length)
 | 
							hash := common.RandomString(length)
 | 
				
			||||||
		exists, err := database.CheckShortLinkHashExists(hash)
 | 
							exists, err := DB.CheckShortLinkIDExists(hash)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return "", err
 | 
								return "", err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -109,114 +114,140 @@ func generateUniqueHash(length int) (string, error) {
 | 
				
			|||||||
func UpdateLinkHandler(c *gin.Context) {
 | 
					func UpdateLinkHandler(c *gin.Context) {
 | 
				
			||||||
	var params shortLinkUpdateRequest
 | 
						var params shortLinkUpdateRequest
 | 
				
			||||||
	if err := c.ShouldBindJSON(¶ms); err != nil {
 | 
						if err := c.ShouldBindJSON(¶ms); err != nil {
 | 
				
			||||||
		respondWithError(c, http.StatusBadRequest, "参数错误: "+err.Error())
 | 
							c.String(http.StatusBadRequest, "参数错误: "+err.Error())
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 先获取原有的短链接
 | 
						// 先获取原有的短链
 | 
				
			||||||
	existingLink, err := database.FindShortLinkByHash(params.Hash)
 | 
						existingLink, err := DB.FindShortLinkByID(params.ID)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		respondWithError(c, http.StatusNotFound, "未找到短链接")
 | 
							c.String(http.StatusUnauthorized, "短链不存在或密码错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 验证密码
 | 
						// 验证密码
 | 
				
			||||||
	if existingLink.Password != params.Password {
 | 
						if existingLink.Password != params.Password {
 | 
				
			||||||
		respondWithError(c, http.StatusUnauthorized, "密码错误")
 | 
							c.String(http.StatusUnauthorized, "短链不存在或密码错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 更新URL,但保持原密码不变
 | 
						jsonData, err := json.Marshal(params.Config)
 | 
				
			||||||
	shortLink := model.ShortLink{
 | 
						if err != nil {
 | 
				
			||||||
		Hash:     params.Hash,
 | 
							c.String(http.StatusBadRequest, "配置格式错误")
 | 
				
			||||||
		Url:      params.Url,
 | 
							return
 | 
				
			||||||
		Password: existingLink.Password, // 保持原密码不变
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if err := DB.UpdataShortLink(params.ID, "config", jsonData); err != nil {
 | 
				
			||||||
	if err := database.SaveShortLink(&shortLink); err != nil {
 | 
							c.String(http.StatusInternalServerError, "数据库错误")
 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
					 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c.String(http.StatusOK, "短链接更新成功")
 | 
						c.String(http.StatusOK, "短链更新成功")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GetRawConfHandler(c *gin.Context) {
 | 
					func GetRawConfHandler(c *gin.Context) {
 | 
				
			||||||
 | 
						id := c.Param("id")
 | 
				
			||||||
	hash := c.Param("hash")
 | 
					 | 
				
			||||||
	password := c.Query("password")
 | 
						password := c.Query("password")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if strings.TrimSpace(hash) == "" {
 | 
						if strings.TrimSpace(id) == "" {
 | 
				
			||||||
		c.String(http.StatusBadRequest, "参数错误")
 | 
							c.String(http.StatusBadRequest, "参数错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	shortLink, err := database.FindShortLinkByHash(hash)
 | 
						shortLink, err := DB.FindShortLinkByID(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
							c.String(http.StatusUnauthorized, "短链不存在或密码错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if shortLink.Password != "" && shortLink.Password != password {
 | 
						if shortLink.Password != "" && shortLink.Password != password {
 | 
				
			||||||
		c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
							c.String(http.StatusUnauthorized, "短链不存在或密码错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	shortLink.LastRequestTime = time.Now().Unix()
 | 
						err = DB.UpdataShortLink(shortLink.ID, "last_request_time", time.Now().Unix())
 | 
				
			||||||
	err = database.SaveShortLink(shortLink)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "数据库错误")
 | 
							c.String(http.StatusInternalServerError, "数据库错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	scheme := "http"
 | 
						template := ""
 | 
				
			||||||
	if c.Request.TLS != nil {
 | 
						switch shortLink.Config.ClashType {
 | 
				
			||||||
		scheme = "https"
 | 
						case model.Clash:
 | 
				
			||||||
 | 
							template = config.GlobalConfig.ClashTemplate
 | 
				
			||||||
 | 
						case model.ClashMeta:
 | 
				
			||||||
 | 
							template = config.GlobalConfig.MetaTemplate
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	host := c.Request.Host
 | 
						sub, err := common.BuildSub(shortLink.Config.ClashType, shortLink.Config, template, config.GlobalConfig.CacheExpire, config.GlobalConfig.RequestRetryTimes)
 | 
				
			||||||
	targetPath := strings.TrimPrefix(shortLink.Url, "/")
 | 
					 | 
				
			||||||
	requestURL := fmt.Sprintf("%s://%s/%s", scheme, host, targetPath)
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	client := &http.Client{
 | 
					 | 
				
			||||||
		Timeout: 30 * time.Second, // 30秒超时
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	response, err := client.Get(requestURL)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "请求错误: "+err.Error())
 | 
							c.String(http.StatusInternalServerError, err.Error())
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer response.Body.Close()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	all, err := io.ReadAll(response.Body)
 | 
						if len(shortLink.Config.Subs) == 1 {
 | 
				
			||||||
 | 
							userInfoHeader, err := common.FetchSubscriptionUserInfo(shortLink.Config.Subs[0], "clash", config.GlobalConfig.RequestRetryTimes)
 | 
				
			||||||
 | 
							if err == nil {
 | 
				
			||||||
 | 
								c.Header("subscription-userinfo", userInfoHeader)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if shortLink.Config.NodeListMode {
 | 
				
			||||||
 | 
							nodelist := M.NodeList{}
 | 
				
			||||||
 | 
							nodelist.Proxy = sub.Proxy
 | 
				
			||||||
 | 
							marshal, err := yaml.Marshal(nodelist)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
		respondWithError(c, http.StatusInternalServerError, "读取错误: "+err.Error())
 | 
								c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							c.String(http.StatusOK, string(marshal))
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						marshal, err := yaml.Marshal(sub)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							c.String(http.StatusInternalServerError, "YAML序列化失败: "+err.Error())
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c.String(http.StatusOK, string(all))
 | 
						c.String(http.StatusOK, string(marshal))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func GetRawConfUriHandler(c *gin.Context) {
 | 
					func GetRawConfUriHandler(c *gin.Context) {
 | 
				
			||||||
 | 
						id := c.Param("id")
 | 
				
			||||||
	hash := c.Query("hash")
 | 
					 | 
				
			||||||
	password := c.Query("password")
 | 
						password := c.Query("password")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if strings.TrimSpace(hash) == "" {
 | 
						if strings.TrimSpace(id) == "" {
 | 
				
			||||||
		c.String(http.StatusBadRequest, "参数错误")
 | 
							c.String(http.StatusBadRequest, "参数错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	shortLink, err := database.FindShortLinkByHash(hash)
 | 
						shortLink, err := DB.FindShortLinkByID(id)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
							c.String(http.StatusUnauthorized, "短链不存在或密码错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if shortLink.Password != "" && shortLink.Password != password {
 | 
						if shortLink.Password != "" && shortLink.Password != password {
 | 
				
			||||||
		c.String(http.StatusNotFound, "未找到短链接或密码错误")
 | 
							c.String(http.StatusUnauthorized, "短链不存在或密码错误")
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c.String(http.StatusOK, shortLink.Url)
 | 
						c.JSON(http.StatusOK, shortLink.Config)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func DeleteShortLinkHandler(c *gin.Context) {
 | 
				
			||||||
 | 
						id := c.Param("id")
 | 
				
			||||||
 | 
						password := c.Query("password")
 | 
				
			||||||
 | 
						shortLink, err := DB.FindShortLinkByID(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							c.String(http.StatusBadRequest, "短链不存在或密码错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if shortLink.Password != password {
 | 
				
			||||||
 | 
							c.String(http.StatusUnauthorized, "短链不存在或密码错误")
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						err = DB.DeleteShortLink(id)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							c.String(http.StatusInternalServerError, "删除失败", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,48 +2,31 @@ package server
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"embed"
 | 
						"embed"
 | 
				
			||||||
	"html/template"
 | 
					 | 
				
			||||||
	"log"
 | 
					 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/bestnite/sub2clash/config"
 | 
					 | 
				
			||||||
	"github.com/bestnite/sub2clash/constant"
 | 
					 | 
				
			||||||
	"github.com/bestnite/sub2clash/model"
 | 
					 | 
				
			||||||
	"github.com/bestnite/sub2clash/server/handler"
 | 
						"github.com/bestnite/sub2clash/server/handler"
 | 
				
			||||||
	"github.com/bestnite/sub2clash/server/middleware"
 | 
						"github.com/bestnite/sub2clash/server/middleware"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/gin-gonic/gin"
 | 
						"github.com/gin-gonic/gin"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//go:embed static
 | 
					//go:embed frontend/dist
 | 
				
			||||||
var staticFiles embed.FS
 | 
					var staticFiles embed.FS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func SetRoute(r *gin.Engine) {
 | 
					func SetRoute(r *gin.Engine) {
 | 
				
			||||||
	tpl, err := template.ParseFS(staticFiles, "static/*")
 | 
						r.GET("/convert/:config", middleware.ZapLogger(), handler.ConvertHandler())
 | 
				
			||||||
	if err != nil {
 | 
						r.GET("/s/:id", middleware.ZapLogger(), handler.GetRawConfHandler)
 | 
				
			||||||
		log.Fatalf("Error parsing templates: %v", err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	r.SetHTMLTemplate(tpl)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	r.GET(
 | 
					 | 
				
			||||||
		"/static/*filepath", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			c.FileFromFS("static/"+c.Param("filepath"), http.FS(staticFiles))
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	r.GET(
 | 
					 | 
				
			||||||
		"/", func(c *gin.Context) {
 | 
					 | 
				
			||||||
			version := constant.Version
 | 
					 | 
				
			||||||
			c.HTML(
 | 
					 | 
				
			||||||
				200, "index.html", gin.H{
 | 
					 | 
				
			||||||
					"Version": version,
 | 
					 | 
				
			||||||
				},
 | 
					 | 
				
			||||||
			)
 | 
					 | 
				
			||||||
		},
 | 
					 | 
				
			||||||
	)
 | 
					 | 
				
			||||||
	r.GET("/clash", middleware.ZapLogger(), handler.SubHandler(model.Clash, config.GlobalConfig.ClashTemplate))
 | 
					 | 
				
			||||||
	r.GET("/meta", middleware.ZapLogger(), handler.SubHandler(model.ClashMeta, config.GlobalConfig.MetaTemplate))
 | 
					 | 
				
			||||||
	r.GET("/s/:hash", middleware.ZapLogger(), handler.GetRawConfHandler)
 | 
					 | 
				
			||||||
	r.POST("/short", middleware.ZapLogger(), handler.GenerateLinkHandler)
 | 
						r.POST("/short", middleware.ZapLogger(), handler.GenerateLinkHandler)
 | 
				
			||||||
	r.PUT("/short", middleware.ZapLogger(), handler.UpdateLinkHandler)
 | 
						r.PUT("/short", middleware.ZapLogger(), handler.UpdateLinkHandler)
 | 
				
			||||||
	r.GET("/short", middleware.ZapLogger(), handler.GetRawConfUriHandler)
 | 
						r.GET("/short/:id", middleware.ZapLogger(), handler.GetRawConfUriHandler)
 | 
				
			||||||
 | 
						r.DELETE("/short/:id", middleware.ZapLogger(), handler.DeleteShortLinkHandler)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						r.GET("/", func(c *gin.Context) {
 | 
				
			||||||
 | 
							c.FileFromFS("frontend/dist/", http.FS(staticFiles))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						r.GET(
 | 
				
			||||||
 | 
							"/assets/*filepath", func(c *gin.Context) {
 | 
				
			||||||
 | 
								c.FileFromFS("frontend/dist/assets/"+c.Param("filepath"), http.FS(staticFiles))
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								server/static/axios.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								server/static/axios.min.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										7
									
								
								server/static/bootstrap.bundle.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								server/static/bootstrap.bundle.min.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										6
									
								
								server/static/bootstrap.min.css
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								server/static/bootstrap.min.css
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -1,218 +0,0 @@
 | 
				
			|||||||
<!DOCTYPE html>
 | 
					 | 
				
			||||||
<html lang="zh-CN" data-bs-theme="light">
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<head>
 | 
					 | 
				
			||||||
    <meta charset="UTF-8" />
 | 
					 | 
				
			||||||
    <meta content="width=device-width, initial-scale=1.0" name="viewport" />
 | 
					 | 
				
			||||||
    <title>sub2clash</title>
 | 
					 | 
				
			||||||
    <!-- Bootstrap CSS -->
 | 
					 | 
				
			||||||
    <link href="./static/bootstrap.min.css" rel="stylesheet" />
 | 
					 | 
				
			||||||
    <!-- Bootstrap JS -->
 | 
					 | 
				
			||||||
    <script src="./static/bootstrap.bundle.min.js"></script>
 | 
					 | 
				
			||||||
    <!-- Axios -->
 | 
					 | 
				
			||||||
    <script src="./static/axios.min.js"></script>
 | 
					 | 
				
			||||||
    <style>
 | 
					 | 
				
			||||||
        .container {
 | 
					 | 
				
			||||||
            max-width: 800px;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        .btn-xs {
 | 
					 | 
				
			||||||
            padding: 2px 2px;
 | 
					 | 
				
			||||||
            /* 调整内边距以减小按钮大小 */
 | 
					 | 
				
			||||||
            font-size: 10px;
 | 
					 | 
				
			||||||
            /* 设置字体大小 */
 | 
					 | 
				
			||||||
            line-height: 1.2;
 | 
					 | 
				
			||||||
            /* 调整行高 */
 | 
					 | 
				
			||||||
            border-radius: 3px;
 | 
					 | 
				
			||||||
            /* 可选的边框半径调整 */
 | 
					 | 
				
			||||||
            height: 25px;
 | 
					 | 
				
			||||||
            width: 25px;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        /* 主题切换按钮样式 */
 | 
					 | 
				
			||||||
        .theme-toggle {
 | 
					 | 
				
			||||||
            position: fixed;
 | 
					 | 
				
			||||||
            top: 20px;
 | 
					 | 
				
			||||||
            right: 20px;
 | 
					 | 
				
			||||||
            z-index: 1000;
 | 
					 | 
				
			||||||
            border: none;
 | 
					 | 
				
			||||||
            border-radius: 50%;
 | 
					 | 
				
			||||||
            width: 50px;
 | 
					 | 
				
			||||||
            height: 50px;
 | 
					 | 
				
			||||||
            font-size: 20px;
 | 
					 | 
				
			||||||
            display: flex;
 | 
					 | 
				
			||||||
            align-items: center;
 | 
					 | 
				
			||||||
            justify-content: center;
 | 
					 | 
				
			||||||
            transition: all 0.3s ease;
 | 
					 | 
				
			||||||
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        .theme-toggle:hover {
 | 
					 | 
				
			||||||
            transform: scale(1.1);
 | 
					 | 
				
			||||||
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    </style>
 | 
					 | 
				
			||||||
</head>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<body>
 | 
					 | 
				
			||||||
    <!-- 主题切换按钮 -->
 | 
					 | 
				
			||||||
    <button class="theme-toggle btn btn-outline-secondary" onclick="toggleTheme()" title="切换深色/浅色模式">
 | 
					 | 
				
			||||||
        <span id="theme-icon">🌙</span>
 | 
					 | 
				
			||||||
    </button>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    <div class="container mt-5">
 | 
					 | 
				
			||||||
        <div class="mb-4">
 | 
					 | 
				
			||||||
            <h2>sub2clash</h2>
 | 
					 | 
				
			||||||
            <span class="text-muted fst-italic">通用订阅链接转 Clash(Meta) 配置工具
 | 
					 | 
				
			||||||
                <a href="https://github.com/bestnite/sub2clash#clash-meta" target="_blank">使用文档</a></span><br /><span
 | 
					 | 
				
			||||||
                class="text-muted fst-italic">注意:本程序非纯前端程序,输入的订阅将被后端缓存,请确保您信任当前站点</span>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        <!-- Input URL -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-5">
 | 
					 | 
				
			||||||
            <label for="apiLink">解析链接:</label>
 | 
					 | 
				
			||||||
            <div class="input-group mb-2">
 | 
					 | 
				
			||||||
                <input class="form-control" id="urlInput" type="text" placeholder="通过生成的链接重新填写下方设置" />
 | 
					 | 
				
			||||||
                <button class="btn btn-primary" onclick="parseInputURL()" type="button">
 | 
					 | 
				
			||||||
                    解析
 | 
					 | 
				
			||||||
                </button>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- API Endpoint -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3">
 | 
					 | 
				
			||||||
            <label for="endpoint">客户端类型:</label>
 | 
					 | 
				
			||||||
            <select class="form-control" id="endpoint" name="endpoint">
 | 
					 | 
				
			||||||
                <option value="clash">Clash</option>
 | 
					 | 
				
			||||||
                <option value="meta" selected>Clash.Meta</option>
 | 
					 | 
				
			||||||
            </select>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Template -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3">
 | 
					 | 
				
			||||||
            <label for="template">模板链接或名称:</label>
 | 
					 | 
				
			||||||
            <input class="form-control" id="template" name="template" placeholder="输入外部模板链接或内部模板名称(可选)" type="text" />
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Subscription Link -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3">
 | 
					 | 
				
			||||||
            <label for="sub">订阅链接:</label>
 | 
					 | 
				
			||||||
            <textarea class="form-control" id="sub" name="sub" placeholder="每行输入一个订阅链接" rows="5"></textarea>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Proxy Link -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3">
 | 
					 | 
				
			||||||
            <label for="proxy">节点分享链接:</label>
 | 
					 | 
				
			||||||
            <textarea class="form-control" id="proxy" name="proxy" placeholder="每行输入一个节点分享链接" rows="5"></textarea>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- User Agent -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3">
 | 
					 | 
				
			||||||
            <label for="user-agent">UA 标识:</label>
 | 
					 | 
				
			||||||
            <textarea class="form-control" id="user-agent" name="user-agent"
 | 
					 | 
				
			||||||
                placeholder="用于获取订阅的 http 请求中的 User-Agent 标识(可选)" rows="3"></textarea>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Refresh -->
 | 
					 | 
				
			||||||
        <div class="form-check mb-3">
 | 
					 | 
				
			||||||
            <input class="form-check-input" id="refresh" name="refresh" type="checkbox" />
 | 
					 | 
				
			||||||
            <label class="form-check-label" for="refresh">强制重新获取订阅</label>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Node List -->
 | 
					 | 
				
			||||||
        <div class="form-check mb-3">
 | 
					 | 
				
			||||||
            <input class="form-check-input" id="nodeList" name="nodeList" type="checkbox" />
 | 
					 | 
				
			||||||
            <label class="form-check-label" for="nodeList">输出为 Node List</label>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Auto Test -->
 | 
					 | 
				
			||||||
        <div class="form-check mb-3">
 | 
					 | 
				
			||||||
            <input class="form-check-input" id="autoTest" name="autoTest" type="checkbox" />
 | 
					 | 
				
			||||||
            <label class="form-check-label" for="autoTest">国家策略组自动测速</label>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Lazy -->
 | 
					 | 
				
			||||||
        <div class="form-check mb-3">
 | 
					 | 
				
			||||||
            <input class="form-check-input" id="lazy" name="lazy" type="checkbox" />
 | 
					 | 
				
			||||||
            <label class="form-check-label" for="lazy">自动测速启用 lazy 模式</label>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- IgnoreCountryGroup -->
 | 
					 | 
				
			||||||
        <div class="form-check mb-3">
 | 
					 | 
				
			||||||
            <input class="form-check-input" id="igcg" name="igcg" type="checkbox" />
 | 
					 | 
				
			||||||
            <label class="form-check-label" for="igcg">不输出国家策略组</label>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Use UDP -->
 | 
					 | 
				
			||||||
        <div class="form-check mb-3">
 | 
					 | 
				
			||||||
            <input class="form-check-input" id="useUDP" name="useUDP" type="checkbox" />
 | 
					 | 
				
			||||||
            <label class="form-check-label" for="useUDP">使用 UDP</label>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Rule Provider -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3" id="ruleProviderGroup">
 | 
					 | 
				
			||||||
            <label>Rule Provider:</label>
 | 
					 | 
				
			||||||
            <button class="btn btn-primary mb-1 btn-xs" onclick="addRuleProvider()" type="button">
 | 
					 | 
				
			||||||
                +
 | 
					 | 
				
			||||||
            </button>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Rule -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3" id="ruleGroup">
 | 
					 | 
				
			||||||
            <label>规则:</label>
 | 
					 | 
				
			||||||
            <button class="btn btn-primary mb-1 btn-xs" onclick="addRule()" type="button">
 | 
					 | 
				
			||||||
                +
 | 
					 | 
				
			||||||
            </button>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Sort -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3">
 | 
					 | 
				
			||||||
            <label for="sort">国家策略组排序规则:</label>
 | 
					 | 
				
			||||||
            <select class="form-control" id="sort" name="sort">
 | 
					 | 
				
			||||||
                <option value="nameasc">名称(升序)</option>
 | 
					 | 
				
			||||||
                <option value="namedesc">名称(降序)</option>
 | 
					 | 
				
			||||||
                <option value="sizeasc">节点数量(升序)</option>
 | 
					 | 
				
			||||||
                <option value="sizedesc">节点数量(降序)</option>
 | 
					 | 
				
			||||||
            </select>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Remove -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3">
 | 
					 | 
				
			||||||
            <label for="remove">排除节点:</label>
 | 
					 | 
				
			||||||
            <input class="form-control" type="text" name="remove" id="remove" placeholder="正则表达式" />
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
        <!-- Rename  -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-3" id="replaceGroup">
 | 
					 | 
				
			||||||
            <label>节点名称替换:</label>
 | 
					 | 
				
			||||||
            <button class="btn btn-primary mb-1 btn-xs" onclick="addReplace()" type="button">
 | 
					 | 
				
			||||||
                +
 | 
					 | 
				
			||||||
            </button>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        <!-- Display the API Link -->
 | 
					 | 
				
			||||||
        <div class="form-group mb-5">
 | 
					 | 
				
			||||||
            <label for="apiLink">配置链接:</label>
 | 
					 | 
				
			||||||
            <div class="input-group mb-2">
 | 
					 | 
				
			||||||
                <input class="form-control" id="apiLink" type="text" placeholder="链接" readonly
 | 
					 | 
				
			||||||
                    style="cursor: not-allowed;" />
 | 
					 | 
				
			||||||
                <button class="btn btn-primary" onclick="copyToClipboard('apiLink',this)" type="button">
 | 
					 | 
				
			||||||
                    复制链接
 | 
					 | 
				
			||||||
                </button>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div class="input-group mb-2">
 | 
					 | 
				
			||||||
                <input class="form-control" id="customId" type="text" placeholder="短链ID(可选)" />
 | 
					 | 
				
			||||||
                <input class="form-control" id="password" type="text" placeholder="密码(可选)" />
 | 
					 | 
				
			||||||
                <button class="btn btn-primary" onclick="generateShortLink()" type="button">
 | 
					 | 
				
			||||||
                    生成短链
 | 
					 | 
				
			||||||
                </button>
 | 
					 | 
				
			||||||
                <button class="btn btn-primary" onclick="copyToClipboard('apiShortLink',this)" type="button">
 | 
					 | 
				
			||||||
                    复制短链
 | 
					 | 
				
			||||||
                </button>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
            <div class="input-group">
 | 
					 | 
				
			||||||
                <input class="form-control" id="apiShortLink" type="text" placeholder="短链接" readonly
 | 
					 | 
				
			||||||
                    style="cursor: not-allowed;" />
 | 
					 | 
				
			||||||
                <button class="btn btn-primary" onclick="updateShortLink()" type="button">
 | 
					 | 
				
			||||||
                    更新短链
 | 
					 | 
				
			||||||
                </button>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        <!-- footer-->
 | 
					 | 
				
			||||||
        <footer>
 | 
					 | 
				
			||||||
            <p class="text-center">
 | 
					 | 
				
			||||||
                Powered by
 | 
					 | 
				
			||||||
                <a class="link-primary" href="https://github.com/bestnite/sub2clash">sub2clash</a>
 | 
					 | 
				
			||||||
            </p>
 | 
					 | 
				
			||||||
            <p class="text-center">Version {{.Version}}</p>
 | 
					 | 
				
			||||||
        </footer>
 | 
					 | 
				
			||||||
    </div>
 | 
					 | 
				
			||||||
</body>
 | 
					 | 
				
			||||||
<script src="./static/index.js"></script>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
</html>
 | 
					 | 
				
			||||||
@@ -1,638 +0,0 @@
 | 
				
			|||||||
function setInputReadOnly(input, readonly) {
 | 
					 | 
				
			||||||
  if (readonly) {
 | 
					 | 
				
			||||||
    input.readOnly = true;
 | 
					 | 
				
			||||||
    input.style.cursor = 'not-allowed';
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    input.readOnly = false;
 | 
					 | 
				
			||||||
    input.style.cursor = 'auto';
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function clearExistingValues() {
 | 
					 | 
				
			||||||
  // 清除简单输入框和复选框的值
 | 
					 | 
				
			||||||
  document.getElementById("endpoint").value = "clash";
 | 
					 | 
				
			||||||
  document.getElementById("sub").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("proxy").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("refresh").checked = false;
 | 
					 | 
				
			||||||
  document.getElementById("autoTest").checked = false;
 | 
					 | 
				
			||||||
  document.getElementById("lazy").checked = false;
 | 
					 | 
				
			||||||
  document.getElementById("igcg").checked = false;
 | 
					 | 
				
			||||||
  document.getElementById("useUDP").checked = false;
 | 
					 | 
				
			||||||
  document.getElementById("template").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("sort").value = "nameasc";
 | 
					 | 
				
			||||||
  document.getElementById("remove").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("apiLink").value = "";
 | 
					 | 
				
			||||||
  document.getElementById("apiShortLink").value = "";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 恢复短链ID和密码输入框状态
 | 
					 | 
				
			||||||
  const customIdInput = document.getElementById("customId");
 | 
					 | 
				
			||||||
  const passwordInput = document.getElementById("password");
 | 
					 | 
				
			||||||
  const generateButton = document.querySelector('button[onclick="generateShortLink()"]');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  customIdInput.value = "";
 | 
					 | 
				
			||||||
  setInputReadOnly(customIdInput, false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  passwordInput.value = "";
 | 
					 | 
				
			||||||
  setInputReadOnly(passwordInput, false);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 恢复生成短链按钮状态
 | 
					 | 
				
			||||||
  generateButton.disabled = false;
 | 
					 | 
				
			||||||
  generateButton.classList.remove('btn-secondary');
 | 
					 | 
				
			||||||
  generateButton.classList.add('btn-primary');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  document.getElementById("nodeList").checked = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 清除由 createRuleProvider, createReplace, 和 createRule 创建的所有额外输入组
 | 
					 | 
				
			||||||
  clearInputGroup("ruleProviderGroup");
 | 
					 | 
				
			||||||
  clearInputGroup("replaceGroup");
 | 
					 | 
				
			||||||
  clearInputGroup("ruleGroup");
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function generateURI() {
 | 
					 | 
				
			||||||
  const queryParams = [];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取 API Endpoint
 | 
					 | 
				
			||||||
  const endpoint = document.getElementById("endpoint").value;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取并组合订阅链接
 | 
					 | 
				
			||||||
  let subLines = document
 | 
					 | 
				
			||||||
    .getElementById("sub")
 | 
					 | 
				
			||||||
    .value.split("\n")
 | 
					 | 
				
			||||||
    .filter((line) => line.trim() !== "");
 | 
					 | 
				
			||||||
  let noSub = false;
 | 
					 | 
				
			||||||
  // 去除 subLines 中空元素
 | 
					 | 
				
			||||||
  subLines = subLines.map((item) => {
 | 
					 | 
				
			||||||
    if (item !== "") {
 | 
					 | 
				
			||||||
      return item;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  if (subLines.length > 0) {
 | 
					 | 
				
			||||||
    queryParams.push(`sub=${encodeURIComponent(subLines.join(","))}`);
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    noSub = true;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取并组合节点分享链接
 | 
					 | 
				
			||||||
  let proxyLines = document
 | 
					 | 
				
			||||||
    .getElementById("proxy")
 | 
					 | 
				
			||||||
    .value.split("\n")
 | 
					 | 
				
			||||||
    .filter((line) => line.trim() !== "");
 | 
					 | 
				
			||||||
  let noProxy = false;
 | 
					 | 
				
			||||||
  // 去除 proxyLines 中空元素
 | 
					 | 
				
			||||||
  proxyLines = proxyLines.map((item) => {
 | 
					 | 
				
			||||||
    if (item !== "") {
 | 
					 | 
				
			||||||
      return item;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  if (proxyLines.length > 0) {
 | 
					 | 
				
			||||||
    queryParams.push(`proxy=${encodeURIComponent(proxyLines.join(","))}`);
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    noProxy = true;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if (noSub && noProxy) {
 | 
					 | 
				
			||||||
    // alert("订阅链接和节点分享链接不能同时为空!");
 | 
					 | 
				
			||||||
    return "";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取订阅user-agent标识
 | 
					 | 
				
			||||||
  const userAgent = document.getElementById("user-agent").value;
 | 
					 | 
				
			||||||
  queryParams.push(`userAgent=${encodeURIComponent(userAgent)}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取复选框的值
 | 
					 | 
				
			||||||
  const refresh = document.getElementById("refresh").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`refresh=${refresh ? "true" : "false"}`);
 | 
					 | 
				
			||||||
  const autoTest = document.getElementById("autoTest").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`autoTest=${autoTest ? "true" : "false"}`);
 | 
					 | 
				
			||||||
  const lazy = document.getElementById("lazy").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`lazy=${lazy ? "true" : "false"}`);
 | 
					 | 
				
			||||||
  const nodeList = document.getElementById("nodeList").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`nodeList=${nodeList ? "true" : "false"}`);
 | 
					 | 
				
			||||||
  const igcg = document.getElementById("igcg").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`ignoreCountryGroup=${igcg ? "true" : "false"}`);
 | 
					 | 
				
			||||||
  const useUDP = document.getElementById("useUDP").checked;
 | 
					 | 
				
			||||||
  queryParams.push(`useUDP=${useUDP ? "true" : "false"}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取模板链接或名称(如果存在)
 | 
					 | 
				
			||||||
  const template = document.getElementById("template").value;
 | 
					 | 
				
			||||||
  if (template.trim() !== "") {
 | 
					 | 
				
			||||||
    queryParams.push(`template=${encodeURIComponent(template)}`);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取Rule Provider和规则
 | 
					 | 
				
			||||||
  const ruleProviders = document.getElementsByName("ruleProvider");
 | 
					 | 
				
			||||||
  const rules = document.getElementsByName("rule");
 | 
					 | 
				
			||||||
  let providers = [];
 | 
					 | 
				
			||||||
  for (let i = 0; i < ruleProviders.length / 5; i++) {
 | 
					 | 
				
			||||||
    let baseIndex = i * 5;
 | 
					 | 
				
			||||||
    let behavior = ruleProviders[baseIndex].value;
 | 
					 | 
				
			||||||
    let url = ruleProviders[baseIndex + 1].value;
 | 
					 | 
				
			||||||
    let group = ruleProviders[baseIndex + 2].value;
 | 
					 | 
				
			||||||
    let prepend = ruleProviders[baseIndex + 3].value;
 | 
					 | 
				
			||||||
    let name = ruleProviders[baseIndex + 4].value;
 | 
					 | 
				
			||||||
    // 是否存在空值
 | 
					 | 
				
			||||||
    if (
 | 
					 | 
				
			||||||
      behavior.trim() === "" ||
 | 
					 | 
				
			||||||
      url.trim() === "" ||
 | 
					 | 
				
			||||||
      group.trim() === "" ||
 | 
					 | 
				
			||||||
      prepend.trim() === "" ||
 | 
					 | 
				
			||||||
      name.trim() === ""
 | 
					 | 
				
			||||||
    ) {
 | 
					 | 
				
			||||||
      // alert("Rule Provider 中存在空值,请检查后重试!");
 | 
					 | 
				
			||||||
      return "";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    providers.push(`[${behavior},${url},${group},${prepend},${name}]`);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  queryParams.push(`ruleProvider=${encodeURIComponent(providers.join(","))}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  let ruleList = [];
 | 
					 | 
				
			||||||
  for (let i = 0; i < rules.length / 2; i++) {
 | 
					 | 
				
			||||||
    if (rules[i * 2].value.trim() !== "") {
 | 
					 | 
				
			||||||
      let rule = rules[i * 2].value;
 | 
					 | 
				
			||||||
      let prepend = rules[i * 2 + 1].value;
 | 
					 | 
				
			||||||
      // 是否存在空值
 | 
					 | 
				
			||||||
      if (rule.trim() === "" || prepend.trim() === "") {
 | 
					 | 
				
			||||||
        // alert("Rule 中存在空值,请检查后重试!");
 | 
					 | 
				
			||||||
        return "";
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      ruleList.push(`[${rule},${prepend}]`);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  queryParams.push(`rule=${encodeURIComponent(ruleList.join(","))}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取排序策略
 | 
					 | 
				
			||||||
  const sort = document.getElementById("sort").value;
 | 
					 | 
				
			||||||
  queryParams.push(`sort=${sort}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取删除节点的正则表达式
 | 
					 | 
				
			||||||
  const remove = document.getElementById("remove").value;
 | 
					 | 
				
			||||||
  if (remove.trim() !== "") {
 | 
					 | 
				
			||||||
    queryParams.push(`remove=${encodeURIComponent(remove)}`);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 获取替换节点名称的正则表达式
 | 
					 | 
				
			||||||
  let replaceList = [];
 | 
					 | 
				
			||||||
  const replaces = document.getElementsByName("replace");
 | 
					 | 
				
			||||||
  for (let i = 0; i < replaces.length / 2; i++) {
 | 
					 | 
				
			||||||
    let replaceStr = `<${replaces[i * 2].value}>`;
 | 
					 | 
				
			||||||
    let replaceTo = `<${replaces[i * 2 + 1].value}>`;
 | 
					 | 
				
			||||||
    if (replaceStr.trim() === "") {
 | 
					 | 
				
			||||||
      // alert("重命名设置中存在空值,请检查后重试!");
 | 
					 | 
				
			||||||
      return "";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    replaceList.push(`[${replaceStr},${replaceTo}]`);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  queryParams.push(`replace=${encodeURIComponent(replaceList.join(","))}`);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return `${endpoint}?${queryParams.join("&")}`;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 将输入框中的 URL 解析为参数
 | 
					 | 
				
			||||||
async function parseInputURL() {
 | 
					 | 
				
			||||||
  // 获取输入框中的 URL
 | 
					 | 
				
			||||||
  const inputURL = document.getElementById("urlInput").value;
 | 
					 | 
				
			||||||
  // 清除现有的输入框值
 | 
					 | 
				
			||||||
  clearExistingValues();
 | 
					 | 
				
			||||||
  if (!inputURL) {
 | 
					 | 
				
			||||||
    alert("请输入有效的链接!");
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  let url;
 | 
					 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    url = new URL(inputURL);
 | 
					 | 
				
			||||||
  } catch (_) {
 | 
					 | 
				
			||||||
    alert("无效的链接!");
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if (url.pathname.includes("/s/")) {
 | 
					 | 
				
			||||||
    let hash = url.pathname.substring(url.pathname.lastIndexOf("/s/") + 3);
 | 
					 | 
				
			||||||
    let q = new URLSearchParams();
 | 
					 | 
				
			||||||
    let password = url.searchParams.get("password");
 | 
					 | 
				
			||||||
    if (password === null) {
 | 
					 | 
				
			||||||
      alert("仅可解析加密短链");
 | 
					 | 
				
			||||||
      return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    q.append("hash", hash);
 | 
					 | 
				
			||||||
    q.append("password", password);
 | 
					 | 
				
			||||||
    try {
 | 
					 | 
				
			||||||
      const response = await axios.get("./short?" + q.toString());
 | 
					 | 
				
			||||||
      url = new URL(window.location.href + response.data);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // 回显配置链接
 | 
					 | 
				
			||||||
      const apiLinkInput = document.querySelector("#apiLink");
 | 
					 | 
				
			||||||
      apiLinkInput.value = `${window.location.origin}${window.location.pathname}${response.data}`;
 | 
					 | 
				
			||||||
      setInputReadOnly(apiLinkInput, true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // 回显短链相关信息
 | 
					 | 
				
			||||||
      const apiShortLinkInput = document.querySelector("#apiShortLink");
 | 
					 | 
				
			||||||
      apiShortLinkInput.value = inputURL;
 | 
					 | 
				
			||||||
      setInputReadOnly(apiShortLinkInput, true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // 设置短链ID和密码,并设置为只读
 | 
					 | 
				
			||||||
      const customIdInput = document.querySelector("#customId");
 | 
					 | 
				
			||||||
      const passwordInput = document.querySelector("#password");
 | 
					 | 
				
			||||||
      const generateButton = document.querySelector('button[onclick="generateShortLink()"]');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      customIdInput.value = hash;
 | 
					 | 
				
			||||||
      setInputReadOnly(customIdInput, true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      passwordInput.value = password;
 | 
					 | 
				
			||||||
      setInputReadOnly(passwordInput, true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // 禁用生成短链按钮
 | 
					 | 
				
			||||||
      generateButton.disabled = true;
 | 
					 | 
				
			||||||
      generateButton.classList.add('btn-secondary');
 | 
					 | 
				
			||||||
      generateButton.classList.remove('btn-primary');
 | 
					 | 
				
			||||||
    } catch (error) {
 | 
					 | 
				
			||||||
      console.log(error);
 | 
					 | 
				
			||||||
      alert("获取短链失败,请检查密码!");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  let params = new URLSearchParams(url.search);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 分配值到对应的输入框
 | 
					 | 
				
			||||||
  const pathSections = url.pathname.split("/");
 | 
					 | 
				
			||||||
  const lastSection = pathSections[pathSections.length - 1];
 | 
					 | 
				
			||||||
  const clientTypeSelect = document.getElementById("endpoint");
 | 
					 | 
				
			||||||
  switch (lastSection.toLowerCase()) {
 | 
					 | 
				
			||||||
    case "meta":
 | 
					 | 
				
			||||||
      clientTypeSelect.value = "meta";
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
    case "clash":
 | 
					 | 
				
			||||||
    default:
 | 
					 | 
				
			||||||
      clientTypeSelect.value = "clash";
 | 
					 | 
				
			||||||
      break;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("sub")) {
 | 
					 | 
				
			||||||
    document.getElementById("sub").value = decodeURIComponent(params.get("sub"))
 | 
					 | 
				
			||||||
      .split(",")
 | 
					 | 
				
			||||||
      .join("\n");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("proxy")) {
 | 
					 | 
				
			||||||
    document.getElementById("proxy").value = decodeURIComponent(
 | 
					 | 
				
			||||||
      params.get("proxy")
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
      .split(",")
 | 
					 | 
				
			||||||
      .join("\n");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("refresh")) {
 | 
					 | 
				
			||||||
    document.getElementById("refresh").checked =
 | 
					 | 
				
			||||||
      params.get("refresh") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("autoTest")) {
 | 
					 | 
				
			||||||
    document.getElementById("autoTest").checked =
 | 
					 | 
				
			||||||
      params.get("autoTest") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("lazy")) {
 | 
					 | 
				
			||||||
    document.getElementById("lazy").checked = params.get("lazy") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("template")) {
 | 
					 | 
				
			||||||
    document.getElementById("template").value = decodeURIComponent(
 | 
					 | 
				
			||||||
      params.get("template")
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("sort")) {
 | 
					 | 
				
			||||||
    document.getElementById("sort").value = params.get("sort");
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("remove")) {
 | 
					 | 
				
			||||||
    document.getElementById("remove").value = decodeURIComponent(
 | 
					 | 
				
			||||||
      params.get("remove")
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("userAgent")) {
 | 
					 | 
				
			||||||
    document.getElementById("user-agent").value = decodeURIComponent(
 | 
					 | 
				
			||||||
      params.get("userAgent")
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("ignoreCountryGroup")) {
 | 
					 | 
				
			||||||
    document.getElementById("igcg").checked =
 | 
					 | 
				
			||||||
      params.get("ignoreCountryGroup") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("replace")) {
 | 
					 | 
				
			||||||
    parseAndFillReplaceParams(decodeURIComponent(params.get("replace")));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("ruleProvider")) {
 | 
					 | 
				
			||||||
    parseAndFillRuleProviderParams(
 | 
					 | 
				
			||||||
      decodeURIComponent(params.get("ruleProvider"))
 | 
					 | 
				
			||||||
    );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("rule")) {
 | 
					 | 
				
			||||||
    parseAndFillRuleParams(decodeURIComponent(params.get("rule")));
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("nodeList")) {
 | 
					 | 
				
			||||||
    document.getElementById("nodeList").checked =
 | 
					 | 
				
			||||||
      params.get("nodeList") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (params.has("useUDP")) {
 | 
					 | 
				
			||||||
    document.getElementById("useUDP").checked =
 | 
					 | 
				
			||||||
      params.get("useUDP") === "true";
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function clearInputGroup(groupId) {
 | 
					 | 
				
			||||||
  // 清空第二个之后的child
 | 
					 | 
				
			||||||
  const group = document.getElementById(groupId);
 | 
					 | 
				
			||||||
  while (group.children.length > 2) {
 | 
					 | 
				
			||||||
    group.removeChild(group.lastChild);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function parseAndFillReplaceParams(replaceParams) {
 | 
					 | 
				
			||||||
  const replaceGroup = document.getElementById("replaceGroup");
 | 
					 | 
				
			||||||
  let matches;
 | 
					 | 
				
			||||||
  const regex = /\[(<.*?>),(<.*?>)\]/g;
 | 
					 | 
				
			||||||
  const str = decodeURIComponent(replaceParams);
 | 
					 | 
				
			||||||
  while ((matches = regex.exec(str)) !== null) {
 | 
					 | 
				
			||||||
    const div = createReplace();
 | 
					 | 
				
			||||||
    const original = matches[1].slice(1, -1); // Remove < and >
 | 
					 | 
				
			||||||
    const replacement = matches[2].slice(1, -1); // Remove < and >
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    div.children[0].value = original;
 | 
					 | 
				
			||||||
    div.children[1].value = replacement;
 | 
					 | 
				
			||||||
    replaceGroup.appendChild(div);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function parseAndFillRuleProviderParams(ruleProviderParams) {
 | 
					 | 
				
			||||||
  const ruleProviderGroup = document.getElementById("ruleProviderGroup");
 | 
					 | 
				
			||||||
  let matches;
 | 
					 | 
				
			||||||
  const regex = /\[(.*?),(.*?),(.*?),(.*?),(.*?)\]/g;
 | 
					 | 
				
			||||||
  const str = decodeURIComponent(ruleProviderParams);
 | 
					 | 
				
			||||||
  while ((matches = regex.exec(str)) !== null) {
 | 
					 | 
				
			||||||
    const div = createRuleProvider();
 | 
					 | 
				
			||||||
    div.children[0].value = matches[1];
 | 
					 | 
				
			||||||
    div.children[1].value = matches[2];
 | 
					 | 
				
			||||||
    div.children[2].value = matches[3];
 | 
					 | 
				
			||||||
    div.children[3].value = matches[4];
 | 
					 | 
				
			||||||
    div.children[4].value = matches[5];
 | 
					 | 
				
			||||||
    ruleProviderGroup.appendChild(div);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function parseAndFillRuleParams(ruleParams) {
 | 
					 | 
				
			||||||
  const ruleGroup = document.getElementById("ruleGroup");
 | 
					 | 
				
			||||||
  let matches;
 | 
					 | 
				
			||||||
  const regex = /\[(.*?),(.*?)\]/g;
 | 
					 | 
				
			||||||
  const str = decodeURIComponent(ruleParams);
 | 
					 | 
				
			||||||
  while ((matches = regex.exec(str)) !== null) {
 | 
					 | 
				
			||||||
    const div = createRule();
 | 
					 | 
				
			||||||
    div.children[0].value = matches[1];
 | 
					 | 
				
			||||||
    div.children[1].value = matches[2];
 | 
					 | 
				
			||||||
    ruleGroup.appendChild(div);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
async function copyToClipboard(elem, e) {
 | 
					 | 
				
			||||||
  const apiLinkInput = document.querySelector(`#${elem}`).value;
 | 
					 | 
				
			||||||
  try {
 | 
					 | 
				
			||||||
    await navigator.clipboard.writeText(apiLinkInput);
 | 
					 | 
				
			||||||
    let text = e.textContent;
 | 
					 | 
				
			||||||
    e.addEventListener("mouseout", function () {
 | 
					 | 
				
			||||||
      e.textContent = text;
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
    e.textContent = "复制成功";
 | 
					 | 
				
			||||||
  } catch (err) {
 | 
					 | 
				
			||||||
    console.error("复制到剪贴板失败:", err);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function createRuleProvider() {
 | 
					 | 
				
			||||||
  const div = document.createElement("div");
 | 
					 | 
				
			||||||
  div.classList.add("input-group", "mb-2");
 | 
					 | 
				
			||||||
  div.innerHTML = `
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Behavior">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Url">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Group">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Prepend">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="ruleProvider" placeholder="Name">
 | 
					 | 
				
			||||||
            <button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
 | 
					 | 
				
			||||||
        `;
 | 
					 | 
				
			||||||
  return div;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function createReplace() {
 | 
					 | 
				
			||||||
  const div = document.createElement("div");
 | 
					 | 
				
			||||||
  div.classList.add("input-group", "mb-2");
 | 
					 | 
				
			||||||
  div.innerHTML = `
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="replace" placeholder="原字符串(正则表达式)">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="replace" placeholder="替换为(可为空)">
 | 
					 | 
				
			||||||
            <button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
 | 
					 | 
				
			||||||
        `;
 | 
					 | 
				
			||||||
  return div;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function createRule() {
 | 
					 | 
				
			||||||
  const div = document.createElement("div");
 | 
					 | 
				
			||||||
  div.classList.add("input-group", "mb-2");
 | 
					 | 
				
			||||||
  div.innerHTML = `
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="rule" placeholder="Rule">
 | 
					 | 
				
			||||||
            <input type="text" class="form-control" name="rule" placeholder="Prepend">
 | 
					 | 
				
			||||||
            <button type="button" class="btn btn-danger" onclick="removeElement(this)">删除</button>
 | 
					 | 
				
			||||||
        `;
 | 
					 | 
				
			||||||
  return div;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function listenInput() {
 | 
					 | 
				
			||||||
  let selectElements = document.querySelectorAll("select");
 | 
					 | 
				
			||||||
  let inputElements = document.querySelectorAll("input");
 | 
					 | 
				
			||||||
  let textAreaElements = document.querySelectorAll("textarea");
 | 
					 | 
				
			||||||
  inputElements.forEach(function (element) {
 | 
					 | 
				
			||||||
    element.addEventListener("input", function () {
 | 
					 | 
				
			||||||
      generateURL();
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  textAreaElements.forEach(function (element) {
 | 
					 | 
				
			||||||
    element.addEventListener("input", function () {
 | 
					 | 
				
			||||||
      generateURL();
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
  selectElements.forEach(function (element) {
 | 
					 | 
				
			||||||
    element.addEventListener("change", function () {
 | 
					 | 
				
			||||||
      generateURL();
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function addRuleProvider() {
 | 
					 | 
				
			||||||
  const div = createRuleProvider();
 | 
					 | 
				
			||||||
  document.getElementById("ruleProviderGroup").appendChild(div);
 | 
					 | 
				
			||||||
  listenInput();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function addRule() {
 | 
					 | 
				
			||||||
  const div = createRule();
 | 
					 | 
				
			||||||
  document.getElementById("ruleGroup").appendChild(div);
 | 
					 | 
				
			||||||
  listenInput();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function addReplace() {
 | 
					 | 
				
			||||||
  const div = createReplace();
 | 
					 | 
				
			||||||
  document.getElementById("replaceGroup").appendChild(div);
 | 
					 | 
				
			||||||
  listenInput();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function removeElement(button) {
 | 
					 | 
				
			||||||
  button.parentElement.remove();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function generateURL() {
 | 
					 | 
				
			||||||
  const apiLink = document.getElementById("apiLink");
 | 
					 | 
				
			||||||
  let uri = generateURI();
 | 
					 | 
				
			||||||
  if (uri === "") {
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  apiLink.value = `${window.location.origin}${window.location.pathname}${uri}`;
 | 
					 | 
				
			||||||
  setInputReadOnly(apiLink, true);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function generateShortLink() {
 | 
					 | 
				
			||||||
  const apiShortLink = document.getElementById("apiShortLink");
 | 
					 | 
				
			||||||
  const password = document.getElementById("password");
 | 
					 | 
				
			||||||
  const customId = document.getElementById("customId");
 | 
					 | 
				
			||||||
  let uri = generateURI();
 | 
					 | 
				
			||||||
  if (uri === "") {
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  axios
 | 
					 | 
				
			||||||
    .post(
 | 
					 | 
				
			||||||
      "./short",
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        url: uri,
 | 
					 | 
				
			||||||
        password: password.value.trim(),
 | 
					 | 
				
			||||||
        customId: customId.value.trim()
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        headers: {
 | 
					 | 
				
			||||||
          "Content-Type": "application/json",
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    .then((response) => {
 | 
					 | 
				
			||||||
      // 设置返回的短链ID和密码
 | 
					 | 
				
			||||||
      customId.value = response.data.hash;
 | 
					 | 
				
			||||||
      password.value = response.data.password;
 | 
					 | 
				
			||||||
      // 生成完整的短链接
 | 
					 | 
				
			||||||
      const shortLink = `${window.location.origin}${window.location.pathname}s/${response.data.hash}?password=${response.data.password}`;
 | 
					 | 
				
			||||||
      apiShortLink.value = shortLink;
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
    .catch((error) => {
 | 
					 | 
				
			||||||
      console.log(error);
 | 
					 | 
				
			||||||
      if (error.response && error.response.data) {
 | 
					 | 
				
			||||||
        alert(error.response.data);
 | 
					 | 
				
			||||||
      } else {
 | 
					 | 
				
			||||||
        alert("生成短链失败,请重试!");
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function updateShortLink() {
 | 
					 | 
				
			||||||
  const password = document.getElementById("password");
 | 
					 | 
				
			||||||
  const apiShortLink = document.getElementById("apiShortLink");
 | 
					 | 
				
			||||||
  let hash = apiShortLink.value;
 | 
					 | 
				
			||||||
  if (hash.startsWith("http")) {
 | 
					 | 
				
			||||||
    let u = new URL(hash);
 | 
					 | 
				
			||||||
    hash = u.pathname.substring(u.pathname.lastIndexOf("/s/") + 3);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if (password.value.trim() === "") {
 | 
					 | 
				
			||||||
    alert("请输入原密码进行验证!");
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  let uri = generateURI();
 | 
					 | 
				
			||||||
  if (uri === "") {
 | 
					 | 
				
			||||||
    return;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  axios
 | 
					 | 
				
			||||||
    .put(
 | 
					 | 
				
			||||||
      "./short",
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        hash: hash,
 | 
					 | 
				
			||||||
        url: uri,
 | 
					 | 
				
			||||||
        password: password.value.trim(),
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        headers: {
 | 
					 | 
				
			||||||
          "Content-Type": "application/json",
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    .then((response) => {
 | 
					 | 
				
			||||||
      alert(`短链 ${hash} 更新成功!`);
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
    .catch((error) => {
 | 
					 | 
				
			||||||
      console.log(error);
 | 
					 | 
				
			||||||
      if (error.response && error.response.status === 401) {
 | 
					 | 
				
			||||||
        alert("密码错误,请输入正确的原密码!");
 | 
					 | 
				
			||||||
      } else if (error.response && error.response.data) {
 | 
					 | 
				
			||||||
        alert(error.response.data);
 | 
					 | 
				
			||||||
      } else {
 | 
					 | 
				
			||||||
        alert("更新短链失败,请重试!");
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// 主题切换功能
 | 
					 | 
				
			||||||
function initTheme() {
 | 
					 | 
				
			||||||
  const html = document.querySelector('html');
 | 
					 | 
				
			||||||
  const themeIcon = document.getElementById('theme-icon');
 | 
					 | 
				
			||||||
  let theme;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 从localStorage获取用户偏好的主题
 | 
					 | 
				
			||||||
  const savedTheme = localStorage.getItem('theme');
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (savedTheme) {
 | 
					 | 
				
			||||||
    // 如果用户之前设置过主题,使用保存的主题
 | 
					 | 
				
			||||||
    theme = savedTheme;
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    // 如果没有设置过,检测系统主题偏好
 | 
					 | 
				
			||||||
    const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
 | 
					 | 
				
			||||||
    theme = prefersDark ? 'dark' : 'light';
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 设置主题
 | 
					 | 
				
			||||||
  html.setAttribute('data-bs-theme', theme);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 更新图标
 | 
					 | 
				
			||||||
  if (theme === 'dark') {
 | 
					 | 
				
			||||||
    themeIcon.textContent = '☀️';
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    themeIcon.textContent = '🌙';
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function toggleTheme() {
 | 
					 | 
				
			||||||
  const html = document.querySelector('html');
 | 
					 | 
				
			||||||
  const currentTheme = html.getAttribute('data-bs-theme');
 | 
					 | 
				
			||||||
  // 切换主题
 | 
					 | 
				
			||||||
  const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
 | 
					 | 
				
			||||||
  html.setAttribute('data-bs-theme', newTheme);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 更新图标
 | 
					 | 
				
			||||||
  if (newTheme === 'dark') {
 | 
					 | 
				
			||||||
    themeIcon.textContent = '☀️';
 | 
					 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    themeIcon.textContent = '🌙';
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // 保存用户偏好到localStorage
 | 
					 | 
				
			||||||
  localStorage.setItem('theme', newTheme);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
listenInput();
 | 
					 | 
				
			||||||
initTheme();
 | 
					 | 
				
			||||||
							
								
								
									
										33
									
								
								test/yaml_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								test/yaml_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					package test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/bestnite/sub2clash/model/proxy"
 | 
				
			||||||
 | 
						"gopkg.in/yaml.v3"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type testStruct struct {
 | 
				
			||||||
 | 
						A proxy.IntOrString `yaml:"a"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestUnmarshal(t *testing.T) {
 | 
				
			||||||
 | 
						yamlData1 := `a: 123`
 | 
				
			||||||
 | 
						res := testStruct{}
 | 
				
			||||||
 | 
						err := yaml.Unmarshal([]byte(yamlData1), &res)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("failed to unmarshal yaml: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if res.A != 123 {
 | 
				
			||||||
 | 
							t.Errorf("expected 123, but got %v", res.A)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						yamlData2 := `a: "123"`
 | 
				
			||||||
 | 
						err = yaml.Unmarshal([]byte(yamlData2), &res)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							t.Errorf("failed to unmarshal yaml: %v", err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if res.A != 123 {
 | 
				
			||||||
 | 
							t.Errorf("expected 123, but got %v", res.A)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										31
									
								
								utils/base64.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								utils/base64.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					package utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/base64"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func DecodeBase64(s string, urlSafe bool) (string, error) {
 | 
				
			||||||
 | 
						s = strings.TrimSpace(s)
 | 
				
			||||||
 | 
						if len(s)%4 != 0 {
 | 
				
			||||||
 | 
							s += strings.Repeat("=", 4-len(s)%4)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						var decodeStr []byte
 | 
				
			||||||
 | 
						var err error
 | 
				
			||||||
 | 
						if urlSafe {
 | 
				
			||||||
 | 
							decodeStr, err = base64.URLEncoding.DecodeString(s)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							decodeStr, err = base64.StdEncoding.DecodeString(s)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return "", err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return string(decodeStr), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func EncodeBase64(s string, urlSafe bool) string {
 | 
				
			||||||
 | 
						if urlSafe {
 | 
				
			||||||
 | 
							return base64.URLEncoding.EncodeToString([]byte(s))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return base64.StdEncoding.EncodeToString([]byte(s))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user