소스 검색

refactor: ts issue mis-used file from client in server

Nicolas Meienberger 2 년 전
부모
커밋
079e1e1bc7

+ 1 - 1
packages/dashboard/package.json

@@ -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 --",

+ 1 - 1
packages/dashboard/public/mockServiceWorker.js

@@ -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.

+ 11 - 11
packages/dashboard/src/client/components/hoc/StatusProvider/StatusProvider.tsx

@@ -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" />;
   }
 

+ 8 - 7
packages/dashboard/src/client/state/systemStore.ts

@@ -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 })),

+ 1 - 1
packages/dashboard/src/pages/_app.tsx

@@ -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(() => {

+ 2 - 2
packages/dashboard/src/server/core/EventDispatcher/EventDispatcher.ts

@@ -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';
 

+ 5 - 2
packages/dashboard/src/server/services/system/system.service.ts

@@ -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);