diff --git a/transfer/tshweb/index.html b/transfer/tshweb/index.html index 4a882a2..32c618a 100644 --- a/transfer/tshweb/index.html +++ b/transfer/tshweb/index.html @@ -1,37 +1,78 @@ - + + + + + Third Culture Upload + + - - - - Third Culture Upload - - - - -

Third Culture Upload

-
- - -

- -
-


-

Make sure to copy the link in the next page!

-

More info on third culture upload here.

-


- - - - - - - - - \ No newline at end of file + +

Third Culture Upload

+
+ + +

+ +
+


+

Make sure to copy the link in the next page!

+

+ More info on third culture upload + here. +

+


+ + + + + + + + diff --git a/transfer/tshweb/transfer.go b/transfer/tshweb/transfer.go new file mode 100644 index 0000000..d26ff47 --- /dev/null +++ b/transfer/tshweb/transfer.go @@ -0,0 +1,164 @@ +package main + +import ( + "fmt" + "io" + "net/http" + "os/exec" + "strings" +) + +func uploadHandler(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPost { + err := r.ParseMultipartForm(15 * 1024 * 1024 * 1024) // limit 15 gb + if err != nil { + http.Error(w, "Unable to parse form", http.StatusBadRequest) + return + } + + file, _, err := r.FormFile("file") + if err != nil { + http.Error(w, "Unable to retrieve file", http.StatusBadRequest) + return + } + defer file.Close() + + // Upload the file + req, err := http.NewRequest("POST", "http://localhost:3880", file) + if err != nil { + http.Error(w, "Error creating request", http.StatusInternalServerError) + return + } + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + http.Error(w, "Error uploading to transfer.sh", http.StatusInternalServerError) + return + } + defer resp.Body.Close() + + // Unique ID to track file for ffmpeg etc + responseURL, err := io.ReadAll(resp.Body) + if err != nil { + http.Error(w, "Error reading response", http.StatusInternalServerError) + return + } + urlParts := strings.Split(string(responseURL), "/") + uniqueID := urlParts[len(urlParts)-1] + + // Convert file to HLS. Work on error catching and flags tomorrow + // IF VIDEO=DO THIS. IF NOT CONTINUE! + // ALSO CHANGE THE CODE. IF VIDEO, REDIRECT TO S3 BUCKET + // CURRENTLY FILE IS STANDARD UPLOAD TO SERVER + cmd := exec.Command("ffmpeg") + + // HTML + w.Header().Set("Content-Type", "text/html") + fmt.Fprint(w, ` + + + + + + Third Culture Upload + + + +

Upload Success

+

Unique ID: %s

+

%s

+ Upload Another + + + `, uniqueID, string(responseURL), string(responseURL)) + return + } + + // Original GET form + w.Header().Set("Content-Type", "text/html") + fmt.Fprint(w, ` + + + + + + Third Culture Upload + + + + +

Third Culture Upload

+
+ + +

+ +
+


+

Make sure to copy the link in the next page!

+

+ More info on third culture upload + here. +

+


+ + + + + + + + + `) +} +func main() { + http.HandleFunc("/", uploadHandler) + fmt.Println("Server started at localhost") + http.ListenAndServe(":3880", nil) +}