Skip to content
Snippets Groups Projects
Commit e6e51486 authored by David Sehnal's avatar David Sehnal
Browse files

model-server: call for static input files, api versioning

parent 23197051
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,8 @@ const config = { ...@@ -67,6 +67,8 @@ const config = {
switch (source.toLowerCase()) { switch (source.toLowerCase()) {
// case 'pdb': return `e:/test/quick/${id}_updated.cif`; // case 'pdb': return `e:/test/quick/${id}_updated.cif`;
case 'pdb': return `e:/test/mol-star/model/out/${id}_updated.bcif`; case 'pdb': return `e:/test/mol-star/model/out/${id}_updated.bcif`;
case 'pdb-bcif': return `e:/test/mol-star/model/out/${id}_updated.bcif`;
case 'pdb-cif': return `e:/test/mol-star/model/out/${id}_updated.cif`;
default: return void 0; default: return void 0;
} }
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* @author David Sehnal <david.sehnal@gmail.com> * @author David Sehnal <david.sehnal@gmail.com>
*/ */
import * as fs from 'fs';
import * as path from 'path';
import * as express from 'express'; import * as express from 'express';
import Config from '../config'; import Config from '../config';
import { ConsoleLogger } from 'mol-util/console-logger'; import { ConsoleLogger } from 'mol-util/console-logger';
...@@ -97,7 +99,35 @@ async function processNextJob() { ...@@ -97,7 +99,35 @@ async function processNextJob() {
// } // }
export function initWebApi(app: express.Express) { export function initWebApi(app: express.Express) {
app.get(makePath('query'), (req, res) => { app.get(makePath('static/:format/:id'), async (req, res) => {
const binary = req.params.format === 'bcif';
const id = req.params.id;
const fn = Config.mapFile(binary ? 'pdb-bcif' : 'pdb-cif', id);
if (!fn || !fs.existsSync(fn)) {
res.status(404);
res.end();
return;
}
fs.readFile(fn, (err, data) => {
if (err) {
res.status(404);
res.end();
return;
}
const f = path.parse(fn);
res.writeHead(200, {
'Content-Type': binary ? 'application/octet-stream' : 'text/plain; charset=utf-8',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'X-Requested-With',
'Content-Disposition': `inline; filename="${f.name}${f.ext}"`
});
res.write(data);
res.end();
});
})
app.get(makePath('api/v1'), (req, res) => {
const query = /\?(.*)$/.exec(req.url)![1]; const query = /\?(.*)$/.exec(req.url)![1];
const args = JSON.parse(decodeURIComponent(query)); const args = JSON.parse(decodeURIComponent(query));
const name = args.name; const name = args.name;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment