This commit is contained in:
oitsjustjose 2021-06-21 22:49:11 -05:00
commit 658a783f6a
8 changed files with 29 additions and 24 deletions

View file

@ -37,18 +37,15 @@ const storage = multer.diskStorage({
},
});
const uploader = multer({
storage,
// limits: { fileSize: 17825792 },
}).single("file");
// Image Uploader
const uploader = multer({ storage }).single("file");
// File Uploader
app.put("/api/file", uploader, putFileHandler);
app.get("/f/:slug", getFileHandler);
// Pastebin
// Codebin
app.put("/api/paste", putTxtHandler);
app.get("/p/:slug", getTxtHandler);
// URL Shortener -- LAST for a reason.
app.get("/c/:slug", getTxtHandler);
// URL Shortener
app.put("/api/url", putUrlHandler);
app.get("/:slug", getUrlHandler);
app.get("/api/:slug", getUrlHandler);
export default app;

View file

@ -3,17 +3,13 @@ import URLs from "../../db/url.schema";
export default async (req: Request, res: Response) => {
try {
const url = await URLs.findById(req.params.slug);
if (url) {
res.redirect(url.url);
const obj = await URLs.findById(req.params.slug);
if (obj) {
res.status(200).send(obj.url);
} else {
res.status(404).send();
}
} catch (ex) {
console.error(ex);
return res.status(500).send({
error: ex,
});
return res.status(500).send({ error: ex });
}
};

View file

@ -6,16 +6,24 @@ import FileUpload from './components/FileUpload';
import NavBar from './components/modules/NavBar';
import TextUpload from './components/TextUpload';
import UrlShortener from './components/UrlShortener';
import CheckUrlRedirect from './axios/getUrlHandler';
const slug = window.location.pathname.match(/[^/][^/]*/g);
export default () => {
// Check to see if slug is worth trying :)
!!slug && CheckUrlRedirect(slug).then((url) => {
window.location.href = url;
}).catch(() => {});
ReactDOM.render(
<React.StrictMode>
<Router>
<NavBar />
<div style={{ paddingTop: `${3.5}em` }} />
<Route exact path="/" component={UrlShortener} />
<Route exact path="/f" component={FileUpload} />
<Route exact path="/p" component={TextUpload} />
<Route exact path="/code" component={TextUpload} />
<Route exact path="/files" component={FileUpload} />
</Router>
</React.StrictMode>,
document.getElementById('root'),

View file

@ -1,3 +1,3 @@
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);

View file

@ -0,0 +1,4 @@
import axios from 'axios';
export default (slug) => axios.get(`/api/${slug}`)
.then((resp) => resp.data);

View file

@ -83,7 +83,7 @@ export default () => {
putTxtHandler(state).then((data) => {
setState({
...state,
result: `${window.location.origin}/p?id=${data}`,
result: `${window.location.origin}/code?id=${data}`,
loading: false,
});
});

View file

@ -20,7 +20,7 @@ export default () => {
putUrlHandler(state.url).then((data) => {
setState({
...state,
result: `${window.location.origin}/${data}`.replace('5000', '3000'),
result: `${window.location.origin}/${data}`,
loading: false,
error: false,
});

View file

@ -10,8 +10,8 @@ export default () => (
<Navbar.Collapse>
<Nav className="mr-auto">
<NavLinkItem name="URL" dest="/" icon={faLink} />
<NavLinkItem name="Code" dest="/p" icon={faCode} />
<NavLinkItem name="File" dest="/f" icon={faFile} />
<NavLinkItem name="Code" dest="/code" icon={faCode} />
<NavLinkItem name="File" dest="/files" icon={faFile} />
</Nav>
</Navbar.Collapse>
</Navbar>