blob: 30e99b31230356ba677a53f907be94b2015f00f6 (
plain)
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
|
package main
import (
"encoding/json"
"fmt"
"os"
)
/* TODO: Make this configurable. */
//var apiHost = "http://127.0.0.1:8080"
var apiHost = "https://images.iamfabulous.de"
var apiUrl = apiHost + "/api/v1/"
func main() {
if len(os.Args) == 1 {
printHelp()
}
for k, v := range os.Args {
if v == "-h" || v == "--help" || v == "help" {
printHelp()
}
if k > 0 {
if stat, err := os.Stat(v); err != nil {
err := urlUpload(apiUrl+"url", v, v)
if err != nil {
fmt.Println("There is an error. Are you sure the url is correct?")
fmt.Printf("\n")
fmt.Println("Technical information: ")
fmt.Println(" "+err.Error(), "\n")
}
} else {
err := fileUpload(apiUrl+"file", v, stat.Name())
if err != nil {
fmt.Println("There is an error. Are you sure the url is correct?")
fmt.Printf("\n")
fmt.Println("Technical information: ")
fmt.Println(" "+err.Error(), "\n")
}
}
}
}
fmt.Println("Have a nice day!")
}
func printResponse(res []byte, name string) {
r := response{}
json.Unmarshal(res, &r)
if r.Success {
fmt.Println("Your image (" + name + ") was uploaded!\n")
fmt.Println("Follow this link: \n" + " " + r.Data.Link)
fmt.Print("\n")
} else {
fmt.Println("There was an error during upload. (" + name + ")")
fmt.Print("\n")
fmt.Println("The website says: \n " + r.Data.Error)
fmt.Print("\n")
}
}
func printHelp() {
pstat, _ := os.Stat(os.Args[0])
programName := pstat.Name()
fmt.Println("Usage: " + os.Args[0] + " [FILE] [URL]")
fmt.Print("\n")
fmt.Println(programName + " uploads an image to " + apiHost + ".")
os.Exit(0)
/*
fmt.Println("Usage: " + os.Args[0] + " [FILE] [URL]")
fmt.Println(" " + os.Args[0] + " --update updates " + programName + " to newest version.")
fmt.Print("\n")
fmt.Println(programName + " uploads an image to " + apiHost + ".")
//fmt.Println("FILE should be a path to a image file.")
os.Exit(0)
*/
}
|