diff options
Diffstat (limited to 'src/js')
45 files changed, 3646 insertions, 707 deletions
diff --git a/src/js/app.js b/src/js/app.js index f8fca5a..b42cbf0 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -1,54 +1,142 @@ -/* Arching Kaos Web UI App Launcher - * - * Kaotisk Hund - 2024 - * - * @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 - * - * - * Body and pageLayout resizer to device's resolution. - * - * TODO: Figure out why it doesn't work in fullscreen App mode (android) - * - */ -body.width = window.innerWidth; -body.height = window.innerHeight; -pageLayout.width = window.innerWidth; -pageLayout.height = window.innerHeight; -mainContainer.style.display = 'block'; -window.innerWidth <= 770 ? isMobile = true : isMobile = false; -isMobile ? doubleFloorMenu.style.display = 'none':doubleFloorMenu.style.display = 'flex'; -function onWindowResize() +// Arching Kaos Web UI App Launcher +// +// Kaotisk Hund - 2024 +// +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 +// + +import { locationHashOnChange } from "./arching-kaos-spa-router.js"; +import { doubleFloorMenu, menuinit, menusel, stellarSubToggle, modulesSubToggle, exploreSubToggle } from './ui/menu.js'; +import { mainLayoutSpawn } from "./ui/mainLayout.js"; +import { scanStellarNetworkForPeers } from "./arching-kaos-stellar-network.js"; +import { checkLocalNodeInfo, checkLocalPeers, checkLocalSchain, seekPeer, seekZblock, showResult } from "./arching-kaos-tools.js"; +import { refreshChat, refreshRadio, setDebug } from "./utils.js"; +import { akfsGetMap, akfsWorkOnChunks } from "./arching-kaos-file-system.js"; + +window.menusel = menusel; +window.locationHashOnChange = locationHashOnChange; +window.stellarSubToggle = stellarSubToggle; +window.modulesSubToggle = modulesSubToggle; +window.exploreSubToggle = exploreSubToggle; +window.scanStellarNetworkForPeers = scanStellarNetworkForPeers; +window.seekZblock = seekZblock; +window.checkLocalNodeInfo = checkLocalNodeInfo; +window.checkLocalPeers = checkLocalPeers; +window.checkLocalSchain = checkLocalSchain; +window.refreshChat = refreshChat; +window.refreshRadio = refreshRadio; +window.setDebug = setDebug; +window.showResult = showResult; +window.seekPeer = seekPeer; + +export function body() { - body.width = window.innerWidth; - body.height = window.innerHeight; - pageLayout.width = window.innerWidth; - pageLayout.height = window.innerHeight; - window.innerWidth <= 770 ? isMobile = true : isMobile = false; - isMobile ? doubleFloorMenu.style.display = 'none':doubleFloorMenu.style.display = 'flex'; + return document.querySelector('body'); } -window.addEventListener('resize', onWindowResize, false); -// And call -menuinit(); -locationHashOnChange(); +export function pageLayout() +{ + return document.querySelector('.page-layout'); +} + +export function mainContainer() +{ + return document.querySelector('.main'); +} + +window.isMobile = false; + +export function aknet() +{ + return document.querySelector('.aknet-network') +} + +export function resultsArea() +{ + return document.querySelector('.results-area') +} + +export function progressPlaceholder() +{ + return document.querySelector('#total-progress'); +} -progressPlaceholder.value = '0'; +export function httpProgressPlaceholder() +{ + return document.querySelector('#http-progress'); +} -progressPlaceholder.max++; +export function currentLogMessageElement() +{ + return document.querySelector('#current-log-message'); +} -if ( activeSettings.stellar.scan ) +export function logsAreaElement() { - scanStellarNetworkForPeers(); + return document.querySelector("#logs-area-element"); } -if ( activeSettings.ak.scan ) +export function radio() +{ + return document.querySelector("#radio-player"); +} + +export function radioButton() +{ + return document.querySelector("#radio-button-controller"); +} + + +body().width = window.innerWidth; +body().height = window.innerHeight; +pageLayout().width = window.innerWidth; +pageLayout().height = window.innerHeight; +mainContainer().style.display = 'block'; +window.innerWidth <= 850 ? window.isMobile = true : window.isMobile = false; + +function onWindowResize() { - ringlocalbell(); - setInterval(ringlocalbell, 10*60*1000); + body.width = window.innerWidth; + body.height = window.innerHeight; + pageLayout.width = window.innerWidth; + pageLayout.height = window.innerHeight; + window.innerWidth <= 850 ? window.isMobile = true : window.isMobile = false; + window.isMobile ? doubleFloorMenu().style.display = 'none': doubleFloorMenu().style.display = 'flex'; } +window.addEventListener('resize', onWindowResize, false); + //scanStellarNetworkForPeers(); // setInterval(scanStellarNetworkForPeers, 60000); +var root = { + head: document.querySelector('head'), + body: document.querySelector('body'), + html: document.querySelector('html') +}; + +// var scripts = [ +// { +// element:"script", +// type: "module", +// src:"./js/ui/mainLayout.js" +// } +// ]; +// +// for ( var i = 0; i < scripts.length; i++ ) +// { +// makeElement(scripts[i], root.body); +// } + +mainLayoutSpawn(); +// And call +menuinit(); +locationHashOnChange(); + +window.isMobile ? doubleFloorMenu().style.display = 'none': doubleFloorMenu().style.display = 'flex'; +// TESTS BELOW +window.akfsGetMap = akfsGetMap; +window.akfsWorkOnChunks = akfsWorkOnChunks; +//akfsGetMap('48965fddebc826632a4bc1bbe1ed6c1909541e1c03023c3cdb481fc3a5b53cfad1b6d92fd4cb77a4f75b6891e4dd005fa26d108b29ba203b732c92e4ce3d5e0c'); // vim: tabstop=4 shiftwidth=4 expandtab softtabstop=4 // @license-end diff --git a/src/js/arching-kaos-decentralized-radio.js b/src/js/arching-kaos-decentralized-radio.js index 061a142..63d2c2a 100644 --- a/src/js/arching-kaos-decentralized-radio.js +++ b/src/js/arching-kaos-decentralized-radio.js @@ -1,10 +1,10 @@ -/* Arching Kaos Dentralized Radio - * - * Kaotisk Hund - 2024 - * - * @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 - * - */ +// Arching Kaos Dentralized Radio +// +// Kaotisk Hund - 2024 +// +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 +// + // var radio = document.querySelector("#radio-player"); // var radioButton = document.querySelector("#radio-button-controller"); diff --git a/src/js/arching-kaos-fetch.js b/src/js/arching-kaos-fetch.js index 523baff..6cf1b76 100644 --- a/src/js/arching-kaos-fetch.js +++ b/src/js/arching-kaos-fetch.js @@ -1,11 +1,15 @@ -/* Arching Kaos Fetch - * - * Kaotisk Hund - 2024 - * - * @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 - * - */ -function archingKaosFetchJSON( url, callback, params ){ +// Arching Kaos Fetch +// +// Kaotisk Hund - 2024 +// +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 +// + +import { archingKaosLog } from "./arching-kaos-log.js"; +import { httpProgressPlaceholder, progressPlaceholder } from "./app.js"; +import { debugLog } from "./utils.js"; + +export function archingKaosFetchJSON( url, callback, params ){ const request = new XMLHttpRequest(); request.addEventListener("load", ()=>{ var json = JSON.parse(request.response); @@ -16,38 +20,77 @@ function archingKaosFetchJSON( url, callback, params ){ } }); request.addEventListener("error", ()=>{ - console.log("An error occured."); + debugLog("An error occured."); }); request.addEventListener("progress", (event)=>{ - if (event.lengthComputable && progressPlaceholder){ - httpProgressPlaceholder.value = (event.loaded / event.total) * 100; + if (event.lengthComputable && progressPlaceholder()){ + httpProgressPlaceholder().value = (event.loaded / event.total) * 100; } else { - httpProgressPlaceholder.value = 0; - console.log("Supposingly zeroed progressPlaceholder"); + httpProgressPlaceholder().value = 0; + debugLog("Supposingly zeroed progressPlaceholder"); } }); request.addEventListener("abort", ()=>{ - console.log("Request aborted."); + debugLog("Request aborted."); }); request.open("GET", url); request.send(); } -async function archingKaosFetchText( url, callback ){ - return fetch(url, { - method:'GET', - headers:{ - Accept: 'application/json' +export async function archingKaosFetchText( url, callback, params ){ + const request = new XMLHttpRequest(); + request.addEventListener("load", ()=>{ + var text = request.response; + if(request.status !== 404){ + callback(text, params); + } else { + archingKaosLog(`ERROR ${request.status} while loading ${url}`); + } + }); + request.addEventListener("error", ()=>{ + debugLog("An error occured."); + }); + request.addEventListener("progress", (event)=>{ + if (event.lengthComputable && progressPlaceholder()){ + httpProgressPlaceholder().value = (event.loaded / event.total) * 100; + } else { + httpProgressPlaceholder.value = 0; + debugLog("Supposingly zeroed progressPlaceholder"); + } + }); + request.addEventListener("abort", ()=>{ + debugLog("Request aborted."); + }); + request.open("GET", url); + request.send(); +} + +export function archingKaosFetchBlob( url, callback, params ){ + const request = new XMLHttpRequest(); + request.addEventListener("load", ()=>{ + var blob = request.response; + if(request.status !== 404){ + callback(blob, params); + } else { + archingKaosLog(`ERROR ${request.status} while loading ${url}`); } - }).then(response=>{ - if(response.ok){ - response.text().then(text=>{ - return callback(text); - }) + }); + request.addEventListener("error", ()=>{ + debugLog("An error occured."); + }); + request.addEventListener("progress", (event)=>{ + if (event.lengthComputable && progressPlaceholder()){ + httpProgressPlaceholder().value = (event.loaded / event.total) * 100; } else { - console.log(e); + httpProgressPlaceholder.value = 0; + debugLog("Supposingly zeroed progressPlaceholder"); } - }) + }); + request.addEventListener("abort", ()=>{ + debugLog("Request aborted."); + }); + request.open("GET", url); + request.send(); } // @license-end diff --git a/src/js/arching-kaos-file-system.js b/src/js/arching-kaos-file-system.js new file mode 100644 index 0000000..4ec85d5 --- /dev/null +++ b/src/js/arching-kaos-file-system.js @@ -0,0 +1,307 @@ +// Arching Kaos File System +// +// Kaotisk Hund - 2024 +// +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 +// + +import { akfsGetChunkURL, akfsGetLeafURL, akfsGetMapURL } from "./url-generators.js"; +import { archingKaosFetchBlob } from "./arching-kaos-fetch.js"; +import { offerDownloadableData } from "./utils.js"; +import {archingKaosLog} from "./arching-kaos-log.js"; +import { makeElement } from "./arching-kaos-generator.js"; + +var thingy = {}; +var leafs_counter = 0; +var leafs_head_counter = 0; +var first_chunk_spotted = 0; +var first_chunk_size = 0; +var final_array_seq = []; +var status = []; +var workspace = []; +var output = ""; + +function drawWorkSpace() +{ + var ele = { + element:"svg", + className: "akfsmap", + viewBox: "0 0 900 50", + version: "1.1", + style:"background-color:#333;width: 100%;height:100%;", + xmlns: "http://www.w3.org/2000/svg", + innerHTML:[ + ] + }; + if ( document.querySelector('svg') === null ) makeElement(ele, document.querySelector('.results-area')); +} + +function akfsReset() +{ + thingy = null; + thingy = {}; + leafs_counter = 0; + leafs_head_counter = 0; + first_chunk_spotted = 0; + first_chunk_size = 0; + final_array_seq = null; + final_array_seq = []; + status = []; + workspace = []; + output = ""; + if ( document.querySelector('svg') !== null ) document.querySelector('svg').remove(); +} + +export function akfsGetMap(hash) +{ + akfsReset(); + drawWorkSpace(); + archingKaosFetchBlob(akfsGetMapURL(hash), akfsFromMapGetLevelOneMapHash, [hash]) + return hash; +} + +function akfsFromMapGetOriginalHash(reply, params) +{ + const [ hash ] = params; + if(typeof(reply) === "string") + { + console.log(reply.split('\n')[0].split(' ')[0]); + } +} + +function akfsFromMapGetOriginalFilename(reply, params) +{ + const [ hash ] = params; + if(typeof(reply) === "string") + { + console.log(reply.split('\n')[0].split(' ')[1]); + } +} + +function akfsFromMapGetLevelOneMapHash(reply, params) +{ + const [ hash ] = params; + var hashregexp = /^[0-9a-f]{128}$/; + const level_1_map = reply.split('\n')[1].split(' ')[0]; + if(typeof(reply) === "string" && hashregexp.test(level_1_map)) + { + archingKaosFetchBlob(akfsGetLeafURL(level_1_map), akfsChunkOrLeaf, [level_1_map, hash, 0]); + thingy = { + leafs: [], + chunks: [], + root_hash: level_1_map, + map_hash: hash + }; + thingy[`${level_1_map}`] = []; + status[`${level_1_map}`] = 'working'; + } +} + +function akfsSerializeChunks(hash) +{ + if ( status[hash] === 'ready' ) + { + if ( thingy.chunks[hash] !== undefined ) + { + final_array_seq.push(hash); + } + else if ( thingy.leafs[hash] !== undefined ) + { + if ( thingy.leafs[hash].head !== undefined ) + { + akfsSerializeChunks(thingy.leafs[hash].head); + } + if ( thingy.leafs[hash].head !== thingy.leafs[hash].tail ) + { + akfsSerializeChunks(thingy.leafs[hash].tail); + } + } + else + { + console.log(`The following hash is failing: ${hash}`) + } + } + else + { + console.log(status); + console.log('next call'); + } +} + +function makeUpData() +{ + let response = ""; + for ( var i = 0; i < final_array_seq.length; i++ ) + { + response += thingy.chunks[final_array_seq[i]].data; + } + return Uint8Array.fromBase64(response.replaceAll('\n', '')); // incompatible atm for Chromium afaik +} + +export function akfsWorkOnChunks() +{ + akfsSerializeChunks(thingy.root_hash); + var data = makeUpData(); + offerDownloadableData(data); + console.log(workspace); +} + +function akfsChunkOrLeaf(reply, params) +{ + var [ hash, previous, wsn ] = params; + if ( workspace[wsn] === undefined ) workspace[wsn] = []; + if ( hash === thingy.root_hash ) workspace[wsn].push(hash); + wsn++; + if ( workspace[wsn] === undefined ) workspace[wsn] = []; + var hashregexp = /^[0-9a-f]{128}$/; + var base64regexp = /^[-A-Za-z0-9+/]*={0,3}$/; + if(typeof(reply) === "string") + { + if ( hashregexp.test(reply.split('\n')[0]) && hashregexp.test(reply.split('\n')[1]) && ( thingy.leafs[hash] === undefined ) ) + { + if ( leafs_counter === 0 ) + { + leafs_counter++; + } + leafs_head_counter++; + if ( previous === thingy.map_hash ) + { + console.log("Previous is a map_hash"); + } + else if ( previous === thingy.root_hash ) + { + console.log("Previous is a root_hash"); + } + if ( hash === thingy.map_hash ) + { + console.log("Current is a map_hash"); + } + else if ( hash === thingy.root_hash ) + { + console.log("Current is a root_hash"); + makeElement({ + element:"circle", + id:`c-${hash}`, + fill:"red", + cx:1+(workspace[wsn].length+1)*3, + cy:2+((wsn-1)*3), + r:"1" + }, document.querySelector('svg')); + } + // if ( thingy[hash] !== undefined ) + // { + // thingy[hash][reply.split('\n')[0]] = []; + // thingy[hash][reply.split('\n')[1]] = []; + // } + archingKaosLog(`${hash} is a leaf`); + var leaf = { + hash: hash, + head: reply.split('\n')[0], + tail: reply.split('\n')[1] + }; + thingy.leafs[leaf.hash] = leaf; + document.querySelector(`#c-${leaf.hash}`).setAttribute("fill", "lightgreen"); + status[leaf.hash] = 'ready'; + status[leaf.head] = 'working'; + archingKaosFetchBlob(akfsGetLeafURL(leaf.head), akfsChunkOrLeaf, [leaf.head, hash, wsn]); + archingKaosFetchBlob(akfsGetChunkURL(leaf.head), akfsChunkOrLeaf, [leaf.head, hash, wsn]); + workspace[wsn].push(leaf.head); + makeElement({ + element:"circle", + id:`c-${leaf.head}`, + fill:"red", + cx:1+(workspace[wsn].length*3), + cy:2+((wsn)*3), + r:"1" + }, document.querySelector('svg')); + if ( leaf.head !== leaf.tail ) + { + status[leaf.tail] = 'working'; + archingKaosFetchBlob(akfsGetLeafURL(leaf.tail), akfsChunkOrLeaf, [leaf.tail, hash, wsn]); + archingKaosFetchBlob(akfsGetChunkURL(leaf.tail), akfsChunkOrLeaf, [leaf.tail, hash, wsn]); + workspace[wsn].push(leaf.tail); + makeElement({ + element:"circle", + id:`c-${leaf.tail}`, + fill:"red", + cx:1+(workspace[wsn].length*3), + cy:2+((wsn)*3), + r:"1" + }, document.querySelector('svg')); + } + } + else if ( base64regexp.test(reply.replaceAll('\n', '')) && ( thingy.chunks[hash] === undefined ) ) + { + if ( first_chunk_spotted === 0 ) + { + first_chunk_spotted = leafs_head_counter; + // console.log(`first_chunk_spotted : ${first_chunk_spotted}`); + first_chunk_size = reply.length; + } + var chunk = { + hash: hash, + data: reply + }; + document.querySelector(`#c-${chunk.hash}`).setAttribute("fill", "lightgreen"); + archingKaosLog(`${hash} is a chunk`); + status[chunk.hash] = 'ready'; + thingy.chunks[chunk.hash] = chunk; + if ( first_chunk_size > chunk.data.length || chunk.data.length < 1024 || ( chunk.data.length < 4096 && first_chunk_size >= 4096 ) ) + { + // akfsWorkOnChunks(); + } + } + else + { + console.log("Unreachable"); + } + } + else if (JSON.parse(reply)) + { + const obj = JSON.parse(reply); + if ( obj.error !== undefined ) console.log( obj.error ); + } + else if (typeof(reply) === "object") + { + console.log("Unreachable"); + } + else + { + console.log("Unreachable"); + } +} + +function akfsStoreChunk(chunk, params) +{ + const [ hash, previous ] = params; + var base64regexp = /^[-A-Za-z0-9+/]*={0,3}$/ + if ( base64regexp.test(chunk) ) + { + thingy.chunks[hash] = { + data: chunk + }; + } +} + +function akfsGetChunk(chunk, params) +{ + const [ hash, previous ] = params; + akfsStoreChunk(chunk, [hash, previous]); +} + +function akfsGetLeaf(leaf, params) +{ + const [hash, previous] = params; + if(typeof(leaf) === "object") + { + archingKaosFetchBlob(akfsGetLeafURL(leaf.head), akfsChunkOrLeaf, [hash, previous]); + archingKaosFetchBlob(akfsGetChunkURL(leaf.head), akfsChunkOrLeaf, [hash, previous]); + if ( leaf.head !== leaf.tail ) + { + archingKaosFetchBlob(akfsGetLeafURL(leaf.tail), akfsChunkOrLeaf, [hash, previous]); + archingKaosFetchBlob(akfsGetChunkURL(leaf.tail), akfsChunkOrLeaf, [hash, previous]); + } + } +} + +// @license-end diff --git a/src/js/arching-kaos-generator.js b/src/js/arching-kaos-generator.js index 67ab351..8dc189c 100644 --- a/src/js/arching-kaos-generator.js +++ b/src/js/arching-kaos-generator.js @@ -1,16 +1,20 @@ -/* Arching Kaos Generator - * - * Kaotisk Hund - 2024 - * - * @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 - * - */ -function makeElement(obj, attachTo) +// Arching Kaos Generator +// +// Kaotisk Hund - 2024 +// +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0 +// + +export function makeElement(obj, attachTo) { - if (obj.element !== 'head' && obj.element !== 'body' ) + if (obj.element !== 'head' && obj.element !== 'body' && obj.element !== 'svg' && obj.element !== 'circle') { var temp = document.createElement(obj.element); } + else if ( obj.element === 'svg' || obj.element === 'circle' ) + { + var temp = document.createElementNS("http://www.w3.org/2000/svg", obj.element); + } else if ( obj.id !== null && document.querySelector('#'+obj.id) ) { var temp = document.querySelector('#'+obj.id); @@ -24,12 +28,17 @@ function makeElement(obj, attachTo) if ( obj.type !== undefined ) temp.type = obj.type; if ( obj.content !== undefined ) temp.content = obj.content; if ( obj.property !== undefined ) temp.property = obj.property; - if ( obj.className !== undefined ) temp.className = obj.className; + if ( obj.className !== undefined && obj.element !== 'svg') temp.className = obj.className; if ( obj.rel !== undefined ) temp.rel = obj.rel; + if ( obj.min !== undefined ) temp.min = obj.min; + if ( obj.max !== undefined ) temp.max = obj.max; + if ( obj.step !== undefined ) temp.step = obj.step; if ( obj.href !== undefined ) temp.href = obj.href; + if ( obj.style !== undefined ) temp.style = obj.style; if ( obj.src !== undefined ) temp.src = obj.src; if ( obj.as !== undefined ) temp.as = obj.as; if ( obj.target !== undefined ) temp.target = obj.target; + if ( obj.onclick !== undefined ) temp.setAttribute("onclick", obj.onclick); if ( obj.alt !== undefined ) temp.alt = obj.alt; if ( obj.charset !== undefined ) temp.charset = obj.charset; if ( obj.value !== undefined ) temp.value = obj.value; @@ -38,6 +47,17 @@ function makeElement(obj, attachTo) if ( obj.placeholder !== undefined ) temp.placeholder = obj.placeholder; if ( obj.classes !== undefined ) temp.classList = obj.classes; if ( obj.innerText !== undefined ) temp.innerText = obj.innerText; + if ( obj.viewBox !== undefined ) temp.setAttribute("viewBox", obj.viewBox); + if ( obj.cx !== |