Skip to content

Commit 78e878f

Browse files
committed
Show the date when the latest release has been done in the admin page
1 parent 2e0d576 commit 78e878f

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

src/client/components/Admin/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { Box, Tabs, Tab } from '@mui/material'
2+
import { Box, Tabs, Tab, Typography } from '@mui/material'
33
import { useTranslation } from 'react-i18next'
44
import {
55
Route,
@@ -11,6 +11,7 @@ import {
1111
} from 'react-router-dom'
1212
import { get } from 'lodash'
1313

14+
import { format } from 'date-fns'
1415
import ChatInstances from './ChatInstances'
1516
import Usage from './Usage'
1617
import Updater from './Updater'
@@ -35,8 +36,16 @@ const Admin = () => {
3536

3637
if (isLoading) return null
3738

39+
const lastRestart = format(new Date(user?.lastRestart), 'dd/MM/yyyy HH.mm.ss')
40+
3841
return (
3942
<Box>
43+
<Box m={2}>
44+
<Typography variant="body1">
45+
{t('admin:lastUpdate')}
46+
{lastRestart}
47+
</Typography>
48+
</Box>
4049
<Box mb={3}>
4150
<RouterTabs>
4251
<Tab

src/client/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface User {
1919
activeCourseIds: string[]
2020
ownCourses: string[]
2121
hasIamAccess?: boolean
22+
lastRestart: any
2223
}
2324

2425
export type Prompt = {

src/server/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import logger from './util/logger'
1212
import { connectToDatabase } from './db/connection'
1313
import seed from './db/seeders'
1414
import setupCron from './util/cron'
15+
import { updateLastRestart } from './util/lastRestart'
1516

1617
const app = express()
1718

@@ -33,6 +34,7 @@ if (inProduction || inStaging) {
3334
app.listen(PORT, async () => {
3435
await connectToDatabase()
3536
await seed()
37+
await updateLastRestart()
3638
if (true || inProduction || inStaging) {
3739
await setupCron()
3840
}

src/server/routes/user.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { User } from '../db/models'
1111
import { getUserStatus, getUsage } from '../chatInstances/usage'
1212
import { DEFAULT_TOKEN_LIMIT } from '../../config'
13+
import { getLastRestart } from '../util/lastRestart'
1314

1415
const userRouter = express.Router()
1516

@@ -42,10 +43,13 @@ userRouter.get('/login', async (req, res) => {
4243

4344
const usage = await getUsage(id)
4445

46+
const lastRestart = await getLastRestart()
47+
4548
return res.send({
4649
...user,
4750
usage,
4851
hasIamAccess: isAdmin || hasIamAccess,
52+
lastRestart,
4953
})
5054
})
5155

src/server/util/lastRestart.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as redis from './redis'
2+
3+
let lastRestart = null
4+
5+
export const updateLastRestart = async () => {
6+
const now = Date.now()
7+
lastRestart = now
8+
await redis.set('LAST_RESTART', now)
9+
}
10+
11+
export const getLastRestart = async () => {
12+
const str = (await redis.get('LAST_RESTART')) ?? lastRestart
13+
const int = Number(str)
14+
return new Date(int)
15+
}

0 commit comments

Comments
 (0)