Skip to content

Instantly share code, notes, and snippets.

View linux08's full-sized avatar
📚
Learning.

David Abimbola linux08

📚
Learning.
View GitHub Profile
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();
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
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 })
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 });
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);
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);
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);
componentDidMount() {
const config = {
method: 'GET',
headers: {
Accept: 'application/json'
},
};
fetch('http://10.0.2.2:5000/images', config)
.then((resp) => resp.json())
.then((res) => {
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;
//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) => {