Small QOL tweaks
This commit is contained in:
parent
781efacc8c
commit
996b8c1572
5 changed files with 26 additions and 7 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import { Request, Response } from 'express'
|
||||
import Images from '../../db/img.schema'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import Images from '../../db/img.schema'
|
||||
|
||||
export default async (req: Request, res: Response) => {
|
||||
try {
|
||||
|
|
@ -15,7 +14,7 @@ export default async (req: Request, res: Response) => {
|
|||
/* If some other IP uploads, we want to add them too */
|
||||
img.uploaders.push(req.clientIp as string)
|
||||
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()
|
||||
|
||||
return res.status(200).send(img._id);
|
||||
return res.status(200).send(img._id)
|
||||
} catch (ex) {
|
||||
console.error(ex)
|
||||
return res.status(500).send({
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ export default async (req: Request, res: Response) => {
|
|||
// Check for an expired link
|
||||
if (moment().isAfter(moment(paste.expiresAt))) {
|
||||
await Pastes.findByIdAndDelete(paste._id)
|
||||
return res.status(404).send("PASTE_EXPIRED")
|
||||
return res.status(404).send("PASTE EXPIRED")
|
||||
}
|
||||
|
||||
return res.json({
|
||||
|
|
|
|||
|
|
@ -1,13 +1,21 @@
|
|||
import { Request, Response } from 'express'
|
||||
import URLs from '../../db/url.schema'
|
||||
|
||||
const isUrlValid = (url: string) => {
|
||||
return url.startsWith("http") || url.startsWith("www")
|
||||
}
|
||||
|
||||
export default async (req: Request, res: Response) => {
|
||||
try {
|
||||
if (!isUrlValid(req.body.url)) {
|
||||
return res.status(422).send("INVALID URL")
|
||||
}
|
||||
|
||||
const url = new URLs()
|
||||
url.url = req.body.url
|
||||
await url.save()
|
||||
|
||||
return res.status(200).send(url._id);
|
||||
return res.status(200).send(url._id)
|
||||
} catch (ex) {
|
||||
console.error(ex)
|
||||
return res.status(500).send({
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ export default () => {
|
|||
if (renderState.notFound) {
|
||||
return (
|
||||
<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>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export default () => {
|
|||
url: null,
|
||||
loading: false,
|
||||
result: null,
|
||||
error: false,
|
||||
});
|
||||
|
||||
const submit = (evt) => {
|
||||
|
|
@ -21,7 +22,12 @@ export default () => {
|
|||
...state,
|
||||
result: `http://${window.location.host}/u/${data}`.replace('5000', '3000'),
|
||||
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>
|
||||
</InputGroup.Append>
|
||||
</InputGroup>
|
||||
{state.error && (
|
||||
<Form.Text className="text-danger">
|
||||
Please enter a valid URL
|
||||
</Form.Text>
|
||||
)}
|
||||
<Form.Text className="danger" />
|
||||
</Form.Group>
|
||||
</Form>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue