update
This commit is contained in:
1 parent
d7a4486b35
commit
144e69e6c4
7 files changed
+14
-81
No files matched your search
@@ -7,6 +7,7 @@ private*.json
|
|||||||
|
|
||||||
/node_modules
|
/node_modules
|
||||||
/bower_components
|
/bower_components
|
||||||
|
/modules/hudozka-api-v1/lib
|
||||||
/public
|
/public
|
||||||
/build
|
/build
|
||||||
/out
|
/out
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ gunzip -c ${build_file} | tar xopf -
|
|||||||
#rm build.tar
|
#rm build.tar
|
||||||
|
|
||||||
npm install --production --loglevel error
|
npm install --production --loglevel error
|
||||||
|
npm install ./modules/hudozka-api-v1/
|
||||||
|
npm install ./modules/hudozka-data/
|
||||||
|
npm install ./modules/hudozka-middlewares/
|
||||||
|
|
||||||
#starting www
|
#starting www
|
||||||
if forever restart ${app}; then
|
if forever restart ${app}; then
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", {
|
|
||||||
value: true
|
|
||||||
});
|
|
||||||
exports.add = add;
|
|
||||||
|
|
||||||
var _koaRoute = require('koa-route');
|
|
||||||
|
|
||||||
var _koaCompose = require('koa-compose');
|
|
||||||
|
|
||||||
var _koaCompose2 = _interopRequireDefault(_koaCompose);
|
|
||||||
|
|
||||||
var _hudozkaMiddlewares = require('hudozka-middlewares');
|
|
||||||
|
|
||||||
var _hudozkaMiddlewares2 = _interopRequireDefault(_hudozkaMiddlewares);
|
|
||||||
|
|
||||||
var _koaQuery = require('koa-query');
|
|
||||||
|
|
||||||
var _koaQuery2 = _interopRequireDefault(_koaQuery);
|
|
||||||
|
|
||||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
||||||
|
|
||||||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { return step("next", value); }, function (err) { return step("throw", err); }); } } return step("next"); }); }; }
|
|
||||||
|
|
||||||
function add(auth, data) {
|
|
||||||
var _this = this;
|
|
||||||
|
|
||||||
return (0, _koaRoute.put)('/timeline', (0, _koaCompose2.default)([_hudozkaMiddlewares2.default.ensureServiceAuth(auth), _hudozkaMiddlewares2.default.ejson(), (0, _koaQuery2.default)({
|
|
||||||
save: (0, _koaQuery.toBoolean)()
|
|
||||||
}), function () {
|
|
||||||
var ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(ctx) {
|
|
||||||
var doSave, post, result;
|
|
||||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
||||||
while (1) {
|
|
||||||
switch (_context.prev = _context.next) {
|
|
||||||
case 0:
|
|
||||||
doSave = ctx.request.query.save || true;
|
|
||||||
post = ctx.request.body;
|
|
||||||
_context.prev = 2;
|
|
||||||
|
|
||||||
if (!doSave) data.timeline.disableSaving();
|
|
||||||
_context.next = 6;
|
|
||||||
return data.timeline.add(post);
|
|
||||||
|
|
||||||
case 6:
|
|
||||||
result = _context.sent;
|
|
||||||
|
|
||||||
if (!doSave) data.timeline.enableSaving();
|
|
||||||
|
|
||||||
ctx.body = result;
|
|
||||||
_context.next = 15;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 11:
|
|
||||||
_context.prev = 11;
|
|
||||||
_context.t0 = _context['catch'](2);
|
|
||||||
|
|
||||||
ctx.status = 400;
|
|
||||||
ctx.body = _context.t0;
|
|
||||||
|
|
||||||
case 15:
|
|
||||||
case 'end':
|
|
||||||
return _context.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, _callee, _this, [[2, 11]]);
|
|
||||||
}));
|
|
||||||
|
|
||||||
return function (_x) {
|
|
||||||
return ref.apply(this, arguments);
|
|
||||||
};
|
|
||||||
}()]));
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
import {put} from 'koa-route';
|
import {put} from 'koa-route';
|
||||||
import compose from 'koa-compose';
|
import compose from 'koa-compose';
|
||||||
import hm from 'hudozka-middlewares';
|
|
||||||
import query from 'koa-query';
|
import query from 'koa-query';
|
||||||
import {toBoolean} from 'koa-query';
|
import {toBoolean} from 'koa-query';
|
||||||
|
import {ejson, ensureServiceAuth} from 'hudozka-middlewares';
|
||||||
|
|
||||||
export function add(auth, data) {
|
export function add(auth, data) {
|
||||||
return put('/timeline', compose([
|
return put('/timeline', compose([
|
||||||
hm.ensureServiceAuth(auth),
|
ensureServiceAuth(auth),
|
||||||
hm.ejson(),
|
ejson(),
|
||||||
query({
|
query({
|
||||||
save: toBoolean()
|
save: toBoolean()
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// auth - fn that returns boolean
|
||||||
export function ensureServiceAuth(auth) {
|
export function ensureServiceAuth(auth) {
|
||||||
return async (ctx, next) => {
|
return async (ctx, next) => {
|
||||||
let service = ctx.request.headers['x-service-name'];
|
let service = ctx.request.headers['x-service-name'];
|
||||||
@@ -10,3 +11,4 @@ export function ensureServiceAuth(auth) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
import {instagramToken} from '../config';
|
import {instagramToken} from '../config';
|
||||||
|
|
||||||
const services = {
|
export const services = {
|
||||||
instagram: instagramToken
|
instagram: instagramToken
|
||||||
};
|
};
|
||||||
|
|
||||||
export const checkAuth = (name, token) => name in services && services[name] === token;
|
export const checkAuth = (name, token) => name in services && services[name] === token;
|
||||||
|
export const authChecker = store => (name, token) => name in store && store[name] === token;
|
||||||
+2
-1
@@ -16,7 +16,7 @@ import config from './config';
|
|||||||
import {redirectionTable} from './config';
|
import {redirectionTable} from './config';
|
||||||
import {routes, queryObject} from './routes';
|
import {routes, queryObject} from './routes';
|
||||||
import {redirect} from './routes/redirect';
|
import {redirect} from './routes/redirect';
|
||||||
import {checkAuth} from './core/service';
|
import {services as serviceKeys, authChecker} from './core/service';
|
||||||
|
|
||||||
const dirPublic = path.join(__dirname, '../public');
|
const dirPublic = path.join(__dirname, '../public');
|
||||||
const dirTemplates = path.join(__dirname, 'templates');
|
const dirTemplates = path.join(__dirname, 'templates');
|
||||||
@@ -49,6 +49,7 @@ export default function(store){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function apis(store){
|
function apis(store){
|
||||||
|
let checkAuth = authChecker(serviceKeys);
|
||||||
return mount('/api/v1', api_v1(checkAuth, store));
|
return mount('/api/v1', api_v1(checkAuth, store));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user