-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: torrent file support on web (#171)
- Loading branch information
Showing
12 changed files
with
288 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
package util | ||
|
||
import "strings" | ||
import ( | ||
"encoding/base64" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
const FileSchema = "FILE" | ||
|
||
func ParseSchema(url string) string { | ||
index := strings.Index(url, ":") | ||
if index == -1 { | ||
return FileSchema | ||
// check is file path | ||
if IsExistsFile(url) { | ||
return FileSchema | ||
} | ||
return "" | ||
} | ||
return strings.ToUpper(url[:index]) | ||
schema := url[:index] | ||
if schema == "data" { | ||
schema, _ = ParseDataUri(url) | ||
} | ||
return strings.ToUpper(schema) | ||
} | ||
|
||
// ParseDataUri parses a data URI and returns the MIME type and decode data. | ||
func ParseDataUri(uri string) (string, []byte) { | ||
re := regexp.MustCompile(`^data:(.*);base64,(.*)$`) | ||
matches := re.FindStringSubmatch(uri) | ||
if len(matches) != 3 { | ||
return "", nil | ||
} | ||
mime := matches[1] | ||
base64Data := matches[2] | ||
// 解码Base64数据 | ||
data, err := base64.StdEncoding.DecodeString(base64Data) | ||
if err != nil { | ||
return "", nil | ||
} | ||
return mime, data | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.