|
|
@ -39,6 +39,7 @@ export default function applyRouter(app) { |
|
|
|
app.get('/public/favicon.ico', (req, res) => { |
|
|
|
app.get('/public/favicon.ico', (req, res) => { |
|
|
|
res.sendFile(path.join(__dirname, '../../dist/public/favicon.ico')) |
|
|
|
res.sendFile(path.join(__dirname, '../../dist/public/favicon.ico')) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
app.use(express.json({ limit: '100mb' })) |
|
|
|
app.use(cookieParser()) |
|
|
|
app.use(cookieParser()) |
|
|
|
app.use( |
|
|
|
app.use( |
|
|
|
express.urlencoded({ |
|
|
|
express.urlencoded({ |
|
|
@ -49,6 +50,14 @@ export default function applyRouter(app) { |
|
|
|
|
|
|
|
|
|
|
|
// app.use('/memes', express.static(process.env.AO_MEMES_DIR))
|
|
|
|
// 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
|
|
|
|
app.use(serverAuth) // below here requires auth token
|
|
|
|
|
|
|
|
|
|
|
|
app.use(spec) // handles event creation
|
|
|
|
app.use(spec) // handles event creation
|
|
|
@ -251,12 +260,55 @@ export default function applyRouter(app) { |
|
|
|
res.json(state.pubState.members) |
|
|
|
res.json(state.pubState.members) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
app.post('/fetchTaskByID', (req, res) => { |
|
|
|
app.post('/fetchTasks', (req, res) => { |
|
|
|
let errRes = [] |
|
|
|
let errRes = [] |
|
|
|
let foundThisTask |
|
|
|
let foundTasks |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('res text is', res.text) |
|
|
|
console.log('AO: server/router.js: fetchTaskByID: ', req.body) |
|
|
|
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 taskIdList = req.body.taskId |
|
|
|
let taskIdListParameterWasSingleValue = false |
|
|
|
let taskIdListParameterWasSingleValue = false |
|
|
|
if (!Array.isArray(taskIdList)) { |
|
|
|
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 errRes = [] |
|
|
|
let foundThisTask |
|
|
|
let foundThisTask |
|
|
|
|
|
|
|
|
|
|
|