Skip to content
Permalink
Browse files

add update checks

includes cache of latest version and page to view if updates are
available with a link to the latest update's release notes and a link to
check for the latest update now, refreshing the cache manually.
  • Loading branch information
robjloranger committed Aug 29, 2019
1 parent 4d97856 commit eae4097677e5592ebd60b8733b7ca65c2d6681ef
Showing with 490 additions and 11 deletions.
  1. +32 −5 admin.go
  2. +4 −1 app.go
  3. +1 −0 config.ini.example
  4. +5 −1 config/config.go
  5. +1 −1 go.mod
  6. +5 −3 routes.go
  7. +315 −0 semver.go
  8. +23 −0 templates/user/admin/app-updates.tmpl
  9. +1 −0 templates/user/include/header.tmpl
  10. +103 −0 updates.go
@@ -13,16 +13,17 @@ package writefreely
import (
"database/sql"
"fmt"
"net/http"
"runtime"
"strconv"
"time"

"github.com/gogits/gogs/pkg/tool"
"github.com/gorilla/mux"
"github.com/writeas/impart"
"github.com/writeas/web-core/auth"
"github.com/writeas/web-core/log"
"github.com/writeas/writefreely/config"
"net/http"
"runtime"
"strconv"
"time"
)

var (
@@ -112,7 +113,6 @@ func handleViewAdminDash(app *App, u *User, w http.ResponseWriter, r *http.Reque
Message: r.FormValue("m"),
ConfigMessage: r.FormValue("cm"),
}

showUserPage(w, "admin", p)
return nil
}
@@ -451,3 +451,30 @@ func adminResetPassword(app *App, u *User, newPass string) error {
}
return nil
}

func handleViewAdminUpdates(app *App, u *User, w http.ResponseWriter, r *http.Request) error {
check := r.URL.Query().Get("check")

if check == "now" && app.cfg.App.UpdateChecks {
app.updates.CheckNow()
}

p := struct {
*UserPage
LastChecked string
LatestVersion string
LatestReleaseURL string
UpdateAvailable bool
}{
UserPage: NewUserPage(app, r, u, "Updates", nil),
}
if app.cfg.App.UpdateChecks {
p.LastChecked = app.updates.lastCheck.Format("January 2, 2006, 3:04 PM")
p.LatestVersion = app.updates.LatestVersion()
p.LatestReleaseURL = app.updates.ReleaseURL()
p.UpdateAvailable = app.updates.AreAvailable()
}

showUserPage(w, "app-updates", p)
return nil
}
5 app.go
@@ -30,7 +30,7 @@ import (
"github.com/gorilla/schema"
"github.com/gorilla/sessions"
"github.com/manifoldco/promptui"
"github.com/writeas/go-strip-markdown"
stripmd "github.com/writeas/go-strip-markdown"
"github.com/writeas/impart"
"github.com/writeas/web-core/auth"
"github.com/writeas/web-core/converter"
@@ -72,6 +72,7 @@ type App struct {
keys *key.Keychain
sessionStore *sessions.CookieStore
formDecoder *schema.Decoder
updates *updatesCache

timeline *localTimeline
}
@@ -346,6 +347,8 @@ func Initialize(apper Apper, debug bool) (*App, error) {
if err != nil {
return nil, fmt.Errorf("init keys: %s", err)
}
apper.App().InitUpdates()

apper.App().InitSession()

apper.App().InitDecoder()
@@ -23,4 +23,5 @@ max_blogs = 1
federation = true
public_stats = true
private = false
update_checks = true

@@ -12,8 +12,9 @@
package config

import (
"gopkg.in/ini.v1"
"strings"

"gopkg.in/ini.v1"
)

const (
@@ -89,6 +90,9 @@ type (

// Defaults
DefaultVisibility string `ini:"default_visibility"`

// Check for Updates
UpdateChecks bool `ini:"update_checks"`
}

// Config holds the complete configuration for running a writefreely instance
2 go.mod
@@ -67,7 +67,7 @@ require (
golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1 // indirect
golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 // indirect
golang.org/x/sys v0.0.0-20190209173611-3b5209105503 // indirect
golang.org/x/tools v0.0.0-20190208222737-3744606dbb67 // indirect
golang.org/x/tools v0.0.0-20190208222737-3744606dbb67
google.golang.org/appengine v1.4.0 // indirect
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c // indirect
gopkg.in/bufio.v1 v1.0.0-20140618132640-567b2bfa514e // indirect
@@ -11,13 +11,14 @@
package writefreely

import (
"net/http"
"path/filepath"
"strings"

"github.com/gorilla/mux"
"github.com/writeas/go-webfinger"
"github.com/writeas/web-core/log"
"github.com/writefreely/go-nodeinfo"
"net/http"
"path/filepath"
"strings"
)

// InitStaticRoutes adds routes for serving static files.
@@ -147,6 +148,7 @@ func InitRoutes(apper Apper, r *mux.Router) *mux.Router {
write.HandleFunc("/admin/page/{slug}", handler.Admin(handleViewAdminPage)).Methods("GET")
write.HandleFunc("/admin/update/config", handler.AdminApper(handleAdminUpdateConfig)).Methods("POST")
write.HandleFunc("/admin/update/{page}", handler.Admin(handleAdminUpdateSite)).Methods("POST")
write.HandleFunc("/admin/updates", handler.Admin(handleViewAdminUpdates)).Methods("GET")

// Handle special pages first
write.HandleFunc("/login", handler.Web(viewLogin, UserLevelNoneRequired))

0 comments on commit eae4097

Please sign in to comment.
You can’t perform that action at this time.