소스 검색

load data

kunickyd 3 년 전
부모
커밋
1c00baec45
1개의 변경된 파일13개의 추가작업 그리고 5개의 파일을 삭제
  1. 13 5
      app.ts

+ 13 - 5
app.ts

@@ -7,8 +7,9 @@ import {
     CommandService_v1Client as CommandService,
     QueryService_v1Client as QueryService
 } from 'iroha-helpers/lib/proto/endpoint_grpc_pb'
-
 import { queries } from 'iroha-helpers'
+import util from 'util'
+import { exec } from 'child_process'
 
 const app = express();
 app.use(bodyParser.json());
@@ -17,6 +18,8 @@ app.use(basicAuth({
     challenge: true
 }));
 
+const asyncExec = util.promisify(exec);
+
 const IROHA_ADMIN_PRIV = "f101537e319568c765b2cc89698325604991dca57b9716b58016b253506cab70";
 const IROHA_ADMIN = "admin@test";
 const IROHA_ADDRESS = "localhost:50051";
@@ -24,7 +27,7 @@ const commandService = new CommandService(IROHA_ADDRESS, grpc.credentials.create
 const queryService = new QueryService(IROHA_ADDRESS, grpc.credentials.createInsecure());
 
 
-
+const CHAIN4ALL_RASTER_CLIP_SCRIPT_PATH = process.env.CHAIN4ALL_RASTER_CLIP_SCRIPT_PATH || '/home/kunickyd/Documents/chain4all/chain4all_raster_clip.sh';
 const CHAIN4ALL_SERVICE_PORT = process.env.CHAIN4ALL_SERVICE_PORT || 3000;
 const IROHA_API_HOST = process.env.IROHA_API_HOST || "http://localhost";
 const IROHA_API_PORT = process.env.IROHA_API_PORT || 5000;
@@ -67,11 +70,16 @@ app.post("/buy", async (req, res, next) => {
             throw Error(JSON.stringify({ error: { name: "Error, request body has no \"user\" property!" } }));
         }
 
+        //TODO validate this properly
         let txDetail = await getTransactionDetail(req.body.txHash, req.body.user);
-
         
+        const { stdout, stderr } = await asyncExec(CHAIN4ALL_RASTER_CLIP_SCRIPT_PATH);
+        
+        if(stderr){
+            throw(stderr);
+        }
 
-        res.send(txDetail);
+        res.send(stdout);
     }
     catch (err) {
         next(err);
@@ -81,7 +89,7 @@ app.post("/buy", async (req, res, next) => {
 async function getTransactionDetail(txHash: string, user: string) {
     let quer: any = await queries.getAccountTransactions({
         privateKey: IROHA_ADMIN_PRIV,
-        creatorAccountId: 'admin@test',
+        creatorAccountId: IROHA_ADMIN,
         queryService,
         timeoutLimit: 5000
     }, {