start on fpaste

This commit is contained in:
nazunalika 2021-12-28 17:52:28 -07:00
parent c243bb32e4
commit 87d0b010aa
Signed by: label
GPG Key ID: 6735C0E1BD65D048
3 changed files with 32 additions and 16 deletions

View File

@ -1,10 +1,31 @@
// support for fpaste
package paste
import (
"fmt"
"os/user"
)
var (
fpasteTimeMap = map[string]string{
"1hour": "1hour",
"1day": "1day",
"1week": "1week",
"1hour": "60",
"1day": "1440",
"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
}

View File

@ -20,7 +20,7 @@ var (
func Rpaste(life string, lexer string, fileContent string) error {
payload := map[string]interface{}{
"expiry": life,
"expiry": rpasteTimeMap[life],
"files": []map[string]string{
{
"name": "paste",
@ -39,12 +39,12 @@ func Rpaste(life string, lexer string, fileContent string) error {
fmt.Println("Uploading...")
resp, err := http.Post("https://rpa.st/api/v1/paste", "application/json", bytes.NewBuffer(payloadJson))
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)
}
var response map[string]interface{}
if resp.StatusCode == 200 {
var response map[string]interface{}
json.NewDecoder(resp.Body).Decode(&response)
url := fmt.Sprintf("%s", response["link"])
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("Removal URL: %s\n", response["removal"])
} 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

View File

@ -21,12 +21,3 @@ var (
PrintUsage 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
//}