Skip to content

Commit

Permalink
make report narrative stream
Browse files Browse the repository at this point in the history
  • Loading branch information
tevko committed Dec 11, 2024
1 parent 1066c15 commit c3aa8dc
Show file tree
Hide file tree
Showing 5 changed files with 883 additions and 1,689 deletions.
34 changes: 31 additions & 3 deletions client-report/src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from "react";
import _ from "lodash";

import * as globals from "./globals";
import URLs from "../util/url";
import DataUtils from "../util/dataUtils";
// import Matrix from "./correlationMatrix/matrix";
import Heading from "./framework/heading";
Expand Down Expand Up @@ -119,11 +120,38 @@ class App extends React.Component {
});
}

getNarrative(report_id) {
return net.polisGet("/api/v3/reportNarrative", {
report_id: report_id,
async getNarrative(report_id) {
let narrativeData = "";
const urlPrefix = URLs.urlPrefix;
const response = await fetch(`${urlPrefix}api/v3/reportNarrative?report_id=${report_id}`, {
credentials: "include",
method: "get",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
});
if (!response.ok || !response.body) {
throw response.statusText;
}

const reader = response.body.getReader();
const decoder = new TextDecoder();
const loopRunner = true;

while (loopRunner) {
const { value, done } = await reader.read();
if (done) {
break;
}
const decodedChunk = decoder.decode(value, { stream: true });

if (!decodedChunk.includes('POLIS-PING:')) narrativeData += decodedChunk;
}

return JSON.parse(narrativeData);
}

getReport(report_id) {
return net
.polisGet("/api/v3/reports", {
Expand Down
11 changes: 7 additions & 4 deletions server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ dotenv.config();

import Promise from "bluebird";
import express from "express";
import compression from "compression";
import cookieParser from "cookie-parser";
import bodyParser from "body-parser";
import morgan from "morgan";

import Config from "./src/config";
Expand Down Expand Up @@ -222,16 +225,16 @@ helpersInitialized.then(
app.use(middleware_responseTime_start);

app.use(redirectIfNotHttps);
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(cookieParser());
// app.use(bodyParser());
app.use(writeDefaultHead);

if (devMode) {
app.use(express.compress());
app.use(compression());
} else {
// Cloudflare would apply gzip if we didn't
// but it's about 2x faster if we do the gzip (for the inbox query on mike's account)
app.use(express.compress());
app.use(compression());
}
app.use(middleware_log_request_body);
app.use(middleware_log_middleware_errors);
Expand Down
Loading

0 comments on commit c3aa8dc

Please sign in to comment.