-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdaemon.js
74 lines (64 loc) · 2.05 KB
/
daemon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// ONLY SUPPORT FOR .png FILES FOR NOW.
//=========================
//=========MODULES=========
//=========================
const express=require('express')
const fs=require('fs')
const web3=require('web3')
const ipfsApi=require('ipfs-api')
const concat = require('concat-stream')
const mkdirp=require('mkdirp')
const lwip=require('lwip')
app = express();
//===========================
//=========CONSTANTS=========
//===========================
const appDataDir=process.env.HOME+'/.EthPhoto/'
const imageDataDir=appDataDir+'img-store/'
const fileDataDir=appDataDir+'file-store/'
const web3Host='http://localhost';
const web3Port='8545';
const ipfsHost='localhost';
const ipfsAPIPort='5001';
const ipfsWebPort='8080';
var ipfs=ipfsApi(ipfsHost,ipfsAPIPort);
var lastBlockNumber=0;
//========================
//=========ROUTES=========
//========================
const gethAPI = require('./gethAPI.js')
const ipfsAPI = require('./ipfsAPI.js')
const fileAPI = require('./fileAPI.js')
const utilAPI = require('./utilAPI.js')
//============================
//========VARIABLES===========
//============================
var mutexForFile={};
var mutexForCountImagesTag={};
var countImagesForTag={};
var indexOfHashInTagFile={};
var getUserCountForHash={};
var getUserImages={};
var thumbnailHashToImageHash={};
var address="";
//===========================
//======END OF VARIABLES=====
//===========================
web3.setProvider(new web3.providers.HttpProvider(web3Host + ':' + web3Port));
if(web3.isConnected()) {
console.log("Ethereum - connected to RPC server");
fs.readFile(appDataDir + 'accountAddress', 'utf-8', function(error, content) {
if(error)
content = createAccount();
address = content;
});
if(!fs.existsSync(imageDataDir))
mkdirp.sync(imageDataDir);
if(!fs.existsSync(fileDataDir))
mkdirp.sync(fileDataDir);
} else {
console.error("Ethereum - no connection to RPC server from 47");
}
app.post('/uploadPhoto', gethAPI.uploadPhotoFromDisk);
app.post('/deletePhoto', gethAPI.deletePhotoFromDisk);
app.post('/viewPhoto', gethAPI.viewPhoto);