This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { httpError } from '../../shared/http/httpError.mjs';
|
||||
|
||||
export function parseUploadPayload(payload) {
|
||||
if (typeof payload.dataUrl === 'string') {
|
||||
const match = payload.dataUrl.match(/^data:[^;]+;base64,(.+)$/);
|
||||
|
||||
if (!match) {
|
||||
throw httpError(400, '"dataUrl" must be a base64 data URL');
|
||||
}
|
||||
|
||||
return Buffer.from(match[1], 'base64');
|
||||
}
|
||||
|
||||
if (typeof payload.contentBase64 === 'string') {
|
||||
return Buffer.from(payload.contentBase64, 'base64');
|
||||
}
|
||||
|
||||
throw httpError(400, 'Upload payload must include "dataUrl" or "contentBase64"');
|
||||
}
|
||||
Reference in New Issue
Block a user