33 lines
771 B
TypeScript
33 lines
771 B
TypeScript
|
|
import { readFileSync } from 'node:fs'
|
||
|
|
|
||
|
|
const dataFile = './server/data/resume.json'
|
||
|
|
|
||
|
|
function cleanData(data) {
|
||
|
|
if (Array.isArray(data)) {
|
||
|
|
return data.map(item => cleanItem(item))
|
||
|
|
}
|
||
|
|
return cleanItem(data)
|
||
|
|
}
|
||
|
|
|
||
|
|
function cleanItem(item) {
|
||
|
|
if (item === null || item === undefined) return item
|
||
|
|
if (typeof item !== 'object') return item
|
||
|
|
|
||
|
|
const cleaned = {}
|
||
|
|
for (const [key, value] of Object.entries(item)) {
|
||
|
|
if (key === '_id' && value?.$oid) {
|
||
|
|
cleaned.id = value.$oid
|
||
|
|
} else if (typeof value === 'object') {
|
||
|
|
cleaned[key] = cleanData(value)
|
||
|
|
} else {
|
||
|
|
cleaned[key] = value
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return cleaned
|
||
|
|
}
|
||
|
|
|
||
|
|
export default defineEventHandler(() => {
|
||
|
|
const raw = readFileSync(dataFile, 'utf-8')
|
||
|
|
return cleanData(JSON.parse(raw))
|
||
|
|
})
|