Skip to content

Commit

Permalink
add package put/get methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyaoi committed Nov 8, 2018
1 parent 24fe39d commit 87f2b09
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 6 deletions.
3 changes: 2 additions & 1 deletion discovery/.gitignore
@@ -1,2 +1,3 @@
node_modules/
dist/
dist/
*.log
1 change: 1 addition & 0 deletions discovery/src/controller/index.ts
@@ -1,2 +1,3 @@
export { default as system } from './system';
export { default as package } from './package';
export { default as pretrained } from './pretrained';
19 changes: 19 additions & 0 deletions discovery/src/controller/pretrained.ts
@@ -0,0 +1,19 @@
import { Context } from 'koa';
import { putPretrained, getPretrained } from '../dynamo/action';
export default class PackageController {
public static async importPretrained (ctx: Context) {
putPretrained('yolo_tiny','https://premium.file.cvtron.xyz/data/yolo_tiny.ckpt');
ctx.status = 200;
ctx.body = {
'code': '200',
'desc': 'success'
};
}
public static async getAllPretrained (ctx: Context) {
ctx.status = 200;
ctx.body = {
'code': '200',
'results': await getPretrained()
}
}
}
49 changes: 47 additions & 2 deletions discovery/src/dynamo/action.ts
@@ -1,9 +1,17 @@
import mapper from './dynamo'
import { Package } from './entity'
import mapper from './dynamo';
import { Package, Pretrained } from './entity';
import { Guid } from 'guid-typescript';
import { isSymbol } from 'util';

/**
* Following will be package manipulations
*/

/**
*
* @param isSymbol
* @param linkedTo
*/
function putPackage (isSymbol: boolean, linkedTo: string) {
const toPutPackage = Object.assign(new Package, {
id: Guid.create(),
Expand All @@ -14,3 +22,40 @@ function putPackage (isSymbol: boolean, linkedTo: string) {
console.log(objectSaved)
})
}
/**
*
* Following will be pretrained manipulations
*/

/**
*
* @param linkedTo
* @param name
*/
function putPretrained (name: string, linkedTo: string) {
const toPutPretrained = Object.assign(new Pretrained, {
id: Guid.create(),
name: name,
linkedTo: linkedTo
})
mapper.put(toPutPretrained).then(objectSaved => {
console.log(objectSaved)
})
}

/**
*
*/
async function getPretrained () {
let results: Pretrained[] = []
for await (const item of mapper.scan(Pretrained)) {
results.push(item)
}
return results
}

export {
putPretrained,
putPackage,
getPretrained
}
9 changes: 9 additions & 0 deletions discovery/src/dynamo/config.ts
@@ -0,0 +1,9 @@
const AWSConfig = {
region: 'us-east-1',
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
}

export {
AWSConfig
}
4 changes: 4 additions & 0 deletions discovery/src/dynamo/dynamo.ts
Expand Up @@ -5,6 +5,10 @@

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

AWS.config.update(AWSConfig)

const mapper = new DataMapper({
client: new DynamoDB({region: 'us-east-1'})
Expand Down
17 changes: 16 additions & 1 deletion discovery/src/dynamo/entity.ts
Expand Up @@ -21,9 +21,24 @@ class Package {

@attribute()
linkedTo: string;
}

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

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

@attribute()
linkedTo: string;

@attribute()
name: string;
}

export {
Package
Package,
Pretrained
}
4 changes: 3 additions & 1 deletion discovery/src/routes.ts
Expand Up @@ -5,6 +5,8 @@ import controller = require('./controller');
const router = new Router();

router.get('/system/status', controller.system.getSystemStatus);
router.post('/packages', controller.package.importPackage)
router.post('/packages', controller.package.importPackage);
router.put('/pretrained', controller.pretrained.importPretrained);
router.get('/pretrained', controller.pretrained.getAllPretrained);

export { router };
3 changes: 2 additions & 1 deletion discovery/tsconfig.json
Expand Up @@ -16,7 +16,8 @@
],
"lib": [
"es2017",
"es6"
"es6",
"esnext.asynciterable"
],
"types": [
"node"
Expand Down

0 comments on commit 87f2b09

Please sign in to comment.