This commit is contained in:
Colin 2024-06-26 11:09:09 -04:00
parent 96a350bb7d
commit 8ab8c110c1
4 changed files with 62 additions and 2 deletions

Binary file not shown.

5
go.mod
View File

@ -2,4 +2,7 @@ module ae-send
go 1.21.1
require golang.org/x/sys v0.21.0
require (
github.com/atotto/clipboard v0.1.4
golang.org/x/sys v0.21.0
)

2
go.sum
View File

@ -1,2 +1,4 @@
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

57
main.go
View File

@ -1,11 +1,17 @@
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
"os/exec"
"strings"
"github.com/atotto/clipboard"
"golang.org/x/sys/windows/registry"
)
@ -27,7 +33,56 @@ func main() {
func processFile(filePath string) {
log.Printf("Processing file: %s", filePath)
// Add your existing file processing logic here
url, err := uploadFile(filePath)
if err != nil {
log.Fatalf("Failed to upload file: %v", err)
}
err = clipboard.WriteAll(url)
if err != nil {
log.Fatalf("Failed to copy URL to clipboard: %v", err)
}
log.Printf("URL copied to clipboard: %s", url)
}
func uploadFile(filename string) (string, error) {
file, err := os.Open(filename)
if err != nil {
return "", fmt.Errorf("failed to open file: %w", err)
}
defer file.Close()
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("file", filename)
if err != nil {
return "", fmt.Errorf("failed to create form file: %w", err)
}
_, err = io.Copy(part, file)
if err != nil {
return "", fmt.Errorf("failed to copy file data: %w", err)
}
writer.Close()
request, err := http.NewRequest("POST", "https://send.aenow.com/upload", body)
if err != nil {
return "", fmt.Errorf("failed to create request: %w", err)
}
request.Header.Set("Content-Type", writer.FormDataContentType())
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
return "", fmt.Errorf("failed to send request: %w", err)
}
defer response.Body.Close()
urlBytes, err := io.ReadAll(response.Body)
if err != nil {
return "", fmt.Errorf("failed to read response: %w", err)
}
return string(urlBytes), nil
}
func installContextMenuItem() {