refactor: ts issue mis-used file from client in server
This commit is contained in:
parent
7e1af1069c
commit
079e1e1bc7
7 changed files with 29 additions and 25 deletions
|
@ -3,7 +3,7 @@
|
|||
"version": "0.8.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"copy:migrations": "cp -r src/server/migrations dist/migrations",
|
||||
"copy:migrations": "mkdir -p dist/migrations && cp -r src/server/migrations dist/migrations",
|
||||
"prisma:pull": "prisma db pull",
|
||||
"test": "dotenv -e .env.test -- jest --colors",
|
||||
"test:client": "jest --colors --selectProjects client --",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/* tslint:disable */
|
||||
|
||||
/**
|
||||
* Mock Service Worker (0.49.1).
|
||||
* Mock Service Worker (1.0.1).
|
||||
* @see https://github.com/mswjs/msw
|
||||
* - Please do NOT modify this file.
|
||||
* - Please do NOT serve this file on production.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React, { ReactElement, useEffect, useRef } from 'react';
|
||||
import router from 'next/router';
|
||||
import { SystemStatus, useSystemStore } from '../../../state/systemStore';
|
||||
import { useSystemStore } from '../../../state/systemStore';
|
||||
import { StatusScreen } from '../../StatusScreen';
|
||||
|
||||
interface IProps {
|
||||
|
@ -13,29 +13,29 @@ export const StatusProvider: React.FC<IProps> = ({ children }) => {
|
|||
|
||||
useEffect(() => {
|
||||
// If previous was not running and current is running, we need to refresh the page
|
||||
if (status === SystemStatus.RUNNING && s.current !== SystemStatus.RUNNING) {
|
||||
if (status === 'RUNNING' && s.current !== 'RUNNING') {
|
||||
router.reload();
|
||||
}
|
||||
if (status === SystemStatus.RUNNING) {
|
||||
s.current = SystemStatus.RUNNING;
|
||||
if (status === 'RUNNING') {
|
||||
s.current = 'RUNNING';
|
||||
}
|
||||
if (status === SystemStatus.RESTARTING) {
|
||||
s.current = SystemStatus.RESTARTING;
|
||||
if (status === 'RESTARTING') {
|
||||
s.current = 'RESTARTING';
|
||||
}
|
||||
if (status === SystemStatus.UPDATING) {
|
||||
s.current = SystemStatus.UPDATING;
|
||||
if (status === 'UPDATING') {
|
||||
s.current = 'UPDATING';
|
||||
}
|
||||
}, [status, s]);
|
||||
|
||||
if (s.current === SystemStatus.LOADING) {
|
||||
if (s.current === 'LOADING') {
|
||||
return <StatusScreen title="" subtitle="" />;
|
||||
}
|
||||
|
||||
if (s.current === SystemStatus.RESTARTING) {
|
||||
if (s.current === 'RESTARTING') {
|
||||
return <StatusScreen title="Your system is restarting..." subtitle="Please do not refresh this page" />;
|
||||
}
|
||||
|
||||
if (s.current === SystemStatus.UPDATING) {
|
||||
if (s.current === 'UPDATING') {
|
||||
return <StatusScreen title="Your system is updating..." subtitle="Please do not refresh this page" />;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import create from 'zustand';
|
||||
|
||||
export enum SystemStatus {
|
||||
RUNNING = 'RUNNING',
|
||||
RESTARTING = 'RESTARTING',
|
||||
UPDATING = 'UPDATING',
|
||||
LOADING = 'LOADING',
|
||||
}
|
||||
const SYSTEM_STATUS = {
|
||||
RUNNING: 'RUNNING',
|
||||
RESTARTING: 'RESTARTING',
|
||||
UPDATING: 'UPDATING',
|
||||
LOADING: 'LOADING',
|
||||
} as const;
|
||||
export type SystemStatus = (typeof SYSTEM_STATUS)[keyof typeof SYSTEM_STATUS];
|
||||
|
||||
type Store = {
|
||||
status: SystemStatus;
|
||||
|
@ -15,7 +16,7 @@ type Store = {
|
|||
};
|
||||
|
||||
export const useSystemStore = create<Store>((set) => ({
|
||||
status: SystemStatus.RUNNING,
|
||||
status: 'RUNNING',
|
||||
version: { current: '0.0.0', latest: '0.0.0' },
|
||||
setStatus: (status: SystemStatus) => set((state) => ({ ...state, status })),
|
||||
setVersion: (version: { current: string; latest?: string }) => set((state) => ({ ...state, version })),
|
||||
|
|
|
@ -16,7 +16,7 @@ function MyApp({ Component, pageProps }: AppProps) {
|
|||
const { setDarkMode } = useUIStore();
|
||||
const { setStatus, setVersion } = useSystemStore();
|
||||
|
||||
trpc.system.status.useQuery(undefined, { networkMode: 'online', onSuccess: (d) => setStatus(d.status || SystemStatus.RUNNING) });
|
||||
trpc.system.status.useQuery(undefined, { networkMode: 'online', onSuccess: (d) => setStatus((d.status as SystemStatus) || 'RUNNING') });
|
||||
const version = trpc.system.getVersion.useQuery(undefined, { networkMode: 'online' });
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -19,7 +19,7 @@ export const EVENT_TYPES = {
|
|||
SYSTEM_INFO: 'system_info',
|
||||
} as const;
|
||||
|
||||
export type EventType = typeof EVENT_TYPES[keyof typeof EVENT_TYPES];
|
||||
export type EventType = (typeof EVENT_TYPES)[keyof typeof EVENT_TYPES];
|
||||
|
||||
type SystemEvent = {
|
||||
id: string;
|
||||
|
@ -35,7 +35,7 @@ const EVENT_STATUS = {
|
|||
WAITING: 'waiting',
|
||||
} as const;
|
||||
|
||||
type EventStatus = typeof EVENT_STATUS[keyof typeof EVENT_STATUS]; // 'running' | 'success' | 'error' | 'waiting';
|
||||
type EventStatus = (typeof EVENT_STATUS)[keyof typeof EVENT_STATUS];
|
||||
|
||||
const WATCH_FILE = '/runtipi/state/events';
|
||||
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import semver from 'semver';
|
||||
import { z } from 'zod';
|
||||
import fetch from 'node-fetch';
|
||||
import { readJsonFile } from '../../common/fs.helpers';
|
||||
import { EventDispatcher } from '../../core/EventDispatcher';
|
||||
import { Logger } from '../../core/Logger';
|
||||
import TipiCache from '../../core/TipiCache';
|
||||
import { getConfig, setConfig } from '../../core/TipiConfig';
|
||||
import { SystemStatus } from '../../../client/state/systemStore';
|
||||
|
||||
const SYSTEM_STATUS = ['UPDATING', 'RESTARTING', 'RUNNING'] as const;
|
||||
type SystemStatus = (typeof SYSTEM_STATUS)[keyof typeof SYSTEM_STATUS];
|
||||
|
||||
const systemInfoSchema = z.object({
|
||||
cpu: z.object({
|
||||
|
@ -43,7 +46,7 @@ export class SystemServiceClass {
|
|||
|
||||
if (!version) {
|
||||
const data = await fetch('https://api.github.com/repos/meienberger/runtipi/releases/latest');
|
||||
const release = await data.json();
|
||||
const release = (await data.json()) as { name: string };
|
||||
|
||||
version = release.name.replace('v', '');
|
||||
await this.cache.set('latestVersion', version?.replace('v', '') || '', 60 * 60);
|
||||
|
|
Loading…
Add table
Reference in a new issue