Skip to content

Commit 9abec97

Browse files
committed
Add 'secret' to report endpoints
1 parent 23accd4 commit 9abec97

File tree

8 files changed

+74
-22
lines changed

8 files changed

+74
-22
lines changed

.env.defaults

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ FGSEA_PRERANKED_SERVICE_URL=https://fgseadev.baderlab.net/v1/preranked
1010
FGSEA_RNASEQ_SERVICE_URL=https://fgseadev.baderlab.net/v1/rnaseq
1111
EM_SERVICE_URL=https://emjavadev.baderlab.net/v1
1212
BRIDGEDB_URL=https://webservice.bridgedb.org
13+
REPORT_SECRET=baderlab

.env.local

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ FGSEA_PRERANKED_SERVICE_URL=http://localhost:8000/preranked
1010
FGSEA_RNASEQ_SERVICE_URL=http://localhost:8000/rnaseq
1111
EM_SERVICE_URL=http://localhost:8080/v1
1212
BRIDGEDB_URL=https://webservice.bridgedb.org
13+
REPORT_SECRET=baderlab

src/client/components/network-editor/export-controller.js

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const Path = {
2525
DATA_ENRICH: 'data/enrichment_results.txt',
2626
DATA_RANKS: 'data/ranks.txt',
2727
DATA_GENESETS: 'data/gene_sets.gmt',
28+
DATA_JSON: 'data/network.json',
2829
README: 'README.md'
2930
};
3031

@@ -60,6 +61,7 @@ export class ExportController {
6061
const blob2 = await this._createNetworkImageBlob(ImageSize.LARGE);
6162
const blob3 = await this._createNetworkPDFBlob();
6263
const blob4 = await this._createSVGLegendBlob();
64+
// const blob5 = await this._createNetworkJSONBlob();
6365
const files = await filesPromise;
6466
const readme = createREADME(this.controller);
6567

@@ -69,6 +71,7 @@ export class ExportController {
6971
zip.file(Path.IMAGE_LARGE, blob2);
7072
zip.file(Path.IMAGE_PDF, blob3);
7173
zip.file(Path.IMAGE_LEGEND, blob4);
74+
// zip.file(Path.DATA_JSON, blob5);
7275
zip.file(Path.DATA_ENRICH, files[0]);
7376
zip.file(Path.DATA_RANKS, files[1]);
7477
zip.file(Path.DATA_GENESETS, files[2]);
@@ -148,6 +151,16 @@ export class ExportController {
148151
return blob;
149152
}
150153

154+
async _createNetworkJSONBlob() {
155+
const { cy } = this.controller;
156+
const json = cy.json();
157+
const blob = new Blob(
158+
[ JSON.stringify(json, null, 2) ], {
159+
type: 'text/plain'
160+
});
161+
return blob;
162+
}
163+
151164
async _createNetworkPDFBlob() {
152165
const { cy } = this.controller;
153166
const blob = await cy.pdf({

src/client/components/report/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { currentTheme } from '../../theme';
66
import Report from './report';
77

88

9-
export function ReportHome() {
9+
export function ReportHome({ secret }) {
1010
const [ theme, setTheme ] = useState(currentTheme);
1111

1212
useEffect(() => {
@@ -22,12 +22,13 @@ export function ReportHome() {
2222
return (
2323
<ThemeProvider theme={theme}>
2424
<CssBaseline />
25-
<Report />
25+
<Report secret={secret} />
2626
</ThemeProvider>
2727
);
2828
}
2929

3030
ReportHome.propTypes = {
31+
secret: PropTypes.string,
3132
};
3233

3334
export default ReportHome;

src/client/components/report/report.js

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useEffect } from 'react';
2+
import PropTypes from 'prop-types';
23
import { getComparator } from '../network-editor/pathway-table';
34
import { Select, MenuItem } from '@material-ui/core';
45
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper } from '@material-ui/core';
@@ -17,34 +18,49 @@ const useStyles = makeStyles((theme) => ({
1718
}));
1819

1920

20-
export function Report() {
21+
async function fetchReport(secret) {
22+
try {
23+
const countRes = await fetch(`/api/report/count/${secret}`);
24+
if(!countRes.ok) {
25+
return 'error';
26+
}
27+
const networkRes = await fetch(`/api/report/networks/${secret}`);
28+
if(!networkRes.ok) {
29+
return 'error';
30+
}
31+
32+
const counts = await countRes.json();
33+
const networks = await networkRes.json();
34+
35+
return { counts, networks };
36+
} catch(err) {
37+
console.log(err);
38+
return 'error';
39+
}
40+
}
41+
42+
43+
export function Report({ secret }) {
2144
const classes = useStyles();
45+
2246
const [ report, setReport ] = useState(null);
2347
const [ order, setOrder] = useState('desc');
2448
const [ orderBy, setOrderBy ] = useState('creationTime');
2549

2650
useEffect(() => {
27-
Promise.all([
28-
fetch('/api/report/count').then(res => res.json()),
29-
fetch('/api/report/networks').then(res => res.json())
30-
])
31-
.then(([ counts, networks ]) => {
32-
const report = { counts, networks };
33-
console.log('report', report);
34-
setReport(report);
35-
})
36-
.catch((error) => console.log(error));
51+
fetchReport(secret).then(setReport);
3752
}, []);
3853

39-
4054
if(!report) {
4155
return <div> Loading... </div>;
56+
} else if(report === 'error') {
57+
return <div> Error fetching report. </div>;
4258
}
4359

4460
const comparator = getComparator(order, orderBy);
4561
const sortedNetworks = report.networks.sort(comparator);
4662

47-
return <div>
63+
return <div style={{padding: '10px'}}>
4864
<h1>EnrichmentMap:RNA-Seq - Usage Report</h1>
4965
<h3>Demo Networks: {report.counts.demo}</h3>
5066
<h3>User Created Networks ({report.counts.user}):</h3>
@@ -73,7 +89,7 @@ export function Report() {
7389
<TableCell align="right"><b>Type</b></TableCell>
7490
<TableCell align="right"><b>Creation Time</b></TableCell>
7591
<TableCell align="right"><b>Last Access Time</b></TableCell>
76-
<TableCell align="right"><b>Open</b></TableCell>
92+
<TableCell align="right"> </TableCell>
7793
</TableRow>
7894
</TableHead>
7995
<TableBody>
@@ -101,4 +117,8 @@ export function Report() {
101117
</div>;
102118
}
103119

120+
Report.propTypes = {
121+
secret: PropTypes.string,
122+
};
123+
104124
export default Report;

src/client/router.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ export function Router() {
4040
)}
4141
/>
4242
<Route
43-
path='/report'
44-
render={(props) => (
45-
<ReportHome {...props} />
46-
)}
43+
path='/report/:secret'
44+
render={(props) => {
45+
const secret = _.get(props, ['match', 'params', 'secret'], _.get(props, 'secret'));
46+
return <ReportHome secret={secret} />;
47+
}}
4748
/>
4849
<Route
4950
path='/document/:id/:secret'

src/server/env.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const LOG_LEVEL = process.env.LOG_LEVEL;
1414
export const BASE_URL = process.env.BASE_URL;
1515
export const UPLOAD_LIMIT = process.env.UPLOAD_LIMIT;
1616
export const TESTING = ('' + process.env.TESTING).toLowerCase() === 'true';
17+
export const REPORT_SECRET = process.env.REPORT_SECRET;
1718

1819
// Service config
1920
export const FGSEA_PRERANKED_SERVICE_URL = process.env.FGSEA_PRERANKED_SERVICE_URL;

src/server/routes/api/report.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import Express from 'express';
22
import Datastore from '../../datastore.js';
33
import { writeCursorToResult } from './index.js';
4+
import { REPORT_SECRET } from '../../env.js';
45

56
const http = Express.Router();
67

78
// Return enrichment results in TSV format
8-
http.get('/count', async function(req, res, next) {
9+
http.get(`/count/:secret`, async function(req, res, next) {
10+
911
try {
12+
const { secret } = req.params;
13+
if(secret !== REPORT_SECRET) {
14+
res.sendStatus(404);
15+
return;
16+
}
17+
1018
const counts = await Datastore.getNetworkCounts();
1119
res.send(JSON.stringify(counts));
1220

@@ -16,8 +24,14 @@ http.get('/count', async function(req, res, next) {
1624
});
1725

1826
// Return enrichment results in TSV format
19-
http.get('/networks', async function(req, res, next) {
27+
http.get(`/networks/:secret`, async function(req, res, next) {
2028
try {
29+
const { secret } = req.params;
30+
if(secret !== REPORT_SECRET) {
31+
res.sendStatus(404);
32+
return;
33+
}
34+
2135
const cursor = await Datastore.getNetworkStatsCursor();
2236
await writeCursorToResult(cursor, res);
2337
cursor.close();

0 commit comments

Comments
 (0)