golink: ignore hyphens and allow changing name

- ignore hyphens, preventing link ambiguity. If hyphens are included
  when creating the link, they are saved as the "canonical" name for
  the link, but links are still resolved without them.

- allow overwriting the "canonical" name for a short link by simply
  recreating it with the new canonical name. Stats are not updated when
  the canonical name is updated, which is probably fine.

Change-Id: Ia962caa846489850784ef15cdfad7f13bafd8842
This commit is contained in:
Will Norris
2022-06-03 10:56:01 -07:00
parent befe7feef2
commit 7460caa6de
+2
View File
@@ -148,6 +148,7 @@ http://go/<input name=short size=20 value="{{.Short}}"> ==&gt; <input name=long
func linkPath(short string) string {
name := url.PathEscape(strings.ToLower(short))
name = strings.ReplaceAll(name, "-", "")
name = strings.ReplaceAll(name, ".", "%2e")
return filepath.Join(*linkDir, name)
}
@@ -302,6 +303,7 @@ func serveSave(w http.ResponseWriter, r *http.Request) {
Created: now,
}
}
dl.Short = short
dl.Long = long
dl.LastEdit = now
dl.Owner = login