diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx
index 9926de3a8..b413056b5 100644
--- a/client/homebrew/pages/archivePage/archivePage.jsx
+++ b/client/homebrew/pages/archivePage/archivePage.jsx
@@ -3,7 +3,6 @@ const React = require('react');
const createClass = require('create-react-class');
const _ = require('lodash');
const cx = require('classnames');
-const Moment = require('moment');
const Nav = require('naturalcrit/nav/nav.jsx');
const Navbar = require('../../navbar/navbar.jsx');
@@ -11,6 +10,7 @@ const RecentNavItem = require('../../navbar/recent.navitem.jsx').both;
const Account = require('../../navbar/account.navitem.jsx');
const NewBrew = require('../../navbar/newbrew.navitem.jsx');
const HelpNavItem = require('../../navbar/help.navitem.jsx');
+const ListPage = require('../basePages/listPage/listPage.jsx');
const request = require('superagent');
@@ -22,7 +22,7 @@ const ArchivePage = createClass({
getInitialState: function () {
return {
query : '',
- foundBrews : null,
+ brewCollection : null,
searching : false,
error : null,
};
@@ -34,80 +34,20 @@ const ArchivePage = createClass({
this.setState({ searching: true, error: null });
request
- .get(`/admin/archive/${this.state.query}`)
- .then((res) => this.setState({ foundBrews: res.body }))
+ .get(`/archive/${this.state.query}`)
+ .then((res) => this.setState({ brewCollection: res.body }))
.catch((err) => this.setState({ error: err }))
.finally(() => this.setState({ searching: false }));
},
renderFoundBrews() {
- const brews = this.state.foundBrews;
+ const brews = this.state.brewCollection;
if (!brews || brews.length === 0) {
return
No brews found.
;
}
- return (
-
- {brews.map((brew, index) => (
-
-
- - Title:
- - {brew.title}
-
- - Authors:
- -
- {brew.authors.map((author, index) => (
-
-
- {author}
-
- {index < brew.authors.length - 1 && ', '}
-
- ))}
-
-
-
- Check the brew
-
-
- - Systems:
- - {brew.systems.join(', ')}
-
- {brew.tags?.length ? (
- <>
-
-
- {brew.tags.map((tag, idx) => {
- const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/);
- return (
-
- {matches[2]}
-
- );
- })}
-
- >
- ) : (
- <>>
- )}
-
- - Last Updated:
- - {Moment(brew.updatedAt).fromNow()}
-
- - Num of Views:
- - {brew.views}
-
-
- ))}
-
- );
+ return ;
+
},
renderForm: function () {
diff --git a/server/admin.api.js b/server/admin.api.js
index 0c6fe1fc7..0884ca03f 100644
--- a/server/admin.api.js
+++ b/server/admin.api.js
@@ -76,28 +76,6 @@ router.get('/admin/lookup/:id', mw.adminOnly, async (req, res, next) => {
return res.status(500).json({ error: 'Internal Server Error' });
}
});
-
-
-/* Searches for matching title, also attempts to partial match */
-router.get('/admin/archive/:title', mw.adminOnly, async (req, res, next) => {
- try {
- const brews = await HomebrewModel.find({
- title: { $regex: req.params.title, $options: 'i' },
- published: true
- }).exec();
-
- if (!brews || brews.length === 0) {
- // No published documents found with the given title
- return res.status(404).json({ error: 'Published documents not found' });
- }
-
- return res.json(brews);
- } catch (error) {
- console.error(error);
- return res.status(500).json({ error: 'Internal Server Error' });
- }
- });
-
/* Find 50 brews that aren't compressed yet */
router.get('/admin/finduncompressed', mw.adminOnly, (req, res)=>{
diff --git a/server/app.js b/server/app.js
index 970c2cd9c..84ea4662b 100644
--- a/server/app.js
+++ b/server/app.js
@@ -67,6 +67,7 @@ app.use((req, res, next)=>{
app.use(homebrewApi);
app.use(require('./admin.api.js'));
+app.use(require('./archive.api.js'));
const HomebrewModel = require('./homebrew.model.js').model;
const welcomeText = require('fs').readFileSync('client/homebrew/pages/homePage/welcome_msg.md', 'utf8');
@@ -480,6 +481,11 @@ app.use(async (err, req, res, next)=>{
res.status(err.status || err.response?.status || 500).send(err);
return;
}
+ if(err.originalUrl?.startsWith('/archive/')) {
+ // console.log('archive error');
+ res.status(err.status || err.response?.status || 500).send(err);
+ return;
+ }
// console.log('non-API error');
const status = err.status || err.code || 500;
@@ -503,6 +509,8 @@ app.use(async (err, req, res, next)=>{
res.send(page);
});
+
+
app.use((req, res)=>{
if(!res.headersSent) {
console.error('Headers have not been sent, responding with a server error.', req.url);
diff --git a/server/archive.api.js b/server/archive.api.js
new file mode 100644
index 000000000..e4c6b704b
--- /dev/null
+++ b/server/archive.api.js
@@ -0,0 +1,31 @@
+const HomebrewModel = require('./homebrew.model.js').model;
+const router = require('express').Router();
+const asyncHandler = require('express-async-handler');
+
+
+const archive = {
+ archiveApi : router,
+ /* Searches for matching title, also attempts to partial match */
+ findBrews : async (req, res, next) => {
+ try {
+ const brews = await HomebrewModel.find({
+ title: { $regex: req.params.query, $options: 'i' },
+ published: true
+ }).exec();
+
+ if (!brews || brews.length === 0) {
+ // No published documents found with the given title
+ return res.status(404).json({ error: 'Published documents not found' });
+ }
+
+ return res.json(brews);
+ } catch (error) {
+ console.error(error);
+ return res.status(500).json({ error: 'Internal Server Error' });
+ }
+ }
+}
+router.get('/archive/:query', asyncHandler(archive.findBrews));
+
+
+module.exports = archive;
\ No newline at end of file