Skip to content

Commit

Permalink
Push pages directly
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasticoFox committed Jul 12, 2024
2 parents 342940e + 06a1928 commit 9a593f9
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 1 deletion.
39 changes: 39 additions & 0 deletions import_direct/034ecc796a_Template_DataAccessAgreement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"pages": [
{
"genesis_hash": "725c2b99a955a690e50a1f22f356a64b02c144dd5adcbc09ac09f861fe2cc45a47185d7a9f5ecc60af86c0e60545aabe8c8c9c34feff92ea1da511ec0e2ef2ac",
"domain_id": "034ecc796a",
"title": "DataAccessAgreement",
"namespace": 10,
"chain_height": 1,
"revisions": {
"725c2b99a955a690e50a1f22f356a64b02c144dd5adcbc09ac09f861fe2cc45a47185d7a9f5ecc60af86c0e60545aabe8c8c9c34feff92ea1da511ec0e2ef2ac": {
"content": {
"rev_id": 51,
"content": {
"main": "<includeonly>\n'''Sender:''' {{{sender}}}<br>\n'''Receiver:''' {{{receiver}}}<br>\n'''Pages:''' {{#arraymap:{{{pages|}}}|,|page|[[page]]|, |and}}<br>\n'''Terms:''' {{{terms|}}}<br>\n<br>\n----\nThis is a Data Access Agreement. <br>\nYou can use this contract to share pages with other users. To do so you can choose from two options:<br>\n1) Share without terms. For this you enter your own wallet address (sender) and the target wallet address (receiver) and the page you want to share. Save the contract and sign it with your wallet to make the contract effective.<br>\n2) Share with terms. For contract to be valid you need to repeat the steps in 1) after those steps you share this contract with the receiver who signs it and sends it back to you. Then the contract will be valid.<br>\n<\/includeonly>\n<noinclude>\n<templatedata>\n{\n\t\"params\": {\n\t\t\"sender\": {\n\t\t\t\"type\": \"wiki-user-name\",\n\t\t\t\"required\": true,\n \"description\": \"Enter your own wallet address.\"\n\t\t},\n\t\t\"receiver\": {\n\t\t\t\"type\": \"wiki-user-name\",\n\t\t\t\"required\": true,\n \"description\": \"Enter the wallet address who you want to share the page with.\"\n\t\t},\n\t\t\"pages\": {\n\t\t\t\"type\": \"wiki-page-name\",\n\t\t\t\"required\": true,\n \"description\": \"Enter the titles of the pages you want to share.\"\n\t\t},\n\t\t\"terms\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"required\": false,\n \"description\": \"If you want add terms under which you want to share pages.\"\n\t\t}\n\t},\n\t\"description\": \"This is a contract to share pages.\",\n\t\"format\": \"{{_\\n|_=_\\n}}\"\n}\n<\/templatedata>\n<\/noinclude>",
"transclusion-hashes": ""
},
"content_hash": "1877d1fb3e27263a8c9ef6c94a01d17a1c8e47d258b041e548e9a3706db4ec7e924bd97e09ef86b7e5904f9c779c7a6ed31272c24cfdcaa023bf07642483bf87"
},
"metadata": {
"domain_id": "034ecc796a",
"time_stamp": "20240703150300",
"previous_verification_hash": "",
"merge_hash": "",
"metadata_hash": "325a0977b1f56ac4f4570db93c15f872955c7f0de1b41422a812d3793ff75da7545ae296e9f120bd636614275a898363314a41c460200432fc83b5a6b0a5a46d",
"verification_hash": "725c2b99a955a690e50a1f22f356a64b02c144dd5adcbc09ac09f861fe2cc45a47185d7a9f5ecc60af86c0e60545aabe8c8c9c34feff92ea1da511ec0e2ef2ac"
},
"signature": null,
"witness": null
}
}
}
],
"site_info": {
"sitename": "Personal Knowledge Container",
"base": "http:\/\/localhost:9352\/index.php\/Main_Page",
"generator": "MediaWiki 1.39.4",
"version": "0.3.0"
}
}
39 changes: 39 additions & 0 deletions import_direct/501f11d3d2_Template_GuardianServitude.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"pages": [
{
"genesis_hash": "2c82d270181179987518d620c102a0fc9db1d5ed7238795cc87d9e1de70ed3b6f67236dd3152881d620f9270b7dcb7fea72bd7e9b859dc2478a3058b078f5204",
"domain_id": "501f11d3d2",
"title": "GuardianServitude",
"namespace": 10,
"chain_height": 1,
"revisions": {
"2c82d270181179987518d620c102a0fc9db1d5ed7238795cc87d9e1de70ed3b6f67236dd3152881d620f9270b7dcb7fea72bd7e9b859dc2478a3058b078f5204": {
"content": {
"rev_id": 47,
"content": {
"main": "This is your '''Guardian Servitude'''.<br><br>\nTo confirm that the signing Guardian is yours, <br>please validate that the signature in this page is the wallet address of your Guardian.<br><br>\nWhen confirmed, '''please sign it with your wallet'''.<br>\n----\nExport this together with your Guardian TLS certificate to establish connection with other users and their Guardians. Send the exported files for them to import.<br>",
"transclusion-hashes": ""
},
"content_hash": "2dbced7516c29b480874961da47e8dbcf84b5883932f22ca286daf956445c8f58c4f620ca977573784749d25d2d250cfed75e910602e62ae80beb9b185d56c52"
},
"metadata": {
"domain_id": "501f11d3d2",
"time_stamp": "20240704152455",
"previous_verification_hash": "",
"merge_hash": "",
"metadata_hash": "21e2c8b48d1d647331e482d5750724db814417cf886b41f2e5e3d47feaccab30c15fe3c5ecf204b0e5f3a7ff2d9f3627dc8fc0bcb645f7daa5c84707805bbacd",
"verification_hash": "2c82d270181179987518d620c102a0fc9db1d5ed7238795cc87d9e1de70ed3b6f67236dd3152881d620f9270b7dcb7fea72bd7e9b859dc2478a3058b078f5204"
},
"signature": null,
"witness": null
}
}
}
],
"site_info": {
"sitename": "Personal Knowledge Container",
"base": "http:\/\/localhost:9352\/index.php\/Main_Page",
"generator": "MediaWiki 1.39.4",
"version": "0.3.0"
}
}
39 changes: 39 additions & 0 deletions import_direct/db3d2ece5a_Template_TlsIdentityClaim.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"pages": [
{
"genesis_hash": "95ce4ec4bf2b92019feff4843ddd7b849db8c7c0bd2afe325566dee7c6d5bcc6d1870032d3fa5230bb2f184a689f9b758f8282a2a1984238178581fb7895df13",
"domain_id": "db3d2ece5a",
"title": "TlsIdentityClaim",
"namespace": 10,
"chain_height": 1,
"revisions": {
"95ce4ec4bf2b92019feff4843ddd7b849db8c7c0bd2afe325566dee7c6d5bcc6d1870032d3fa5230bb2f184a689f9b758f8282a2a1984238178581fb7895df13": {
"content": {
"rev_id": 26,
"content": {
"main": "<includeonly>\n'''Host:''' {{{host}}}<br>\n'''Port:''' {{{port}}}<br>\n'''Guardian Address:''' {{{guardian}}}<br>\n<br>\n----\nThis is a Client TLS Certificate of the Guardian. <br>\n\n<\/includeonly>\n<noinclude>\n<templatedata>\n{\n\t\"params\": {\n\t\t\"host\": {\n\t\t\t\"type\": \"line\",\n\t\t\t\"required\": true,\n\t\t\t\"description\": \"IP Address of the Host\"\n\t\t},\n\t\t\"port\": {\n\t\t\t\"type\": \"line\",\n\t\t\t\"required\": true,\n\t\t\t\"description\": \"Port\"\n\t\t},\n\t\t\"guardian\": {\n\t\t\t\"type\": \"wiki-user-name\",\n\t\t\t\"required\": true,\n\t\t\t\"description\": \"Wallet address of the Guardian.\"\n\t\t}\n\t},\n\t\"description\": \"This is a TLS certificate of a Guardian\",\n\t\"format\": \"{{_\\n|_=_\\n}}\",\n\t\"paramOrder\": [\n\t\t\"guardian\",\n\t\t\"host\",\n\t\t\"port\"\n\t]\n}\n<\/templatedata>\n<\/noinclude>",
"transclusion-hashes": ""
},
"content_hash": "426a1b6d994e042deb55a1373ae87f44e4d117f3d9045e756fa8b1c129479c4d923577a19b7492d959db5d0c26a484d24172615f9021450beede9f28f0b7e3d3"
},
"metadata": {
"domain_id": "db3d2ece5a",
"time_stamp": "20240706104029",
"previous_verification_hash": "",
"merge_hash": "",
"metadata_hash": "4a466d61ca1d5cac3945a093745ed282f837184dbc25776d74fcd3877bfbb43319f93cb411d271c2564e309ff3b4ce458f78b36be47d5126b453a38e90598fb8",
"verification_hash": "95ce4ec4bf2b92019feff4843ddd7b849db8c7c0bd2afe325566dee7c6d5bcc6d1870032d3fa5230bb2f184a689f9b758f8282a2a1984238178581fb7895df13"
},
"signature": null,
"witness": null
}
}
}
],
"site_info": {
"sitename": "Personal Knowledge Container",
"base": "http:\/\/localhost:9352\/index.php\/Main_Page",
"generator": "MediaWiki 1.39.4",
"version": "0.3.0"
}
}
2 changes: 1 addition & 1 deletion scripts/push_pages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function pushHashChainJson {
}')

# Perform POST request
response=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "Content-Type: application/json" --data "$payload" "$apiUrl/import")
response=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "Content-Type: application/json" --data "$payload" "$apiUrl/import?direct=false")
#commenting out to write to file response=$(curl -s -o response.txt -w "%{http_code}" -X POST -H "Content-Type: application/json" --data "$payload" "$apiUrl/import")
if [[ "$response" != "200" ]]; then
echo "/import failed"
Expand Down
66 changes: 66 additions & 0 deletions scripts/push_pages_directly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

server="http://localhost:9352"
apiUrl="$server/rest.php/data_accounting"

function pushHashChainJson {
filename="$1"
fileContent=$(cat "$filename")
pages=$(echo "$fileContent" | jq '.pages')

# Get length of the pages array
len=$(echo "$pages" | jq '. | length')

# Iterate through pages
for (( i=0; i<$len; i++ )); do
page=$(echo "$pages" | jq ".[$i]")
site_info=$(echo "$fileContent" | jq '.site_info')

# Construct context object
context=$(echo "$page" | jq "{
genesis_hash: .genesis_hash,
domain_id: .domain_id,
latest_verification_hash: .latest_verification_hash,
title: .title,
namespace: .namespace,
chain_height: .chain_height,
site_info: $site_info
}")

revisions=$(echo "$page" | jq '.revisions')

# Loop through each key-value pair in revisions
for verificationHash in $(echo "${revisions}" | jq 'keys | .[]'); do
revision=$(echo "${revisions}" | jq ".[$verificationHash]")
echo "Pushing $verificationHash"

# Construct payload
payload=$(jq -n --argjson context "$context" --argjson revision "$revision" '{
context: $context,
revision: $revision
}')

# Perform POST request
response=$(curl -s -o /dev/null -w "%{http_code}" -X POST -H "Content-Type: application/json" --data "$payload" "$apiUrl/import?direct=true")
#commenting out to write to file response=$(curl -s -o response.txt -w "%{http_code}" -X POST -H "Content-Type: application/json" --data "$payload" "$apiUrl/import")
if [[ "$response" != "200" ]]; then
echo "/import failed"
#cat response.txt | jq .
exit 1
fi
done
done
}

# Main loop over JSON files in directory
#folderPath="import"
folderPath="import_direct"
for filename in "$folderPath"/*.json; do
if [[ -f "$filename" ]]; then
echo "Processing $filename"
pushHashChainJson "$filename"
else
echo "$filename is not a JSON file, hence skipping."
fi
done

0 comments on commit 9a593f9

Please sign in to comment.