mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Merge branch 'main' into assets
This commit is contained in:
@@ -119,6 +119,10 @@ router.get(
|
||||
res.setHeader('Content-Type', file.type);
|
||||
res.removeHeader('Content-Disposition');
|
||||
|
||||
if (req.query.hasOwnProperty('download') === false) {
|
||||
res.removeHeader('Content-Disposition');
|
||||
}
|
||||
|
||||
stream.pipe(res);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -49,7 +49,7 @@ router.get(
|
||||
router.get(
|
||||
'/me',
|
||||
asyncHandler(async (req, res, next) => {
|
||||
if (!req.accountability?.user || !req.accountability?.role) {
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
|
||||
|
||||
@@ -58,11 +58,21 @@ router.get(
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
|
||||
const item = await service.readByKey(req.accountability.user, req.sanitizedQuery);
|
||||
try {
|
||||
const item = await service.readByKey(req.accountability.user, req.sanitizedQuery);
|
||||
res.locals.payload = { data: item || null };
|
||||
} catch (error) {
|
||||
if (error instanceof ForbiddenException) {
|
||||
res.locals.payload = { data: { id: req.accountability.user } };
|
||||
return next();
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
res.locals.payload = { data: item || null };
|
||||
return next();
|
||||
}),
|
||||
respond
|
||||
|
||||
@@ -101,7 +101,7 @@ fields:
|
||||
display: user
|
||||
- collection: directus_files
|
||||
field: modified_on
|
||||
interface: dateTime
|
||||
interface: datetime
|
||||
locked: true
|
||||
special: date-updated
|
||||
width: half
|
||||
@@ -111,4 +111,4 @@ fields:
|
||||
display: datetime
|
||||
- collection: directus_files
|
||||
field: created_by
|
||||
display: user
|
||||
display: user
|
||||
|
||||
@@ -7,7 +7,10 @@ export function parseFilter(filter: Filter, accountability: Accountability | nul
|
||||
if (val === 'true') return true;
|
||||
if (val === 'false') return false;
|
||||
|
||||
if (key === '_in' || key === '_nin') return toArray(val);
|
||||
if (key === '_in' || key === '_nin') {
|
||||
if (typeof val === 'string' && val.includes(',')) return val.split(',');
|
||||
else return toArray(val);
|
||||
}
|
||||
|
||||
if (val === '$NOW') return new Date();
|
||||
if (val === '$CURRENT_USER') return accountability?.user || null;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Accountability, Query, Sort, Filter, Meta } from '../types';
|
||||
import logger from '../logger';
|
||||
import { parseFilter } from '../utils/parse-filter';
|
||||
import { flatten } from 'lodash';
|
||||
|
||||
export function sanitizeQuery(
|
||||
rawQuery: Record<string, any>,
|
||||
@@ -75,6 +76,9 @@ function sanitizeFields(rawFields: any) {
|
||||
if (typeof rawFields === 'string') fields = rawFields.split(',');
|
||||
else if (Array.isArray(rawFields)) fields = rawFields as string[];
|
||||
|
||||
// Case where array item includes CSV (fe fields[]=id,name):
|
||||
fields = flatten(fields.map((field) => (field.includes(',') ? field.split(',') : field)));
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user