2022-07-20 00:33:06 +00:00
|
|
|
|
|
|
|
export function encode(buffer) {
|
|
|
|
return buffer
|
|
|
|
.toString('base64')
|
|
|
|
.replace(/\+/g, '-') // Convert '+' to '-'
|
|
|
|
.replace(/\//g, '_') // Convert '/' to '_'
|
|
|
|
.replace(/=+$/, '') // Remove ending '='
|
|
|
|
}
|
|
|
|
|
|
|
|
export function decode(base64StringUrlSafe) {
|
|
|
|
let base64String = base64StringUrlSafe.replace(/-/g, '+').replace(/_/g, '/')
|
|
|
|
switch (base64String.length % 4) {
|
|
|
|
case 2:
|
|
|
|
base64String += '=='
|
|
|
|
break
|
|
|
|
case 3:
|
|
|
|
base64String += '='
|
|
|
|
break
|
|
|
|
}
|
|
|
|
return Buffer.from(base64String, 'base64')
|
|
|
|
}
|
2022-08-02 12:34:52 +00:00
|
|
|
|
|
|
|
export function parseMediaAndBanner(item) {
|
|
|
|
if (item.banner_path) {
|
|
|
|
item.banner_path = 'https://cdn.nfp.is' + item.banner_path
|
2023-11-30 04:13:08 +00:00
|
|
|
item.banner_alt_prefix = 'https://cdn.nfp.is' + (item.banner_alt_prefix || '')
|
2022-08-02 12:34:52 +00:00
|
|
|
}
|
|
|
|
if (item.media_path) {
|
|
|
|
item.media_path = 'https://cdn.nfp.is' + item.media_path
|
2023-11-30 04:13:08 +00:00
|
|
|
item.media_alt_prefix = 'https://cdn.nfp.is' + (item.media_alt_prefix || '')
|
2022-08-02 12:34:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function contentToBlocks(content) {
|
|
|
|
if (!content) return content
|
|
|
|
|
|
|
|
if (content[0] === '{') {
|
|
|
|
try {
|
|
|
|
return JSON.parse(content)
|
|
|
|
} catch (err) {
|
|
|
|
return {
|
|
|
|
time: new Date().getTime(),
|
|
|
|
blocks: [
|
|
|
|
{id: '1', type: 'paragraph', data: { text: 'Error parsing content: ' + err.message }},
|
|
|
|
],
|
|
|
|
version: '2.25.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
time: new Date().getTime(),
|
|
|
|
blocks: [
|
|
|
|
{id: '1', type: 'htmlraw', data: { html: content }},
|
|
|
|
],
|
|
|
|
version: '2.25.0'
|
|
|
|
}
|
|
|
|
}
|