Skip to content

Commit

Permalink
Merge pull request #303 from unarxiv/xzyaoi/feat/pipeline
Browse files Browse the repository at this point in the history
Xzyaoi/feat/pipeline
  • Loading branch information
Xiaozhe Yao authored Mar 24, 2019
2 parents 92bf89b + 7b50b1c commit e8d9ec4
Show file tree
Hide file tree
Showing 25 changed files with 352 additions and 738 deletions.
28 changes: 0 additions & 28 deletions Pipfile

This file was deleted.

397 changes: 0 additions & 397 deletions Pipfile.lock

This file was deleted.

5 changes: 0 additions & 5 deletions cvpm/requirements.txt

This file was deleted.

2 changes: 2 additions & 0 deletions discovery/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
release: yarn run build
web: node dist/src/server.js
7 changes: 5 additions & 2 deletions discovery/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cvtron-discovery-node",
"name": "cvpm-discovery-node",
"version": "1.0.0",
"description": "The CVTron Discovery Service in Node",
"description": "The CVPM Discovery Service in Node",
"main": "index.js",
"scripts": {
"dev": "nodemon --watch 'src/**/*' -e ts,tsx --exec 'ts-node' ./src/server.ts",
Expand Down Expand Up @@ -51,10 +51,13 @@
"cross-env": "5.2.0",
"jest": "24.5.0",
"nodemon": "1.18.10",
"prettier": "^1.16.4",
"supertest": "4.0.2",
"ts-jest": "24.0.0",
"ts-node": "8.0.3",
"tslint": "5.14.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "3.3.4000"
}
}
16 changes: 8 additions & 8 deletions discovery/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import * as dotenv from 'dotenv';
dotenv.config({ path: '.env' });

export interface IConfig {
port: number;
debugLogging: boolean;
secret: string;
version: string;
blogURL: string;
cognitoPoolId: string;
cognitoClientId: string;
cognitoRegion: string;
debugLogging: boolean;
port: number;
secret: string;
version: string;
stripe: string;
sentryDSN: string;
}

const config: IConfig = {
port: +process.env.PORT || 3000,
debugLogging: process.env.NODE_ENV == 'development',
secret: process.env.secret || 'your-secret-whatever',
version: process.env.VERSION || 'v0.0.3@alpha',
blogURL: process.env.BLOG_URL || 'https://write.as/api/collections/autoai',
cognitoPoolId: process.env.COGNITO_POOL_ID || '',
cognitoClientId: process.env.COGNITO_CLIENT_ID || '',
cognitoRegion: process.env.COGNITO_REGION || '',
debugLogging: process.env.NODE_ENV === 'development',
port: +process.env.PORT || 3000,
secret: process.env.secret || 'your-secret-whatever',
version: process.env.VERSION || 'v0.0.3@alpha',
stripe: process.env.STRIPEID || '',
sentryDSN: process.env.SENTRYDSN || '',
};
Expand Down
11 changes: 4 additions & 7 deletions discovery/src/controller/news.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { BaseContext } from 'koa'
import axios from 'axios'
import axios from 'axios';
import { BaseContext } from 'koa';
import { config } from '../config';

export default class NewsController {
public static async queryNews (ctx: BaseContext) {
console.log('quering news')
await axios.get(config.blogURL + '/posts').then(function (res:any) {
console.log(res)
await axios.get(config.blogURL + '/posts').then(function (res: any) {
ctx.status = 200;
ctx.body = res.data.data.posts;
}).catch(function (err) {
console.log(err)
ctx.status = 500;
ctx.body = 'An error occured on the blog service';
})
});
}
}
2 changes: 0 additions & 2 deletions discovery/src/controller/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import { ImportPackageRequest } from './entity';
export default class PackageController {
public static async importPackage (ctx: BaseContext) {
const toImportPackage: Package = new Package();

console.log(toImportPackage);
}
}
10 changes: 5 additions & 5 deletions discovery/src/controller/paywall.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { BaseContext } from 'koa';
import paymentService from '../service/payment'
import paymentService from '../service/payment';

export default class PaywallController {
public static async createCustomer (ctx: BaseContext) {
const requestbody = ctx.request.body
const customer = await paymentService.createCustomer(requestbody.email)
const requestbody = ctx.request.body;
const customer = await paymentService.createCustomer(requestbody.email);
ctx.status = 200;
ctx.body = {
'code': 200,
'results': 'success',
'customer': customer
'customer': customer,
'results': 'success'
};
}
}
2 changes: 1 addition & 1 deletion discovery/src/controller/pretrained.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseContext } from 'koa';
import { putPretrained, getPretrained } from '../dynamo/action';
import { getPretrained, putPretrained } from '../dynamo/action';
export default class PackageController {
public static async importPretrained (ctx: BaseContext) {
putPretrained('yolo_tiny', 'https://premium.file.cvtron.xyz/data/yolo_tiny.ckpt');
Expand Down
14 changes: 6 additions & 8 deletions discovery/src/controller/ticket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseContext } from 'koa'
import { freshdesk } from '../service/ticket'
import { BaseContext } from 'koa';
import { freshdesk } from '../service/ticket';

export default class TicketController {
public static async createTicket (ctx: BaseContext) {
Expand All @@ -11,17 +11,15 @@ export default class TicketController {
description: body.description,
status: 2,
priority: body.priority
}).then(function (res:any) {
}).then(function (res: any) {
ctx.status = 200;
console.log(res)
ctx.body = {
'code': 200,
'results': res.data
}
}).catch(function (err:any) {
console.log(err)
};
}).catch(function (err: any) {
ctx.status = 400;
ctx.body = err.response.data;
})
});
}
}
4 changes: 2 additions & 2 deletions discovery/src/controller/user.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BaseContext } from 'koa';
import { getUserInfo } from '../service/auth'
import { getUserInfo } from '../service/auth';
export default class UserController {
/**
* Validate Access Token, a.k.a Get User information
* @param ctx
*/
public static async validateAccessToken(ctx: BaseContext) {
const body = ctx.request.body;
getUserInfo(body.accessToken)
getUserInfo(body.accessToken);
}
}
19 changes: 8 additions & 11 deletions discovery/src/dynamo/action.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mapper from './dynamo';
import { Package, Pretrained, Registry } from './entity';
import { Guid } from 'guid-typescript';
import { isSymbol } from 'util';
import mapper from './dynamo';
import { Package, Pretrained, Registry } from './entity';

/**
* Following will be package manipulations
Expand All @@ -15,11 +15,10 @@ import { isSymbol } from 'util';
function putPackage (isSymbol: boolean, linkedTo: string) {
const toPutPackage = Object.assign(new Package, {
id: Guid.create(),
isSymbol: isSymbol,
linkedTo: linkedTo
isSymbol,
linkedTo
});
mapper.put(toPutPackage).then(objectSaved => {
console.log(objectSaved);
});
}
/**
Expand All @@ -35,11 +34,10 @@ function putPackage (isSymbol: boolean, linkedTo: string) {
function putPretrained (name: string, linkedTo: string) {
const toPutPretrained = Object.assign(new Pretrained, {
id: Guid.create(),
name: name,
linkedTo: linkedTo
name,
linkedTo
});
mapper.put(toPutPretrained).then(objectSaved => {
console.log(objectSaved);
});
}

Expand Down Expand Up @@ -68,11 +66,10 @@ async function getRegistries () {
async function addRegistry (name: string, urlPrefix: string) {
const toAddRegistry = Object.assign(new Registry, {
id: Guid.create(),
name: name,
urlPrefix: urlPrefix,
name,
urlPrefix,
});
mapper.put(toAddRegistry).then(objectSaved => {
console.log(objectSaved);
});
}

Expand Down
2 changes: 1 addition & 1 deletion discovery/src/dynamo/dynamo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import { DataMapper } from '@aws/dynamodb-data-mapper';
import DynamoDB = require('aws-sdk/clients/dynamodb');
import AWS = require('aws-sdk');
import DynamoDB = require('aws-sdk/clients/dynamodb');
import { AWSConfig } from './config';

AWS.config.update(AWSConfig);
Expand Down
24 changes: 12 additions & 12 deletions discovery/src/dynamo/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,46 @@ import {
@table('cvpm-package')
class Package {
@hashKey()
id: string;
public id: string;

@rangeKey({defaultProvider: () => new Date()})
createdAt: Date;
public createdAt: Date;

@attribute()
isSymbol: boolean;
public isSymbol: boolean;

@attribute()
linkedTo: string;
public linkedTo: string;
}

@table('cvpm-pretrained')
class Pretrained {
@hashKey()
id: string;
public id: string;

@rangeKey({defaultProvider: () => new Date()})
createdAt: Date;
public createdAt: Date;

@attribute()
linkedTo: string;
public linkedTo: string;

@attribute()
name: string;
public name: string;
}

@table('cvpm-registry')
class Registry {
@hashKey()
id: string;
public id: string;

@rangeKey({defaultProvider: () => new Date()})
createdAt: Date;
public createdAt: Date;

@attribute()
name: string;
public name: string;

@attribute()
urlPrefix: string;
public urlPrefix: string;
}

export {
Expand Down
6 changes: 3 additions & 3 deletions discovery/src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { config } from './config';

const Sentry = require('@sentry/node')
Sentry.init({})
const Sentry = require('@sentry/node');
Sentry.init({});

export {
Sentry
}
};
1 change: 0 additions & 1 deletion discovery/src/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ async function getCount(limit: number) {
};
result.push(each_result);
}
console.log(result);
return result;
}

Expand Down
15 changes: 6 additions & 9 deletions discovery/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import * as helmet from 'koa-helmet';
import * as passport from 'koa-passport';
import * as session from 'koa-session';

import { initParse } from './parse';
import { config } from './config';
import { Sentry } from './logging';
import { initParse } from './parse';
import { router } from './routes';
import { Sentry } from './logging'

import * as os from 'os';

Expand Down Expand Up @@ -39,10 +39,7 @@ app.use(cors());
app.use(helmet());
app.use(bodyParser());
app.use(router.routes()).use(router.allowedMethods());
app.on('error', err=>{
console.error(err)
Sentry.captureException(err)
})
app.listen(config.port);
console.log('CVPM Discovery Service Started on port: ' + config.port)
console.info(config)
app.on('error', err => {
Sentry.captureException(err);
});
app.listen(config.port);
Loading

0 comments on commit e8d9ec4

Please sign in to comment.