mirror of
https://github.com/directus/directus.git
synced 2026-02-15 05:05:06 -05:00
Run prettier
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
import { RequestHandler } from "express";
|
||||
import asyncHandler from "express-async-handler";
|
||||
import env from "../env";
|
||||
import { getCacheKey } from "../utils/get-cache-key";
|
||||
import { RequestHandler } from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import env from '../env';
|
||||
import { getCacheKey } from '../utils/get-cache-key';
|
||||
import cache from '../cache';
|
||||
import { Transform, transforms } from 'json2csv';
|
||||
import { PassThrough } from 'stream';
|
||||
|
||||
export const respond: RequestHandler = asyncHandler(async (req, res) => {
|
||||
if (req.method.toLowerCase() === 'get' && env.CACHE_ENABLED === true && cache && !req.sanitizedQuery.export) {
|
||||
if (
|
||||
req.method.toLowerCase() === 'get' &&
|
||||
env.CACHE_ENABLED === true &&
|
||||
cache &&
|
||||
!req.sanitizedQuery.export
|
||||
) {
|
||||
const key = getCacheKey(req);
|
||||
await cache.set(key, res.locals.payload);
|
||||
}
|
||||
@@ -34,7 +39,9 @@ export const respond: RequestHandler = asyncHandler(async (req, res) => {
|
||||
res.set('Content-Type', 'text/csv');
|
||||
const stream = new PassThrough();
|
||||
stream.end(Buffer.from(JSON.stringify(res.locals.payload.data), 'utf-8'));
|
||||
const json2csv = new Transform({ transforms: [transforms.flatten({ separator: '.' })] });
|
||||
const json2csv = new Transform({
|
||||
transforms: [transforms.flatten({ separator: '.' })],
|
||||
});
|
||||
return stream.pipe(json2csv).pipe(res);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user