diff --git a/frontend/src/api/camera.js b/frontend/src/api/camera.js deleted file mode 100644 index 323467eb..00000000 --- a/frontend/src/api/camera.js +++ /dev/null @@ -1,53 +0,0 @@ -import axios from "./index"; -import { - download, - set, - setErrors, - setLoading, setLoadingFiles, -} from "../redux/cameraSlice"; -import {handleErrors} from "./errors"; - - -class CameraApi { - static createFolder = (token, folder) => dispatch => { - dispatch(setLoadingFiles(folder)); - axios - .put(`${base}/create-folder/?folder=${folder}`, {}, { headers: { Authorization: token } }) - .then((response) => dispatch(set(response.data))) - .catch((err) => handleErrors(err, dispatch, setErrors)); - }; - static deleteFolder = (token, folder) => dispatch => { - dispatch(setLoadingFiles(folder)); - axios - .delete(`${base}/delete-folder/?folder=${folder}`, { headers: { Authorization: token } }) - .then((response) => dispatch(set(response.data))) - .catch((err) => handleErrors(err, dispatch, setErrors)); - }; - static deleteImage = (token, filename) => dispatch => { - dispatch(setLoadingFiles(filename)); - axios - .delete(`${base}/delete/?filename=${filename}`, { headers: { Authorization: token } }) - .then((response) => dispatch(set(response.data))) - .catch((err) => handleErrors(err, dispatch, setErrors)); - }; - static downloadImage = (token, filename) => dispatch => { - dispatch(setLoadingFiles(filename)); - axios - .put(`${base}/download/?filename=${filename}`, {}, { headers: { Authorization: token } }) - .then((response) => { - dispatch(download({data: response.data, filename})) - }) - .catch((err) => handleErrors(err, dispatch, setErrors)); - }; - static getList = (token, path = null) => (dispatch) => { - dispatch(setLoading(true)); - axios - .get(`${base}/` + (path ? `?path=${path}` : ""), { headers: { Authorization: token } }) - .then((response) => dispatch(set(response.data))) - .catch((err) => handleErrors(err, dispatch, setErrors)); - }; -} - -const base = "camera"; - -export default CameraApi; diff --git a/frontend/src/app/AppRoutes.js b/frontend/src/app/AppRoutes.js index 6ffa9322..2e4d2331 100644 --- a/frontend/src/app/AppRoutes.js +++ b/frontend/src/app/AppRoutes.js @@ -6,7 +6,6 @@ import { useSelector } from "react-redux"; const Dashboard = lazy(() => import('./dashboard/Dashboard')); const Bots = lazy(() => import('./bots/Bots')); -const Camera = lazy(() => import ("./apps/Camera")); const Commands = lazy(() => import('./commands/Commands')); const Crons = lazy(() => import('./commands/crons/Crons')); const Devices = lazy(() => import('./apps/devices/Devices')); @@ -67,7 +66,6 @@ const AppRoutes = () => { {user?.is_staff && } - {user?.is_staff && } {user?.is_staff && } {user?.is_staff && } {user?.is_staff && } diff --git a/frontend/src/app/apps/Camera.js b/frontend/src/app/apps/Camera.js deleted file mode 100644 index 29502706..00000000 --- a/frontend/src/app/apps/Camera.js +++ /dev/null @@ -1,165 +0,0 @@ -import React, { useEffect, useState } from 'react' -import { useDispatch, useSelector } from "react-redux"; -import {BallTriangle, Circles } from "react-loader-spinner"; -import CameraApi from "../../api/camera"; -import { setMessagesOpen } from "../../redux/cameraSlice"; -import Errors from "../shared/Errors"; -import Alert from "react-bootstrap/Alert"; - -export const Camera = () => { - const dispatch = useDispatch(); - const token = useSelector((state) => state.auth.token) - const { errors, loading, loadingFiles, messages, messagesOpen, path, results } = useSelector(state => state.camera) - - useEffect(() => { - !results && dispatch(CameraApi.getList(token)); - }, []); - - useEffect(() => {dispatch(setMessagesOpen(Boolean(messages)))}, [messages]) - - const [currentImage, setCurrentImage] = useState(null) - const setImage = filename => { - const base = process.env.NODE_ENV === 'development' - ? "http://localhost:5678" - : `https://${window.location.hostname}` - setCurrentImage({ - name: filename, - url: `${base}/static/media/${path}/${filename}`}) - const video = document.getElementById("video"); - if (video) video.load() - } - - return ( -
-
-

Camera

- -
-
-
-
-
-

- Available Images -
- -
-
- Storage -
- -

- - {messagesOpen && dispatch(setMessagesOpen(false))}> - {messages[0]} - {messages?.[1]} - } -
    - { - loading ? - : <> - { - path &&
  • dispatch(CameraApi.getList(token, path.split("/").slice(0, path.split("/").length - 1).join("/")))}>..
  • - } - { - !results?.length &&
  • No files found
  • - } - { - results?.map(result => -
  • - - result.is_file - ? result.is_local ? setImage(result.name) : null - : result.is_local ? dispatch(CameraApi.getList(token, result.name)) : null} - > - {" "} - {result.name}{result.is_file ? ` [${result.size} MB] ` : " "} - - { - loadingFiles?.includes(result.is_file && path ? `${path}/${result.name}` : result.name) - ? - : - !result.is_local - ? result.is_file - ? dispatch(CameraApi.downloadImage(token, `${path}${path ? "/": ""}${result.name}`)) - : dispatch(CameraApi.createFolder(token, result.name)) - : result.is_file - ? dispatch(CameraApi.deleteImage(token, `${path}${path ? "/": ""}${result.name}`)) - : dispatch(CameraApi.deleteFolder(token, result.name))} - /> - } -
  • ) - } - - } -
-
-
-
-
-
-
-

{currentImage?.name}

- { - currentImage?.name.endsWith(".jpg") - ? {currentImage?.name} - : currentImage?.name.endsWith(".mp4") - ? - : null - } -
-
-
-
-
- ) -} - -export default Camera diff --git a/frontend/src/app/shared/Sidebar.js b/frontend/src/app/shared/Sidebar.js index a30300dc..ffe71358 100644 --- a/frontend/src/app/shared/Sidebar.js +++ b/frontend/src/app/shared/Sidebar.js @@ -254,11 +254,6 @@ const Sidebar = () => {
    -
  • - - Camera - -
  • Devices diff --git a/frontend/src/redux/cameraSlice.js b/frontend/src/redux/cameraSlice.js deleted file mode 100644 index 9bfe3122..00000000 --- a/frontend/src/redux/cameraSlice.js +++ /dev/null @@ -1,51 +0,0 @@ -import { createSlice } from "@reduxjs/toolkit"; - -export const cameraSlice = createSlice({ - name: "livecam", - initialState: { - errors: null, - loading: false, - loadingFiles: null, - messages: null, - messagesOpen: false, - path: null, - results: null, - }, - reducers: { - download: (state, action) => { - state.errors = null - state.loading = false - state.loadingFiles = state.loadingFiles?.filter(file => file !== action.payload.filename) - state.path = action.payload.data.path; - state.results = action.payload.data.results; - }, - set: (state, action) => { - state.errors = null - state.loading = false - state.loadingFiles = null - state.path = action.payload.path; - state.results = action.payload.results; - }, - setMessagesOpen: (state, action) => { - state.messagesOpen = action.payload - }, - setErrors: (state, action) => { - state.errors = action.payload; - state.loading = false; - state.loadingFiles = null; - }, - setLoading: (state, action) => {state.loading = action.payload}, - setLoadingFiles: (state, action) => { - state.loadingFiles = - !state.loadingFiles - ? [action.payload] - : [...state.loadingFiles, action.payload]; - - } - }, -}); - -export const { download, set, setErrors, setLoading, setLoadingFiles, setMessagesOpen, upload } = - cameraSlice.actions; - -export default cameraSlice.reducer; diff --git a/frontend/src/redux/store.js b/frontend/src/redux/store.js index 5d750718..eaf62c21 100644 --- a/frontend/src/redux/store.js +++ b/frontend/src/redux/store.js @@ -2,7 +2,6 @@ import { configureStore } from "@reduxjs/toolkit"; import accountsReducer from "../redux/accountsSlice"; import authReducer from "../redux/authSlice"; import botReducer from "../redux/botsSlice"; -import cameraReducer from "./cameraSlice"; import categoriesReducer from "./categoriesSlice"; import creditReducer from "../redux/creditSlice" import commandsReducer from "../redux/commandsSlice" @@ -33,7 +32,6 @@ export default configureStore({ accounts: accountsReducer, auth: authReducer, bots: botReducer, - camera: cameraReducer, categories: categoriesReducer, commands: commandsReducer, credit: creditReducer,