From 6264efc71486b72923621f47b4b8ca793ea51db6 Mon Sep 17 00:00:00 2001
From: Eric Bower
Date: Sun, 12 Nov 2023 11:00:09 -0500
Subject: [PATCH 1/3] feat(pastes): set custom expiration and set paste to
unlisted
---
pastes/html/help.page.tmpl | 33 +++++++++++++-
pastes/html/marketing.page.tmpl | 6 ++-
pastes/scp_hooks.go | 80 ++++++++++++++++-----------------
3 files changed, 74 insertions(+), 45 deletions(-)
diff --git a/pastes/html/help.page.tmpl b/pastes/html/help.page.tmpl
index 80853e22..fe7c1adb 100644
--- a/pastes/html/help.page.tmpl
+++ b/pastes/html/help.page.tmpl
@@ -109,8 +109,8 @@ scp ./delete.txt {{.Site.Domain}}:/
- #
- Can I pipe my paste?
+ #
+ Can I pipe my paste?
Yes!
@@ -120,6 +120,35 @@ scp ./delete.txt {{.Site.Domain}}:/
# if the tty warning annoys you
echo "foobar" | ssh -T pastes.sh
+
+
+
+ #
+ Can I set the expiration date to a paste?
+
+
+ Yes. The default expiration date for a paste is 90 days.
+ We do allow the user to set the paste to never expire.
+ We also allow custom duration
+ or timestamp.
+
+ echo "foobar" | ssh pastes.sh FILENAME expires=false
+ echo "foobar" | ssh pastes.sh FILENAME expires=2023-12-12
+ echo "foobar" | ssh pastes.sh FILENAME expires=1h
+
+
+
+
+ #
+ Can I have my pastes from my user page?
+
+
+ Yes. Unlisted in this context means it does not show up on
+ your user landing page where we should all of your pastes.
+ In this case, yes, you can "hide" it using a pipe command.
+
+ echo "foobar" | ssh pastes.sh FILENAME hidden=true
+
{{template "marketing-footer" .}}
{{end}}
diff --git a/pastes/html/marketing.page.tmpl b/pastes/html/marketing.page.tmpl
index 4a71c7ab..7d5a3fd5 100644
--- a/pastes/html/marketing.page.tmpl
+++ b/pastes/html/marketing.page.tmpl
@@ -85,7 +85,9 @@ echo "foobar" | ssh -T pastes.sh
Features
- - Pastes last 90 days
+ - Pastes last 90 days by default
+ - Ability to set custom expiration
+ - Ability to "hide" pastes
- Bring your own editor
- Terminal workflow with no installation
- Public-key based authentication
@@ -106,7 +108,7 @@ echo "foobar" | ssh -T pastes.sh
Roadmap
- - Ability to customize expiration
+ - Mobile support?
diff --git a/pastes/scp_hooks.go b/pastes/scp_hooks.go
index c833775f..adceb600 100644
--- a/pastes/scp_hooks.go
+++ b/pastes/scp_hooks.go
@@ -43,57 +43,55 @@ func (p *FileHooks) FileMeta(s ssh.Session, data *filehandlers.PostMetaData) err
data.ExpiresAt = &expiresAt
}
- if p.Db.HasFeatureForUser(data.User.ID, "pastes-advanced") {
- var hidden bool
- var expiresFound bool
- var expires *time.Time
+ var hidden bool
+ var expiresFound bool
+ var expires *time.Time
- cmd := s.Command()
+ cmd := s.Command()
- for _, arg := range cmd {
- if strings.Contains(arg, "=") {
- splitArg := strings.Split(arg, "=")
- if len(splitArg) != 2 {
+ for _, arg := range cmd {
+ if strings.Contains(arg, "=") {
+ splitArg := strings.Split(arg, "=")
+ if len(splitArg) != 2 {
+ continue
+ }
+
+ switch splitArg[0] {
+ case "hidden":
+ val, err := strconv.ParseBool(splitArg[1])
+ if err != nil {
+ continue
+ }
+
+ hidden = val
+ case "expires":
+ val, err := strconv.ParseBool(splitArg[1])
+ if err == nil {
+ expiresFound = !val
continue
}
- switch splitArg[0] {
- case "hidden":
- val, err := strconv.ParseBool(splitArg[1])
- if err != nil {
- continue
- }
-
- hidden = val
- case "expires":
- val, err := strconv.ParseBool(splitArg[1])
- if err == nil {
- expiresFound = !val
- continue
- }
-
- duration, err := time.ParseDuration(splitArg[1])
- if err == nil {
- expiresFound = true
- expireTime := time.Now().Add(duration)
- expires = &expireTime
- continue
- }
-
- expireTime, err := dateparse.ParseStrict(splitArg[1])
- if err == nil {
- expiresFound = true
- expires = &expireTime
- }
+ duration, err := time.ParseDuration(splitArg[1])
+ if err == nil {
+ expiresFound = true
+ expireTime := time.Now().Add(duration)
+ expires = &expireTime
+ continue
+ }
+
+ expireTime, err := dateparse.ParseStrict(splitArg[1])
+ if err == nil {
+ expiresFound = true
+ expires = &expireTime
}
}
}
+ }
- data.Hidden = hidden
+ data.Hidden = hidden
- if expiresFound {
- data.ExpiresAt = expires
- }
+ if expiresFound {
+ data.ExpiresAt = expires
}
return nil
From 0aa5169dabb99a5176bff488eca0ba3ca40b7544 Mon Sep 17 00:00:00 2001
From: Eric Bower
Date: Sun, 12 Nov 2023 11:25:53 -0500
Subject: [PATCH 2/3] edits
---
pastes/html/help.page.tmpl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pastes/html/help.page.tmpl b/pastes/html/help.page.tmpl
index fe7c1adb..3b803883 100644
--- a/pastes/html/help.page.tmpl
+++ b/pastes/html/help.page.tmpl
@@ -140,11 +140,11 @@ echo "foobar" | ssh -T pastes.sh
#
- Can I have my pastes from my user page?
+ Can I hide pastes from my landing page?
Yes. Unlisted in this context means it does not show up on
- your user landing page where we should all of your pastes.
+ your user landing page where we show all of your pastes.
In this case, yes, you can "hide" it using a pipe command.
echo "foobar" | ssh pastes.sh FILENAME hidden=true
From 70a34e4c4d5847facbf50b30bd934c4d47ab2735 Mon Sep 17 00:00:00 2001
From: Eric Bower
Date: Sun, 12 Nov 2023 11:39:03 -0500
Subject: [PATCH 3/3] feat(pastes): show expiration date in website
---
pastes/api.go | 7 +++++++
pastes/html/post.page.tmpl | 1 +
2 files changed, 8 insertions(+)
diff --git a/pastes/api.go b/pastes/api.go
index 09552fce..5526f885 100644
--- a/pastes/api.go
+++ b/pastes/api.go
@@ -55,6 +55,7 @@ type PostPageData struct {
Contents template.HTML
PublishAtISO string
PublishAt string
+ ExpiresAt string
}
type TransparencyPageData struct {
@@ -185,6 +186,10 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
logger.Error(err)
}
+ expiresAt := "never"
+ if post.ExpiresAt != nil {
+ expiresAt = post.ExpiresAt.Format("02 Jan, 2006")
+ }
data = PostPageData{
Site: *cfg.GetSiteData(),
@@ -199,6 +204,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
Username: username,
BlogName: blogName,
Contents: template.HTML(parsedText),
+ ExpiresAt: expiresAt,
}
} else {
logger.Infof("post not found %s/%s", username, slug)
@@ -213,6 +219,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
Username: username,
BlogName: blogName,
Contents: "oops! we can't seem to find this post.",
+ ExpiresAt: "",
}
}
diff --git a/pastes/html/post.page.tmpl b/pastes/html/post.page.tmpl
index e5003432..7c2e3096 100644
--- a/pastes/html/post.page.tmpl
+++ b/pastes/html/post.page.tmpl
@@ -33,6 +33,7 @@
|
raw
+ expires: {{.ExpiresAt}}