♻️(backend) rename convert-markdown endpoint
Renamed the `convert-markdown` endpoint to `convert` as a general-purpose conversion endpoint for integration with DocSpec conversion (DOCX import), without altering its existing functionality. In a future contribution, this endpoint will not only support conversion from Markdown -> BlockNote -> Yjs but also directly BlockNote -> Yjs. Signed-off-by: Stephan Meijer <me@stephanmeijer.com>
This commit is contained in:
@@ -29,7 +29,7 @@ These are the environment variables you can set for the `impress-backend` contai
|
|||||||
| COLLABORATION_WS_NOT_CONNECTED_READY_ONLY | Users not connected to the collaboration server cannot edit | false |
|
| COLLABORATION_WS_NOT_CONNECTED_READY_ONLY | Users not connected to the collaboration server cannot edit | false |
|
||||||
| COLLABORATION_WS_URL | collaboration websocket url | |
|
| COLLABORATION_WS_URL | collaboration websocket url | |
|
||||||
| CONVERSION_API_CONTENT_FIELD | Conversion api content field | content |
|
| CONVERSION_API_CONTENT_FIELD | Conversion api content field | content |
|
||||||
| CONVERSION_API_ENDPOINT | Conversion API endpoint | convert-markdown |
|
| CONVERSION_API_ENDPOINT | Conversion API endpoint | convert |
|
||||||
| CONVERSION_API_SECURE | Require secure conversion api | false |
|
| CONVERSION_API_SECURE | Require secure conversion api | false |
|
||||||
| CONVERSION_API_TIMEOUT | Conversion api timeout | 30 |
|
| CONVERSION_API_TIMEOUT | Conversion api timeout | 30 |
|
||||||
| CONTENT_SECURITY_POLICY_DIRECTIVES | A dict of directives set in the Content-Security-Policy header | All directives are set to 'none' |
|
| CONTENT_SECURITY_POLICY_DIRECTIVES | A dict of directives set in the Content-Security-Policy header | All directives are set to 'none' |
|
||||||
|
|||||||
@@ -639,7 +639,7 @@ class Base(Configuration):
|
|||||||
|
|
||||||
# Conversion endpoint
|
# Conversion endpoint
|
||||||
CONVERSION_API_ENDPOINT = values.Value(
|
CONVERSION_API_ENDPOINT = values.Value(
|
||||||
default="convert-markdown",
|
default="convert",
|
||||||
environ_name="CONVERSION_API_ENDPOINT",
|
environ_name="CONVERSION_API_ENDPOINT",
|
||||||
environ_prefix=None,
|
environ_prefix=None,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ describe('Server Tests', () => {
|
|||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('POST /api/convert-markdown with incorrect API key should return 403', async () => {
|
test('POST /api/convert with incorrect API key should return 403', async () => {
|
||||||
const response = await request(app as any)
|
const response = await request(app as any)
|
||||||
.post('/api/convert-markdown')
|
.post('/api/convert')
|
||||||
.set('Origin', origin)
|
.set('Origin', origin)
|
||||||
.set('Authorization', 'wrong-api-key');
|
.set('Authorization', 'wrong-api-key');
|
||||||
|
|
||||||
@@ -31,9 +31,9 @@ describe('Server Tests', () => {
|
|||||||
expect(response.body.error).toBe('Forbidden: Invalid API Key');
|
expect(response.body.error).toBe('Forbidden: Invalid API Key');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('POST /api/convert-markdown with a Bearer token', async () => {
|
test('POST /api/convert with a Bearer token', async () => {
|
||||||
const response = await request(app as any)
|
const response = await request(app as any)
|
||||||
.post('/api/convert-markdown')
|
.post('/api/convert')
|
||||||
.set('Origin', origin)
|
.set('Origin', origin)
|
||||||
.set('Authorization', 'Bearer test-secret-api-key');
|
.set('Authorization', 'Bearer test-secret-api-key');
|
||||||
|
|
||||||
@@ -41,9 +41,9 @@ describe('Server Tests', () => {
|
|||||||
expect(response.status).toBe(403);
|
expect(response.status).toBe(403);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('POST /api/convert-markdown with missing body param content', async () => {
|
test('POST /api/convert with missing body param content', async () => {
|
||||||
const response = await request(app as any)
|
const response = await request(app as any)
|
||||||
.post('/api/convert-markdown')
|
.post('/api/convert')
|
||||||
.set('Origin', origin)
|
.set('Origin', origin)
|
||||||
.set('Authorization', 'yprovider-api-key');
|
.set('Authorization', 'yprovider-api-key');
|
||||||
|
|
||||||
@@ -51,9 +51,9 @@ describe('Server Tests', () => {
|
|||||||
expect(response.body.error).toBe('Invalid request: missing content');
|
expect(response.body.error).toBe('Invalid request: missing content');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('POST /api/convert-markdown with body param content being an empty string', async () => {
|
test('POST /api/convert with body param content being an empty string', async () => {
|
||||||
const response = await request(app as any)
|
const response = await request(app as any)
|
||||||
.post('/api/convert-markdown')
|
.post('/api/convert')
|
||||||
.set('Origin', origin)
|
.set('Origin', origin)
|
||||||
.set('Authorization', 'yprovider-api-key')
|
.set('Authorization', 'yprovider-api-key')
|
||||||
.send({
|
.send({
|
||||||
@@ -39,20 +39,20 @@ describe('Server Tests', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow JSON payloads up to 500kb for the CONVERT_MARKDOWN route', async () => {
|
it('should allow JSON payloads up to 500kb for the CONVERT route', async () => {
|
||||||
const largePayload = 'a'.repeat(400 * 1024); // 400kb payload
|
const largePayload = 'a'.repeat(400 * 1024); // 400kb payload
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post(routes.CONVERT_MARKDOWN)
|
.post(routes.CONVERT)
|
||||||
.send({ data: largePayload })
|
.send({ data: largePayload })
|
||||||
.set('Content-Type', 'application/json');
|
.set('Content-Type', 'application/json');
|
||||||
|
|
||||||
expect(response.status).not.toBe(413);
|
expect(response.status).not.toBe(413);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject JSON payloads larger than 500kb for the CONVERT_MARKDOWN route', async () => {
|
it('should reject JSON payloads larger than 500kb for the CONVERT route', async () => {
|
||||||
const oversizedPayload = 'a'.repeat(501 * 1024); // 501kb payload
|
const oversizedPayload = 'a'.repeat(501 * 1024); // 501kb payload
|
||||||
const response = await request(app)
|
const response = await request(app)
|
||||||
.post(routes.CONVERT_MARKDOWN)
|
.post(routes.CONVERT)
|
||||||
.send({ data: oversizedPayload })
|
.send({ data: oversizedPayload })
|
||||||
.set('Content-Type', 'application/json');
|
.set('Content-Type', 'application/json');
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ interface ErrorResponse {
|
|||||||
error: string;
|
error: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const convertMarkdownHandler = async (
|
export const convertHandler = async (
|
||||||
req: Request<
|
req: Request<
|
||||||
object,
|
object,
|
||||||
ConversionResponse | ErrorResponse,
|
ConversionResponse | ErrorResponse,
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
export * from './collaborationResetConnectionsHandler';
|
export * from './collaborationResetConnectionsHandler';
|
||||||
export * from './collaborationWSHandler';
|
export * from './collaborationWSHandler';
|
||||||
export * from './convertMarkdownHandler';
|
export * from './convertHandler';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export const routes = {
|
export const routes = {
|
||||||
COLLABORATION_WS: '/collaboration/ws/',
|
COLLABORATION_WS: '/collaboration/ws/',
|
||||||
COLLABORATION_RESET_CONNECTIONS: '/collaboration/api/reset-connections/',
|
COLLABORATION_RESET_CONNECTIONS: '/collaboration/api/reset-connections/',
|
||||||
CONVERT_MARKDOWN: '/api/convert-markdown/',
|
CONVERT: '/api/convert/',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { PORT } from '../env';
|
|||||||
import {
|
import {
|
||||||
collaborationResetConnectionsHandler,
|
collaborationResetConnectionsHandler,
|
||||||
collaborationWSHandler,
|
collaborationWSHandler,
|
||||||
convertMarkdownHandler,
|
convertHandler,
|
||||||
} from '../handlers';
|
} from '../handlers';
|
||||||
import { corsMiddleware, httpSecurity, wsSecurity } from '../middlewares';
|
import { corsMiddleware, httpSecurity, wsSecurity } from '../middlewares';
|
||||||
import { routes } from '../routes';
|
import { routes } from '../routes';
|
||||||
@@ -22,7 +22,7 @@ import { logger } from '../utils';
|
|||||||
export const initServer = () => {
|
export const initServer = () => {
|
||||||
const { app } = expressWebsockets(express());
|
const { app } = expressWebsockets(express());
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
if (req.path === routes.CONVERT_MARKDOWN) {
|
if (req.path === routes.CONVERT) {
|
||||||
// Large transcript files are bigger than the default '100kb' limit
|
// Large transcript files are bigger than the default '100kb' limit
|
||||||
return express.json({ limit: '500kb' })(req, res, next);
|
return express.json({ limit: '500kb' })(req, res, next);
|
||||||
}
|
}
|
||||||
@@ -47,9 +47,9 @@ export const initServer = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route to convert markdown
|
* Route to convert Markdown or BlockNote blocks
|
||||||
*/
|
*/
|
||||||
app.post(routes.CONVERT_MARKDOWN, httpSecurity, convertMarkdownHandler);
|
app.post(routes.CONVERT, httpSecurity, convertHandler);
|
||||||
|
|
||||||
Sentry.setupExpressErrorHandler(app);
|
Sentry.setupExpressErrorHandler(app);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user