mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
fix walk recursive & field definitions
This commit is contained in:
parent
5c62a23254
commit
4448ecd6fe
@ -9,10 +9,10 @@ function walkRecursive(data, fields, fieldName, callback, _key?) {
|
|||||||
if (!Array.isArray(fields)) {
|
if (!Array.isArray(fields)) {
|
||||||
throw new Error('please provide an fields array for the walkRecursive helper')
|
throw new Error('please provide an fields array for the walkRecursive helper')
|
||||||
}
|
}
|
||||||
if (data && typeof data === 'string' && fields.includes(_key)) {
|
// console.log(_key)
|
||||||
// well we found what we searched for, lets replace the value with our callback result
|
const fieldDef = fields.find((f) => f.field === _key)
|
||||||
const key = _key.split('!')
|
if (data && typeof data === 'string' && fieldDef) {
|
||||||
if (key.length === 1 || key[1] !== fieldName) data = callback(data, key[0])
|
if (!fieldDef.excludes?.includes(fieldName)) data = callback(data, _key)
|
||||||
} else if (data && Array.isArray(data)) {
|
} else if (data && Array.isArray(data)) {
|
||||||
// go into the rabbit hole and dig through that array
|
// go into the rabbit hole and dig through that array
|
||||||
data.forEach((res, index) => {
|
data.forEach((res, index) => {
|
||||||
|
|||||||
@ -3,11 +3,11 @@ import { cleanHtml } from '../middleware/helpers/cleanHtml'
|
|||||||
|
|
||||||
// exclamation mark separetes field names, that should not be sanitized
|
// exclamation mark separetes field names, that should not be sanitized
|
||||||
const fields = [
|
const fields = [
|
||||||
'content!message',
|
{ field: 'content', excludes: ['message'] },
|
||||||
'contentExcerpt',
|
{ field: 'contentExcerpt' },
|
||||||
'reasonDescription',
|
{ field: 'reasonDescription' },
|
||||||
'description!embed',
|
{ field: 'description', excludes: ['embed'] },
|
||||||
'descriptionExcerpt',
|
{ field: 'descriptionExcerpt' },
|
||||||
]
|
]
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user