Files
speckle-server/packages/server/modules/comments/services/commentTextService.js
T
Gergő Jedlicska ed458fb619 Add blob storage backend (#802)
* feat(server): add server authz pipeline rework first sketch

* feat(server authz): add new server authz middleware poc implementation

* test(server authz): add unittests for the new server authz workflow

* feat(wip rework of fileuploads vs blob storage): add basim impl of separate blob storage service

* feat(fileimport service): refactored file import service to utilize the new asssetstorage service

* refactor(server errors): refactor server errors to use the shared module definitions

Now all the errors inherit from BaseError

* refactor(fileimport service): cleanup after refactor

* feat(frontend fileimports): use the new blob storage for downloading the original file

* refactor(server fileimports): clean up the remnants of S3 storage from file imports

* refactor(server authz): centralize generic authz pipeline configs

* refactor(server blob storage): refactor / rename everything to use the `blob-storage` name

* ci(circleci): add s3 objectstorage environment variables

* ci(circleci): fix missing env variables

* ci(circleci): add minio test container

* ci(circleci): fix minio app startup

* ci(circleci): enable circleci remote docker

* ci(circleci): fix minio startup

* ci(cirleci): detach and wait properly for minio to start

* ci(circleci): revert to additional minio img config, it only fails when the container is stopped ?!

* ci(circleci): disable file uploads

* fix(fileimports): update with blob storage refactor leftovers

* feat(server blob storage): add blob storage graphql api

* refactor(server errors): merge new errors to shared module

* fix(server comments rte): fix import for RTE error

* chore(fileimports): remove node-fetch from dependency

* chore(server): remove body parser dependency

* fix(server blob storage): fix gql api

* fix(frontend): fix fileupload item not loading the new upload status, cause of premature event fire

* feat(server blob storage): fix file size limit and allow for public streams

* Update packages/server/modules/blobstorage/graph/schemas/blobstorage.graphql

Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>

* chore(blobstorage): fix PR review issues

* fix(server): fix import bugs

Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
2022-06-16 11:31:03 +02:00

53 lines
1.7 KiB
JavaScript

const { RichTextParseError } = require('@/modules/shared/errors')
const {
isTextEditorValueSchema,
isTextEditorDoc,
convertBasicStringToDocument,
isSerializedTextEditorValueSchema
} = require('@/modules/core/services/richTextEditorService')
const { isString } = require('lodash')
const COMMENT_SCHEMA_VERSION = '1.0.0'
const COMMENT_SCHEMA_TYPE = 'stream_comment'
/**
* Build comment.text value from a ProseMirror doc
* @param {import("@tiptap/core").JSONContent} doc
* @returns {import('@/modules/core/services/richTextEditorService').SmartTextEditorValueSchema}
*/
function buildCommentTextFromInput(doc) {
if (!isTextEditorDoc(doc)) {
throw new RichTextParseError('Unexpected comment input doc!')
}
return {
version: COMMENT_SCHEMA_VERSION,
type: COMMENT_SCHEMA_TYPE,
doc
}
}
/**
* Ensure a comment value pulled from db (string or schema JSON) is formatted to be a text editor schema
* @param {string|import('@/modules/core/services/richTextEditorService').SmartTextEditorValueSchema} stringOrSchema
* @returns {import('@/modules/core/services/richTextEditorService').SmartTextEditorValueSchema}
*/
function ensureCommentSchema(stringOrSchema) {
if (isTextEditorValueSchema(stringOrSchema)) return stringOrSchema
if (isString(stringOrSchema)) {
const deserializedSchema = isSerializedTextEditorValueSchema(stringOrSchema)
if (deserializedSchema) return deserializedSchema
// A basic string, convert it to the schema format
const basicTextDoc = convertBasicStringToDocument(stringOrSchema)
return buildCommentTextFromInput(basicTextDoc)
}
throw new RichTextParseError('Unexpected comment schema format')
}
module.exports = {
buildCommentTextFromInput,
ensureCommentSchema
}