@@ -720,17 +720,17 @@ module.exports = {
720
720
// LEVEL 0
721
721
// This content may be moved into another Sqlite database eventually
722
722
//
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);" ,
726
726
727
727
728
728
// LEVEL 1
729
729
// This could be store in another Sqlite database, but it could also be derived from that data
730
730
//
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);" ,
734
734
735
735
736
736
// LEVEL 2
@@ -864,7 +864,7 @@ module.exports = {
864
864
let baseComponentIdOfItem = yz . helpers . getValueOfCodeString ( code , "base_component_id" )
865
865
let itemName = yz . helpers . getValueOfCodeString ( code , "display_name" )
866
866
let iconUrl = yz . helpers . getValueOfCodeString ( code , "logo_url" )
867
- let ipfsHashId = await OnlyIpfsHash . of ( code )
867
+ let ipfsHashId = await yz . getDistributedKey ( code )
868
868
let readWriteStatus = ""
869
869
let readOnly = yz . helpers . getValueOfCodeString ( code , "read_only" )
870
870
@@ -924,7 +924,7 @@ module.exports = {
924
924
}
925
925
} ,
926
926
getIpfsHash : async function ( sometext ) {
927
- let ipfsHash = await OnlyIpfsHash . of ( sometext )
927
+ let ipfsHash = await yz . getDistributedKey ( sometext )
928
928
return ipfsHash
929
929
} ,
930
930
saveCodeV3 : async function ( thisDb , code , options ) {
@@ -982,7 +982,7 @@ module.exports = {
982
982
let readWriteStatus = null
983
983
let codeChangesStr = null
984
984
let numCodeChanges = null
985
- let sha1sum = await OnlyIpfsHash . of ( code )
985
+ let sha1sum = await yz . getDistributedKey ( code )
986
986
let userId = null
987
987
let propertiesAsJsonString = null
988
988
let existingCodeAlreadyInSystemCodeTable
@@ -1059,7 +1059,7 @@ module.exports = {
1059
1059
1060
1060
1061
1061
// ********** 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 )
1063
1063
if ( sha1sum2 != sha1sum ) {
1064
1064
console . log ( "Code SHA do not match - code has been changed while saving" )
1065
1065
throw "Code SHA do not match - code has been changed while saving"
@@ -1807,7 +1807,7 @@ module.exports = {
1807
1807
//
1808
1808
//
1809
1809
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 ] )
1811
1811
if ( contentRecord ) {
1812
1812
let returnValue = contentRecord . ipfs_content
1813
1813
if ( returnValue ) {
@@ -1844,7 +1844,7 @@ module.exports = {
1844
1844
1845
1845
await mm . executeQuickSql ( thisDb ,
1846
1846
`update
1847
- level_1_ipfs_hash_metadata
1847
+ level_1_content_metadata
1848
1848
set
1849
1849
status = ?,
1850
1850
process_attempts = process_attempts + 1
@@ -1895,7 +1895,7 @@ module.exports = {
1895
1895
1896
1896
await mm . executeQuickSql ( thisDb ,
1897
1897
`update
1898
- level_1_ipfs_hash_metadata
1898
+ level_1_content_metadata
1899
1899
set
1900
1900
status = ?,
1901
1901
process_attempts = process_attempts + 1
@@ -1909,7 +1909,7 @@ module.exports = {
1909
1909
console . log ( "No corresponding code record available yet" )
1910
1910
await mm . executeQuickSql ( thisDb ,
1911
1911
`update
1912
- level_1_ipfs_hash_metadata
1912
+ level_1_content_metadata
1913
1913
set
1914
1914
process_attempts = process_attempts + 1
1915
1915
where
@@ -1948,7 +1948,7 @@ module.exports = {
1948
1948
1949
1949
await mm . executeQuickSql ( thisDb ,
1950
1950
`update
1951
- level_1_ipfs_hash_metadata
1951
+ level_1_content_metadata
1952
1952
set
1953
1953
status = ?,
1954
1954
process_attempts = process_attempts + 1
@@ -2090,8 +2090,12 @@ module.exports = {
2090
2090
// Yazz we often need the IPFS hash of some content (via the getIpfsHash( ) fn)
2091
2091
// just in case the front end IPFS server is not available
2092
2092
//---------------------------------------------------------------------------
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
+ }
2095
2099
} ,
2096
2100
getDistributedContent : async function ( { thisDb , ipfsHash } ) {
2097
2101
//---------------------------------------------------------------------------
@@ -2122,8 +2126,8 @@ module.exports = {
2122
2126
2123
2127
2124
2128
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 ] )
2127
2131
2128
2132
// if the content is stored in Sqlite then get the content from sqlite
2129
2133
if ( metadataStoredInSqlite && contentStoredInSqlite ) {
@@ -2166,6 +2170,7 @@ module.exports = {
2166
2170
2167
2171
// figure out the content options and scope
2168
2172
let mm = this
2173
+ let yz = this
2169
2174
let contentValueToStore = content
2170
2175
let contentType = "STRING"
2171
2176
let scope = "GLOBAL" ;
@@ -2193,12 +2198,12 @@ module.exports = {
2193
2198
}
2194
2199
}
2195
2200
2196
- justHash = await OnlyIpfsHash . of ( contentValueToStore )
2201
+ justHash = await yz . getDistributedKey ( contentValueToStore )
2197
2202
2198
2203
//
2199
2204
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 ] )
2202
2207
2203
2208
// if the content is stored in Sqlite then do nothing
2204
2209
if ( metadataStoredInSqlite && contentStoredInSqlite ) {
@@ -2209,13 +2214,13 @@ module.exports = {
2209
2214
} else {
2210
2215
await mm . executeQuickSql (
2211
2216
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 (?,?)" ,
2213
2218
[ justHash , contentValueToStore ] )
2214
2219
2215
2220
await mm . executeQuickSql (
2216
2221
thisDb ,
2217
2222
`insert or replace into
2218
- level_1_ipfs_hash_metadata
2223
+ level_1_content_metadata
2219
2224
(
2220
2225
ipfs_hash,
2221
2226
content_type,
@@ -2321,7 +2326,7 @@ module.exports = {
2321
2326
res . on ( 'end' , async function ( ) {
2322
2327
//console.log('end: ' );
2323
2328
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 = ?" ,
2325
2330
[ ipfs_hash ] )
2326
2331
await mm . executeQuickSql ( thisDb ,
2327
2332
`update
@@ -2347,6 +2352,7 @@ module.exports = {
2347
2352
mm . inDistributeContentToPeer = false
2348
2353
} ,
2349
2354
saveItemToIpfs : async function ( srcCode ) {
2355
+ let yz = this
2350
2356
//---------------------------------------------------------------------------
2351
2357
//
2352
2358
// saveItemToIpfs( .. )
@@ -2359,7 +2365,7 @@ module.exports = {
2359
2365
let promise = new Promise ( async function ( returnfn ) {
2360
2366
let justHash = null
2361
2367
try {
2362
- justHash = await OnlyIpfsHash . of ( srcCode )
2368
+ justHash = await yz . getDistributedKey ( srcCode )
2363
2369
let fullIpfsFilePath = path . join ( fullIpfsFolderPath , justHash )
2364
2370
2365
2371
fs . writeFileSync ( fullIpfsFilePath , srcCode ) ;
@@ -2464,7 +2470,7 @@ module.exports = {
2464
2470
`select
2465
2471
ipfs_hash
2466
2472
from
2467
- level_1_ipfs_hash_metadata
2473
+ level_1_content_metadata
2468
2474
where
2469
2475
scope='GLOBAL'
2470
2476
and
@@ -2516,7 +2522,7 @@ module.exports = {
2516
2522
`select
2517
2523
ipfs_hash
2518
2524
from
2519
- level_1_ipfs_hash_metadata
2525
+ level_1_content_metadata
2520
2526
where
2521
2527
scope='GLOBAL' and sent_to_master is null
2522
2528
LIMIT 1` )
@@ -2525,7 +2531,7 @@ module.exports = {
2525
2531
2526
2532
await mm . executeQuickSql ( thisDb ,
2527
2533
`update
2528
- level_1_ipfs_hash_metadata
2534
+ level_1_content_metadata
2529
2535
set
2530
2536
sent_to_master = ?
2531
2537
where
@@ -2717,7 +2723,7 @@ module.exports = {
2717
2723
`select
2718
2724
ipfs_content
2719
2725
from
2720
- level_0_ipfs_content
2726
+ level_0_cached_content
2721
2727
where
2722
2728
ipfs_hash = ?` ,
2723
2729
[ nextIpfsQueueRecord . ipfs_hash ] )
@@ -2779,7 +2785,7 @@ module.exports = {
2779
2785
`select
2780
2786
ipfs_hash
2781
2787
from
2782
- level_1_ipfs_hash_metadata
2788
+ level_1_content_metadata
2783
2789
where
2784
2790
status is null
2785
2791
order by
@@ -2860,7 +2866,7 @@ module.exports = {
2860
2866
} ,
2861
2867
oldsynchonizeContentAmongPeers : async function ( thisDb ) {
2862
2868
//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 )
2864
2870
if ( rows . length == 0 ) {
2865
2871
return null
2866
2872
}
0 commit comments