Allow instance rebuild via interface

This commit is contained in:
Tom Wiesing 2022-10-12 16:27:07 +02:00
parent 5e7c5b2d23
commit 1e1d1a3cad
No known key found for this signature in database
2 changed files with 40 additions and 6 deletions

View file

@ -4,10 +4,11 @@
<title>Distillery Status Page - {{ .Info.Slug }}</title>
<h1 id="top">Distillery Status Page - {{ .Info.Slug }}</h1>
<p>
<a href=".">Reload</a>
<a href="/dis/index">Back to index</a>
</p>
<p>
<div>
<b>Slug:</b> <code>{{ .Info.Slug }}</code> <br />
<b>URL:</b> <a href="{{ .Info.URL }}" target="_blank" rel="noopener noreferrer">{{ .Info.URL }}</a> <br />
<hr />
@ -25,6 +26,11 @@
<hr />
<b>Created:</b> <code class="date">{{ .Instance.Created.Format "2006-01-02T15:04:05Z07:00" }}</code> <br />
<b>Last Rebuild:</b> <code class="date">{{ .Info.LastRebuild.Format "2006-01-02T15:04:05Z07:00" }}</code> <br />
<hr>
<p>
<button class="remote-action" data-action="rebuild" data-param="{{ .Instance.Slug }}" data-target="#rebuild" data-buffer="20">Rebuild</button>
<pre class="remote-action-out" id="rebuild"></pre>
</p>
<hr />
<b>FilesystemBase:</b> <code>{{ .Instance.FilesystemBase }}</code> <br />
<b>AutoBlindUpdateEnabled:</b> <code>{{ .Instance.AutoBlindUpdateEnabled }}</code> <br />
@ -64,12 +70,13 @@
</tbody>
</table>
<hr />
</p>
<p>
<button class="remote-action" data-action="snapshot" data-param="{{ .Instance.Slug }}" data-target="#snapshot" data-buffer="20">Take a snapshot</button>
<pre class="remote-action-out" id="snapshot"></pre>
</p>
</div>
<p>
<button class="remote-action" data-action="snapshot" data-param="{{ .Instance.Slug }}" data-target="#snapshot" data-buffer="20">Take a snapshot</button>
<pre class="remote-action-out" id="snapshot"></pre>
</p>
<footer>
Generated at <code>{{ .Time }}</code>

View file

@ -21,6 +21,12 @@ func (info *Info) serveSocket(conn httpx.WebSocketConnection) {
return
}
info.serverSocketSnapshot(string(slug.Bytes), info.socketWriter(conn))
case "rebuild":
slug, ok := <-conn.Read()
if !ok {
return
}
info.serverSocketRebuild(string(slug.Bytes), info.socketWriter(conn))
}
}
@ -61,3 +67,24 @@ func (info *Info) serverSocketSnapshot(slug string, writer *status.LineBuffer) {
stream.Println("Done")
}
func (info *Info) serverSocketRebuild(slug string, writer *status.LineBuffer) {
stream := stream.NewIOStream(writer, writer, nil, 0)
// get the wisski
wissKI, err := info.Instances.WissKI(slug)
if err != nil {
stream.EPrintln(err)
return
}
{
err := wissKI.Build(stream, true)
if err != nil {
stream.EPrintln(err)
return
}
}
stream.Println("Done")
}