diff --git a/manifest.json b/manifest.json index 44ef11e..f60667c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "A8N", - "version": "1.0.3", + "version": "1.0.4", "icons": { "16": "icons/icon16.png", "64": "icons/icon32.png", diff --git a/package.json b/package.json index 0d034a4..108af0f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "a8n-extension", - "version": "1.0.3", + "version": "1.0.4", "private": true, "scripts": { "serve": "vite preview", @@ -24,7 +24,6 @@ "@types/react-dom": "^18.2.7", "@vitejs/plugin-react": "^4.0.4", "@webcomponents/custom-elements": "^1.6.0", - "axios": "^1.5.0", "npm-build-zip": "^1.0.3", "puppeteer-core": "^13.0.0", "react": "^18.2.0", diff --git a/src/App.tsx b/src/App.tsx index cdb8890..6d7611e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,7 +9,7 @@ import { CrxMessage } from './ts/interface/CrxInterface'; import { setIsPlaying } from './ts/reducers/process'; import { setSnackbarMessage } from './ts/reducers/dialog'; import { useCookies } from 'react-cookie'; -import { getUser } from './ts/api/Axios'; +import { fetchUser } from './ts/api/Fetch'; import { CircularProgress } from '@mui/material'; import Loading from './components/Loading'; @@ -37,7 +37,7 @@ export default () => { setCookie('SantaRosalia', result.SantaRosalia, { httpOnly : true }); - getUser().then(user => { + fetchUser().then(user => { dispatch(setUser(user)); dispatch(setIsSignIn(true)); setIsLoading(false); diff --git a/src/ServiceWorker.ts b/src/ServiceWorker.ts index 680a0f7..66f7f07 100644 --- a/src/ServiceWorker.ts +++ b/src/ServiceWorker.ts @@ -26,7 +26,7 @@ import { CrxInfo } from "@CrxClass/CrxInfo"; import { CrxBrowserOpenEvent } from "@CrxClass/CrxBrowserOpenEvent"; import { test } from "./ts/api/CrxPuppeteerTest"; import { Executor } from "./ts/class/Executor"; -import { getAccessToken } from "./ts/api/Axios"; +import { fetchProcess, putProcess } from "./ts/api/Fetch"; const crxInfo = new CrxInfo(); console.log('%c ______'+'%c ___'+'%c _______'+'%c ________ ','color:red','color:orange','color:yellow','color:green') @@ -87,22 +87,12 @@ export const onMessage = async (message : CrxMessage, sender : chrome.runtime.Me const { CRX_RECORDS } = await getItemFromLocalStorage([CRX_STATE.CRX_RECORDS]); const { user } = await chrome.storage.local.get('user'); - const result = await fetch(import.meta.env.VITE_HOME + 'api/process', { - method : 'PUT', - body : JSON.stringify({ - name : message.payload.name, - data : JSON.stringify(CRX_RECORDS), - userId : user.id - }) + const result = await putProcess(JSON.stringify({ + name : message.payload.name, + data : JSON.stringify(CRX_RECORDS), + userId : user.id + })); - - }); - - if (result.ok) { - - } else { - - } await closeWindow(crxInfo.RECORDING_TARGET_WINDOW_ID); break; } @@ -111,21 +101,12 @@ export const onMessage = async (message : CrxMessage, sender : chrome.runtime.Me break; } case CRX_COMMAND.CMD_START_PROCESS : { - const { user } = await chrome.storage.local.get('user'); - const result = await fetch(import.meta.env.VITE_HOME + 'api/process', { - method : 'POST', - body : JSON.stringify({ - id : message.payload.id, - userId : user.id - }) - - }) - if (result.ok) { - const body = await result.json(); - const data = JSON.parse(body.data); - new Executor(data); + const processId = message.payload.id + const result = await fetchProcess(processId); + if (result) { + new Executor(JSON.parse(result.data)); } else { - sendMessageToView(CRX_COMMAND.CMD_SET_SNACKBAR_MESSAGE, {message : '토큰 만료'}); + sendMessageToView(CRX_COMMAND.CMD_SET_SNACKBAR_MESSAGE, {message : '실행 오류'}); } } diff --git a/src/components/ProcessSelect.tsx b/src/components/ProcessSelect.tsx index eb0c6fa..4407f4b 100644 --- a/src/components/ProcessSelect.tsx +++ b/src/components/ProcessSelect.tsx @@ -1,22 +1,19 @@ import { getProcessId, getProcesses, setProcessId, setProcesses } from "@/ts/reducers/process" import { Divider, List, ListItem, ListItemButton, MenuItem, Select } from "@mui/material" import { useEffect, useState } from "react" -import { axios } from "@/ts/api/Axios" import { useAppDispatch, useAppSelector } from "@/ts/hooks" -import { getUser } from "@/ts/reducers/user" import ProcessItemButton from "./ProcessItemButton" +import { fetchProcesses } from "@/ts/api/Fetch" export default () => { const dispatch = useAppDispatch(); - const processId = useAppSelector(getProcessId); const processes = useAppSelector(getProcesses); - const user = useAppSelector(getUser); const setId = (id: string) => { dispatch(setProcessId(id)); } useEffect(() => { - axios.get(`/api/process`).then(result => { - dispatch(setProcesses(result.data)); + fetchProcesses().then(result => { + dispatch(setProcesses(result)); }); }, []); const processMenuItems = processes.map((v, i) =>{ diff --git a/src/ts/api/Axios.ts b/src/ts/api/Axios.ts deleted file mode 100644 index c813c65..0000000 --- a/src/ts/api/Axios.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Axios from 'axios'; - -export const getAccessToken = async () => { - const result = await chrome.storage.local.get('user'); - if (result.user && result.user.accessToken) return result.user.accessToken; - else return ''; -} - -export const axios = Axios.create({ - baseURL : import.meta.env.VITE_HOME, -}); - -export const getUser = async () => { - const res = await axios.get('/api/user'); - if (res.status !== 200) throw res.data; - return res.data; -} \ No newline at end of file diff --git a/src/ts/api/Fetch.ts b/src/ts/api/Fetch.ts new file mode 100644 index 0000000..ba78bb5 --- /dev/null +++ b/src/ts/api/Fetch.ts @@ -0,0 +1,61 @@ +import { FetchURL, Method } from '@CrxInterface'; + +class FetchLM { + baseURL: string + constructor () { + this.baseURL = import.meta.env.VITE_HOME; + } + async get (URL: FetchURL, parameter?: string) { + parameter = parameter ? `/${parameter}` : ''; + const response = await fetch(this.baseURL + URL + parameter, { + method : Method.GET, + }); + if (!response.ok) throw response; + return await response.json(); + } + async post (URL: FetchURL, body?: string) { + const response = await fetch(this.baseURL + URL, { + method : Method.POST, + body : body + }); + if (!response.ok) throw response; + return await response.json(); + } + async put (URL: FetchURL, body?: string) { + const response = await fetch(this.baseURL + URL, { + method : Method.PUT, + body : body + }); + if (!response.ok) throw response; + return await response.json(); + } + async delete (URL: FetchURL) { + const response = await fetch(this.baseURL + URL, { + method : Method.DELETE, + }); + if (!response.ok) throw response; + return await response.json(); + } +} + +export const fetchLM = new FetchLM(); + +export const fetchUser = async () => { + const res = await fetchLM.get(FetchURL.user); + return res; +} + +export const fetchProcesses = async () => { + const result = await fetchLM.get(FetchURL.process); + return result; +} + +export const fetchProcess = async (processId: string) => { + const result = await fetchLM.get(FetchURL.process, processId); + return result; +} + +export const putProcess = async (body: string) => { + const result = await fetchLM.put(FetchURL.process, body); + return result; +} \ No newline at end of file diff --git a/src/ts/interface/CrxInterface.ts b/src/ts/interface/CrxInterface.ts index 2ec8097..364facc 100644 --- a/src/ts/interface/CrxInterface.ts +++ b/src/ts/interface/CrxInterface.ts @@ -224,4 +224,17 @@ export interface ExecuteActionParameter { alertOption? : AlertOption dataScrapingOptionString? : string script?: string +} + +export enum Method { + GET = 'GET', + POST = 'POST', + PUT = 'PUT', + DELETE = 'DELETE' +} + +export enum FetchURL { + user = 'api/user', + process = 'api/process' + } \ No newline at end of file