From 26a64f20764b2406b797b2d94cd7a11f77c5bbb0 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Thu, 1 Aug 2024 23:22:42 +0200 Subject: fix: add comments to the Go source --- tmp.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tmp.go') diff --git a/tmp.go b/tmp.go index 612fc51..2f2c4f2 100644 --- a/tmp.go +++ b/tmp.go @@ -16,6 +16,13 @@ var COMPRESSED_EXTENSIONS = []string{".jpg", ".webm", ".ogg", ".gz", ".bz2", ".z ".avi", ".jar", ".opus", ".ogv", ".flac", ".msi", ".m4a"} +// THE VARIABLE URL_VARIANTS IS MEANT TO BE EDITED. Change various +// attributes to correspond to your situation. +// If new section is added (as here I have also 'tmp' for fedorapeople.org) +// and the script has a symlink named as the section (so I have tmp as +// a symlink to this script) it saves the file to the location defined in +// such section when called under the other name. +// So, `tmp filename` saves file filename to fedorapeople for me. var URL_VARIANTS = map[string]map[string]string{ "wotan": { "base_url": "wotan:Export/", @@ -80,6 +87,7 @@ func main() { if err != nil { log.Fatal(err) } + // To make scp happy modifiedFname := strings.Replace(fname, ":", "_", 1) err = os.Rename(fname, modifiedFname) if err != nil { @@ -93,10 +101,13 @@ func main() { } targetURL := config["target_url"] + filepath.Base(modifiedFname) + // Make target_URL into a safe URL safeTargetURL := url.QueryEscape(targetURL) safeTargetURL = strings.Replace(safeTargetURL, "%3A", ":", 1) fmt.Println(safeTargetURL) + // curl -s 'http://is.gd/create.php?format=simple&url=www.example.com' + // http://is.gd/MOgh5q if shortenAPI, ok := config["shorten_api"]; ok { shortenedURLBytes, err := exec.Command("curl", "-s", shortenAPI+safeTargetURL).Output() if err != nil { @@ -106,6 +117,7 @@ func main() { fmt.Println(shortenedURL) } + // The script should have no side-effects if COMPRESSED { os.Remove(modifiedFname) } else { -- cgit