From bf2ccdb5a7fd240484ea49f5b005d8ea084e72fe Mon Sep 17 00:00:00 2001 From: Levi Date: Tue, 1 Aug 2023 18:56:39 +0800 Subject: [PATCH] fix: torrent file path resolve (#173) --- README.md | 2 +- README_ja-JP.md | 2 +- README_zh-CN.md | 2 +- pkg/util/url.go | 9 +++------ pkg/util/url_test.go | 14 +++++++------- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 1fb4f4ab..6540b80b 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ This project is divided into two parts, the front end uses `flutter`, the back e ### Environment 1. Golang 1.19+ -2. Flutter 3.7+ +2. Flutter 3.10+ ### Clone diff --git a/README_ja-JP.md b/README_ja-JP.md index 316db9fe..3ecc25af 100644 --- a/README_ja-JP.md +++ b/README_ja-JP.md @@ -74,7 +74,7 @@ docker コンテナが起動しているときは、`http://localhost:9999` か ### 環境 1. Go 言語 1.19+ -2. Flutter 3.7+ +2. Flutter 3.10+ ### クローン diff --git a/README_zh-CN.md b/README_zh-CN.md index 8f80fc55..b8a8503f 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -74,7 +74,7 @@ docker-compose up -d ### 环境要求 1. Golang 1.19+ -2. Flutter 3.7+ +2. Flutter 3.10+ ### 克隆项目 diff --git a/pkg/util/url.go b/pkg/util/url.go index 0d9680c8..ee1170cf 100644 --- a/pkg/util/url.go +++ b/pkg/util/url.go @@ -10,12 +10,9 @@ const FileSchema = "FILE" func ParseSchema(url string) string { index := strings.Index(url, ":") - if index == -1 { - // check is file path - if IsExistsFile(url) { - return FileSchema - } - return "" + // if no schema or windows path like C:\a.txt, return FILE + if index == -1 || index == 1 { + return FileSchema } schema := url[:index] if schema == "data" { diff --git a/pkg/util/url_test.go b/pkg/util/url_test.go index 8ee88df7..ec8833b4 100644 --- a/pkg/util/url_test.go +++ b/pkg/util/url_test.go @@ -36,13 +36,6 @@ func TestParseSchema(t *testing.T) { }, want: "FILE", }, - { - name: "file-not-exists", - args: args{ - url: "not.txt", - }, - want: "", - }, { name: "file-no-scheme", args: args{ @@ -57,6 +50,13 @@ func TestParseSchema(t *testing.T) { }, want: "APPLICATION/X-BITTORRENT", }, + { + name: "windows-path", + args: args{ + url: "D:\\bt.torrent", + }, + want: "FILE", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {