Fixes
This commit is contained in:
parent
e54ac03319
commit
658a783f6a
8 changed files with 29 additions and 24 deletions
|
|
@ -37,18 +37,15 @@ const storage = multer.diskStorage({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const uploader = multer({
|
const uploader = multer({ storage }).single("file");
|
||||||
storage,
|
// File Uploader
|
||||||
// limits: { fileSize: 17825792 },
|
|
||||||
}).single("file");
|
|
||||||
// Image Uploader
|
|
||||||
app.put("/api/file", uploader, putFileHandler);
|
app.put("/api/file", uploader, putFileHandler);
|
||||||
app.get("/f/:slug", getFileHandler);
|
app.get("/f/:slug", getFileHandler);
|
||||||
// Pastebin
|
// Codebin
|
||||||
app.put("/api/paste", putTxtHandler);
|
app.put("/api/paste", putTxtHandler);
|
||||||
app.get("/p/:slug", getTxtHandler);
|
app.get("/c/:slug", getTxtHandler);
|
||||||
// URL Shortener -- LAST for a reason.
|
// URL Shortener
|
||||||
app.put("/api/url", putUrlHandler);
|
app.put("/api/url", putUrlHandler);
|
||||||
app.get("/:slug", getUrlHandler);
|
app.get("/api/:slug", getUrlHandler);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,13 @@ import URLs from "../../db/url.schema";
|
||||||
|
|
||||||
export default async (req: Request, res: Response) => {
|
export default async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const url = await URLs.findById(req.params.slug);
|
const obj = await URLs.findById(req.params.slug);
|
||||||
|
if (obj) {
|
||||||
if (url) {
|
res.status(200).send(obj.url);
|
||||||
res.redirect(url.url);
|
|
||||||
} else {
|
} else {
|
||||||
res.status(404).send();
|
res.status(404).send();
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
console.error(ex);
|
return res.status(500).send({ error: ex });
|
||||||
return res.status(500).send({
|
|
||||||
error: ex,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,24 @@ import FileUpload from './components/FileUpload';
|
||||||
import NavBar from './components/modules/NavBar';
|
import NavBar from './components/modules/NavBar';
|
||||||
import TextUpload from './components/TextUpload';
|
import TextUpload from './components/TextUpload';
|
||||||
import UrlShortener from './components/UrlShortener';
|
import UrlShortener from './components/UrlShortener';
|
||||||
|
import CheckUrlRedirect from './axios/getUrlHandler';
|
||||||
|
|
||||||
|
const slug = window.location.pathname.match(/[^/][^/]*/g);
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
|
// Check to see if slug is worth trying :)
|
||||||
|
!!slug && CheckUrlRedirect(slug).then((url) => {
|
||||||
|
window.location.href = url;
|
||||||
|
}).catch(() => {});
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<Router>
|
<Router>
|
||||||
<NavBar />
|
<NavBar />
|
||||||
<div style={{ paddingTop: `${3.5}em` }} />
|
<div style={{ paddingTop: `${3.5}em` }} />
|
||||||
<Route exact path="/" component={UrlShortener} />
|
<Route exact path="/" component={UrlShortener} />
|
||||||
<Route exact path="/f" component={FileUpload} />
|
<Route exact path="/code" component={TextUpload} />
|
||||||
<Route exact path="/p" component={TextUpload} />
|
<Route exact path="/files" component={FileUpload} />
|
||||||
</Router>
|
</Router>
|
||||||
</React.StrictMode>,
|
</React.StrictMode>,
|
||||||
document.getElementById('root'),
|
document.getElementById('root'),
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
export default (slug) => axios.get(`/p/${slug}`).then((resp) => resp.data);
|
export default (slug) => axios.get(`/c/${slug}`).then((resp) => resp.data);
|
||||||
|
|
|
||||||
4
frontend/src/axios/getUrlHandler.js
Normal file
4
frontend/src/axios/getUrlHandler.js
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export default (slug) => axios.get(`/api/${slug}`)
|
||||||
|
.then((resp) => resp.data);
|
||||||
|
|
@ -83,7 +83,7 @@ export default () => {
|
||||||
putTxtHandler(state).then((data) => {
|
putTxtHandler(state).then((data) => {
|
||||||
setState({
|
setState({
|
||||||
...state,
|
...state,
|
||||||
result: `${window.location.origin}/p?id=${data}`,
|
result: `${window.location.origin}/code?id=${data}`,
|
||||||
loading: false,
|
loading: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ export default () => {
|
||||||
putUrlHandler(state.url).then((data) => {
|
putUrlHandler(state.url).then((data) => {
|
||||||
setState({
|
setState({
|
||||||
...state,
|
...state,
|
||||||
result: `${window.location.origin}/${data}`.replace('5000', '3000'),
|
result: `${window.location.origin}/${data}`,
|
||||||
loading: false,
|
loading: false,
|
||||||
error: false,
|
error: false,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ export default () => (
|
||||||
<Navbar.Collapse>
|
<Navbar.Collapse>
|
||||||
<Nav className="mr-auto">
|
<Nav className="mr-auto">
|
||||||
<NavLinkItem name="URL" dest="/" icon={faLink} />
|
<NavLinkItem name="URL" dest="/" icon={faLink} />
|
||||||
<NavLinkItem name="Code" dest="/p" icon={faCode} />
|
<NavLinkItem name="Code" dest="/code" icon={faCode} />
|
||||||
<NavLinkItem name="File" dest="/f" icon={faFile} />
|
<NavLinkItem name="File" dest="/files" icon={faFile} />
|
||||||
</Nav>
|
</Nav>
|
||||||
</Navbar.Collapse>
|
</Navbar.Collapse>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue