Skip to content

Commit

Permalink
Update to encoda 1.0.8 and other updates [elifesciences/enhanced-prep…
Browse files Browse the repository at this point in the history
  • Loading branch information
nlisgo committed Oct 15, 2024
1 parent 22cce9b commit 3c0a3d4
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 62 deletions.
5 changes: 3 additions & 2 deletions integration-tests/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('api', () => {
.post('/')
.send(xml.toString())
.expect(200)
.then((response) => expect(response.headers['content-type']).toBe('application/vnd.elife.encoda.v1.0.7+json; charset=utf-8'));
.then((response) => expect(response.headers['content-type']).toBe('application/vnd.elife.encoda.v1.0.8+json; charset=utf-8'));
});

it.each([
Expand All @@ -20,6 +20,7 @@ describe('api', () => {
'1.0.3',
'1.0.6',
'1.0.7',
'1.0.8',
])('should use the specified version - %s', async (version) => {
const mimeType = `application/vnd.elife.encoda.v${version}+json`;
await request(app)
Expand All @@ -34,7 +35,7 @@ describe('api', () => {
'unknown',
'1.0.4',
'1.0.5',
'1.0.8',
'1.0.9',
])('should error if you specify wrong version - %s', async (version) => {
const mimeType = `application/vnd.elife.encoda.v${version}+json`;
await request(app)
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
"@stencila/encoda-1-0-3": "npm:@stencila/[email protected]",
"@stencila/encoda-1-0-6": "npm:@stencila/[email protected]",
"@stencila/encoda-1-0-7": "npm:@stencila/[email protected]",
"body-parser": "^1.20.2",
"express": "^4.18.2"
"@stencila/encoda-1-0-8": "npm:@stencila/[email protected]",
"body-parser": "^1.20.3",
"express": "^4.21.1"
},
"scripts": {
"start": "ts-node src/server.ts",
Expand Down
17 changes: 11 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { convert as convert_1_0_2 } from '@stencila/encoda-1-0-2';
import { convert as convert_1_0_3 } from '@stencila/encoda-1-0-3';
import { convert as convert_1_0_6 } from '@stencila/encoda-1-0-6';
import { convert as convert_1_0_7 } from '@stencila/encoda-1-0-7';
import { mkdtempSync, writeFileSync, rmdirSync } from 'fs';
import { convert as convert_1_0_8 } from '@stencila/encoda-1-0-8';
import { mkdtempSync, writeFileSync, rmSync } from 'fs';
import { tmpdir } from 'os';

const app = express();
Expand Down Expand Up @@ -37,25 +38,29 @@ app.post('/', async (req, res) => {
const replacementPath = typeof req.query.replacementPath === 'string' ? req.query.replacementPath : '';

const versionResponders = {
'application/vnd.elife.encoda.v1.0.8+json': async () => {
res.json(JSON.parse(((await convert_1_0_8(xmlFile, undefined, parameters)) ?? '{}').replaceAll(tempOutput, replacementPath)));
rmSync(tempOutput, { recursive: true, force: true });
},
'application/vnd.elife.encoda.v1.0.7+json': async () => {
res.json(JSON.parse(((await convert_1_0_7(xmlFile, undefined, parameters)) ?? '{}').replaceAll(tempOutput, replacementPath)));
rmdirSync(tempOutput, { recursive: true });
rmSync(tempOutput, { recursive: true, force: true });
},
'application/vnd.elife.encoda.v1.0.6+json': async () => {
res.json(JSON.parse(((await convert_1_0_6(xmlFile, undefined, parameters)) ?? '{}').replaceAll(tempOutput, replacementPath)));
rmdirSync(tempOutput, { recursive: true });
rmSync(tempOutput, { recursive: true, force: true });
},
'application/vnd.elife.encoda.v1.0.3+json': async () => {
res.json(JSON.parse(((await convert_1_0_3(xmlFile, undefined, parameters)) ?? '{}').replaceAll(tempOutput, replacementPath)));
rmdirSync(tempOutput, { recursive: true });
rmSync(tempOutput, { recursive: true, force: true });
},
'application/vnd.elife.encoda.v1.0.2+json': async () => {
res.json(JSON.parse(((await convert_1_0_2(xmlFile, undefined, parameters)) ?? '{}').replaceAll(tempOutput, replacementPath)));
rmdirSync(tempOutput, { recursive: true });
rmSync(tempOutput, { recursive: true, force: true });
},
'application/vnd.elife.encoda.v1.0.1+json': async () => {
res.json(JSON.parse(((await convert_1_0_1(xmlFile, undefined, parameters)) ?? '{}').replaceAll(tempOutput, replacementPath)));
rmdirSync(tempOutput, { recursive: true });
rmSync(tempOutput, { recursive: true, force: true });
},
default: async () => {
res.status(406).send({ error: 'the requested content type is not supported' });
Expand Down
Loading

0 comments on commit 3c0a3d4

Please sign in to comment.