-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
104 lines (95 loc) · 2.73 KB
/
main.go
File metadata and controls
104 lines (95 loc) · 2.73 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"FFast/ffast"
"FFast/ffast/cacheCode"
"bufio"
"fmt"
"log"
"os"
"strings"
"sync"
)
// Take input from the Interactive Terminal
func takeInput(prompt string, placeholder string, defaultValue string, optional bool) string {
reader := bufio.NewReader(os.Stdin)
fmt.Print(prompt)
url, err := reader.ReadString('\n')
if err != nil {
log.Fatal("Could not read the Input")
}
input := strings.TrimSpace(url)
if !optional && input == "" {
log.Fatal("[ERROR] ",placeholder," cannot be empty")
}
if input == "" {
input = defaultValue
}
return input
}
func start() {
URL := ""
name := ""
cURL,cName, err := cacheCode.GetCurrentPasteBinURL()
if err != nil {
fmt.Println("No current PasteBin URL found in cache.")
URL = takeInput("Enter the Fucking-Fast URL: ", "URL", "", false)
name = takeInput("Enter the name for the download: ", "Name", "", true)
cacheCode.SaveCurrentPasteBinURL(URL, name)
} else {
fmt.Println("Current PasteBin Cache Found : ")
fmt.Println("Name: ",cName)
fmt.Println("URL: ", cURL)
useCache := takeInput("Do you want to use the cached URL? (Y/n): ", "Use Cache", "Y", true)
if strings.ToUpper(useCache) == "Y" {
URL = cURL
name = cName
cacheCode.SaveCurrentPasteBinURL(URL, name)
} else {
URL = takeInput("Enter the Fucking-Fast URL: ", "URL", "", false)
name = takeInput("Enter the name for the download: ", "Name", "", true)
cacheCode.SaveCurrentPasteBinURL(URL, name)
}
}
ff := ffast.Create(URL,name)
ff.DecodePrivateBin()
ff.SelectLinks()
ff.DownloadParts()
}
func waitForExit(wg *sync.WaitGroup) {
fmt.Println("Press Enter to exit...")
reader := bufio.NewReader(os.Stdin)
_, _ = reader.ReadString('\n')
wg.Done()
}
func main() {
args := os.Args
if len(args) < 2 {
fmt.Println("Usage: ffast [options], where options can be:")
fmt.Println(" start, s, --start, -s, --run\t\tStart the interactive terminal")
fmt.Println(" --clear-cache, -c\tClear the cached PasteBin URL")
fmt.Println(" --help, -h\t\tShow this help message")
wg := sync.WaitGroup{}
wg.Add(1)
go waitForExit(&wg)
wg.Wait()
return
}
switch args[1] {
case "--help", "-h":
fmt.Println("Usage: ffast [options], where options can be:")
fmt.Println(" --start, -s\t\tStart the interactive terminal")
fmt.Println(" --clear-cache, -c\tClear the cached PasteBin URL")
fmt.Println(" --help, -h\t\tShow this help message")
case "--start", "-s", "start", "s", "run":
start()
case "--clear-cache", "-c":
err := cacheCode.ClearDownloadStateCache()
if err != nil {
log.Fatal("Failed to clear cache:", err)
}
fmt.Println("Cache cleared successfully.")
default:
fmt.Println("Unknown option:", args[1])
fmt.Println("Use --help or -h to see the available options.")
}
}