This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.getScreenShot = async (req, res) => { | |
| const { address } = req.query; | |
| // web address you want to screenshot , Default is medium.com | |
| const webAddress = `https://${( address || 'medium')}.com`; | |
| try { | |
| const browser = await puppeteer.launch(); | |
| const page = await browser.newPage(); | |
| await page.goto(webAddress); | |
| await page.screenshot({ path: `./assets/snapshot.png` }); | |
| await browser.close(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const code =fs.readFileSync('./contracts/StoreHash.sol').toString(); | |
| const solc = require('solc'); | |
| const compiledCode = solc.compile(code); | |
| const abi =JSON.parse(compiledCode.contracts[':SaveAddress'].interface); | |
| const SavingContract = new web3.eth.Contract(abi, '0xb1caf625d9d29421dfd8dae4a7a9083b4175f80a'); | |
| // where 0xb1caf625d9d29421dfd8dae4a7a9083b4175f80a is the ethereum address |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| upload = async () => { | |
| this.setState({ | |
| loading: true | |
| }); | |
| if (!this.state.uploadStatus) { | |
| this.setState({ loading: null }) | |
| return alert('Image yet to be uploaded') | |
| } | |
| if (this.state.label === '') { | |
| this.setState({ loading: null }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| selectImage = async () => { | |
| ImagePicker.showImagePicker(options, async (response) => { | |
| if (response.didCancel) { | |
| this.setState({ error: 'Image upload failed', loading: null }); | |
| } else if (response.error) { | |
| this.setState({ error: 'Image upload failed', loading: null }); | |
| } else if (response.customButton) { | |
| this.setState({ error: 'Image upload failed', loading: null }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.create = async (req, res) => { | |
| try { | |
| const data = { | |
| label: req.body.label, | |
| ipfsHash: req.data.ipfsHash, | |
| ipfsAddress: `https://gateway.ipfs.io/ipfs/${req.data.ipfsHash}`, | |
| transactionHash: req.data.ipfsHash, | |
| blockHash: req.data.blockHash, | |
| }; | |
| const resp = await Image.create(data); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.postData = async (req, res, next) => { | |
| try { | |
| const { hash } = req.data[0]; | |
| const accounts = await web3.eth.getAccounts(); | |
| const resp = await SavingContract.methods.saveHash(hash) | |
| .send({ | |
| from: accounts[0], | |
| }); | |
| const data = Object.assign({ ipfsHash: hash }, resp); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.uploadFile = async (req, res, next) => { | |
| if (!req.file) { | |
| return res.status(422).json({ | |
| error: 'File needs to be provided.', | |
| }); | |
| } | |
| const mime = req.file.mimetype; | |
| if (mime.split('/')[0] !== 'image') { | |
| fs.unlink(req.file.path); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| componentDidMount() { | |
| const config = { | |
| method: 'GET', | |
| headers: { | |
| Accept: 'application/json' | |
| }, | |
| }; | |
| fetch('http://10.0.2.2:5000/images', config) | |
| .then((resp) => resp.json()) | |
| .then((res) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pragma solidity ^0.4.0; | |
| contract SaveAddress { | |
| string ipfsHash; | |
| function saveHash(string x) public { | |
| ipfsHash = x; | |
| } | |
| function getHash( string y) public view returns ( string x) { | |
| return ipfsHash; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //orders the item in an array of object by their ranking in ascending order | |
| function sort(data) { | |
| return data.sort((a, b) => { | |
| return a.ranking - b.ranking; | |
| }); | |
| }; | |
| //find the average ranking present in an array of object; | |
| function average(data) { | |
| return ( | |
| data.reduce((prev, curr) => { |