Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
feat: ipfs support
Browse files Browse the repository at this point in the history
  • Loading branch information
sven committed Dec 22, 2022
1 parent d5706f3 commit 315c8b6
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/Texts.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Texts extends React.Component {

const data = JSON.parse(message)
const replySurb = message.replySurb

if (!data.hasOwnProperty('error')) {
let userData = he.decode(data['text'])
// Decrypt if text is encrypted
Expand Down Expand Up @@ -256,6 +256,8 @@ class Texts extends React.Component {
} else {
this.setState({
text: he.decode(data['error']),
isDataRetrieved: true,
isPasteRetrieved: true
})
}
}
Expand Down
41 changes: 31 additions & 10 deletions src/UserInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ class UserInput extends React.Component {
urlId: null,
buttonSendClick: false,
burnChecked: false,
burnCheckedEnable: true,
textReceived: null,
//urlIdGet: null,
buttonGetClick: false,
files: null,
isFileAttached: false,
isPrivate: true,
isIpfs: false
}

this.files = null
Expand Down Expand Up @@ -106,7 +108,7 @@ class UserInput extends React.Component {

displayReceived(message) {
const content = message

if (content.length > 0) {
if (content.toLowerCase().includes('error')) {
this.setState({
Expand All @@ -126,22 +128,18 @@ class UserInput extends React.Component {
buttonGetClick: false,
})
} else {
if (!this.isJson(content)) {

this.setState({
urlId: content,
urlId: JSON.parse(content),
buttonSendClick: false,
})

window.scrollTo({
top: 0,
behavior: 'smooth',
})
} else {
this.setState({
textReceived: JSON.parse(content),
buttonGetClick: false,
})
}


}
}
}
Expand Down Expand Up @@ -306,6 +304,7 @@ class UserInput extends React.Component {
private: this.state.isPrivate,
burn: this.state.burnChecked,
encParams: this.state.isPrivate ? encrypted[1] : '',
ipfs: this.state.isIpfs
},
}

Expand Down Expand Up @@ -490,7 +489,7 @@ class UserInput extends React.Component {
}}
>
<Tooltip
title="message will be deleted when read"
title="message will be deleted when read. Not compatible with IPFS upload"
size="sm"
placement="bottom"
>
Expand All @@ -500,8 +499,10 @@ class UserInput extends React.Component {
burnChecked: event.target.checked,
})
}
disabled={!this.state.burnCheckedEnable}
size="sm"
label="Burn after reading"
checked={this.state.burnChecked}
/>
</Tooltip>

Expand All @@ -520,6 +521,26 @@ class UserInput extends React.Component {
label="Public paste"
/>
</Tooltip>

<Tooltip
title="Warning it's an experimental ferature. Paste will be uploaded on IPFS"
size="sm"
placement="bottom"
>
<Checkbox
onChange={(event) => {
this.setState({
isIpfs: event.target.checked,
burnCheckedEnable: !event.target.checked,
burnChecked: false
})


}}
size="sm"
label="Store on IPFS (experimental)"
/>
</Tooltip>
</Box>

<Textarea
Expand Down
14 changes: 12 additions & 2 deletions src/components/SuccessUrlId.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class SuccessUrlId extends React.Component {
url:
SERVER_NAME +
'/#/' +
this.props.urlId +
this.props.urlId.url_id +
(this.props.encKey ? '&key=' + this.props.encKey : ''),
urlId: this.props.urlId,
urlId: this.props.urlId.url_id,
open: false,
ipfs: this.props.urlId.ipfs,
hash: this.props.urlId.hash,
textButton: 'Copy to clipboard',
}

Expand Down Expand Up @@ -134,6 +136,14 @@ class SuccessUrlId extends React.Component {
</Tooltip>
</Tooltip>
</ClickAwayListener>
{this.state.ipfs ? (
<>
{' '}
<br /> IPFS CID: {this.state.hash}
</>
) : (
''
)}
</Typography>
</div>
</Alert>
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = {
},
open: false,
compress: false,
port: 8080,
port: 8081,
},
experiments: {
syncWebAssembly: true,
Expand Down

0 comments on commit 315c8b6

Please sign in to comment.