Cleared History
This commit is contained in:
commit
f50f3f97f8
7 changed files with 288 additions and 0 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
bin/
|
||||||
|
|
||||||
|
tmp/
|
||||||
|
vendor/
|
||||||
|
log/
|
58
Makefile
Normal file
58
Makefile
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
.PHONY: build debug clean
|
||||||
|
|
||||||
|
GOOS ?= $(shell go env GOOS)
|
||||||
|
GOARCH ?= $(shell go env GOARCH)
|
||||||
|
BIN_DIR := bin
|
||||||
|
BIN_NAME := paste
|
||||||
|
|
||||||
|
|
||||||
|
build:
|
||||||
|
ifeq ($(GOOS),windows)
|
||||||
|
$(MAKE) build_windows
|
||||||
|
else
|
||||||
|
$(MAKE) build_single
|
||||||
|
endif
|
||||||
|
|
||||||
|
build_all: build_amd64 build_arm64 build_386 build_arm build_ppc64 build_ppc64le build_s390x build_mips64 build_windows build_windows_386
|
||||||
|
|
||||||
|
build_amd64:
|
||||||
|
GOARCH=amd64 $(MAKE) build_single
|
||||||
|
|
||||||
|
build_arm64:
|
||||||
|
GOARCH=arm64 $(MAKE) build_single
|
||||||
|
|
||||||
|
build_386:
|
||||||
|
GOARCH=386 $(MAKE) build_single
|
||||||
|
|
||||||
|
build_arm:
|
||||||
|
GOARCH=arm GOARM=7 $(MAKE) build_single
|
||||||
|
|
||||||
|
build_ppc64:
|
||||||
|
GOARCH=ppc64 $(MAKE) build_single
|
||||||
|
|
||||||
|
build_ppc64le:
|
||||||
|
GOARCH=ppc64le $(MAKE) build_single
|
||||||
|
|
||||||
|
build_s390x:
|
||||||
|
GOARCH=s390x $(MAKE) build_single
|
||||||
|
|
||||||
|
build_mips64:
|
||||||
|
GOARCH=mips64 $(MAKE) build_single
|
||||||
|
|
||||||
|
build_windows:
|
||||||
|
$(MAKE) build_single_windows GOOS=windows GOARCH=amd64
|
||||||
|
|
||||||
|
build_windows_386:
|
||||||
|
$(MAKE) build_single_windows GOOS=windows GOARCH=386
|
||||||
|
|
||||||
|
build_single_windows:
|
||||||
|
go build -o $(BIN_DIR)/$(BIN_NAME)-$(GOOS)-$(GOARCH).exe
|
||||||
|
|
||||||
|
build_single:
|
||||||
|
go build -o $(BIN_DIR)/$(BIN_NAME)-$(GOOS)-$(GOARCH)
|
||||||
|
|
||||||
|
debug:
|
||||||
|
go build -tags debug -gcflags "all=-N -l" -o $(BIN_DIR)/$(BIN_NAME)-$(GOOS)-$(GOARCH)-debug
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -rf $(BIN_DIR)
|
134
cmd/pastes/main.go
Normal file
134
cmd/pastes/main.go
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
package pastes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
API_BASE_URL = "https://bin.tritan.gg/api"
|
||||||
|
HTML_BASE_URL = "https://bin.tritan.gg"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateNewPaste(c *cli.Context) error {
|
||||||
|
if c.NArg() < 1 {
|
||||||
|
return fmt.Errorf("content argument is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
inputData := c.Args().First()
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", API_BASE_URL+"/quick", bytes.NewBuffer([]byte(inputData)))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("User-Agent", "quickpaste/1.0")
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create paste: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
contentType := resp.Header.Get("Content-Type")
|
||||||
|
if !strings.Contains(contentType, "application/json") {
|
||||||
|
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||||
|
return fmt.Errorf("unexpected response: %s", string(bodyBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
var response PasteResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
||||||
|
return fmt.Errorf("failed to decode response: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if response.Error {
|
||||||
|
return fmt.Errorf("API error: %s", response.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Pasted - ID: %s\nLink: %s\n", response.Data.ID, HTML_BASE_URL+"/"+response.Data.ID)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetPaste(c *cli.Context) error {
|
||||||
|
if c.NArg() < 1 {
|
||||||
|
return fmt.Errorf("paste ID is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
pasteID := c.Args().First()
|
||||||
|
rawOutput := c.Bool("raw")
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", fmt.Sprintf("%s/pastes/%s", API_BASE_URL, pasteID), nil)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("User-Agent", "quickpaste/1.0")
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get paste: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
var response PasteResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
||||||
|
return fmt.Errorf("failed to decode response: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if response.Error {
|
||||||
|
return fmt.Errorf("API error: %s", response.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rawOutput {
|
||||||
|
fmt.Print(response.Data.Content)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Content: %s\nCreated at: %s\n", response.Data.Content, response.Data.CreatedAt.Format("2006-01-02 15:04:05"))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ReadFileAndCreatePaste(c *cli.Context) error {
|
||||||
|
if c.NArg() < 1 {
|
||||||
|
return fmt.Errorf("file path is required")
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath := c.Args().First()
|
||||||
|
content, err := os.ReadFile(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to read file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", API_BASE_URL+"/quick", bytes.NewBuffer([]byte(content)))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
req.Header.Set("User-Agent", "quickpaste/1.0")
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create paste: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var response PasteResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
|
||||||
|
return fmt.Errorf("failed to decode response: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if response.Error {
|
||||||
|
return fmt.Errorf("API error: %s", response.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Pasted file - ID: %s\nLink: %s\n", response.Data.ID, HTML_BASE_URL+"/"+response.Data.ID)
|
||||||
|
return nil
|
||||||
|
}
|
21
cmd/pastes/structs.go
Normal file
21
cmd/pastes/structs.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package pastes
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type PasteResponse struct {
|
||||||
|
Status int `json:"status"`
|
||||||
|
Error bool `json:"error"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Paste struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
Password *string `json:"password,omitempty"`
|
||||||
|
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
|
||||||
|
ExpireAfterViewing bool `json:"expireAfterViewing"`
|
||||||
|
}
|
11
go.mod
Normal file
11
go.mod
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
module tools_quickpaste
|
||||||
|
|
||||||
|
go 1.23.4
|
||||||
|
|
||||||
|
require github.com/urfave/cli/v2 v2.27.5
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
|
||||||
|
)
|
8
go.sum
Normal file
8
go.sum
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/urfave/cli/v2 v2.27.5 h1:WoHEJLdsXr6dDWoJgMq/CboDmyY/8HMMH1fTECbih+w=
|
||||||
|
github.com/urfave/cli/v2 v2.27.5/go.mod h1:3Sevf16NykTbInEnD0yKkjDAeZDS0A6bzhBH5hrMvTQ=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4=
|
||||||
|
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
51
main.go
Normal file
51
main.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"tools_quickpaste/cmd/pastes"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
app := &cli.App{
|
||||||
|
Name: "paste-cli",
|
||||||
|
Usage: "Securely share code, text, and messages with anyone.",
|
||||||
|
Commands: []*cli.Command{
|
||||||
|
{
|
||||||
|
Name: "create",
|
||||||
|
Aliases: []string{"c"},
|
||||||
|
Usage: "Create a new paste from text input",
|
||||||
|
Action: pastes.CreateNewPaste,
|
||||||
|
ArgsUsage: "<content>",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "file",
|
||||||
|
Aliases: []string{"f"},
|
||||||
|
Usage: "Create a new paste from a file",
|
||||||
|
Action: pastes.ReadFileAndCreatePaste,
|
||||||
|
ArgsUsage: "<filepath>",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "get",
|
||||||
|
Aliases: []string{"g"},
|
||||||
|
Usage: "Get a paste",
|
||||||
|
ArgsUsage: "<paste_id>",
|
||||||
|
Action: pastes.GetPaste,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "raw",
|
||||||
|
Aliases: []string{"r"},
|
||||||
|
Usage: "Display raw content only",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := app.Run(os.Args); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue