start on fpaste
This commit is contained in:
parent
c243bb32e4
commit
87d0b010aa
@ -1,10 +1,31 @@
|
|||||||
// support for fpaste
|
// support for fpaste
|
||||||
package paste
|
package paste
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/user"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
fpasteTimeMap = map[string]string{
|
fpasteTimeMap = map[string]string{
|
||||||
"1hour": "1hour",
|
"1hour": "60",
|
||||||
"1day": "1day",
|
"1day": "1440",
|
||||||
"1week": "1week",
|
"1week": "10080",
|
||||||
}
|
}
|
||||||
|
fpasteAPIKey = "5uZ30dTZE1a5V0WYhNwcMddBRDpk6UzuzMu-APKM38iMHacxdA0n4vCqA34avNyt"
|
||||||
|
fpasteUserAgent = "fpaste/0.4.0.0"
|
||||||
|
fpasteTitle = "UNTITLED" // we'll need to make this changeable in the future
|
||||||
|
fpastePrivate = "1"
|
||||||
|
fpasteUserName = "user"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Fpaste(life string, lexer string, fileContent string) error {
|
||||||
|
// Set username as the author
|
||||||
|
user, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Username could not be found")
|
||||||
|
} else {
|
||||||
|
fpasteUserName = user.Name
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -20,7 +20,7 @@ var (
|
|||||||
|
|
||||||
func Rpaste(life string, lexer string, fileContent string) error {
|
func Rpaste(life string, lexer string, fileContent string) error {
|
||||||
payload := map[string]interface{}{
|
payload := map[string]interface{}{
|
||||||
"expiry": life,
|
"expiry": rpasteTimeMap[life],
|
||||||
"files": []map[string]string{
|
"files": []map[string]string{
|
||||||
{
|
{
|
||||||
"name": "paste",
|
"name": "paste",
|
||||||
@ -39,12 +39,12 @@ func Rpaste(life string, lexer string, fileContent string) error {
|
|||||||
fmt.Println("Uploading...")
|
fmt.Println("Uploading...")
|
||||||
resp, err := http.Post("https://rpa.st/api/v1/paste", "application/json", bytes.NewBuffer(payloadJson))
|
resp, err := http.Post("https://rpa.st/api/v1/paste", "application/json", bytes.NewBuffer(payloadJson))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Could not contact rpaste endpoint")
|
fmt.Println("Could not contact rpaste endpoint (https://rpa.st/api/v1)")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode == 200 {
|
|
||||||
var response map[string]interface{}
|
var response map[string]interface{}
|
||||||
|
if resp.StatusCode == 200 {
|
||||||
json.NewDecoder(resp.Body).Decode(&response)
|
json.NewDecoder(resp.Body).Decode(&response)
|
||||||
url := fmt.Sprintf("%s", response["link"])
|
url := fmt.Sprintf("%s", response["link"])
|
||||||
ss := strings.Split(url, "/")
|
ss := strings.Split(url, "/")
|
||||||
@ -54,7 +54,11 @@ func Rpaste(life string, lexer string, fileContent string) error {
|
|||||||
fmt.Printf("Raw URL: https://rpa.st/raw/%s\n", slug)
|
fmt.Printf("Raw URL: https://rpa.st/raw/%s\n", slug)
|
||||||
fmt.Printf("Removal URL: %s\n", response["removal"])
|
fmt.Printf("Removal URL: %s\n", response["removal"])
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("ERROR: %d\n", resp.StatusCode)
|
json.NewDecoder(resp.Body).Decode(&response)
|
||||||
|
fmt.Printf("ERROR: %d, %s\n", resp.StatusCode, response["message"])
|
||||||
|
if resp.StatusCode == 500 {
|
||||||
|
fmt.Println("You cannot upload binary data.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -21,12 +21,3 @@ var (
|
|||||||
PrintUsage bool
|
PrintUsage bool
|
||||||
SysInfo bool
|
SysInfo bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// todo: put in support to find conf file in order:
|
|
||||||
// -> user's home ~/.rpaste
|
|
||||||
// -> /etc/rpaste/rpaste.conf
|
|
||||||
// -> or ignore everything and use custom provided (optional)
|
|
||||||
|
|
||||||
//func init() {
|
|
||||||
// var err error
|
|
||||||
//}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user