From b971de699668d3212c7e826f37b049f1b2055a92 Mon Sep 17 00:00:00 2001
From: deicidus <>
Date: Mon, 13 Jun 2022 16:53:25 -0700
Subject: [PATCH] tiny stuff
---
src/modules/context.ts | 2 +-
src/routes/index.svelte | 3 ++
src/server/router.ts | 91 +++++++++++++++++++++++++++++++++++++++--
3 files changed, 92 insertions(+), 4 deletions(-)
diff --git a/src/modules/context.ts b/src/modules/context.ts
index 5a279b2..761f327 100644
--- a/src/modules/context.ts
+++ b/src/modules/context.ts
@@ -53,7 +53,7 @@ const actions = {
let isMuted = getters.member.muted
if (!isMuted) {
try {
- //let flip = new Audio(require('../sounds/pageturn.wav'))
+ let flip = new Audio(require('../sounds/pageturn.wav'))
flip.volume = flip.volume * 0.33
flip.play()
} catch (err) {}
diff --git a/src/routes/index.svelte b/src/routes/index.svelte
index 1b19274..1d6c3ea 100644
--- a/src/routes/index.svelte
+++ b/src/routes/index.svelte
@@ -148,8 +148,11 @@ svg img static:
todo
+ - add ability to install and verify install of ao-server via ao-cli
- render manual in browser
- add ability to view state.aos list in cli
+ - add ability to connect your AO server to another AO in ao-cli
+ - add command-line chatroom to ao-cli (host or join)
- start to add more metadata to AOs in list: sshKey, isSharable, maybe isVerified. maybe sublist of aos: for each ao (or hops variable)
features
diff --git a/src/server/router.ts b/src/server/router.ts
index ec7929f..a263534 100755
--- a/src/server/router.ts
+++ b/src/server/router.ts
@@ -39,6 +39,7 @@ export default function applyRouter(app) {
app.get('/public/favicon.ico', (req, res) => {
res.sendFile(path.join(__dirname, '../../dist/public/favicon.ico'))
})
+ app.use(express.json({ limit: '100mb' }))
app.use(cookieParser())
app.use(
express.urlencoded({
@@ -48,6 +49,14 @@ export default function applyRouter(app) {
)
// app.use('/memes', express.static(process.env.AO_MEMES_DIR))
+
+ // Returns a list of all the tor addresses this AO knows about
+ // todo: Next upgrade will make a distinction between bootstrapping addresses and private connections
+ app.get('/bootstrap', (req, res) => {
+ console.log('/bootstrap', state.serverState.ao)
+ const onions = state.serverState.ao.map(ao => ao.address)
+ res.json({ addresses: onions })
+ })
app.use(serverAuth) // below here requires auth token
@@ -251,12 +260,55 @@ export default function applyRouter(app) {
res.json(state.pubState.members)
})
- app.post('/fetchTaskByID', (req, res) => {
+ app.post('/fetchTasks', (req, res) => {
let errRes = []
- let foundThisTask
+ let foundTasks
+ console.log('res text is', res.text)
console.log('AO: server/router.js: fetchTaskByID: ', req.body)
+ let taskIdList = req.body.taskIds
+ if (!Array.isArray(taskIdList)) {
+ console.log('/fetchTasks only accepts an array of taskIds in JSON parameter named taskIds, request failed')
+ res.status(400).send({ success: false, errorList: errRes })
+ return false
+ }
+
+ let allTaskIdsAreSane = true
+ taskIdList.some(taskId => {
+ if (!validators.isTaskId_sane(taskId, errRes)) {
+ console.log('Not all requested task IDs are sane:', taskId)
+ allTaskIdsAreSane = false
+ return true
+ }
+ })
+
+ let foundThisTaskList = []
+ let foundAllTaskItems = false
+ if (allTaskIdsAreSane === true) {
+ state.pubState.tasks.some(taskItem => {
+ if (taskIdList.includes(taskItem.taskId)) {
+ foundThisTaskList.push(taskItem)
+ taskIdList.splice(taskIdList.indexOf(taskItem.taskId), 1)
+ if (taskIdList.length === 0) {
+ foundAllTaskItems = true
+ return true
+ }
+ }
+ })
+
+ if (foundThisTaskList.length === 0) {
+ res.status(400).send({ success: false, errorList: errRes })
+ } else {
+ res.status(200).json(foundThisTaskList)
+ }
+ }
+ })
+
+ app.post('/fetchTaskByID', (req, res) => {
+ let errRes = []
+ let foundThisTask
+
let taskIdList = req.body.taskId
let taskIdListParameterWasSingleValue = false
if (!Array.isArray(taskIdList)) {
@@ -463,7 +515,40 @@ export default function applyRouter(app) {
}
})
- app.post('/fetchTaskByName', (req, res) => {
+ app.post('/fetchTaskByName_exact', (req, res) => {
+ console.log("/fetchTaskByName_exact")
+ let errRes = []
+ let foundThisTask
+
+ const trimmedTaskName = req.body.taskName.trim().toLowerCase()
+ if (validators.isTaskName_sane(req.body.taskName, errRes)) {
+ let taskName = req.body.taskName
+ state.pubState.tasks.some(taskItem => {
+ if (taskItem.name.toLowerCase() === trimmedTaskName) {
+ foundThisTask = taskItem
+ return true
+ }
+ })
+
+ if (foundThisTask) {
+ // console.log("AO: server/router.js: fetchTaskByName: task found: ", {"taskName": req.body.taskName, "result": foundThisTask})
+ res.status(200).send(foundThisTask)
+ } else {
+ console.log('AO: server/router.js: fetchTaskByName_exact: task not found ', {
+ 'req.body': req.body,
+ foundThisTask,
+ })
+ errRes.push('task name not found')
+ res.status(204).send({ success: false, errorList: errRes })
+ }
+ } else {
+ // console.log("AO: server/router.js: fetchTaskByName: invalid taskName: ", { "req.body": req.body, foundThisTask } )
+ res.status(400).send(errRes)
+ }
+ })
+
+ app.post('/fetchTaskByName_exact', (req, res) => {
+ console.log("/fetchTaskByName")
let errRes = []
let foundThisTask