Small QOL tweaks

This commit is contained in:
oitsjustjose 2020-10-17 09:41:52 -05:00
commit 996b8c1572
5 changed files with 26 additions and 7 deletions

View file

@ -1,7 +1,6 @@
import { Request, Response } from 'express' import { Request, Response } from 'express'
import Images from '../../db/img.schema'
import fs from 'fs' import fs from 'fs'
import path from 'path' import Images from '../../db/img.schema'
export default async (req: Request, res: Response) => { export default async (req: Request, res: Response) => {
try { try {
@ -15,7 +14,7 @@ export default async (req: Request, res: Response) => {
/* If some other IP uploads, we want to add them too */ /* If some other IP uploads, we want to add them too */
img.uploaders.push(req.clientIp as string) img.uploaders.push(req.clientIp as string)
await img.save() await img.save()
return res.status(200).send(img._id); return res.status(200).send(img._id)
} }
} }
@ -27,7 +26,7 @@ export default async (req: Request, res: Response) => {
await img.save() await img.save()
return res.status(200).send(img._id); return res.status(200).send(img._id)
} catch (ex) { } catch (ex) {
console.error(ex) console.error(ex)
return res.status(500).send({ return res.status(500).send({

View file

@ -10,7 +10,7 @@ export default async (req: Request, res: Response) => {
// Check for an expired link // Check for an expired link
if (moment().isAfter(moment(paste.expiresAt))) { if (moment().isAfter(moment(paste.expiresAt))) {
await Pastes.findByIdAndDelete(paste._id) await Pastes.findByIdAndDelete(paste._id)
return res.status(404).send("PASTE_EXPIRED") return res.status(404).send("PASTE EXPIRED")
} }
return res.json({ return res.json({

View file

@ -1,13 +1,21 @@
import { Request, Response } from 'express' import { Request, Response } from 'express'
import URLs from '../../db/url.schema' import URLs from '../../db/url.schema'
const isUrlValid = (url: string) => {
return url.startsWith("http") || url.startsWith("www")
}
export default async (req: Request, res: Response) => { export default async (req: Request, res: Response) => {
try { try {
if (!isUrlValid(req.body.url)) {
return res.status(422).send("INVALID URL")
}
const url = new URLs() const url = new URLs()
url.url = req.body.url url.url = req.body.url
await url.save() await url.save()
return res.status(200).send(url._id); return res.status(200).send(url._id)
} catch (ex) { } catch (ex) {
console.error(ex) console.error(ex)
return res.status(500).send({ return res.status(500).send({

View file

@ -47,7 +47,7 @@ export default () => {
if (renderState.notFound) { if (renderState.notFound) {
return ( return (
<CSSTransition classNames="react-router" appear in timeout={300}> <CSSTransition classNames="react-router" appear in timeout={300}>
<h2 className="v-center">Paste Not Found</h2> <h2 className="v-center">Paste Not Found Or Expired</h2>
</CSSTransition> </CSSTransition>
); );
} }

View file

@ -10,6 +10,7 @@ export default () => {
url: null, url: null,
loading: false, loading: false,
result: null, result: null,
error: false,
}); });
const submit = (evt) => { const submit = (evt) => {
@ -21,7 +22,12 @@ export default () => {
...state, ...state,
result: `http://${window.location.host}/u/${data}`.replace('5000', '3000'), result: `http://${window.location.host}/u/${data}`.replace('5000', '3000'),
loading: false, loading: false,
error: false,
}); });
}).catch((ex) => {
if (ex.response && ex.response.data === 'INVALID URL') {
setState({ ...state, error: true });
}
}); });
} }
}; };
@ -47,6 +53,12 @@ export default () => {
</Button> </Button>
</InputGroup.Append> </InputGroup.Append>
</InputGroup> </InputGroup>
{state.error && (
<Form.Text className="text-danger">
Please enter a valid URL
</Form.Text>
)}
<Form.Text className="danger" />
</Form.Group> </Form.Group>
</Form> </Form>