mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 07:08:10 +00:00
[web] fix contentviews, simplify related logic
This commit is contained in:
parent
c1ba6b6c21
commit
99eca6dfed
@ -1,7 +1,7 @@
|
||||
import React, { Component } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
import * as ContentViews from './ContentView/ContentViews'
|
||||
import { Edit, ViewServer, ViewImage } from './ContentView/ContentViews'
|
||||
import * as MetaViews from './ContentView/MetaViews'
|
||||
import ShowFullContentButton from './ContentView/ShowFullContentButton'
|
||||
|
||||
@ -16,7 +16,7 @@ ContentView.propTypes = {
|
||||
message: PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
ContentView.isContentTooLarge = msg => msg.contentLength > 1024 * 1024 * (ContentViews.ViewImage.matches(msg) ? 10 : 0.2)
|
||||
ContentView.isContentTooLarge = msg => msg.contentLength > 1024 * 1024 * (ViewImage.matches(msg) ? 10 : 0.2)
|
||||
|
||||
function ContentView(props) {
|
||||
const { flow, message, contentView, isDisplayLarge, displayLarge, onContentChange, readonly } = props
|
||||
@ -33,10 +33,15 @@ function ContentView(props) {
|
||||
return <MetaViews.ContentTooLarge {...props} onClick={displayLarge}/>
|
||||
}
|
||||
|
||||
const View = ContentViews[contentView] || ContentViews['ViewServer']
|
||||
let view;
|
||||
if(contentView === "Edit") {
|
||||
view = <Edit flow={flow} message={message} onChange={onContentChange}/>
|
||||
} else {
|
||||
view = <ViewServer flow={flow} message={message} contentView={contentView}/>
|
||||
}
|
||||
return (
|
||||
<div className="contentview">
|
||||
<View flow={flow} message={message} contentView={contentView} readonly={readonly} onChange={onContentChange}/>
|
||||
{view}
|
||||
<ShowFullContentButton/>
|
||||
</div>
|
||||
)
|
||||
|
@ -55,7 +55,7 @@ export default function withContentLoader(View) {
|
||||
return this.setState({request: undefined, content: ""})
|
||||
}
|
||||
|
||||
let requestUrl = MessageUtils.getContentURL(props.flow, props.message, (View.name == 'ViewServer' ? props.contentView : undefined))
|
||||
let requestUrl = MessageUtils.getContentURL(props.flow, props.message, props.contentView)
|
||||
|
||||
// We use XMLHttpRequest instead of fetch() because fetch() is not (yet) abortable.
|
||||
let request = new XMLHttpRequest();
|
||||
|
@ -2,7 +2,7 @@ import React, { Component } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
import { setContentViewDescription, setContent } from '../../ducks/ui/flow'
|
||||
import ContentLoader from './ContentLoader'
|
||||
import withContentLoader from './ContentLoader'
|
||||
import { MessageUtils } from '../../flow/utils'
|
||||
import CodeEditor from './CodeEditor'
|
||||
|
||||
@ -28,7 +28,7 @@ Edit.propTypes = {
|
||||
function Edit({ content, onChange }) {
|
||||
return <CodeEditor content={content} onChange={onChange}/>
|
||||
}
|
||||
Edit = ContentLoader(Edit)
|
||||
Edit = withContentLoader(Edit)
|
||||
|
||||
export class PureViewServer extends Component {
|
||||
static propTypes = {
|
||||
@ -94,6 +94,6 @@ const ViewServer = connect(
|
||||
setContentViewDescription,
|
||||
setContent
|
||||
}
|
||||
)(ContentLoader(PureViewServer))
|
||||
)(withContentLoader(PureViewServer))
|
||||
|
||||
export { Edit, ViewServer, ViewImage }
|
||||
|
Loading…
Reference in New Issue
Block a user