From 25c9265f590a69272e6f2825e7dc20ff0815effb Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 16:17:50 +0530 Subject: [PATCH 01/20] feat: proper retrieval of user from local storage --- src/context/auth.tsx | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/context/auth.tsx b/src/context/auth.tsx index cb5c01df..2f0dcd5d 100644 --- a/src/context/auth.tsx +++ b/src/context/auth.tsx @@ -21,7 +21,7 @@ const initialState = { const AuthContext = createContext<{ state: InitialStateType; - dispatch: any; + dispatch: React.Dispatch; }>({ state: initialState, dispatch: () => null, @@ -46,38 +46,34 @@ const reducer = (state: InitialStateType, action: ActionType) => { const AuthProvider = ({ children }: AuthProviderProps) => { const [state, dispatch] = useReducer(reducer, initialState); - const navigate = useNavigate(); axios.defaults.withCredentials = true; - // get user info from local storage useEffect(() => { - dispatch({ - type: 'LOGIN', - payload: JSON.parse(window.localStorage.getItem('user') || 'null'), - }); + const storedUser = window.localStorage.getItem('user'); + if (storedUser) { + dispatch({ type: 'LOGIN', payload: JSON.parse(storedUser) }); + } }, []); axios.interceptors.response.use( function (response) { - // any status code that lies within the range of 2XX causes this function to trigger return response; }, function (error) { - // any status codes that fall outside the range of 2XX cause this function to trigger - let res = error.response; + const res = error.response; if (res.status === 401 && res.config && !res.config.__isRetryRequest) { return new Promise((resolve, reject) => { axios .get('http://localhost:8080/auth/logout') - .then((data) => { + .then(() => { console.log('/401 error > logout'); dispatch({ type: 'LOGOUT' }); window.localStorage.removeItem('user'); - navigate('/login'); // Replace router.push with navigate + navigate('/login'); }) .catch((err) => { - console.log('AXIOS INTERCEPTORS ERROR:', err); + console.error('AXIOS INTERCEPTORS ERROR:', err); reject(error); }); }); @@ -86,16 +82,12 @@ const AuthProvider = ({ children }: AuthProviderProps) => { } ); - // csrf - include tokens in the axios header every time a request is made useEffect(() => { const getCsrfToken = async () => { try { const { data } = await axios.get('http://localhost:8080/csrf-token'); - console.log('CSRF Token Response:', data); - if (data && data.csrfToken) { + if (data.csrfToken) { (axios.defaults.headers as any)['X-CSRF-TOKEN'] = data.csrfToken; - } else { - console.error('CSRF token not found in the response'); } } catch (error) { console.error('Error fetching CSRF token:', error); @@ -105,8 +97,10 @@ const AuthProvider = ({ children }: AuthProviderProps) => { }, []); return ( - {children} + + {children} + ); }; -export { AuthContext, AuthProvider }; +export { AuthContext, AuthProvider }; \ No newline at end of file From e847646fb6abe69723b0bf502c2231d0fa3e70f2 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 17:13:57 +0530 Subject: [PATCH 02/20] feat: api_key in user model --- server/src/models/User.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/src/models/User.ts b/server/src/models/User.ts index d5a93a7a..40eb2198 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -5,6 +5,7 @@ interface UserAttributes { id: number; email: string; password: string; + api_key?: string | null; } // Optional fields for creating a new user @@ -14,6 +15,7 @@ class User extends Model implements User public id!: number; public email!: string; public password!: string; + public api_key!: string | null; } User.init( @@ -35,6 +37,10 @@ User.init( type: DataTypes.STRING, allowNull: false, }, + api_key: { + type: DataTypes.STRING, + allowNull: true, + }, }, { sequelize, From 554d5f31d9b2f0fc079df83a741caee97fb5bc21 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 17:15:35 +0530 Subject: [PATCH 03/20] feat: gen api ket --- server/src/utils/api.ts | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 server/src/utils/api.ts diff --git a/server/src/utils/api.ts b/server/src/utils/api.ts new file mode 100644 index 00000000..cc1eb61f --- /dev/null +++ b/server/src/utils/api.ts @@ -0,0 +1,3 @@ +export const genAPIKey = (): string => { + return [...Array(30)].map(() => ((Math.random() * 36) | 0).toString(36)).join(''); +}; From 3c13b19fa471c5bf3763727260dccbdb1a119abe Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 17:21:34 +0530 Subject: [PATCH 04/20] feat: generate api ket --- server/src/routes/api.ts | 42 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 server/src/routes/api.ts diff --git a/server/src/routes/api.ts b/server/src/routes/api.ts new file mode 100644 index 00000000..9dd81595 --- /dev/null +++ b/server/src/routes/api.ts @@ -0,0 +1,42 @@ +import { Router, Request, Response } from 'express'; +import { genAPIKey } from '../utils/api'; +import User from '../models/User'; + +export const router = Router(); + +interface AuthenticatedRequest extends Request { + user?: { id: string }; +} + +router.get('/generate-api-key', async (req: AuthenticatedRequest, res) => { + try { + if (!req.user) { + return res.status(401).json({ ok: false, error: 'Unauthorized' }); + } + const user = await User.findByPk(req.user.id, { + attributes: { exclude: ['password'] }, + }); + + if (!user) { + return res.status(404).json({ message: 'User not found' }); + } + + // Check if user already has an API key + if (user.api_key) { + return res.status(400).json({ message: 'API key already exists' }); + } + + const apiKey = genAPIKey(); + + user.api_key = apiKey; + await user.save(); + + return res.status(200).json({ + message: 'API key generated successfully', + api_key: apiKey, + }); + } catch (error) { + return res.status(500).json({ message: 'Error generating API key', error }); + } + }); + \ No newline at end of file From d1819c9570bc043f1348c999c977d7d65835d128 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 17:21:56 +0530 Subject: [PATCH 05/20] chore: lint --- server/src/routes/api.ts | 44 +++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/server/src/routes/api.ts b/server/src/routes/api.ts index 9dd81595..cc417bfb 100644 --- a/server/src/routes/api.ts +++ b/server/src/routes/api.ts @@ -13,30 +13,28 @@ router.get('/generate-api-key', async (req: AuthenticatedRequest, res) => { if (!req.user) { return res.status(401).json({ ok: false, error: 'Unauthorized' }); } - const user = await User.findByPk(req.user.id, { + const user = await User.findByPk(req.user.id, { attributes: { exclude: ['password'] }, }); - - if (!user) { - return res.status(404).json({ message: 'User not found' }); - } - - // Check if user already has an API key - if (user.api_key) { - return res.status(400).json({ message: 'API key already exists' }); - } - - const apiKey = genAPIKey(); - - user.api_key = apiKey; - await user.save(); - - return res.status(200).json({ - message: 'API key generated successfully', - api_key: apiKey, - }); + + if (!user) { + return res.status(404).json({ message: 'User not found' }); + } + + if (user.api_key) { + return res.status(400).json({ message: 'API key already exists' }); + } + + const apiKey = genAPIKey(); + + user.api_key = apiKey; + await user.save(); + + return res.status(200).json({ + message: 'API key generated successfully', + api_key: apiKey, + }); } catch (error) { - return res.status(500).json({ message: 'Error generating API key', error }); + return res.status(500).json({ message: 'Error generating API key', error }); } - }); - \ No newline at end of file +}); From 91a69022cb8bac3c80d225a37789d258b1eb1c58 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 17:47:26 +0530 Subject: [PATCH 06/20] feat: requireAPIKey middleware --- server/src/middlewares/api.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 server/src/middlewares/api.ts diff --git a/server/src/middlewares/api.ts b/server/src/middlewares/api.ts new file mode 100644 index 00000000..c79529eb --- /dev/null +++ b/server/src/middlewares/api.ts @@ -0,0 +1,15 @@ +import { Request, Response } from "express"; +import User from "../models/User"; + +export const requireAPIKey = async (req: Request, res: Response, next: any) => { + const apiKey = req.headers['x-api-key']; + if (!apiKey) { + return res.status(401).json({ error: "API key is missing" }); + } + const user = await User.findOne({ where: { api_key: apiKey } }); + if (!user) { + return res.status(403).json({ error: "Invalid API key" }); + } + req.user = user; + next(); +}; From a2abc57642c84c73ef61da36bf919e6e28c83666 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 17:48:56 +0530 Subject: [PATCH 07/20] feat: generate api key --- server/src/routes/auth.ts | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index b1431c10..ff421d0d 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -3,6 +3,7 @@ import User from '../models/User'; import jwt from 'jsonwebtoken'; import { hashPassword, comparePassword } from '../utils/auth'; import { requireSignIn } from '../middlewares/auth'; +import { genAPIKey } from '../utils/api'; export const router = Router(); interface AuthenticatedRequest extends Request { @@ -88,4 +89,35 @@ router.get('/current-user', requireSignIn, async (req: AuthenticatedRequest, res console.error('Error in current-user route:', error); return res.status(500).json({ ok: false, error: `Could not fetch current user: ${error.message}` }); } -}); \ No newline at end of file +}); + +router.post('/generate-api-key', async (req: AuthenticatedRequest, res) => { + try { + if (!req.user) { + return res.status(401).json({ ok: false, error: 'Unauthorized' }); + } + const user = await User.findByPk(req.user.id, { + attributes: { exclude: ['password'] }, + }); + + if (!user) { + return res.status(404).json({ message: 'User not found' }); + } + + if (user.api_key) { + return res.status(400).json({ message: 'API key already exists' }); + } + + const apiKey = genAPIKey(); + + user.api_key = apiKey; + await user.save(); + + return res.status(200).json({ + message: 'API key generated successfully', + api_key: apiKey, + }); + } catch (error) { + return res.status(500).json({ message: 'Error generating API key', error }); + } +}); From 4b18bcd815e4901c1cba8ec6d9083815aa10c0d6 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 17:49:19 +0530 Subject: [PATCH 08/20] feat: pass requireSignIn middleware --- server/src/routes/auth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index ff421d0d..3effb0d2 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -91,7 +91,7 @@ router.get('/current-user', requireSignIn, async (req: AuthenticatedRequest, res } }); -router.post('/generate-api-key', async (req: AuthenticatedRequest, res) => { +router.post('/generate-api-key', requireSignIn, async (req: AuthenticatedRequest, res) => { try { if (!req.user) { return res.status(401).json({ ok: false, error: 'Unauthorized' }); From c13a0de5adde6b2b2586f94f451b5e202763ec75 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 22:39:39 +0530 Subject: [PATCH 09/20] feat: get all recordings --- server/src/api/index.ts | 62 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/server/src/api/index.ts b/server/src/api/index.ts index e1e4e5a4..bc023417 100644 --- a/server/src/api/index.ts +++ b/server/src/api/index.ts @@ -1,5 +1,57 @@ -const genAPIKey = () => { - return [...Array(30)] - .map((e) => ((Math.random() * 36) | 0).toString(36)) - .join(''); -}; \ No newline at end of file +import { deleteFile, readFile, readFiles, saveFile } from "../workflow-management/storage"; +import { Router, Request, Response } from 'express'; +export const router = Router(); + +const formatRecording = (recordingData: any) => { + const recordingMeta = recordingData.recording_meta; + const workflow = recordingData.recording.workflow || []; + const firstWorkflowStep = workflow[0]?.where?.url || ''; + + const inputParameters = [ + { + type: "string", + name: "originUrl", + label: "Origin URL", + required: true, + defaultValue: firstWorkflowStep, + }, + ]; + + return { + id: recordingMeta.id, + name: recordingMeta.name, + createdAt: new Date(recordingMeta.create_date).getTime(), + inputParameters, + }; + }; + + + router.get("/api/recordings", async (req: Request, res: Response) => { + try { + const fileContents = await readFiles('./../storage/recordings/'); + + const formattedRecordings = fileContents.map((fileContent: string) => { + const recordingData = JSON.parse(fileContent); + return formatRecording(recordingData); + }); + + const response = { + statusCode: 200, + messageCode: "success", + robots: { + totalCount: formattedRecordings.length, + items: formattedRecordings, + }, + }; + + res.status(200).json(response); + } catch (error) { + console.error("Error fetching recordings:", error); + res.status(500).json({ + statusCode: 500, + messageCode: "error", + message: "Failed to retrieve recordings", + }); + } + }); + \ No newline at end of file From 159c5262c749ad1c5054e2243617836aa748cb84 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 22:39:57 +0530 Subject: [PATCH 10/20] chore: lint --- server/src/api/index.ts | 89 ++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/server/src/api/index.ts b/server/src/api/index.ts index bc023417..c4ff87ea 100644 --- a/server/src/api/index.ts +++ b/server/src/api/index.ts @@ -6,52 +6,51 @@ const formatRecording = (recordingData: any) => { const recordingMeta = recordingData.recording_meta; const workflow = recordingData.recording.workflow || []; const firstWorkflowStep = workflow[0]?.where?.url || ''; - + const inputParameters = [ - { - type: "string", - name: "originUrl", - label: "Origin URL", - required: true, - defaultValue: firstWorkflowStep, - }, - ]; - - return { - id: recordingMeta.id, - name: recordingMeta.name, - createdAt: new Date(recordingMeta.create_date).getTime(), - inputParameters, - }; - }; - - - router.get("/api/recordings", async (req: Request, res: Response) => { - try { - const fileContents = await readFiles('./../storage/recordings/'); - - const formattedRecordings = fileContents.map((fileContent: string) => { - const recordingData = JSON.parse(fileContent); - return formatRecording(recordingData); - }); - - const response = { - statusCode: 200, - messageCode: "success", - robots: { - totalCount: formattedRecordings.length, - items: formattedRecordings, + { + type: "string", + name: "originUrl", + label: "Origin URL", + required: true, + defaultValue: firstWorkflowStep, }, - }; - - res.status(200).json(response); + ]; + + return { + id: recordingMeta.id, + name: recordingMeta.name, + createdAt: new Date(recordingMeta.create_date).getTime(), + inputParameters, + }; +}; + + +router.get("/api/recordings", async (req: Request, res: Response) => { + try { + const fileContents = await readFiles('./../storage/recordings/'); + + const formattedRecordings = fileContents.map((fileContent: string) => { + const recordingData = JSON.parse(fileContent); + return formatRecording(recordingData); + }); + + const response = { + statusCode: 200, + messageCode: "success", + robots: { + totalCount: formattedRecordings.length, + items: formattedRecordings, + }, + }; + + res.status(200).json(response); } catch (error) { - console.error("Error fetching recordings:", error); - res.status(500).json({ - statusCode: 500, - messageCode: "error", - message: "Failed to retrieve recordings", - }); + console.error("Error fetching recordings:", error); + res.status(500).json({ + statusCode: 500, + messageCode: "error", + message: "Failed to retrieve recordings", + }); } - }); - \ No newline at end of file +}); From a854894034adf7e6076a3f9ab4f1eda18172bc0a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 22:40:35 +0530 Subject: [PATCH 11/20] refactor: rename to record.ts --- server/src/api/{index.ts => record.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename server/src/api/{index.ts => record.ts} (100%) diff --git a/server/src/api/index.ts b/server/src/api/record.ts similarity index 100% rename from server/src/api/index.ts rename to server/src/api/record.ts From 1f15794ffcdc3ec84072bd72a3dc428d91e31ba4 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 22:41:46 +0530 Subject: [PATCH 12/20] feat: pass requireAPIKey middleware --- server/src/api/record.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index c4ff87ea..b7789335 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -1,5 +1,6 @@ import { deleteFile, readFile, readFiles, saveFile } from "../workflow-management/storage"; import { Router, Request, Response } from 'express'; +import { requireAPIKey } from "../middlewares/api"; export const router = Router(); const formatRecording = (recordingData: any) => { @@ -26,7 +27,7 @@ const formatRecording = (recordingData: any) => { }; -router.get("/api/recordings", async (req: Request, res: Response) => { +router.get("/api/recordings", requireAPIKey, async (req: Request, res: Response) => { try { const fileContents = await readFiles('./../storage/recordings/'); From be5f1ef40a347318c503e9455815962f336ee57c Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 22:56:44 +0530 Subject: [PATCH 13/20] feat: get robot by name --- server/src/api/record.ts | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index b7789335..adef7da6 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -55,3 +55,52 @@ router.get("/api/recordings", requireAPIKey, async (req: Request, res: Response) }); } }); + + +const formatRecordingById = (recordingData: any) => { + const recordingMeta = recordingData.recording_meta; + const workflow = recordingData.recording.workflow || []; + const firstWorkflowStep = workflow[0]?.where?.url || ''; + + const inputParameters = [ + { + type: "string", + name: "originUrl", + label: "Origin URL", + required: true, + defaultValue: firstWorkflowStep, + }, + ]; + + return { + id: recordingMeta.id, + name: recordingMeta.name, + createdAt: new Date(recordingMeta.create_date).getTime(), + inputParameters, + }; + }; + + router.get("/recordings/:fileName", requireAPIKey, async (req: Request, res: Response) => { + try { + const fileContent = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`); + + const recordingData = JSON.parse(fileContent); + const formattedRecording = formatRecording(recordingData); + + const response = { + statusCode: 200, + messageCode: "success", + robot: formattedRecording, + }; + + res.status(200).json(response); + } catch (error) { + console.error("Error fetching recording:", error); + res.status(404).json({ + statusCode: 404, + messageCode: "not_found", + message: `Recording with name "${req.params.fileName}" not found.`, + }); + } + }); + \ No newline at end of file From 2a62df4b42fcb1f8cb7755f2ad976acc52dd7e06 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 22:57:07 +0530 Subject: [PATCH 14/20] chore: lint --- server/src/api/record.ts | 77 ++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index adef7da6..49a45d60 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -61,46 +61,45 @@ const formatRecordingById = (recordingData: any) => { const recordingMeta = recordingData.recording_meta; const workflow = recordingData.recording.workflow || []; const firstWorkflowStep = workflow[0]?.where?.url || ''; - - const inputParameters = [ - { - type: "string", - name: "originUrl", - label: "Origin URL", - required: true, - defaultValue: firstWorkflowStep, - }, - ]; - - return { - id: recordingMeta.id, - name: recordingMeta.name, - createdAt: new Date(recordingMeta.create_date).getTime(), - inputParameters, - }; - }; - router.get("/recordings/:fileName", requireAPIKey, async (req: Request, res: Response) => { + const inputParameters = [ + { + type: "string", + name: "originUrl", + label: "Origin URL", + required: true, + defaultValue: firstWorkflowStep, + }, + ]; + + return { + id: recordingMeta.id, + name: recordingMeta.name, + createdAt: new Date(recordingMeta.create_date).getTime(), + inputParameters, + }; +}; + +router.get("/recordings/:fileName", requireAPIKey, async (req: Request, res: Response) => { try { - const fileContent = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`); - - const recordingData = JSON.parse(fileContent); - const formattedRecording = formatRecording(recordingData); - - const response = { - statusCode: 200, - messageCode: "success", - robot: formattedRecording, - }; - - res.status(200).json(response); + const fileContent = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`); + + const recordingData = JSON.parse(fileContent); + const formattedRecording = formatRecording(recordingData); + + const response = { + statusCode: 200, + messageCode: "success", + robot: formattedRecording, + }; + + res.status(200).json(response); } catch (error) { - console.error("Error fetching recording:", error); - res.status(404).json({ - statusCode: 404, - messageCode: "not_found", - message: `Recording with name "${req.params.fileName}" not found.`, - }); + console.error("Error fetching recording:", error); + res.status(404).json({ + statusCode: 404, + messageCode: "not_found", + message: `Recording with name "${req.params.fileName}" not found.`, + }); } - }); - \ No newline at end of file +}); From d59c8fa03cc81672ed1d8a42d4e5e9b161463c07 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 22:58:01 +0530 Subject: [PATCH 15/20] refactor: rename to robots --- server/src/api/record.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 49a45d60..90ab23eb 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -27,7 +27,7 @@ const formatRecording = (recordingData: any) => { }; -router.get("/api/recordings", requireAPIKey, async (req: Request, res: Response) => { +router.get("/api/robots", requireAPIKey, async (req: Request, res: Response) => { try { const fileContents = await readFiles('./../storage/recordings/'); @@ -80,7 +80,7 @@ const formatRecordingById = (recordingData: any) => { }; }; -router.get("/recordings/:fileName", requireAPIKey, async (req: Request, res: Response) => { +router.get("/api/robots/:fileName", requireAPIKey, async (req: Request, res: Response) => { try { const fileContent = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`); From 1330c740aa4928c90589fd32cca7dce289e3d649 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 22:58:32 +0530 Subject: [PATCH 16/20] fix: use formatRecordingById --- server/src/api/record.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 90ab23eb..13e3fbbd 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -85,7 +85,7 @@ router.get("/api/robots/:fileName", requireAPIKey, async (req: Request, res: Res const fileContent = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`); const recordingData = JSON.parse(fileContent); - const formattedRecording = formatRecording(recordingData); + const formattedRecording = formatRecordingById(recordingData); const response = { statusCode: 200, From e0d17f5e6737d9c3baa026895ad68627c54380e0 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Thu, 26 Sep 2024 22:59:37 +0530 Subject: [PATCH 17/20] chore: remove unused imports --- server/src/api/record.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/api/record.ts b/server/src/api/record.ts index 13e3fbbd..a7e39029 100644 --- a/server/src/api/record.ts +++ b/server/src/api/record.ts @@ -1,4 +1,4 @@ -import { deleteFile, readFile, readFiles, saveFile } from "../workflow-management/storage"; +import { readFile, readFiles } from "../workflow-management/storage"; import { Router, Request, Response } from 'express'; import { requireAPIKey } from "../middlewares/api"; export const router = Router(); From 5be7fe6bad639b5846a89951ef2d15a9bf97661a Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 27 Sep 2024 23:38:45 +0530 Subject: [PATCH 18/20] fix: format --- server/src/workflow-management/integrations/gsheet.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/workflow-management/integrations/gsheet.ts b/server/src/workflow-management/integrations/gsheet.ts index 3ce55341..11a84023 100644 --- a/server/src/workflow-management/integrations/gsheet.ts +++ b/server/src/workflow-management/integrations/gsheet.ts @@ -122,4 +122,3 @@ export const processGoogleSheetUpdates = async () => { await new Promise(resolve => setTimeout(resolve, 5000)); } }; - \ No newline at end of file From 2d886a825911ab43d6c2d0209f9b24b254c380c3 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Fri, 27 Sep 2024 23:39:30 +0530 Subject: [PATCH 19/20] feat: interpretation log --- src/components/molecules/InterpretationLog.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/molecules/InterpretationLog.tsx b/src/components/molecules/InterpretationLog.tsx index 3feda80c..1af5bc8c 100644 --- a/src/components/molecules/InterpretationLog.tsx +++ b/src/components/molecules/InterpretationLog.tsx @@ -25,7 +25,7 @@ interface InterpretationLogProps { setIsOpen: (isOpen: boolean) => void; } -export const InterpretationLog: React.FC = ({ isOpen, setIsOpen }) => { +export const InterpretationLog: React.FC = ({ isOpen, setIsOpen }) => { const [log, setLog] = useState(''); const [selectedOption, setSelectedOption] = useState('10'); const [customValue, setCustomValue] = useState(''); @@ -66,12 +66,12 @@ export const InterpretationLog: React.FC = ({ isOpen, se setLog((prevState) => prevState + '\n' + '---------- Serializable output data received ----------' + '\n' + JSON.stringify(data, null, 2) + '\n' + '--------------------------------------------------'); - + // Set table data if (Array.isArray(data)) { setTableData(data); } - + scrollLogToBottom(); }, [log, scrollLogToBottom]); @@ -104,7 +104,7 @@ export const InterpretationLog: React.FC = ({ isOpen, se // Extract columns dynamically from the first item of tableData const columns = tableData.length > 0 ? Object.keys(tableData[0]) : []; - + return (
: null} - - - - - Interpreter settings - - { - Object.keys(row.interpreterSettings).map((setting, index) => { - if (setting === 'params') { - return ( -
- - - Recording parameters - - { - Object.keys(row.interpreterSettings.params).map((param, index) => { - return ( - - {/*@ts-ignore*/} - {param}: {row.interpreterSettings.params[param].toString()} - - ) - }) - } -
- ) - } - return ( - - {/*@ts-ignore*/} - {setting}: {row.interpreterSettings[setting].toString()} - - ) - }) - } -
- - { !row || !row.serializableOutput || !row.binaryOutput - || (Object.keys(row.serializableOutput).length === 0 && Object.keys(row.binaryOutput).length === 0) - ? The output is empty. : null } - - {row.serializableOutput && - Object.keys(row.serializableOutput).length !== 0 && -
- - - Serializable output - { Object.keys(row.serializableOutput).map((key) => { - return ( -
- - {key}: - Download - - -
-                    {row.serializableOutput[key] ? JSON.stringify(row.serializableOutput[key], null, 2)
-                    : 'The output is empty.'}
-                  
-
-
- ) - })} -
- } - {row.binaryOutput - && Object.keys(row.binaryOutput).length !== 0 && -
- - - Binary output - { Object.keys(row.binaryOutput).map((key) => { - try { - const binaryBuffer = JSON.parse(row.binaryOutput[key].data); - const b64 = Buffer.from(binaryBuffer.data).toString('base64'); + + +
+ + {interpretationInProgress ? currentLog : row.log} + +
+
+ + {interpretationInProgress ? : null} + + + + + Interpreter settings + + { + Object.keys(row.interpreterSettings).map((setting, index) => { + if (setting === 'params') { return ( - - - {key}: - Download +
+ + + Recording parameters - {key} - + { + Object.keys(row.interpreterSettings.params).map((param, index) => { + return ( + + {/*@ts-ignore*/} + {param}: {row.interpreterSettings.params[param].toString()} + + ) + }) + } +
) - } catch (e) { - console.log(e) - return - {key}: The image failed to render - } + return ( + + {/*@ts-ignore*/} + {setting}: {row.interpreterSettings[setting].toString()} + + ) + }) + } +
+ + {!row || !row.serializableOutput || !row.binaryOutput + || (Object.keys(row.serializableOutput).length === 0 && Object.keys(row.binaryOutput).length === 0) + ? The output is empty. : null} + + {row.serializableOutput && + Object.keys(row.serializableOutput).length !== 0 && +
+ + + Serializable output + {Object.keys(row.serializableOutput).map((key) => { + return ( +
+ + {key}: + Download + + +
+                        {row.serializableOutput[key] ? JSON.stringify(row.serializableOutput[key], null, 2)
+                          : 'The output is empty.'}
+                      
+
+
+ ) })} -
- } -
+
+ } + {row.binaryOutput + && Object.keys(row.binaryOutput).length !== 0 && +
+ + + Binary output + {Object.keys(row.binaryOutput).map((key) => { + try { + const binaryBuffer = JSON.parse(row.binaryOutput[key].data); + const b64 = Buffer.from(binaryBuffer.data).toString('base64'); + return ( + + + {key}: + Download + + {key} + + ) + } catch (e) { + console.log(e) + return + {key}: The image failed to render + + } + })} +
+ } +
);