Skip to content

Commit a86f3f8

Browse files
committed
renamed DB indexes
Add prefix "IPFS_" to all IPFS addresses Starting to code the multi hash content ID algorithm Add a property hash_algorithm("SHA256") Rename to "level_1_content_metadata" Added a better term for source code control in the app Trying to get rid of direct references to IPFS
1 parent 97f9ee8 commit a86f3f8

File tree

4 files changed

+68
-44
lines changed

4 files changed

+68
-44
lines changed

public/go.html

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,17 +2078,34 @@
20782078
return ret
20792079
}
20802080
async function getIpfsHash ( sometext ) {
2081-
if (yz.mainVars.ipfs) {
2082-
let ret = await yz.mainVars.ipfs.add(sometext, {onlyHash: true})
2083-
2084-
return ret.path
2085-
} else {
2086-
let resulthash = await postToYazzReturnJson(
2087-
"/http_post_extract_commit_hash_id_from_code",
2088-
{text: sometext}
2089-
)
2090-
2091-
return resulthash.ipfsHash
2081+
let hashingAlgorithm = "IPFS"
2082+
let overrideHashingAlgorithm = yz.helpers.getValueOfCodeString(sometext, "hash_algorithm")
2083+
if (overrideHashingAlgorithm) {
2084+
hashingAlgorithm = overrideHashingAlgorithm
2085+
}
2086+
if (hashingAlgorithm == "IPFS") {
2087+
if (yz.mainVars.ipfs) {
2088+
let ret = await yz.mainVars.ipfs.add(sometext, {onlyHash: true})
2089+
return "IPFS_" + ret.path
2090+
} else {
2091+
let resulthash = await postToYazzReturnJson(
2092+
"/http_post_extract_commit_hash_id_from_code",
2093+
{text: sometext}
2094+
)
2095+
return resulthash.ipfsHash
2096+
}
2097+
} else if (hashingAlgorithm == "SHA256") {
2098+
debugger
2099+
if (yz.mainVars.ipfs) {
2100+
let ret = await yz.mainVars.ipfs.add(sometext, {onlyHash: true})
2101+
return "IPFS_" + ret.path
2102+
} else {
2103+
let resulthash = await postToYazzReturnJson(
2104+
"/http_post_extract_commit_hash_id_from_code",
2105+
{text: sometext}
2106+
)
2107+
return resulthash.ipfsHash
2108+
}
20922109
}
20932110
}
20942111
async function registerComponent ( vueComponentObject ) {

public/visifile_drivers/all_system_components/appEditorV3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ v-if="$refs.editor_component_ref.model && $refs.editor_component_ref.model.forms
463463
style='height:35px; margin-right: 0px;'
464464
class='img-fluid'>
465465
</img>
466-
Deliver
466+
Revisions
467467
468468
</a>
469469

public/visifile_drivers/apps/todo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ async function(args) {
33
base_component_id("todo")
44
is_app(true)
55
display_name("Todo App")
6+
hash_algorithm("SHA256")
67
visibility("PUBLIC")
78
component_type("APP")
89
description("This will create a demo todo app")

src/yazz_helper_module.js

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -720,17 +720,17 @@ module.exports = {
720720
// LEVEL 0
721721
// This content may be moved into another Sqlite database eventually
722722
//
723-
"CREATE TABLE IF NOT EXISTS level_0_ipfs_content (ipfs_hash TEXT, ipfs_content TEXT, UNIQUE(ipfs_hash));",
724-
"INSERT OR REPLACE INTO table_versions (table_name , version_number) VALUES ('level_0_ipfs_content',1);",
725-
"CREATE INDEX IF NOT EXISTS ipfs_hashes_idx ON level_0_ipfs_content (ipfs_hash);",
723+
"CREATE TABLE IF NOT EXISTS level_0_cached_content (ipfs_hash TEXT, ipfs_content TEXT, UNIQUE(ipfs_hash));",
724+
"INSERT OR REPLACE INTO table_versions (table_name , version_number) VALUES ('level_0_cached_content',1);",
725+
"CREATE INDEX IF NOT EXISTS level_0_cached_content_idx ON level_0_cached_content (ipfs_hash);",
726726

727727

728728
// LEVEL 1
729729
// This could be store in another Sqlite database, but it could also be derived from that data
730730
//
731-
"CREATE TABLE IF NOT EXISTS level_1_ipfs_hash_metadata (ipfs_hash TEXT , status TEXT , process_attempts INTEGER, content_type TEXT , scope TEXT , stored_in_ipfs INTEGER , sent_to_master TEXT , read_from_local_ipfs INTEGER, error TEXT , last_ipfs_ping_millis INTEGER, temp_debug_content TEXT, UNIQUE(ipfs_hash));",
732-
"INSERT OR REPLACE INTO table_versions (table_name , version_number) VALUES ('level_1_ipfs_hash_metadata',1);",
733-
"CREATE INDEX IF NOT EXISTS ipfs_hashes_idx ON level_1_ipfs_hash_metadata (ipfs_hash);",
731+
"CREATE TABLE IF NOT EXISTS level_1_content_metadata (ipfs_hash TEXT , status TEXT , process_attempts INTEGER, content_type TEXT , scope TEXT , stored_in_ipfs INTEGER , sent_to_master TEXT , read_from_local_ipfs INTEGER, error TEXT , last_ipfs_ping_millis INTEGER, temp_debug_content TEXT, UNIQUE(ipfs_hash));",
732+
"INSERT OR REPLACE INTO table_versions (table_name , version_number) VALUES ('level_1_content_metadata',1);",
733+
"CREATE INDEX IF NOT EXISTS level_1_content_metadata_idx ON level_1_content_metadata (ipfs_hash);",
734734

735735

736736
// LEVEL 2
@@ -864,7 +864,7 @@ module.exports = {
864864
let baseComponentIdOfItem = yz.helpers.getValueOfCodeString(code,"base_component_id")
865865
let itemName = yz.helpers.getValueOfCodeString(code,"display_name")
866866
let iconUrl = yz.helpers.getValueOfCodeString(code,"logo_url")
867-
let ipfsHashId = await OnlyIpfsHash.of(code)
867+
let ipfsHashId = await yz.getDistributedKey(code)
868868
let readWriteStatus = ""
869869
let readOnly = yz.helpers.getValueOfCodeString(code,"read_only")
870870

@@ -924,7 +924,7 @@ module.exports = {
924924
}
925925
},
926926
getIpfsHash: async function ( sometext ) {
927-
let ipfsHash = await OnlyIpfsHash.of(sometext)
927+
let ipfsHash = await yz.getDistributedKey(sometext)
928928
return ipfsHash
929929
},
930930
saveCodeV3: async function ( thisDb , code , options ) {
@@ -982,7 +982,7 @@ module.exports = {
982982
let readWriteStatus = null
983983
let codeChangesStr = null
984984
let numCodeChanges = null
985-
let sha1sum = await OnlyIpfsHash.of(code)
985+
let sha1sum = await yz.getDistributedKey(code)
986986
let userId = null
987987
let propertiesAsJsonString = null
988988
let existingCodeAlreadyInSystemCodeTable
@@ -1059,7 +1059,7 @@ module.exports = {
10591059

10601060

10611061
// ********** if the code has been changed then DO NOT SAVE IT! This is a basic tamper proof mechanism **********
1062-
let sha1sum2 = await OnlyIpfsHash.of(code)
1062+
let sha1sum2 = await yz.getDistributedKey(code)
10631063
if (sha1sum2 != sha1sum) {
10641064
console.log("Code SHA do not match - code has been changed while saving")
10651065
throw "Code SHA do not match - code has been changed while saving"
@@ -1807,7 +1807,7 @@ module.exports = {
18071807
//
18081808
//
18091809
try {
1810-
let contentRecord = await mm.getQuickSqlOneRow(thisDb,"select ipfs_content from level_0_ipfs_content where ipfs_hash = ?",[ipfsHash])
1810+
let contentRecord = await mm.getQuickSqlOneRow(thisDb,"select ipfs_content from level_0_cached_content where ipfs_hash = ?",[ipfsHash])
18111811
if (contentRecord) {
18121812
let returnValue = contentRecord.ipfs_content
18131813
if (returnValue) {
@@ -1844,7 +1844,7 @@ module.exports = {
18441844

18451845
await mm.executeQuickSql(thisDb,
18461846
`update
1847-
level_1_ipfs_hash_metadata
1847+
level_1_content_metadata
18481848
set
18491849
status = ?,
18501850
process_attempts = process_attempts + 1
@@ -1895,7 +1895,7 @@ module.exports = {
18951895

18961896
await mm.executeQuickSql(thisDb,
18971897
`update
1898-
level_1_ipfs_hash_metadata
1898+
level_1_content_metadata
18991899
set
19001900
status = ?,
19011901
process_attempts = process_attempts + 1
@@ -1909,7 +1909,7 @@ module.exports = {
19091909
console.log("No corresponding code record available yet")
19101910
await mm.executeQuickSql(thisDb,
19111911
`update
1912-
level_1_ipfs_hash_metadata
1912+
level_1_content_metadata
19131913
set
19141914
process_attempts = process_attempts + 1
19151915
where
@@ -1948,7 +1948,7 @@ module.exports = {
19481948

19491949
await mm.executeQuickSql(thisDb,
19501950
`update
1951-
level_1_ipfs_hash_metadata
1951+
level_1_content_metadata
19521952
set
19531953
status = ?,
19541954
process_attempts = process_attempts + 1
@@ -2090,8 +2090,12 @@ module.exports = {
20902090
// Yazz we often need the IPFS hash of some content (via the getIpfsHash( ) fn)
20912091
// just in case the front end IPFS server is not available
20922092
//---------------------------------------------------------------------------
2093-
let ipfsHash = await OnlyIpfsHash.of( content )
2094-
return ipfsHash
2093+
let yz = this
2094+
return "IPFS_" + ipfsHash
2095+
} else if (hashingAlgorithm == "SHA256") {
2096+
let ipfsHash = await OnlyIpfsHash.of(content)
2097+
return "IPFS_" + ipfsHash
2098+
}
20952099
},
20962100
getDistributedContent: async function ( { thisDb , ipfsHash } ) {
20972101
//---------------------------------------------------------------------------
@@ -2122,8 +2126,8 @@ module.exports = {
21222126

21232127

21242128
try {
2125-
contentStoredInSqlite = await mm.getQuickSqlOneRow(thisDb, "select * from level_0_ipfs_content where ipfs_hash = ?", [ ipfsHash ])
2126-
metadataStoredInSqlite = await mm.getQuickSqlOneRow(thisDb, "select * from level_1_ipfs_hash_metadata where ipfs_hash = ?", [ ipfsHash ])
2129+
contentStoredInSqlite = await mm.getQuickSqlOneRow(thisDb, "select * from level_0_cached_content where ipfs_hash = ?", [ ipfsHash ])
2130+
metadataStoredInSqlite = await mm.getQuickSqlOneRow(thisDb, "select * from level_1_content_metadata where ipfs_hash = ?", [ ipfsHash ])
21272131

21282132
// if the content is stored in Sqlite then get the content from sqlite
21292133
if (metadataStoredInSqlite && contentStoredInSqlite) {
@@ -2166,6 +2170,7 @@ module.exports = {
21662170

21672171
// figure out the content options and scope
21682172
let mm = this
2173+
let yz = this
21692174
let contentValueToStore = content
21702175
let contentType = "STRING"
21712176
let scope = "GLOBAL";
@@ -2193,12 +2198,12 @@ module.exports = {
21932198
}
21942199
}
21952200

2196-
justHash = await OnlyIpfsHash.of(contentValueToStore)
2201+
justHash = await yz.getDistributedKey(contentValueToStore)
21972202

21982203
//
21992204
try {
2200-
contentStoredInSqlite = await mm.getQuickSqlOneRow(thisDb, "select * from level_0_ipfs_content where ipfs_hash = ?", [ justHash ])
2201-
metadataStoredInSqlite = await mm.getQuickSqlOneRow(thisDb, "select * from level_1_ipfs_hash_metadata where ipfs_hash = ?", [ justHash ])
2205+
contentStoredInSqlite = await mm.getQuickSqlOneRow(thisDb, "select * from level_0_cached_content where ipfs_hash = ?", [ justHash ])
2206+
metadataStoredInSqlite = await mm.getQuickSqlOneRow(thisDb, "select * from level_1_content_metadata where ipfs_hash = ?", [ justHash ])
22022207

22032208
// if the content is stored in Sqlite then do nothing
22042209
if (metadataStoredInSqlite && contentStoredInSqlite) {
@@ -2209,13 +2214,13 @@ module.exports = {
22092214
} else {
22102215
await mm.executeQuickSql(
22112216
thisDb,
2212-
"insert into level_0_ipfs_content (ipfs_hash,ipfs_content) values (?,?)",
2217+
"insert into level_0_cached_content (ipfs_hash,ipfs_content) values (?,?)",
22132218
[justHash,contentValueToStore])
22142219

22152220
await mm.executeQuickSql(
22162221
thisDb,
22172222
`insert or replace into
2218-
level_1_ipfs_hash_metadata
2223+
level_1_content_metadata
22192224
(
22202225
ipfs_hash,
22212226
content_type,
@@ -2321,7 +2326,7 @@ module.exports = {
23212326
res.on('end', async function () {
23222327
//console.log('end: ' );
23232328
await mm.executeQuickSql(thisDb,
2324-
"update level_1_ipfs_hash_metadata set sent_to_master = 'TRUE' where ipfs_hash = ?",
2329+
"update level_1_content_metadata set sent_to_master = 'TRUE' where ipfs_hash = ?",
23252330
[ipfs_hash] )
23262331
await mm.executeQuickSql(thisDb,
23272332
`update
@@ -2347,6 +2352,7 @@ module.exports = {
23472352
mm.inDistributeContentToPeer = false
23482353
},
23492354
saveItemToIpfs: async function ( srcCode ) {
2355+
let yz = this
23502356
//---------------------------------------------------------------------------
23512357
//
23522358
// saveItemToIpfs( .. )
@@ -2359,7 +2365,7 @@ module.exports = {
23592365
let promise = new Promise(async function(returnfn) {
23602366
let justHash = null
23612367
try {
2362-
justHash = await OnlyIpfsHash.of( srcCode )
2368+
justHash = await yz.getDistributedKey( srcCode )
23632369
let fullIpfsFilePath = path.join( fullIpfsFolderPath , justHash )
23642370

23652371
fs.writeFileSync( fullIpfsFilePath , srcCode );
@@ -2464,7 +2470,7 @@ module.exports = {
24642470
`select
24652471
ipfs_hash
24662472
from
2467-
level_1_ipfs_hash_metadata
2473+
level_1_content_metadata
24682474
where
24692475
scope='GLOBAL'
24702476
and
@@ -2516,7 +2522,7 @@ module.exports = {
25162522
`select
25172523
ipfs_hash
25182524
from
2519-
level_1_ipfs_hash_metadata
2525+
level_1_content_metadata
25202526
where
25212527
scope='GLOBAL' and sent_to_master is null
25222528
LIMIT 1`)
@@ -2525,7 +2531,7 @@ module.exports = {
25252531

25262532
await mm.executeQuickSql(thisDb,
25272533
`update
2528-
level_1_ipfs_hash_metadata
2534+
level_1_content_metadata
25292535
set
25302536
sent_to_master = ?
25312537
where
@@ -2717,7 +2723,7 @@ module.exports = {
27172723
`select
27182724
ipfs_content
27192725
from
2720-
level_0_ipfs_content
2726+
level_0_cached_content
27212727
where
27222728
ipfs_hash = ?`,
27232729
[nextIpfsQueueRecord.ipfs_hash])
@@ -2779,7 +2785,7 @@ module.exports = {
27792785
`select
27802786
ipfs_hash
27812787
from
2782-
level_1_ipfs_hash_metadata
2788+
level_1_content_metadata
27832789
where
27842790
status is null
27852791
order by
@@ -2860,7 +2866,7 @@ module.exports = {
28602866
},
28612867
oldsynchonizeContentAmongPeers: async function ( thisDb ) {
28622868
//console.log("Sync")
2863-
let contentNotSentToPeer = await this.getQuickSql(thisDb, "select ipfs_hash from level_1_ipfs_hash_metadata where sent_to_master != 'TRUE' limit 1", params)
2869+
let contentNotSentToPeer = await this.getQuickSql(thisDb, "select ipfs_hash from level_1_content_metadata where sent_to_master != 'TRUE' limit 1", params)
28642870
if (rows.length == 0) {
28652871
return null
28662872
}

0 commit comments

Comments
 (0)