-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (58 loc) · 1.42 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// main.go
package main
import (
"bufio"
"fmt"
"github.com/atotto/clipboard"
"os"
"strings"
)
func main() {
clear()
url := getURLFromArgsOrPrompt()
if !isValidQiwiURL(url) {
return
}
newLink, fileName := processURL(url)
if newLink == "" {
return
}
handleDownloadDecision(newLink, fileName)
}
func getURLFromArgsOrPrompt() string {
if len(os.Args) > 1 {
return os.Args[1]
}
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter download link: ")
url, _ := reader.ReadString('\n')
return strings.TrimSpace(url)
}
func isValidQiwiURL(url string) bool {
if strings.HasPrefix(url, "https://qiwi.gg/folder") {
fmt.Println("Error: Folder handling isn't implemented at the moment.")
return false
} else if !strings.HasPrefix(url, "https://qiwi.gg/file") {
fmt.Println("Error: Invalid URL. Only qiwi.gg/file URLs are supported.")
return false
}
return true
}
func confirmDownload() bool {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Do you want to download the file? (y/n): ")
response, _ := reader.ReadString('\n')
return strings.HasPrefix(strings.TrimSpace(strings.ToLower(response)), "y")
}
func handleDownloadDecision(newLink, fileName string) {
if confirmDownload() {
downloadFile(newLink, fileName)
} else {
err := clipboard.WriteAll(newLink)
if err != nil {
fmt.Println("Failed to copy to clipboard:", err)
} else {
fmt.Println("Download link copied to clipboard.")
}
}
}