|
|
@ -5,18 +5,22 @@ import { |
|
|
|
getViewAndModelFromRequestByAliasOrId |
|
|
|
getViewAndModelFromRequestByAliasOrId |
|
|
|
} from './helpers'; |
|
|
|
} from './helpers'; |
|
|
|
import apiMetrics from '../../helpers/apiMetrics'; |
|
|
|
import apiMetrics from '../../helpers/apiMetrics'; |
|
|
|
|
|
|
|
import View from '../../../models/View'; |
|
|
|
|
|
|
|
|
|
|
|
async function csvDataExport(req: Request, res: Response) { |
|
|
|
async function csvDataExport(req: Request, res: Response) { |
|
|
|
const { view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
|
|
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); |
|
|
|
|
|
|
|
let targetView = view; |
|
|
|
const { offset, elapsed, data } = await extractCsvData(view, req); |
|
|
|
if (!targetView) { |
|
|
|
|
|
|
|
targetView = await View.getDefaultView(model.id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const { offset, elapsed, data } = await extractCsvData(targetView, req); |
|
|
|
|
|
|
|
|
|
|
|
res.set({ |
|
|
|
res.set({ |
|
|
|
'Access-Control-Expose-Headers': 'nc-export-offset', |
|
|
|
'Access-Control-Expose-Headers': 'nc-export-offset', |
|
|
|
'nc-export-offset': offset, |
|
|
|
'nc-export-offset': offset, |
|
|
|
'nc-export-elapsed-time': elapsed, |
|
|
|
'nc-export-elapsed-time': elapsed, |
|
|
|
'Content-Disposition': `attachment; filename="${encodeURI( |
|
|
|
'Content-Disposition': `attachment; filename="${encodeURI( |
|
|
|
view.title |
|
|
|
targetView.title |
|
|
|
)}-export.csv"` |
|
|
|
)}-export.csv"` |
|
|
|
}); |
|
|
|
}); |
|
|
|
res.send(data); |
|
|
|
res.send(data); |
|
|
|