@@ -6,12 +6,17 @@ import { HttpCode, HttpError } from "../../common/http"
66import { Options } from "../../common/util"
77import { HttpProvider , HttpProviderOptions , HttpResponse , Route } from "../http"
88import { ApiHttpProvider } from "./api"
9+ import { UpdateHttpProvider } from "./update"
910
1011/**
1112 * Top-level and fallback HTTP provider.
1213 */
1314export class MainHttpProvider extends HttpProvider {
14- public constructor ( options : HttpProviderOptions , private readonly api : ApiHttpProvider ) {
15+ public constructor (
16+ options : HttpProviderOptions ,
17+ private readonly api : ApiHttpProvider ,
18+ private readonly update : UpdateHttpProvider ,
19+ ) {
1520 super ( options )
1621 }
1722
@@ -77,13 +82,14 @@ export class MainHttpProvider extends HttpProvider {
7782 response . content = response . content
7883 . replace ( / { { COMMIT} } / g, this . options . commit )
7984 . replace ( / { { BASE} } / g, this . base ( route ) )
80- . replace ( / { { APP_ L I S T : R U N N I N G } } / g, this . getAppRows ( recent . running ) )
85+ . replace ( / { { UPDATE:N A M E } } / , await this . getUpdate ( ) )
86+ . replace ( / { { APP_ L I S T : R U N N I N G } } / , this . getAppRows ( recent . running ) )
8187 . replace (
82- / { { APP_ L I S T : E D I T O R S } } / g ,
88+ / { { APP_ L I S T : E D I T O R S } } / ,
8389 this . getAppRows ( apps . filter ( ( app ) => app . categories && app . categories . includes ( "Editor" ) ) ) ,
8490 )
8591 . replace (
86- / { { APP_ L I S T : O T H E R } } / g ,
92+ / { { APP_ L I S T : O T H E R } } / ,
8793 this . getAppRows ( apps . filter ( ( app ) => ! app . categories || ! app . categories . includes ( "Editor" ) ) ) ,
8894 )
8995 return response
@@ -94,8 +100,8 @@ export class MainHttpProvider extends HttpProvider {
94100 response . content = response . content
95101 . replace ( / { { COMMIT} } / g, this . options . commit )
96102 . replace ( / { { BASE} } / g, this . base ( route ) )
97- . replace ( / { { APP_ N A M E } } / g , name )
98- . replace ( / " { { O P T I O N S } } " / g , `'${ JSON . stringify ( options ) } '` )
103+ . replace ( / { { APP_ N A M E } } / , name )
104+ . replace ( / " { { O P T I O N S } } " / , `'${ JSON . stringify ( options ) } '` )
99105 return response
100106 }
101107
@@ -108,8 +114,8 @@ export class MainHttpProvider extends HttpProvider {
108114 }
109115
110116 private getAppRow ( app : Application ) : string {
111- return `<div class="app -row">
112- <a class="open " href=".${ app . path } ">
117+ return `<div class="block -row">
118+ <a class="item -row -link " href=".${ app . path } ">
113119 ${
114120 app . icon
115121 ? `<img class="icon" src="data:image/png;base64,${ app . icon } "></img>`
@@ -127,4 +133,46 @@ export class MainHttpProvider extends HttpProvider {
127133 }
128134 </div>`
129135 }
136+
137+ private async getUpdate ( ) : Promise < string > {
138+ if ( ! this . update . enabled ) {
139+ return "Updates are disabled"
140+ }
141+
142+ const humanize = ( time : number ) : string => {
143+ const d = new Date ( time )
144+ const pad = ( t : number ) : string => ( t < 10 ? "0" : "" ) + t
145+ return (
146+ `${ d . getFullYear ( ) } -${ pad ( d . getMonth ( ) + 1 ) } -${ pad ( d . getDate ( ) ) } ` +
147+ ` ${ pad ( d . getHours ( ) ) } :${ pad ( d . getMinutes ( ) ) } `
148+ )
149+ }
150+
151+ const update = await this . update . getUpdate ( )
152+ if ( this . update . isLatestVersion ( update ) ) {
153+ return `<div class="block-row">
154+ <div class="item">
155+ ${ update . version }
156+ <div class="sub">Up to date</div>
157+ </div>
158+ <div class="item">
159+ ${ humanize ( update . checked ) }
160+ <a class="sub -link" href="./update/check">Check now</a>
161+ </div>
162+ <div class="item" >Current: ${ this . update . currentVersion } </div>
163+ </div>`
164+ }
165+
166+ return `<div class="block-row">
167+ <a class="item -link" href="./update">
168+ ${ update . version }
169+ <div class="sub">Out of date</div>
170+ </a>
171+ <div class="item">
172+ ${ humanize ( update . checked ) }
173+ <a class="sub -link" href="./update/check">Check now</a>
174+ </div>
175+ <div class="item" >Current: ${ this . update . currentVersion } </div>
176+ </div>`
177+ }
130178}
0 commit comments