Skip to content

♻️(backend) rename convert-markdown endpoint #1105

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_URL | Collaboration websocket url | |
| 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_TIMEOUT | Conversion api timeout | 30 |
| CRISP_WEBSITE_ID | Crisp website id for support | |
Expand Down
2 changes: 1 addition & 1 deletion src/backend/impress/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ class Base(Configuration):

# Conversion endpoint
CONVERSION_API_ENDPOINT = values.Value(
default="convert-markdown",
default="convert",
environ_name="CONVERSION_API_ENDPOINT",
environ_prefix=None,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,39 @@ describe('Server Tests', () => {
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)
.post('/api/convert-markdown')
.post('/api/convert')
.set('Origin', origin)
.set('Authorization', 'wrong-api-key');

expect(response.status).toBe(403);
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)
.post('/api/convert-markdown')
.post('/api/convert')
.set('Origin', origin)
.set('Authorization', 'Bearer test-secret-api-key');

// Warning: Changing the authorization header to Bearer token format will break backend compatibility with this microservice.
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)
.post('/api/convert-markdown')
.post('/api/convert')
.set('Origin', origin)
.set('Authorization', 'yprovider-api-key');

expect(response.status).toBe(400);
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)
.post('/api/convert-markdown')
.post('/api/convert')
.set('Origin', origin)
.set('Authorization', 'yprovider-api-key')
.send({
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/servers/y-provider/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 response = await request(app)
.post(routes.CONVERT_MARKDOWN)
.post(routes.CONVERT)
.send({ data: largePayload })
.set('Content-Type', 'application/json');

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 response = await request(app)
.post(routes.CONVERT_MARKDOWN)
.post(routes.CONVERT)
.send({ data: oversizedPayload })
.set('Content-Type', 'application/json');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ErrorResponse {
error: string;
}

export const convertMarkdownHandler = async (
export const convertHandler = async (
req: Request<
object,
ConversionResponse | ErrorResponse,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/servers/y-provider/src/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './collaborationResetConnectionsHandler';
export * from './collaborationWSHandler';
export * from './convertMarkdownHandler';
export * from './convertHandler';
2 changes: 1 addition & 1 deletion src/frontend/servers/y-provider/src/routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const routes = {
COLLABORATION_WS: '/collaboration/ws/',
COLLABORATION_RESET_CONNECTIONS: '/collaboration/api/reset-connections/',
CONVERT_MARKDOWN: '/api/convert-markdown/',
CONVERT: '/api/convert/',
};
8 changes: 4 additions & 4 deletions src/frontend/servers/y-provider/src/servers/appServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PORT } from '../env';
import {
collaborationResetConnectionsHandler,
collaborationWSHandler,
convertMarkdownHandler,
convertHandler,
} from '../handlers';
import { corsMiddleware, httpSecurity, wsSecurity } from '../middlewares';
import { routes } from '../routes';
Expand All @@ -22,7 +22,7 @@ import { logger } from '../utils';
export const initServer = () => {
const { app } = expressWebsockets(express());
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
return express.json({ limit: '500kb' })(req, res, next);
}
Expand All @@ -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);

Expand Down
Loading