Refactor file handling to prioritize internal data directories for backups and uploads; enhance error handling and logging for metadata and CSV operations.
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 47s
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 47s
This commit is contained in:
@@ -4,13 +4,20 @@ import path from 'path'
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const cwd = process.cwd()
|
||||
|
||||
// In production (.output/server), working dir is .output
|
||||
|
||||
// Prefer internal server/data, fallback to public/data
|
||||
let csvPath
|
||||
if (cwd.endsWith('.output')) {
|
||||
csvPath = path.join(cwd, '../public/data/termine.csv')
|
||||
csvPath = path.join(cwd, '../server/data/termine.csv')
|
||||
// fallback
|
||||
if (!(await fs.access(csvPath).then(()=>true).catch(()=>false))) {
|
||||
csvPath = path.join(cwd, '../public/data/termine.csv')
|
||||
}
|
||||
} else {
|
||||
csvPath = path.join(cwd, 'public/data/termine.csv')
|
||||
csvPath = path.join(cwd, 'server/data/termine.csv')
|
||||
if (!(await fs.access(csvPath).then(()=>true).catch(()=>false))) {
|
||||
csvPath = path.join(cwd, 'public/data/termine.csv')
|
||||
}
|
||||
}
|
||||
|
||||
const csv = await fs.readFile(csvPath, 'utf-8')
|
||||
|
||||
Reference in New Issue
Block a user