Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added IPFS support for image upload / download
- Loading branch information
Benjamin Flanagin
committed
Jul 30, 2018
1 parent
8860380
commit 6ddcf57
Showing
13 changed files
with
230 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
function mediaAdd(file,type) { | ||
|
||
//console.log("adding things " + file) | ||
var ipfsReference = file.toString().split(" ") | ||
|
||
|
||
var returned = "http://localhost:8080/ipfs/"+ipfsReference[1] | ||
|
||
db.transaction(function (tx) { | ||
|
||
var dataSTR = "INSERT INTO Media VALUES(?,?,?,?,?,?)" | ||
var data = [schoolCode, userCode, type,ipfsReference[2], ipfsReference[1], d.getTime( | ||
)] | ||
|
||
var check = tx.executeSql( | ||
"SELECT * from Media WHERE hash = '" + ipfsReference[1] + "'") | ||
|
||
if (check.rows.length !== 1) { | ||
tx.executeSql(dataSTR, data) | ||
} | ||
}) | ||
|
||
return returned | ||
} | ||
|
||
function mediaRetrieve(hash) { | ||
|
||
db.readTransaction(function (tx) { | ||
|
||
var check = tx.executeSql( | ||
"SELECT * from Media WHERE hash = '" + hash + "'") | ||
|
||
if (check.rows.length === 1) { | ||
|
||
} | ||
}) | ||
|
||
} | ||
|
||
function grabImage(userCode,type) { | ||
|
||
/* checks for existence of an image based on what and who owns it, instead of a hash and returns the ipfs url */ | ||
|
||
var returned = "" | ||
|
||
db.readTransaction(function (tx) { | ||
|
||
var check = tx.executeSql( | ||
"SELECT * from Media WHERE owner = '"+userCode+"' AND type = '" + type + "' ORDER BY creationdate DESC") | ||
|
||
if(check.rows.length !==0) { | ||
switch(type) { | ||
case "profile":returned = "http://localhost:8080/ipfs/"+check.rows.item(0).hash | ||
break | ||
case "general":returned = "http://localhost:8080/ipfs/"+check.rows.item(0).hash | ||
break | ||
|
||
} | ||
} else { | ||
console.log("no image found") | ||
} | ||
|
||
}) | ||
|
||
return returned | ||
} | ||
|
This file contains 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
This file contains 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
Oops, something went wrong.