From 105a4c537b0b6dbddb876433fa0e38701b7dd675 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 3 Dec 2024 15:01:42 -0800 Subject: [PATCH] Help page with shortcut contents --- main.go | 27 +++++ static/help.html | 279 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 306 insertions(+) create mode 100644 static/help.html diff --git a/main.go b/main.go index f918c5b..b3b23f3 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( type ShortLinks struct { tmpl *template.Template + help *template.Template mux *http.ServeMux db *sql.DB r *rand.Rand @@ -44,6 +45,11 @@ func NewShortLinks(db *sql.DB, domainAliases map[string]string, writableDomains return nil, fmt.Errorf("static/index.html: %w", err) } + help, err := template.New("help.html").ParseFiles("static/help.html") + if err != nil { + return nil, fmt.Errorf("static/help.html: %w", err) + } + oai, err := newOAIClientFromEnv() if err != nil { return nil, fmt.Errorf("newOAIClientFromEnv: %w", err) @@ -51,6 +57,7 @@ func NewShortLinks(db *sql.DB, domainAliases map[string]string, writableDomains sl := &ShortLinks{ tmpl: tmpl, + help: help, mux: http.NewServeMux(), db: db, r: rand.New(rand.NewSource(uint64(time.Now().UnixNano()))), @@ -127,6 +134,11 @@ func (sl *ShortLinks) serveShort(w http.ResponseWriter, r *http.Request) { short := r.PathValue("short") + if sl.isWritable(r.Host) && short == "_help" { + sl.serveHelp(w, r) + return + } + long, err := sl.getLong(short, sl.getDomain(r.Host)) if err != nil { sl.serveRootWithPath(w, r, short) @@ -220,6 +232,21 @@ func (sl *ShortLinks) serveSuggest(w http.ResponseWriter, r *http.Request) { }) } +func (sl *ShortLinks) serveHelp(w http.ResponseWriter, r *http.Request) { + if !sl.isWritable(r.Host) { + sendError(w, http.StatusNotFound, "not found") + return + } + + err := sl.help.Execute(w, map[string]any{ + "host": r.Host, + }) + if err != nil { + sendError(w, http.StatusInternalServerError, "error executing template: %s", err) + return + } +} + func (sl *ShortLinks) genShort(domain string) (string, error) { for chars := 3; chars <= 10; chars++ { b := make([]byte, chars) diff --git a/static/help.html b/static/help.html new file mode 100644 index 0000000..217595a --- /dev/null +++ b/static/help.html @@ -0,0 +1,279 @@ + + + + + + + + + + + + +
+ + Share + Copy + Custom + + + + Receive + URLs + input from + Share Sheet +
+
+ If there's no input: +
+ Get Clipboard +
+ + + Get contents of + https://{{ .host }}/ + + + + Method: + POST +
+ + Request Body: + Form +
+ + Key: + long +
+ + Type: + Text +
+ + Value: + Shortcut Input +
+ + + Get + Value + for + short + in + Contents of URL + + + + Set variable + short + to + Dictionary Value + + + + Get + Value + for + domain + in + Contents of URL + + + + Set variable + domain + to + Dictionary Value + + + + Combine + https:// + domain + / + short + + + with + Custom + Text + + + + Share + Combined Text + + Type: + URL + +
+ + + + Receive + URLs + input from + Share Sheet +
+
+ If there's no input: +
+ Get Clipboard +
+ + + Get contents of + https://{{ .host }}/ + + + + Method: + POST +
+ + Request Body: + Form +
+ + Key: + long +
+ + Type: + Text +
+ + Value: + Shortcut Input +
+ + + Get + Value + for + short + in + Contents of URL + + + + Set variable + short + to + Dictionary Value + + + + Get + Value + for + domain + in + Contents of URL + + + + Set variable + domain + to + Dictionary Value + + + + Combine + https:// + domain + / + short + + + with + Custom + Text + + + + Copy + Combined Text + to clipboard + + Type: + URL + +
+ + + + Receive + URLs + input from + Share Sheet +
+
+ If there's no input: +
+ Get Clipboard +
+ + + URL + Encode + Shortcut Input + + + + Combine + https://{{ .host }}/?long= + URL Encoded Text + + + with + Custom + Text + + + + Open + Combined Text + + Type: + URL + +
+
+
+ +