Skip to content

Commit

Permalink
Rework part of the lib to be more versatile
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Apr 14, 2021
1 parent f83c729 commit 5f61732
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 105 deletions.
9 changes: 4 additions & 5 deletions example/actions/image.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

const {Stream} = require ('../..');
const {Stream, withType} = require ('../..');
const Future = require ('fluture');
const fs = require ('fs');
const path = require ('path');

const access = x => y => Future.node (c => fs.access (x, y, c));

module.exports = req => Future.go (function* () {
module.exports = _ => req => Future.go (function* () {
if (!req.query.file) {
yield Future.reject (
new Error ('You need to provide a query named "file"')
Expand All @@ -24,7 +24,6 @@ module.exports = req => Future.go (function* () {
(_ => new Error ('No read access to the requested file'))
(access (file) (fs.constants.R_OK));

return Stream (200)
(path.extname (req.query.file))
(fs.createReadStream (file));
return withType (path.extname (req.query.file))
(Stream (Future.encase (fs.createReadStream) (file)));
});
2 changes: 1 addition & 1 deletion example/actions/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {Next} = require ('../..');
const Future = require ('fluture');

module.exports = (req, locals) => {
module.exports = locals => req => {
const session = {id: req.headers['x-authenticated-user']};
const newLocals = Object.assign ({session}, locals);
return Future.resolve (Next (newLocals));
Expand Down
4 changes: 2 additions & 2 deletions example/actions/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {Render} = require ('../..');
const Future = require ('fluture');

module.exports = (req, locals) => {
module.exports = locals => _ => {
const user = locals.session.id ? `user ${locals.session.id}` : 'stranger';
return Future.resolve (Render (200) ('index') ({user}));
return Future.resolve (Render ('index') ({user}));
};
4 changes: 2 additions & 2 deletions example/actions/welcomeJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const {Json} = require ('../..');
const Future = require ('fluture');

module.exports = (req, locals) => {
module.exports = locals => _ => {
const welcome = locals.session.id ? `user ${locals.session.id}` : 'stranger';
return Future.resolve (Json (200) ({welcome}));
return Future.resolve (Json ({welcome}));
};
Loading

0 comments on commit 5f61732

Please sign in to comment.