Files
speckle-server/packages/server/modules/workspaces/helpers/images.ts
T
Chuck Driesler ac6dd70d27 feat(workspaces): default workspace project role (#3013)
* feat(workspaces): enable default project role in workspace

* fix(workspaces): not satisfying

* chore(workspaces): phrasing

* fix(workspaces): use new field in role mapping

* chore(workspaces): use roles

* fix(workspaces): update tests

* fix(workspaces): more parallel role update errors

* chore(workspaces): like this now

* chore(workspaces): revert changes to deps

* fix(workspaces): assert domain type conversion at gql layer

* fix(workspaces): repair tests

* fix(workspaces): fix more tests
2024-09-17 22:17:10 +02:00

21 lines
776 B
TypeScript

import { WorkspaceInvalidUpdateError } from '@/modules/workspaces/errors/workspace'
export const validateImageString = (imageString: string): void => {
// Validate string is a reasonable size
if (new TextEncoder().encode(imageString).length > 1024 * 1024 * 10) {
throw new WorkspaceInvalidUpdateError('Provided logo must be smaller than 10 MB')
}
// Validate string is base64 image
const [prefix, ...rest] = imageString.split(',')
const imageData = rest.pop()
if (!prefix || !prefix.startsWith('data:image') || !imageData) {
throw new WorkspaceInvalidUpdateError('Provided logo is malformed')
}
if (Buffer.from(imageData, 'base64').toString('base64') !== imageData) {
throw new WorkspaceInvalidUpdateError('Provided logo is malformed')
}
}