mirror of
https://github.com/standardnotes/server
synced 2026-10-16 09:13:26 -04:00
23 lines
663 B
TypeScript
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')}`
|
|
}
|
|
}
|