~ekez/negativefour

8ac64125d2a74d447da8019cf9b59244f61dc8b5 — Zeke Medley 8 months ago 2fdc475
Don't require deployment to exist to see the status of a delete job

Deletion will remove the deployment..
4 files changed, 19 insertions(+), 16 deletions(-)

M serve/app.js
M serve/helpers/db.js
M www/routes/status.js
M www/routes/view.js
M serve/app.js => serve/app.js +1 -1
@@ 181,7 181,7 @@ app.post('/delete', requireAuth, function(req, res) {
	jobStatusMap.get(childProcessID).stderr += data
    })

    child.on('exit', code => {
    child.on('exit', async code => {
	jobStatusMap.get(childProcessID).exitCode = code
	if (code !== 0) {
	    sendDiscordAlert(`undeploy of (${name}) for (${user}) failed with exit code (${code})`)

M serve/helpers/db.js => serve/helpers/db.js +1 -1
@@ 39,7 39,7 @@ module.exports.registerDeploy = async (useremail, name, clearnet, darknet) => {

// Webpages are uniquely identified by their name and the controling
// user.
module.exports.registerUndeploy = async (userEmail, name) => {
module.exports.registerUndeploy = async (useremail, name) => {
    const client = await getClient()
    await client.query(`DELETE FROM deployments WHERE useremail='${useremail}' AND name='${name}'`)
}

M www/routes/status.js => www/routes/status.js +16 -13
@@ 46,27 46,30 @@ router.get('/:jobID/:name/:type', requireAuth, async function(req, res, next) {
	if (status.exitCode !== undefined) {
	    const code = status.exitCode
	    if (code === 0) {
		const deployments = await db.getUserDeployment(req.useremail, name)
		let clearnet = name
		if (type === 'deploy') {
		    const deployments = await db.getUserDeployment(req.useremail, name)

		if (deployments.length !== 1) {
		    return res.status(404).render('error', {
			message: `404 - there is no deployment with name (${name})`,
			userEmail: req.useremail,
			error: {
			    status: 'If you got here from the homepage this is likely an internal error. Please send me an email if you think something is wrong.',
			    stack: `${req.url}
		    if (deployments.length !== 1) {
			return res.status(404).render('error', {
			    message: `404 - there is no deployment with name (${name})`,
			    userEmail: req.useremail,
			    error: {
				status: 'If you got here from the homepage this is likely an internal error. Please send me an email if you think something is wrong.',
				stack: `${req.url}

${deployments}`,
			}
		    })
			    }
			})
		    }
		    const deployment = deployments[0]
		    clearnet = deployment.clearnet
		}

		const deployment = deployments[0]

		return res.status(200).render('status-success', {
		    status: status,
		    userEmail: req.useremail,
		    clearnet: deployment.clearnet,
		    clearnet: clearnet,
		    type: type,
		})
	    } else {

M www/routes/view.js => www/routes/view.js +1 -1
@@ 42,7 42,7 @@ ${deployments}`,

    return res.status(200).render('view-deployment', {
	userEmail: req.useremail,
	page: deployment,``
	page: deployment,
    })
})