Compare commits

..

No commits in common. "d53ceba7ee80e94bca18804d4bd4abc354b127a8" and "8d86bdd33d0dadf59e51dbb7419e379d0786be5c" have entirely different histories.

7 changed files with 5 additions and 66 deletions

View file

@ -1,8 +0,0 @@
POSTGRES_PASSWORD="secret"
DATABASE_URL="postgresql://postgres:secret@localhost/pastes?sslmode=disable"
PASTES_SSH_PORT="2222"
PASTES_WEB_PORT="3000"
PASTES_DOMAIN="pastes.test:3000"
PASTES_EMAIL="me@pastey.com"
PASTES_SUBDOMAINS=1
PASTES_PROTOCOL="http"

View file

@ -23,7 +23,6 @@ export PASTES_SSH_PORT=2222
export PASTES_WEB_PORT=3000
export PASTES_DOMAIN="pastes.sh"
export PASTES_EMAIL="hello@pastes.sh"
export PASTES_PROTOCOL="http"
```
I just use `direnv` which will load my `.env` file.

4
go.mod
View file

@ -2,10 +2,8 @@ module git.sr.ht/~erock/pastes.sh
go 1.18
// replace git.sr.ht/~erock/wish => /home/erock/pico/wish
require (
git.sr.ht/~erock/wish v0.0.0-20220714033621-620d4ba1aa5d
git.sr.ht/~erock/wish v0.0.0-20220713141740-64595ee518ac
github.com/alecthomas/chroma v0.10.0
github.com/charmbracelet/wish v0.5.0
github.com/gliderlabs/ssh v0.3.4

8
go.sum
View file

@ -2,14 +2,6 @@ git.sr.ht/~erock/wish v0.0.0-20220707194507-66e938674d95 h1:q3G01ELBZt3EZEOiYWfw
git.sr.ht/~erock/wish v0.0.0-20220707194507-66e938674d95/go.mod h1:QZKk7m9jc9iXah90daPGhQkSfNfxSVvpb6nfVeI+MM0=
git.sr.ht/~erock/wish v0.0.0-20220713141740-64595ee518ac h1:d+q9VPi+kaZpYpZOoXPSEx2KtZ3Gcmkz+x/lpb/V6bU=
git.sr.ht/~erock/wish v0.0.0-20220713141740-64595ee518ac/go.mod h1:QZKk7m9jc9iXah90daPGhQkSfNfxSVvpb6nfVeI+MM0=
git.sr.ht/~erock/wish v0.0.0-20220714010731-7947bf10c388 h1:goL6fa09OPdg+LB2ceJGlx4QkPO+42QI/zqB6tbaKAA=
git.sr.ht/~erock/wish v0.0.0-20220714010731-7947bf10c388/go.mod h1:QZKk7m9jc9iXah90daPGhQkSfNfxSVvpb6nfVeI+MM0=
git.sr.ht/~erock/wish v0.0.0-20220714031334-670ce9b92be6 h1:MXCqjuHgZ081oVyBb4JO6jMyKLA3HTsvOVJJBFF3L/Y=
git.sr.ht/~erock/wish v0.0.0-20220714031334-670ce9b92be6/go.mod h1:QZKk7m9jc9iXah90daPGhQkSfNfxSVvpb6nfVeI+MM0=
git.sr.ht/~erock/wish v0.0.0-20220714031736-47b0eaae6231 h1:o5oGYrwl3Qpug5DnjPa3+m/EsWhN2zZveYqHQVvbUe4=
git.sr.ht/~erock/wish v0.0.0-20220714031736-47b0eaae6231/go.mod h1:QZKk7m9jc9iXah90daPGhQkSfNfxSVvpb6nfVeI+MM0=
git.sr.ht/~erock/wish v0.0.0-20220714033621-620d4ba1aa5d h1:M/Ub98kMgfAZ/4jjbSLsc58TLqYGYzmMr0bxsSyUvgc=
git.sr.ht/~erock/wish v0.0.0-20220714033621-620d4ba1aa5d/go.mod h1:QZKk7m9jc9iXah90daPGhQkSfNfxSVvpb6nfVeI+MM0=
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=

View file

@ -482,8 +482,6 @@ func StartApiServer() {
defer db.Close()
logger := cfg.Logger
go CronDeleteExpiredPosts(cfg, db)
staticRoutes := createStaticRoutes()
mainRoutes := createMainRoutes(staticRoutes)
subdomainRoutes := createSubdomainRoutes(staticRoutes)

View file

@ -28,7 +28,6 @@ func NewConfigSite() *ConfigSite {
subdomains := GetEnv("PASTES_SUBDOMAINS", "0")
port := GetEnv("PASTES_WEB_PORT", "3000")
dbURL := GetEnv("DATABASE_URL", "")
protocol := GetEnv("PASTES_PROTOCOL", "https")
subdomainsEnabled := false
if subdomains == "1" {
subdomainsEnabled = true
@ -45,7 +44,6 @@ func NewConfigSite() *ConfigSite {
ConfigCms: config.ConfigCms{
Domain: domain,
Port: port,
Protocol: protocol,
Email: email,
DbURL: dbURL,
Description: "a pastebin for hackers.",
@ -65,7 +63,7 @@ func (c *ConfigSite) GetSiteData() *SitePageData {
func (c *ConfigSite) BlogURL(username string) string {
if c.IsSubdomains() {
return fmt.Sprintf("%s://%s.%s", c.Protocol, username, c.Domain)
return fmt.Sprintf("//%s.%s", username, c.Domain)
}
return fmt.Sprintf("/%s", username)
@ -74,7 +72,7 @@ func (c *ConfigSite) BlogURL(username string) string {
func (c *ConfigSite) PostURL(username, filename string) string {
fname := url.PathEscape(filename)
if c.IsSubdomains() {
return fmt.Sprintf("%s://%s.%s/%s", c.Protocol, username, c.Domain, fname)
return fmt.Sprintf("//%s.%s/%s", username, c.Domain, fname)
}
return fmt.Sprintf("/%s/%s", username, fname)
@ -86,7 +84,7 @@ func (c *ConfigSite) IsSubdomains() bool {
func (c *ConfigSite) RssBlogURL(username string) string {
if c.IsSubdomains() {
return fmt.Sprintf("%s://%s.%s/rss", c.Protocol, username, c.Domain)
return fmt.Sprintf("//%s.%s/rss", username, c.Domain)
}
return fmt.Sprintf("/%s/rss", username)
@ -102,7 +100,7 @@ func (c *ConfigSite) HomeURL() string {
func (c *ConfigSite) ReadURL() string {
if c.IsSubdomains() {
return fmt.Sprintf("%s://%s/read", c.Protocol, c.Domain)
return fmt.Sprintf("https://%s/read", c.Domain)
}
return "/read"

View file

@ -1,38 +0,0 @@
package internal
import (
"time"
"git.sr.ht/~erock/wish/cms/db"
)
func deleteExpiredPosts(cfg *ConfigSite, dbpool db.DB) error {
cfg.Logger.Infof("checking for expired posts")
now := time.Now()
// delete posts that are older than three days
expired := now.AddDate(0, 0, -3)
posts, err := dbpool.FindPostsBeforeDate(&expired)
if err != nil {
return err
}
postIds := []string{}
for _, post := range posts {
postIds = append(postIds, post.ID)
}
cfg.Logger.Infof("deleteing (%d) expired posts", len(postIds))
err = dbpool.RemovePosts(postIds)
if err != nil {
return err
}
return nil
}
func CronDeleteExpiredPosts(cfg *ConfigSite, dbpool db.DB) {
for {
deleteExpiredPosts(cfg, dbpool)
time.Sleep(1 * time.Hour)
}
}