Browse Source

tiny stuff

main
deicidus 3 years ago
parent
commit
b971de6996
  1. 2
      src/modules/context.ts
  2. 3
      src/routes/index.svelte
  3. 91
      src/server/router.ts

2
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) {}

3
src/routes/index.svelte

@ -148,8 +148,11 @@ svg img static:
</ul>
<h2>todo</h2>
<ul>
<li>add ability to install and verify install of ao-server via ao-cli</li>
<li>render manual in browser</li>
<li>add ability to view state.aos list in cli</li>
<li>add ability to connect your AO server to another AO in ao-cli</li>
<li>add command-line chatroom to ao-cli (host or join)</li>
<li>start to add more metadata to AOs in list: sshKey, isSharable, maybe isVerified. maybe sublist of aos: for each ao (or hops variable)</li>
</ul>
<h2>features</h2>

91
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

Loading…
Cancel
Save