diff options
| author | jackyzha0 <[email protected]> | 2020-05-15 22:11:13 -0700 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2020-05-15 22:11:13 -0700 |
| commit | 0b37c8b715b8f5ebea4472c9e7d6104ca8adbdc8 (patch) | |
| tree | ab7fe8b5f50d2705fc3804562b66bc3dc773ef4b /frontend/src/components/renderers | |
| parent | Merge pull request #25 from jackyzha0/security (diff) | |
| download | ctrl-v-0b37c8b715b8f5ebea4472c9e7d6104ca8adbdc8.tar.xz ctrl-v-0b37c8b715b8f5ebea4472c9e7d6104ca8adbdc8.zip | |
add view raw button
Diffstat (limited to 'frontend/src/components/renderers')
| -rw-r--r-- | frontend/src/components/renderers/Raw.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/frontend/src/components/renderers/Raw.js b/frontend/src/components/renderers/Raw.js new file mode 100644 index 0000000..a8d0e31 --- /dev/null +++ b/frontend/src/components/renderers/Raw.js @@ -0,0 +1,56 @@ +import React from 'react'; +import { FetchPaste } from '../../helpers/httpHelper' + +class Raw extends React.Component { + + constructor(props) { + super(props); + this.state = { + content: '', + }; + } + + render() { + const styles = { + wordWrap: "break-word", + whiteSpace: "pre-wrap", + lineHeight: "initial", + fontSize: "0.8em", + padding: "0 1em" + } + + return ( + <pre style={styles}> + {this.state.content} + </pre> + ); + } + + componentDidMount() { + FetchPaste(this.props.hash) + .then((response) => { + const data = response.data + this.setState({ content: data.content }) + }).catch((error) => { + const resp = error.response + + // catch 401 unauth (password protected) + if (resp.status === 401) { + this.setState({ content: 'err: password protected' }) + return + } + + // some weird err + if (resp !== undefined) { + const errTxt = `${resp.statusText}: ${resp.data}` + this.setState({ content: errTxt }) + return + } + + // some weird err (e.g. network) + this.setState({ content: error }) + }) + } +} + +export default Raw
\ No newline at end of file |