-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Universal Web
committed
Mar 23, 2023
1 parent
495fb60
commit bb176fb
Showing
13 changed files
with
235 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,40 @@ | ||
module.exports = (server) => { | ||
const { | ||
logImprt, | ||
utility: { | ||
isPlainObject, | ||
eachObjectAsync, | ||
isArray, | ||
eachAsync, | ||
assign | ||
}, | ||
app | ||
} = server; | ||
logImprt('SERVER APP API', __dirname); | ||
async function add(method, methodName) { | ||
app[methodName] = method; | ||
console.log('Extended App API', methodName); | ||
import { onMessage } from './onMessage.js'; | ||
import { | ||
isPlainObject, | ||
eachObjectAsync, | ||
isArray, | ||
eachAsync, | ||
assign | ||
} from 'Acid'; | ||
import { imported } from 'utilities/logs.js'; | ||
imported('SERVER APP API'); | ||
async function add(app, methodName, method) { | ||
app.set(methodName, method); | ||
console.log('Extended App API', methodName); | ||
} | ||
export async function addApi(methodName, method) { | ||
const { app } = this; | ||
if (isPlainObject(methodName)) { | ||
return eachObjectAsync(methodName, (childMethod, childMethodName) => { | ||
add(app, childMethodName, childMethod); | ||
}); | ||
} | ||
async function addApi(methodName, method) { | ||
if (isPlainObject(methodName)) { | ||
return eachObjectAsync(methodName, add); | ||
} | ||
return add(methodName, method); | ||
return add(app, methodName, method); | ||
} | ||
async function remove(app, method, methodName) { | ||
app.delete(methodName); | ||
} | ||
export async function removeApi(methods) { | ||
const { app } = this; | ||
if (isPlainObject(methods)) { | ||
return eachObjectAsync(methods, (method, methodName) => { | ||
remove(app, methodName); | ||
}); | ||
} | ||
async function remove(method, methodName) { | ||
app[methodName] = null; | ||
if (isArray(methods)) { | ||
return eachAsync(methods, (methodName) => { | ||
remove(app, methodName); | ||
}); | ||
} | ||
async function removeApi(methodName) { | ||
if (isPlainObject(methodName)) { | ||
return eachObjectAsync(methodName, remove); | ||
} | ||
if (isArray(methodName)) { | ||
return eachAsync(methodName, remove); | ||
} | ||
return remove(methodName); | ||
} | ||
assign(server.api, { | ||
add: addApi, | ||
remove: removeApi | ||
}); | ||
require('./onMessage')(server); | ||
}; | ||
return remove(app, methods); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,48 @@ | ||
module.exports = (server) => { | ||
import { | ||
stringify, | ||
hasValue | ||
} from 'Acid'; | ||
import { | ||
success, failed, imported, msgSent, info | ||
} from 'utilities/logs.js'; | ||
imported('ON PUBLIC MESSAGE'); | ||
export async function onMessage(socket, message) { | ||
const { app, } = this; | ||
const { | ||
cnsl, | ||
logImprt, | ||
error: logError, | ||
success, | ||
app, | ||
utility: { | ||
stringify, | ||
hasValue | ||
} | ||
} = server; | ||
logImprt('ON PUBLIC MESSAGE', __dirname); | ||
const onMessage = async (socket, message) => { | ||
const { | ||
body, | ||
sid, | ||
api | ||
} = message; | ||
if (!api) { | ||
return logError(`Invalid no method name given. ${stringify(message)}`); | ||
} | ||
const method = app[api]; | ||
if (method) { | ||
if (body) { | ||
if (hasValue(sid)) { | ||
cnsl(`Request:${api} RequestID: ${sid}`); | ||
console.log(message.body); | ||
const response = { | ||
sid | ||
}; | ||
const hasResponse = await method(socket, message, response); | ||
if (hasResponse) { | ||
socket.send(response); | ||
} | ||
return; | ||
} else { | ||
const eid = message.eid; | ||
if (hasValue(eid)) { | ||
success(`Request:${method} Emit ID:${eid} ${stringify(message)}`); | ||
return method(socket, body, message); | ||
} else { | ||
return logError(`Invalid Request type. No Emit ID was given. ${stringify(message)}`); | ||
} | ||
body, | ||
sid, | ||
api | ||
} = message; | ||
if (!api) { | ||
return failed(`Invalid no method name given. ${stringify(message)}`); | ||
} | ||
const method = app[api]; | ||
if (method) { | ||
if (body) { | ||
if (hasValue(sid)) { | ||
info(`Request:${api} RequestID: ${sid}`); | ||
console.log(message.body); | ||
const response = { | ||
sid | ||
}; | ||
const hasResponse = await method(socket, message, response); | ||
if (hasResponse) { | ||
socket.send(response); | ||
} | ||
return; | ||
} else { | ||
return logError(`Invalid Request no body was sent. ${stringify(message)}`); | ||
const eid = message.eid; | ||
if (hasValue(eid)) { | ||
success(`Request:${method} Emit ID:${eid} ${stringify(message)}`); | ||
return method(socket, body, message); | ||
} else { | ||
return failed(`Invalid Request type. No Emit ID was given. ${stringify(message)}`); | ||
} | ||
} | ||
} else { | ||
return logError(`Invalid method name given. ${stringify(message)}`); | ||
return failed(`Invalid Request no body was sent. ${stringify(message)}`); | ||
} | ||
}; | ||
server.api.onMessage = onMessage; | ||
}; | ||
} else { | ||
return failed(`Invalid method name given. ${stringify(message)}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { promise } from 'Acid'; | ||
import { info } from '../utilities/logs.js'; | ||
export async function bind(server) { | ||
export async function bindServer() { | ||
const { | ||
server: rawServer, | ||
server, | ||
configuration: { | ||
port, | ||
ip, | ||
} | ||
} = this; | ||
info(`BIND SERVER`); | ||
await promise((accept) => { | ||
rawServer.bind(port, ip, accept); | ||
server.bind(port, ip, accept); | ||
info(`SERVER BOUND: IP:${ip} - PORT:${port}`); | ||
}); | ||
return server; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { write } from '../file.js'; | ||
import { encode } from '../crypto.js'; | ||
export default async function saveCertificate(certificate, directory, certificateName = 'profile') { | ||
export async function saveCertificate(certificate, directory, certificateName = 'profile') { | ||
await write(`${directory}/${certificateName}.cert`, encode(certificate)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.