[www] - hudozka-data, hudozka-api-v1, hudozka-middlewares

This commit is contained in:
Roman Timashev committed 2017-09-19 13:46:16 +03:00
1 parent 5ad321ec0e
commit 6eb35930ea
24 files changed
-350

No files matched your search

-3
View File
@@ -12,8 +12,5 @@ gunzip -c ${build_file} | tar xopf -
#rm build.tar
npm install --production --loglevel error
npm install ./modules/hudozka-api-v1/
npm install ./modules/hudozka-data/
npm install ./modules/hudozka-middlewares/
echo "Deploying finish. Please restart hudozka.service manually"
-1
View File
@@ -1 +0,0 @@
node_modules/
-2
View File
@@ -1,2 +0,0 @@
.idea/
src/
-19
View File
@@ -1,19 +0,0 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (auth, data) {
return (0, _koaCompose2.default)([(0, _timeline.add)(auth, data)]);
};
var _timeline = require('./api/timeline');
var _koaCompose = require('koa-compose');
var _koaCompose2 = _interopRequireDefault(_koaCompose);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
;
-26
View File
@@ -1,26 +0,0 @@
{
"name": "hudozka-api-v1",
"private": true,
"version": "0.0.1",
"description": "",
"main": "lib/index.js",
"scripts": {
"compile": "babel --presets es2015,stage-0 src/ -d lib/",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"ejson": "^2.1.2",
"hudozka-middlewares": "file:../hudozka-middlewares",
"koa-compose": "^3.1.0",
"koa-query": "0.0.2",
"koa-route": "^3.1.0",
"request-promise": "^2.0.1"
},
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0"
}
}
@@ -1,30 +0,0 @@
import {put} from 'koa-route';
import compose from 'koa-compose';
import query from 'koa-query';
import {toBoolean} from 'koa-query';
import {ejson, ensureServiceAuth} from 'hudozka-middlewares';
export function add(auth, data) {
return put('/timeline', compose([
ensureServiceAuth(auth),
ejson(),
query({
save: toBoolean()
}),
async(ctx) => {
let doSave = ctx.request.query.save || true;
let post = ctx.request.body;
try {
if(!doSave) data.timeline.disableSaving();
let result = await data.timeline.add(post);
if(!doSave) data.timeline.enableSaving();
ctx.body = result;
} catch (e) {
ctx.status = 400;
ctx.body = e;
}
}
]));
}
-8
View File
@@ -1,8 +0,0 @@
import {add as timelineAdd} from './api/timeline';
import compose from 'koa-compose';
export default function (auth, data) {
return compose([
timelineAdd(auth, data)
]);
};
-3
View File
@@ -1,3 +0,0 @@
node_modules/
lib/
.idea/
-2
View File
@@ -1,2 +0,0 @@
src/
.idea/
-21
View File
@@ -1,21 +0,0 @@
{
"name": "hudozka-data",
"private": true,
"version": "0.0.2",
"description": "",
"main": "lib/index.js",
"scripts": {
"compile": "babel --plugins async-to-promises --presets es2015,stage-0 src/ -d lib/",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-plugin-async-to-promises": "^1.0.5",
"babel-polyfill": "^6.16.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
"mongodb": "^2.2.12"
}
}
-44
View File
@@ -1,44 +0,0 @@
import {EventEmitter} from 'events'
export default class Data extends EventEmitter {
constructor(store) {
super()
this.save = true
this.store = store
}
broadcast(data) {
this.emit('update', data)
}
disableSaving() {
this.save = false
}
enableSaving() {
this.save = true
}
async create(data) {
const id = data.id
if (!id) throw new Error('Field `id` not found in Data object')
const query = {id: id}
await this.store.update(query, data, {upsert: true})
const result = await this.store.findOne(query)
this.emit('update', result)
return result
}
async read(id) {
return this.store.findOne({id: id})
}
async find(query, skip = 0, limit = 0) {
const cursor = this.store
.find(query)
.skip(skip)
if (limit) cursor.limit(limit)
return await cursor.toArray()
}
}
-11
View File
@@ -1,11 +0,0 @@
import Timeline from './Timeline'
import Schedule from './Schedule'
import Document from './Document'
export default class DataManager {
constructor(stores) {
this.timeline = new Timeline(stores.timeline)
this.schedule = new Schedule(stores.schedules)
this.document = new Document(stores.documents)
}
}
-5
View File
@@ -1,5 +0,0 @@
import Data from './Data'
export default class Document extends Data {
}
-44
View File
@@ -1,44 +0,0 @@
import Data from './Data';
export default class Schedule extends Data {
create() {
}
read() {
}
delete() {
}
find(query) {
}
add(post) {
let savePost = async(post) => {
const id = post.id;
const type = post.type;
const query = {id: id, type: type};
await this.store.update(query, post, {upsert: true});
let document = await this.store.find(query).limit(1).toArray();
return document[0];
};
let add = async(post) => {
let document = post;
if (this.save) {
document = await savePost(post);
}
this.broadcast(document);
return document;
};
return add(post);
}
}
-51
View File
@@ -1,51 +0,0 @@
import Data from './Data'
export default class Timeline extends Data {
async create(post) {
let savePost = async(post) => {
const id = post.id
const type = post.type
const query = {id: id, type: type}
await this.store.update(query, post, {upsert: true})
let document = await this.store.find(query).limit(1).toArray()
return document[0]
}
let add = async(post) => {
let document = post
if (this.save) {
document = await savePost(post)
}
this.broadcast(document)
return document
}
return add(post)
}
add(post) {
let savePost = async(post) => {
const id = post.id
const type = post.type
const query = {id: id, type: type}
await this.store.update(query, post, {upsert: true})
let document = await this.store.find(query).limit(1).toArray()
return document[0]
}
let add = async(post) => {
let document = post
if (this.save) {
document = await savePost(post)
}
this.broadcast(document)
return document
}
return add(post)
}
}
-2
View File
@@ -1,2 +0,0 @@
import DataManager from './DataManager';
export default DataManager;
-18
View File
@@ -1,18 +0,0 @@
require('babel-polyfill')
const Data = require('../lib/Data').default
//const Data = require('../src/Data')
const MongoClient = require('mongodb').MongoClient
MongoClient
.connect('mongodb://localhost:27017/hudozka')
.then(function (db) {
const store = db.collection('documents')
const data = new Data(store)
data.find({})
.then(function(data){
console.log('data >')
console.log(data)
})
})
-3
View File
@@ -1,3 +0,0 @@
node_modules/
lib/
.idea/
-2
View File
@@ -1,2 +0,0 @@
src/
.idea/
-21
View File
@@ -1,21 +0,0 @@
{
"name": "hudozka-middlewares",
"private": true,
"version": "0.0.1",
"description": "",
"main": "lib/index.js",
"scripts": {
"compile": "babel --presets es2015,stage-0 src/ -d lib/",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"ejson": "^2.1.2"
},
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0"
}
}
-15
View File
@@ -1,15 +0,0 @@
import {parse} from 'ejson';
export function ejson(type='application/ejson') {
return async (ctx, next) => {
let t = ctx.request.headers['content-type'];
let data = ctx.request.body;
if (t === type){
data = typeof data === 'string' ? data : JSON.stringify(data);
ctx.request.body = parse(data);
}
await next();
};
}
@@ -1,14 +0,0 @@
// auth - fn that returns boolean
export function ensureServiceAuth(auth) {
return async (ctx, next) => {
let service = ctx.request.headers['x-service-name'];
let token = ctx.request.headers['x-service-token'];
if (!auth(service, token)) {
ctx.status = 401;
} else {
await next();
}
};
}
-2
View File
@@ -1,2 +0,0 @@
export {ejson} from './ejson';
export {ensureServiceAuth} from './ensureServiceAuth';
-3
View File
@@ -26,9 +26,6 @@
"co": "^4.4.0",
"ejson": "^2.1.2",
"handlebars": "^4.0.5",
"hudozka-api-v1": "file:modules/hudozka-api-v1",
"hudozka-data": "file:modules/hudozka-data",
"hudozka-middlewares": "file:modules/hudozka-middlewares",
"instagram-node": "^0.5.1",
"koa": "^2.0.0-alpha.3",
"koa-bodyparser": "^3.0.0",