diff --git a/app/router.go b/app/router.go index edd7c28b87..3f5982c8a3 100644 --- a/app/router.go +++ b/app/router.go @@ -6,6 +6,7 @@ import ( "net/http" "net/url" "strings" + "sync" "github.com/PuerkitoBio/ghost/handlers" "github.com/gorilla/mux" @@ -132,17 +133,35 @@ func RegisterReportPostHandler(a Adder, router *mux.Router) { })) } +var newVersion = struct { + sync.Mutex + *xfer.NewVersionInfo +}{} + +// NewVersion is called to expose new version information to /api +func NewVersion(version, downloadURL string) { + newVersion.Lock() + defer newVersion.Unlock() + newVersion.NewVersionInfo = &xfer.NewVersionInfo{ + Version: version, + DownloadURL: downloadURL, + } +} + func apiHandler(rep Reporter) CtxHandlerFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request) { report, err := rep.Report(ctx) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } + newVersion.Lock() + defer newVersion.Unlock() respondWith(w, http.StatusOK, xfer.Details{ - ID: UniqueID, - Version: Version, - Hostname: hostname.Get(), - Plugins: report.Plugins, + ID: UniqueID, + Version: Version, + Hostname: hostname.Get(), + Plugins: report.Plugins, + NewVersion: newVersion.NewVersionInfo, }) } } diff --git a/client/app/scripts/components/app.js b/client/app/scripts/components/app.js index e04b6571fc..93f4e5cc10 100644 --- a/client/app/scripts/components/app.js +++ b/client/app/scripts/components/app.js @@ -53,6 +53,7 @@ function getStateFromStores() { updatePaused: AppStore.isUpdatePaused(), updatePausedAt: AppStore.getUpdatePausedAt(), version: AppStore.getVersion(), + versionUpdate: AppStore.getVersionUpdate(), plugins: AppStore.getPlugins(), websocketClosed: AppStore.isWebsocketClosed() }; @@ -183,7 +184,9 @@ export default class App extends React.Component { activeOptions={this.state.activeTopologyOptions} /> -