Skip to content

Commit

Permalink
Dep update + cache re-work
Browse files Browse the repository at this point in the history
  • Loading branch information
sentivate committed May 12, 2022
1 parent 2c98e15 commit b66dc10
Show file tree
Hide file tree
Showing 16 changed files with 1,314 additions and 1,206 deletions.
2,194 changes: 1,168 additions & 1,026 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,50 @@
},
"company": "Universal Web, Inc",
"dependencies": {
"Acid": "^3.0.4",
"Acid": "^3.0.5",
"base64-img": "^1.0.4",
"compression": "^1.7.4",
"docredux": "^3.0.0",
"figlet": "^1.5.2",
"hyper-express": "^5.9.1",
"hyper-express": "^6.1.3",
"image-size": "^1.0.1",
"is-valid-path": "^0.1.1",
"live-directory": "^2.3.2",
"mongoose": "^6.2.9",
"msgpackr": "^1.5.5",
"mongoose": "^6.3.2",
"msgpackr": "^1.5.7",
"node-dir": "^0.1.17",
"node-watch": "^0.7.3",
"qrcode": "^1.5.0",
"sharp": "^0.30.3",
"sharp": "^0.30.4",
"sodium-native": "^3.3.0",
"string_decoder": "^1.3.0",
"textlint": "^12.1.1",
"truncate-utf8-bytes": "^1.0.2",
"uuid": "^8.3.2",
"walk": "^2.3.15",
"webtorrent": "^1.8.12",
"webtorrent": "^1.8.16",
"zip-a-folder": "^1.1.3"
},
"description": "Sentivate Network Client, Server Module, UDSP, Universal Web Socket, & certificate generation. This serves as a service & browser prototype.",
"devDependencies": {
"@babel/core": "^7.17.8",
"@babel/core": "^7.17.10",
"@babel/eslint-parser": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@babel/preset-env": "^7.17.10",
"@septdirworkshop/ukfontawesome": "^5.15.1",
"auto-changelog": "^2.4.0",
"electron": "^18.0.0",
"electron": "^18.2.0",
"electron-builder": "*",
"esformatter": "*",
"eslint": "^8.12.0",
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.6.1",
"prettier": "^2.6.2",
"ractive": "^1.4.0",
"rollup": "^2.70.1",
"rollup": "^2.72.1",
"rollup-plugin-terser": "^7.0.2",
"testatron": "^2.1.0",
"uikit": "^3.13.5"
"uikit": "^3.14.1"
},
"engines": {
"node": ">=12.9.1"
Expand Down
4 changes: 4 additions & 0 deletions uwBridge/.babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": [],
"plugins": []
}
90 changes: 49 additions & 41 deletions uwBridge/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const utility = require('Acid');
const fs = require('fs');
const {
open: openStream
} = require('fs/promises');
const fsAsync = require('fs').promises;
const {
client
} = require('./system/client');
Expand Down Expand Up @@ -32,8 +30,11 @@ const fileUtility = require('../utilities/file');
const consoleUtility = require('../utilities/console');
const certificateUtility = require('../utilities/certificate');
const certificatesUtility = require('../utilities/certificates');
const assetsRegex = RegExp('/assets/');
const rawRegex = RegExp('/raw/');
const startsWithAssets = '/assets/';
const startsWithAssetsReplace = '/assets';
const startsWithWellKnown = '/.well-known/';
const startsWithWellKnownReplace = '/.well-known';
const startsWithRaw = '/raw/';
class uwBridge {
constructor(config) {
return promise(async (accept) => {
Expand Down Expand Up @@ -94,7 +95,10 @@ class uwBridge {
}
return thisBind.events[eventNames].push(callback);
}
async handleRequest(host, indexPage, liveAssets, publicDir, request, response) {
async notFound(response) {
return response.status(404).send();
}
async handleRequest(host, indexPage, liveAssets, liveAssetsWellKnown, staticAssetsDirectory, publicDir, request, response) {
const requestPath = request.path;
console.log(request.headers['cf-connecting-ip'], requestPath);
if (!request.headers['cf-connecting-ip']) {
Expand All @@ -107,54 +111,47 @@ class uwBridge {
if (requestPath === '/') {
return response.type('html').send(`${indexPage}<script>_realip='${request.headers['cf-connecting-ip']}'</script>`);
}
if (assetsRegex.test(requestPath)) {
const file = liveAssets.get(requestPath);
if (requestPath.startsWith(startsWithWellKnown)) {
const file = liveAssetsWellKnown.get(requestPath.replace(startsWithWellKnownReplace, ''));
if (file === undefined) {
return this.notFound(response);
}
console.log(file.name === 'apple-app-site-association');
response.header('content-type', 'application/json');
return response.send(file.buffer);
}
if (requestPath.startsWith(startsWithAssets)) {
const file = liveAssets.get(requestPath.replace(startsWithAssetsReplace, ''));
if (file === undefined) {
return response.status(200).send();
return this.notFound(response);
}
return response.type(file.extension).send(file.buffer);
} else if (rawRegex.test(requestPath)) {
}
if (requestPath.startsWith(startsWithRaw)) {
const fileLocation = normalize(join(publicDir, requestPath));
console.log(publicDir, fileLocation);
if (!fileLocation.includes(publicDir)) {
return response.status(404).send();
return this.notFound(response);
}
console.log('PASSED', fileLocation);
const fileCheck = await promise((accept) => {
fs.stat(publicDir + requestPath, (err, stats) => {
if (err) {
return accept(false);
}
return accept(stats);
});
});
console.log('STREAMING FILE', fileCheck);
if (fileCheck) {
try {
// response.header('x-is-streamed', 'true');
// const use_chunked_encoding = request.headers['x-chunked-encoding'] === 'true';
const file = fs.readFileSync(fileLocation);
console.log(file);
return response.type(getFileExtension(fileLocation)).send(file);
// return response.stream(stream, use_chunked_encoding ? undefined : fileCheck.size);
} catch {
return response.status(404).send();
}
} else {
return response.status(404).send();
try {
const file = await fsAsync.readFile(fileLocation);
console.log('SENDING', fileLocation);
return response.type(getFileExtension(fileLocation)).send(file);
} catch {
return this.notFound(response);
}
} else {
return response.type('html').send(`${indexPage}<script>_realip='${request.headers['cf-connecting-ip']}'</script>`);
}
return response.type('html').send(`${indexPage}<script>_realip='${request.headers['cf-connecting-ip']}'</script>`);
}
async httpCreate() {
const {
config: {
host,
staticAssetsDirectory,
publicDir,
wellknownDirectory,
server,
http: {
indexLocation
indexLocation,
}
}
} = this;
Expand All @@ -168,8 +165,16 @@ class uwBridge {
indexPage = fs.readFileSync(indexLocation);
});
console.log(indexPage);
const liveAssetsWellKnown = new LiveDirectory({
path: wellknownDirectory,
keep() {
return true;
}
});
await liveAssetsWellKnown.ready();
console.log(liveAssetsWellKnown.files);
const liveAssets = new LiveDirectory({
path: publicDir,
path: staticAssetsDirectory,
keep: {
extensions: ['.css', '.html', '.js', '.json', '.csv', '.png', '.jpg', '.svg', '.woff2', '.woff', '.otf']
},
Expand All @@ -179,8 +184,9 @@ class uwBridge {
});
await liveAssets.ready();
this.LiveAssets = liveAssets;
this.liveAssetsWellKnown = liveAssetsWellKnown;
this.server.get('/*', async (request, response) => {
return this.handleRequest(host, indexPage, liveAssets, publicDir, request, response);
return this.handleRequest(host, indexPage, liveAssets, liveAssetsWellKnown, staticAssetsDirectory, publicDir, request, response);
});
console.log('http service');
}
Expand All @@ -205,7 +211,9 @@ class uwBridge {
config.apiSystemDir = resolve(config.apiDir, `./system/`);
config.siteDir = resolve(directory, `./filesystem/`);
config.publicDir = resolve(config.siteDir, `./public/`);
config.staticAssetsDirectory = resolve(config.publicDir, `./assets/`);
config.resourceDir = resolve(directory, `./filesystem/asset/`);
config.wellknownDirectory = resolve(config.siteDir, `./public/.well-known/`);
config.http.indexLocation = resolve(config.siteDir, `./public/index.html`);
config.http.indexErrorLocation = resolve(config.siteDir, `./public/error.html`);
}
Expand Down Expand Up @@ -275,7 +283,7 @@ class uwBridge {
return clientSocket.close();
}
console.log(clientSocket, `${clientSocket.context?.ip || clientSocket.ip} is now connected using websockets!`);
console.log(`user ${clientSocket.context} has connected to consume news events`);
console.log(`USER:${stringify(clientSocket.context)} is connected to the websocket`);
client(clientSocket, this);
});
}
Expand Down
3 changes: 3 additions & 0 deletions uwBridge/notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// response.header('x-is-streamed', 'true');
// const use_chunked_encoding = request.headers['x-chunked-encoding'] === 'true';
// return response.stream(stream, use_chunked_encoding ? undefined : fileCheck.size);
65 changes: 0 additions & 65 deletions uwBridge/production.js

This file was deleted.

34 changes: 25 additions & 9 deletions uwBridge/system/compile/build/front/bundle.js

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions uwBridge/system/compile/build/front/coreBundle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function() {
const {
isPlainObject: isPlainObject$3, virtualStorage, crate: crate$4, hasValue: hasValue$6
isPlainObject: isPlainObject$4, virtualStorage, crate: crate$4, hasValue: hasValue$6
} = $;
const app = {
events: {},
Expand All @@ -25,8 +25,10 @@
},
componentStore(keyPath, keyValue) {
if (hasValue$6(keyValue)) {
return Ractive.sharedSet(keyPath, keyValue);
} else if (isPlainObject$3(keyPath)) {
if (Ractive.sharedGet(keyPath) !== keyValue) {
return Ractive.sharedSet(keyPath, keyValue);
}
} else if (isPlainObject$4(keyPath)) {
return Ractive.sharedSet(keyPath);
}
return Ractive.sharedGet(keyPath);
Expand Down Expand Up @@ -157,7 +159,8 @@
jsonParse,
isFileJS,
isFileJSON,
isFileCSS
isFileCSS,
isPlainObject: isPlainObject$3
}
} = app;
const headNode$1 = querySelector$2('head');
Expand All @@ -172,6 +175,9 @@
const checksumData$1 = (item) => {
const checksumString = crate$3.getItem(`cs-${item}`);
if (checksumString) {
if (isPlainObject$3(checksumString)) {
return checksumString;
}
const checksum = jsonParse(checksumString);
if (checksum) {
return checksum;
Expand All @@ -180,9 +186,8 @@
};
app.checksumData = checksumData$1;
const checksumReturn = (item) => {
const checksumString = crate$3.getItem(`cs-${item}`);
if (checksumString) {
const checksum = jsonParse(checksumString);
const checksum = checksumData$1(item);
if (checksum) {
if (checksum?.cs) {
return checksum.cs;
}
Expand Down Expand Up @@ -253,6 +258,14 @@
if (fileContents === true) {
if (!imported$1[filePath]) {
fileContents = crate$3.getItem(filePath);
if (fileContents) {
console.log(filePath);
const checksumUpdate = checksumData$1(filePath);
if (checksumUpdate) {
checksumUpdate.time = Date.now();
crate$3.setItem(`cs-${filePath}`, checksumUpdate);
}
}
}
} else if (fileContents !== false) {
if (app.debug) {
Expand Down Expand Up @@ -510,11 +523,14 @@
}
} else {
const localstoredCache = crate$2.getItem(filePath);
// console.log(filePath, localstoredCache);
// console.log('Local File Cache check', filePath, localstoredCache?.length);
if (localstoredCache && isString$5(localstoredCache)) {
console.log(filePath);
const cacheTimeElapsed = checksumData(filePath);
// console.log('Local File Cache check time elapsed', filePath, cacheTimeElapsed);
if (cacheTimeElapsed) {
const timeElapsed = Date.now() - cacheTimeElapsed.time;
// console.log('Local File Cache check time elapsed compute', filePath, timeElapsed, timeElapsed <= app.cacheExpire);
if (timeElapsed <= app.cacheExpire) {
try {
const hotModule = await hotloadJS(localstoredCache, filePath);
Expand Down
2 changes: 1 addition & 1 deletion uwBridge/system/compile/build/worker/bundle.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion uwBridge/system/compile/source/front/core/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const app = {
},
componentStore(keyPath, keyValue) {
if (hasValue(keyValue)) {
return Ractive.sharedSet(keyPath, keyValue);
if (Ractive.sharedGet(keyPath) !== keyValue) {
return Ractive.sharedSet(keyPath, keyValue);
}
} else if (isPlainObject(keyPath)) {
return Ractive.sharedSet(keyPath);
}
Expand Down
Loading

0 comments on commit b66dc10

Please sign in to comment.