Skip to content

Commit

Permalink
Add antimalware check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kudinov committed Sep 25, 2024
1 parent 7b03648 commit 4d3163b
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 3 deletions.
33 changes: 33 additions & 0 deletions frontend/app/modules/antimalware/AntimalwarePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { FC } from 'react'
import { observer } from 'mobx-react'
import styled from 'styled-components'
import { useStore } from '../../hooks/useStore'
import FeatureHeader from '../../components/FeatureHeader'
import Button from '../../components/Button'
import FeaturePage from '../../components/FeaturePage'

const Buttons = styled.div`
display: flex;
justify-content: space-between;
`

const AntimalwarePage: FC = () => {
const { antimalwareStore: store } = useStore()

const handleOpenRegularFile = () => store.openFile(false)

const handleOpenInfectedFile = () => store.openFile(true)

return (
<FeaturePage>
<FeatureHeader name="Антивирусная проверка файлов" />
Открыть файл
<Buttons>
<Button onClick={handleOpenRegularFile} id="submit" title="Обычный" icon="image" />
<Button onClick={handleOpenInfectedFile} id="submit" title="Зараженный" icon="bug_report" />
</Buttons>
</FeaturePage>
)
}

export default observer(AntimalwarePage)
35 changes: 35 additions & 0 deletions frontend/app/modules/antimalware/antimalware.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as SDK from '@expressms/smartapp-sdk'
import { RootStore } from '../../store/rootStore'
import { File, STATUS, StatusResponse } from '@expressms/smartapp-sdk/build/main/types'
import { makeAutoObservable } from 'mobx'

export class AntimalwareStore {
rootStore: RootStore

constructor(rootStore: RootStore) {
makeAutoObservable(this)

this.rootStore = rootStore
}

async openFile(infected: boolean): Promise<void> {
try {
const response = (await SDK.Bridge?.sendBotEvent({
method: 'get_example_file',
params: {
fileType: infected ? 'infected' : 'regular',
},
})) as StatusResponse

if (response.payload.status === STATUS.ERROR) {
this.rootStore.toastStore.showToast(`Ошибка получения файла ${response.payload}`)
return
}

const [file] = response.files as File[]
await SDK.openFile(file)
} catch (e) {
this.rootStore.toastStore.showToast(`Ошибка получения файла ${e?.message}`)
}
}
}
4 changes: 4 additions & 0 deletions frontend/app/modules/features-list/ClientFeatures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ const ClientFeatures: FC = () => {
<span className="material-icons">folder_off</span>
Очистка кеша статики
</StyledLink>
<StyledLink to="antimalware">
<span className="material-icons">bug_report</span>
Антивирусная проверка файлов
</StyledLink>
</>
)
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/modules/features-list/FeaturesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import MaxFileSizePage from '../max-file-size/MaxFileSizePage'
import SendBotCommandPage from '../send-bot-command/SendBotCommandPage'
import HideLogsPage from '../hide-logs/HideLogsPage'
import CleanCachePage from '../clean-cache/CleanCachePage'
import AntimalwarePage from '../antimalware/AntimalwarePage'

const Wrapper = styled.div`
margin-bottom: 30px;
Expand Down Expand Up @@ -106,6 +107,7 @@ const FeaturesListPage = () => {
<Route path="/send-bot-command" element={<SendBotCommandPage />} />
<Route path="/hide-log-data" element={<HideLogsPage />} />
<Route path="/clean-cache" element={<CleanCachePage />} />
<Route path="/antimalware" element={<AntimalwarePage />} />
</Routes>
</Wrapper>
{store.showMainLoader && <MainLoader />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const SendBotCommandPage: FC = () => {
<Input onChange={handleBodyChange} value={body} id="body" />
Данные
<Input onChange={handleDataChange} value={data} id="data" />
<Button onClick={handleSubmit} id="submit" title="Отправить" />
<Button onClick={handleSubmit} id="submit" title="Отправить" disabled={!userHuid || !body} />
<br />
<br />
{store.response && <JsonViewer data={store.response} id="response" />}
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/store/rootStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { MaxFileSizeStore } from '../modules/max-file-size/max-file-size.store'
import { SendBotCommandStore } from '../modules/send-bot-command/send-bot-command.store'
import { HideLogsStore } from '../modules/hide-logs/hide-logs.store'
import { CleanCacheStore } from '../modules/clean-cache/clean-cache.store'
import { AntimalwareStore } from '../modules/antimalware/antimalware.store'

export class RootStore {
appStore: AppStore
Expand Down Expand Up @@ -68,6 +69,7 @@ export class RootStore {
sendBotCommandStore: SendBotCommandStore
hideLogsStore: HideLogsStore
cleanCacheStore: CleanCacheStore
antimalwareStore: AntimalwareStore

constructor() {
this.appStore = new AppStore(this)
Expand Down Expand Up @@ -104,5 +106,6 @@ export class RootStore {
this.sendBotCommandStore = new SendBotCommandStore(this)
this.hideLogsStore = new HideLogsStore(this)
this.cleanCacheStore = new CleanCacheStore(this)
this.antimalwareStore = new AntimalwareStore(this)
}
}
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-feature-smartapp",
"version": "2.4.5",
"version": "2.5.0",
"description": "SmartApp with all features",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion frontend/smartapp-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"manifestVersion": "1.0.0",
"smartAppVersion": "",
"bundlePath": "",
"changeLog": "Блокировка кнопки отправки для AT"
"changeLog": "Антивирусная проверкуа файлов"
}

0 comments on commit 4d3163b

Please sign in to comment.