Files
standardnotes-server/packages/syncing-server/src/Domain/Item/ContentDecoder.ts
T

23 lines
663 B
TypeScript

import { injectable } from 'inversify'
import { ContentDecoderInterface } from './ContentDecoderInterface'
@injectable()
export class ContentDecoder implements ContentDecoderInterface {
decode(content: string): Record<string, unknown> {
try {
const contentBuffer = Buffer.from(content.substring(3), 'base64')
const decodedContent = contentBuffer.toString()
return JSON.parse(decodedContent)
} catch (error) {
return {}
}
}
encode(content: Record<string, unknown>): string | undefined {
const stringifiedContent = JSON.stringify(content)
return `000${Buffer.from(stringifiedContent).toString('base64')}`
}
}