/** * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug * Copyright (c) * Released under the AGPL-3.0 License. */ import React, { useEffect } from 'react'; import { observer, useLocalStore } from 'mobx-react'; import { Card, Progress, Modal, Collapse, Steps } from 'antd'; import { ShrinkOutlined, CaretRightOutlined, LoadingOutlined, CloseOutlined } from '@ant-design/icons'; import OutView from './OutView'; import { http, X_TOKEN } from 'libs'; import styles from './index.module.less'; import store from './store'; function Ext1Console(props) { const outputs = useLocalStore(() => ({})); useEffect(props.request.mode === 'read' ? readDeploy : doDeploy, []) function readDeploy() { let socket; http.get(`/api/deploy/request/${props.request.id}/`) .then(res => { Object.assign(outputs, res.outputs) if (res.status === '2') { socket = _makeSocket() } }) return () => socket && socket.close() } function doDeploy() { let socket; http.post(`/api/deploy/request/${props.request.id}/`) .then(res => { Object.assign(outputs, res.outputs) socket = _makeSocket() }) return () => socket && socket.close() } function _makeSocket() { let index = 0; const token = props.request.id; const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const socket = new WebSocket(`${protocol}//${window.location.host}/api/ws/request/${token}/?x-token=${X_TOKEN}`); socket.onopen = () => socket.send(String(index)); socket.onmessage = e => { if (e.data === 'pong') { socket.send(String(index)) } else { index += 1; const {key, data, step, status} = JSON.parse(e.data); if (data !== undefined) outputs[key].data.push(data); if (step !== undefined) outputs[key].step = step; if (status !== undefined) outputs[key].status = status; } } return socket } function StepItem(props) { let icon = null; if (props.step === props.item.step && props.item.status !== 'error') { icon = } return } function switchMiniMode() { const value = store.tabModes[props.request.id]; store.tabModes[props.request.id] = !value } return store.tabModes[props.request.id] ? (
{props.request.name}
store.showConsole(props.request, true)}/>
{Object.values(outputs).map(item => ( ))}
) : ( store.showConsole(props.request, true)} title={[ {props.request.name},
]}> }> {Object.values(outputs).map((item, index) => ( {item.title} }> ))}
) } export default observer(Ext1Console)