Skip to content

Commit

Permalink
fix(Filesystem): API and Next app work well together
Browse files Browse the repository at this point in the history
  • Loading branch information
danactive committed May 8, 2021
1 parent a355a72 commit 0fb2613
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 229 deletions.
6 changes: 4 additions & 2 deletions api/server/plugins/editAlbum/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ const handler = ({ query: { raw: isRaw } }, reply) => new Promise((resolve) => {
};
const viewPath = 'plugins/editAlbum/components/page.jsx';

const handleResponse = (json) => ((isRaw) ? resolve(reply(formatJson(json))) : resolve(reply.view(viewPath, formatJson(json))));
const handleResponse = ({ body: { galleries: json } }) => ((isRaw)
? resolve(reply(formatJson(json)))
: resolve(reply.view(viewPath, formatJson(json))));
const handleError = routes.createErrorReply(reply);

gallery.getGalleries()
gallery.get()
.then(handleResponse)
.catch(handleError);
});
Expand Down
4 changes: 2 additions & 2 deletions api/server/plugins/gallery/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ async function register(server) {
options: {
tags: ['api'],
handler: async () => {
const { body } = await gallery.get();
return body;
const { body: { galleries } } = await gallery.get();
return { galleries };
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion api/server/plugins/home/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const gallery = require('../../../../../app/pages/api/galleries/local');
async function handler(request, reply) {
const isRaw = request.query.raw;
const viewPath = 'plugins/home/components/page.jsx';
const galleries = await gallery.getGalleries();
const { body: { galleries } } = await gallery.get();
const out = { galleries };

if (isRaw) {
Expand Down
6 changes: 3 additions & 3 deletions api/server/plugins/utils/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const glob = require('glob');
const path = require('path');

const configFile = require('../../../../../config.json');
const utilsFactory = require('../../../../../app/pages/api/admin/filesystem/utils');

const config = {
get: (dotpath) => dotProp.get(configFile, dotpath),
Expand Down Expand Up @@ -33,8 +34,7 @@ function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}



const fileMethods = utilsFactory();

fileMethods.videoToThumbsPath = (filepath = null, gallery = null) => {
if (filepath === null || gallery === null) {
Expand Down Expand Up @@ -76,5 +76,5 @@ fileMethods.glob = (sourceFolder, pattern, options = {}) => new Promise((resolve
});

module.exports = {
env, config, clone
env, config, clone, file: fileMethods,
};
5 changes: 3 additions & 2 deletions api/server/plugins/walk/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const routes = require('../../../lib/routes');
const files = require('./files');
const files = require('../../../../../app/pages/api/admin/filesystem/local');
const validation = require('../../../lib/validation');

const routeWalkPath = {
Expand All @@ -8,7 +8,8 @@ const routeWalkPath = {
options: {
handler: async function handler({ query: { path } }) {
try {
return files.listFiles(path);
const { body } = await files.get(path);
return { files: body.files };
} catch (e) {
return routes.wrapError(e);
}
Expand Down
3 changes: 0 additions & 3 deletions api/server/plugins/walk/test/.eslintrc.js

This file was deleted.

93 changes: 0 additions & 93 deletions api/server/plugins/walk/test/cases.js

This file was deleted.

24 changes: 0 additions & 24 deletions api/server/plugins/walk/test/files.jest.js

This file was deleted.

20 changes: 0 additions & 20 deletions api/server/plugins/walk/test/files.spec.js

This file was deleted.

17 changes: 0 additions & 17 deletions api/server/plugins/walk/test/index.spec.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports[`renders homepage unchanged 1`] = `
className="title"
>
Welcome to
<a
href="https://nextjs.org"
>
Expand All @@ -19,6 +20,7 @@ exports[`renders homepage unchanged 1`] = `
className="description"
>
Get started by editing
<code>
pages/index.js
</code>
Expand Down
13 changes: 0 additions & 13 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
},
"dependencies": {
"app-root-path": "^3.0.0",
"boom": "^7.0.0",
"glob": "^7.1.6",
"mime-types": "^2.1.28",
"next": "^10.0.0",
Expand Down
Loading

0 comments on commit 0fb2613

Please sign in to comment.