diff --git a/src/servers/model/config.ts b/src/servers/model/config.ts index 8ae2425e76e98e9dd8e0f4d7c4903802b0e55f2c..a18919c842ebc67959c4ef6b86fc09a031b2969c 100644 --- a/src/servers/model/config.ts +++ b/src/servers/model/config.ts @@ -67,6 +67,8 @@ const config = { switch (source.toLowerCase()) { // case 'pdb': return `e:/test/quick/${id}_updated.cif`; 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; } } diff --git a/src/servers/model/server/api-web.ts b/src/servers/model/server/api-web.ts index 2e80b9eb09d31abf6d5bff986fbf449445229279..4151a933a43d13a9dac465772a04f7346bb2f174 100644 --- a/src/servers/model/server/api-web.ts +++ b/src/servers/model/server/api-web.ts @@ -4,6 +4,8 @@ * @author David Sehnal <david.sehnal@gmail.com> */ +import * as fs from 'fs'; +import * as path from 'path'; import * as express from 'express'; import Config from '../config'; import { ConsoleLogger } from 'mol-util/console-logger'; @@ -97,7 +99,35 @@ async function processNextJob() { // } 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 args = JSON.parse(decodeURIComponent(query)); const name = args.name;