Instagram Microservice Update

This commit is contained in:
tmshv committed 2016-03-25 17:06:18 +03:00
1 parent ec52ee2c2a
commit bb97677d39
10 files changed
+38 -24

No files matched your search

+6 -6
View File
@@ -9,9 +9,9 @@ gunzip -c ${build_file} | tar xopf -
npm install --production --loglevel error npm install --production --loglevel error
#starting www #starting www
if forever restart src/index.js; then #if forever restart ${script}; then
echo Instagram Microservice restarted # echo Instagram Microservice restarted
else #else
forever start src/index.js # forever start ${script}
echo Instagram Microservice started # echo Instagram Microservice started
fi #fi
+3 -1
View File
@@ -3,6 +3,7 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"scripts": { "scripts": {
"devwebpack": "NODE_ENV=development webpack",
"webpack": "webpack", "webpack": "webpack",
"start": "babel-node src/index.js", "start": "babel-node src/index.js",
"build": "babel src -d out" "build": "babel src -d out"
@@ -18,11 +19,12 @@
"koa-bodyparser": "^3.0.0", "koa-bodyparser": "^3.0.0",
"koa-compose": "^3.1.0", "koa-compose": "^3.1.0",
"koa-convert": "^1.2.0", "koa-convert": "^1.2.0",
"koa-logger": "^2.0.0",
"koa-mount": "^2.0.0", "koa-mount": "^2.0.0",
"koa-route": "^3.0.0", "koa-route": "^3.0.0",
"koa-session-mongo": "^1.1.0", "koa-session-mongo": "^1.1.0",
"koa-session-store": "^1.1.1", "koa-session-store": "^1.1.1",
"koa-static": "^2.0.0", "koa-static": "^3.0.0",
"mongodb": "^2.1.10", "mongodb": "^2.1.10",
"mz": "^2.3.1", "mz": "^2.3.1",
"react": "^0.14.7", "react": "^0.14.7",
+1 -1
View File
@@ -11,7 +11,7 @@ export default class App extends React.Component{
<h1>Панель управления инстаграмом художки</h1> <h1>Панель управления инстаграмом художки</h1>
<p>Чтобы управлять, вы должны быть <a href="https://instagram.com/hudozka">hudozka</a></p> <p>Чтобы управлять, вы должны быть <a href="https://instagram.com/hudozka">hudozka</a></p>
<a href="/auth" onClick={this.handleClick.bind(this)}>Войти</a> <a href="auth" onClick={this.handleClick.bind(this)}>Войти</a>
</div> </div>
) )
} }
+10 -4
View File
@@ -12,13 +12,19 @@ let privateData = JSON.parse(
readFileSync(privatePath, 'utf-8') readFileSync(privatePath, 'utf-8')
); );
export const staticPath = path.join(
__dirname,
'../build'
);
export const port = isProduction ? 18000 : 3000; export const port = isProduction ? 18000 : 3000;
// export const pathPrefix = isProduction ? '/service/instagram' : ''; export const pathPrefix = isProduction ? '/service/instagram' : '';
export const pathPrefix = ''; export const baseHref = isProduction ? '/service/instagram/' : '/';
// export const pathPrefix = '';
export const indexPath = path.join( export const indexPath = path.join(
__dirname, __dirname,
'./templates/index.html' // './templates/index.html'
// '../build/main.html' '../build/main.html'
); );
// export const indexPath = '../build/main.html'; // export const indexPath = '../build/main.html';
+2
View File
@@ -34,6 +34,8 @@ export async function updateSubscription(callbackUrl) {
let data = await instagram.subscriptions.list(); let data = await instagram.subscriptions.list();
let activeSubscriptions = data.result; let activeSubscriptions = data.result;
console.log(`Active subscriptions ${activeSubscriptions}`);
let objectSubscriptions = activeSubscriptions.filter(i => i.object === 'user' && !i.object_id && i.callback_url === callbackUrl) let objectSubscriptions = activeSubscriptions.filter(i => i.object === 'user' && !i.object_id && i.callback_url === callbackUrl)
if (!objectSubscriptions.length) { if (!objectSubscriptions.length) {
-1
View File
@@ -25,7 +25,6 @@ function main(){
} }
await clearSubscriptions(); await clearSubscriptions();
await updateSubscription(updateSubscriptionCallbackUrl); await updateSubscription(updateSubscriptionCallbackUrl);
repeat(updateSubscriptionDelay)(() => { repeat(updateSubscriptionDelay)(() => {
updateSubscription(updateSubscriptionCallbackUrl); updateSubscription(updateSubscriptionCallbackUrl);
+5 -5
View File
@@ -1,7 +1,7 @@
import fs from 'mz/fs'; import fs from 'mz/fs';
import compose from 'koa-compose'; import compose from 'koa-compose';
import route from 'koa-route'; import route from 'koa-route';
import {indexPath, pathPrefix as root} from '../config'; import {indexPath, pathPrefix} from '../config';
import main from './main'; import main from './main';
import {auth, authCallback, authOut} from './auth'; import {auth, authCallback, authOut} from './auth';
@@ -18,7 +18,7 @@ export function statelessRouters() {
export function routers() { export function routers() {
return compose([ return compose([
main(), // main(),
auth(), auth(),
authCallback(), authCallback(),
authOut(), authOut(),
@@ -29,10 +29,10 @@ export function routers() {
]); ]);
} }
export const url = path => `${root}${path}`; export const url = (path, root=pathPrefix) => `${root}${path}`;
// export const url = path => path; // export const url = path => path;
export const get = (path, fn) => route['get'](url(path), fn); export const get = (path, fn) => route['get'](url(path, ''), fn);
export const post = (path, fn) => route['post'](url(path), fn); export const post = (path, fn) => route['post'](url(path, ''), fn);
export function index(fn){ export function index(fn){
return async (ctx) => { return async (ctx) => {
+4 -2
View File
@@ -1,6 +1,7 @@
import Koa from 'koa'; import Koa from 'koa';
import mount from 'koa-mount'; import mount from 'koa-mount';
import serve from 'koa-static'; import serve from 'koa-static';
import logger from 'koa-logger';
import convert from 'koa-convert'; import convert from 'koa-convert';
import sessionStore from 'koa-session-store'; import sessionStore from 'koa-session-store';
import store from 'koa-session-mongo'; import store from 'koa-session-mongo';
@@ -9,14 +10,15 @@ import bodyParser from 'koa-bodyparser';
import {db} from './core/db'; import {db} from './core/db';
import instagram from './middlewares/instagram'; import instagram from './middlewares/instagram';
import {routers, statelessRouters} from './routers'; import {routers, statelessRouters} from './routers';
import {pathPrefix, sessionSecret, sessionExpirationTime} from './config'; import {pathPrefix, staticPath, sessionSecret, sessionExpirationTime} from './config';
export default function(){ export default function(){
const app = new Koa(); const app = new Koa();
app.proxy = true; app.proxy = true;
app.keys = [sessionSecret]; app.keys = [sessionSecret];
app.use(convert(serve('../build'))); app.use(logger());
app.use(serve(staticPath));
app.use(bodyParser()); app.use(bodyParser());
app.use(statelessRouters()); app.use(statelessRouters());
app.use(session('sid', sessionExpirationTime)); app.use(session('sid', sessionExpirationTime));
@@ -3,6 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Instagram Control</title> <title>Instagram Control</title>
<base href="<%= htmlWebpackPlugin.options.baseHref %>">
</head> </head>
<body> <body>
<div class="app-container"></div> <div class="app-container"></div>
+6 -4
View File
@@ -6,6 +6,8 @@ const isProduction = env === 'production';
// import autoprefixer from 'autoprefixer'; // import autoprefixer from 'autoprefixer';
import {baseHref} from './src/config';
module.exports = { module.exports = {
entry: './src/app.js', entry: './src/app.js',
watch: !isProduction, watch: !isProduction,
@@ -29,10 +31,10 @@ module.exports = {
plugins: [ plugins: [
// new webpack.HotModuleReplacementPlugin(), // new webpack.HotModuleReplacementPlugin(),
new HTML({ new HTML({
filename: 'main.html', filename: 'index.html',
title: 'Instagram', template: 'src/templates/index.ejs',
template: 'src/templates/index.html', inject: 'body',
inject: 'body' baseHref: baseHref
}) })
], ],
module: { module: {