mirror of
https://github.com/directus/directus.git
synced 2026-01-28 15:28:24 -05:00
adding to all gets
when fetching add ?TTL=600&dTTL=600 for use the cache
This commit is contained in:
@@ -47,6 +47,7 @@ router.get(
|
||||
'/:collection/:field',
|
||||
validateCollection,
|
||||
useCollection('directus_fields'),
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new FieldsService({ accountability: req.accountability });
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import Busboy from 'busboy';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import FilesService from '../services/files';
|
||||
import MetaService from '../services/meta';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import { File, PrimaryKey } from '../types';
|
||||
import formatTitle from '@directus/format-title';
|
||||
@@ -67,7 +68,11 @@ const multipartHandler = asyncHandler(async (req, res, next) => {
|
||||
storage: payload.storage || disk,
|
||||
};
|
||||
|
||||
const primaryKey = await service.upload(fileStream, payloadWithRequiredFields, existingPrimaryKey);
|
||||
const primaryKey = await service.upload(
|
||||
fileStream,
|
||||
payloadWithRequiredFields,
|
||||
existingPrimaryKey
|
||||
);
|
||||
savedFiles.push(primaryKey);
|
||||
tryDone();
|
||||
});
|
||||
@@ -112,7 +117,7 @@ router.post(
|
||||
);
|
||||
|
||||
const importSchema = Joi.object({
|
||||
url: Joi.string().required()
|
||||
url: Joi.string().required(),
|
||||
});
|
||||
|
||||
router.post(
|
||||
@@ -128,7 +133,7 @@ router.post(
|
||||
const service = new FilesService({ accountability: req.accountability });
|
||||
|
||||
const fileResponse = await axios.get<NodeJS.ReadableStream>(req.body.url, {
|
||||
responseType: 'stream'
|
||||
responseType: 'stream',
|
||||
});
|
||||
|
||||
const parsedURL = url.parse(fileResponse.request.res.responseUrl);
|
||||
@@ -139,7 +144,7 @@ router.post(
|
||||
storage: (env.STORAGE_LOCATIONS as string).split(',')[0].trim(),
|
||||
type: fileResponse.headers['content-type'],
|
||||
title: formatTitle(filename),
|
||||
...req.body
|
||||
...req.body,
|
||||
};
|
||||
|
||||
delete payload.url;
|
||||
@@ -148,11 +153,12 @@ router.post(
|
||||
const record = await service.readByKey(primaryKey, req.sanitizedQuery);
|
||||
return res.json({ data: record || null });
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new FilesService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import FoldersService from '../services/folders';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
@@ -23,6 +24,7 @@ router.post(
|
||||
router.get(
|
||||
'/',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new FoldersService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
@@ -37,6 +39,7 @@ router.get(
|
||||
router.get(
|
||||
'/:pk',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new FoldersService({ accountability: req.accountability });
|
||||
const record = await service.readByKey(req.params.pk, req.sanitizedQuery);
|
||||
|
||||
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import ItemsService from '../services/items';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import collectionExists from '../middleware/collection-exists';
|
||||
import MetaService from '../services/meta';
|
||||
import { RouteNotFoundException } from '../exceptions';
|
||||
@@ -29,6 +30,7 @@ router.get(
|
||||
'/:collection',
|
||||
collectionExists,
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new ItemsService(req.collection, { accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
|
||||
@@ -3,6 +3,7 @@ import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import PermissionsService from '../services/permissions';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import MetaService from '../services/meta';
|
||||
import { InvalidCredentialsException } from '../exceptions';
|
||||
|
||||
@@ -24,6 +25,7 @@ router.post(
|
||||
router.get(
|
||||
'/',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new PermissionsService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
@@ -38,6 +40,7 @@ router.get(
|
||||
router.get(
|
||||
'/me',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
if (!req.accountability?.user || !req.accountability?.role) {
|
||||
throw new InvalidCredentialsException();
|
||||
@@ -49,19 +52,20 @@ router.get(
|
||||
query.filter = {
|
||||
...(query.filter || {}),
|
||||
role: {
|
||||
_eq: req.accountability.role
|
||||
}
|
||||
}
|
||||
_eq: req.accountability.role,
|
||||
},
|
||||
};
|
||||
|
||||
const items = await service.readByQuery(req.sanitizedQuery);
|
||||
|
||||
return res.json({ data: items || null });
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/:pk',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new PermissionsService({ accountability: req.accountability });
|
||||
const record = await service.readByKey(Number(req.params.pk), req.sanitizedQuery);
|
||||
|
||||
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import PresetsService from '../services/presets';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
@@ -23,6 +24,7 @@ router.post(
|
||||
router.get(
|
||||
'/',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new PresetsService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
@@ -37,6 +39,7 @@ router.get(
|
||||
router.get(
|
||||
'/:pk',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new PresetsService({ accountability: req.accountability });
|
||||
const record = await service.readByKey(req.params.pk, req.sanitizedQuery);
|
||||
|
||||
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import RelationsService from '../services/relations';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
@@ -23,6 +24,7 @@ router.post(
|
||||
router.get(
|
||||
'/',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new RelationsService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
@@ -37,6 +39,7 @@ router.get(
|
||||
router.get(
|
||||
'/:pk',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new RelationsService({ accountability: req.accountability });
|
||||
const record = await service.readByKey(req.params.pk, req.sanitizedQuery);
|
||||
|
||||
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import RevisionsService from '../services/revisions';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
@@ -26,6 +27,7 @@ router.get(
|
||||
'/:pk',
|
||||
useCollection('directus_revisions'),
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new RevisionsService({ accountability: req.accountability });
|
||||
const record = await service.readByKey(req.params.pk, req.sanitizedQuery);
|
||||
|
||||
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import RolesService from '../services/roles';
|
||||
import MetaService from '../services/meta';
|
||||
|
||||
@@ -23,6 +24,7 @@ router.post(
|
||||
router.get(
|
||||
'/',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new RolesService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
@@ -37,6 +39,7 @@ router.get(
|
||||
router.get(
|
||||
'/:pk',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new RolesService({ accountability: req.accountability });
|
||||
const record = await service.readByKey(req.params.pk, req.sanitizedQuery);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import express from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import SettingsService from '../services/settings';
|
||||
|
||||
@@ -10,6 +11,7 @@ router.get(
|
||||
'/',
|
||||
useCollection('directus_settings'),
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new SettingsService({ accountability: req.accountability });
|
||||
const records = await service.readSingleton(req.sanitizedQuery);
|
||||
|
||||
@@ -4,6 +4,7 @@ import sanitizeQuery from '../middleware/sanitize-query';
|
||||
import Joi from 'joi';
|
||||
import { InvalidPayloadException, InvalidCredentialsException } from '../exceptions';
|
||||
import useCollection from '../middleware/use-collection';
|
||||
import cacheMiddleware from '../middleware/cache';
|
||||
import UsersService from '../services/users';
|
||||
import MetaService from '../services/meta';
|
||||
import AuthService from '../services/authentication';
|
||||
@@ -26,6 +27,7 @@ router.post(
|
||||
router.get(
|
||||
'/',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
const metaService = new MetaService({ accountability: req.accountability });
|
||||
@@ -40,6 +42,7 @@ router.get(
|
||||
router.get(
|
||||
'/me',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
@@ -55,6 +58,7 @@ router.get(
|
||||
router.get(
|
||||
'/:pk',
|
||||
sanitizeQuery,
|
||||
cacheMiddleware,
|
||||
asyncHandler(async (req, res) => {
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
const items = await service.readByKey(req.params.pk, req.sanitizedQuery);
|
||||
@@ -153,38 +157,44 @@ router.post(
|
||||
})
|
||||
);
|
||||
|
||||
router.post('/me/tfa/enable/', asyncHandler(async (req, res) => {
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
router.post(
|
||||
'/me/tfa/enable/',
|
||||
asyncHandler(async (req, res) => {
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
const url = await service.enableTFA(req.accountability.user);
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
const url = await service.enableTFA(req.accountability.user);
|
||||
|
||||
return res.json({ data: { otpauth_url: url }});
|
||||
}));
|
||||
return res.json({ data: { otpauth_url: url } });
|
||||
})
|
||||
);
|
||||
|
||||
router.post('/me/tfa/disable', asyncHandler(async (req, res) => {
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
router.post(
|
||||
'/me/tfa/disable',
|
||||
asyncHandler(async (req, res) => {
|
||||
if (!req.accountability?.user) {
|
||||
throw new InvalidCredentialsException();
|
||||
}
|
||||
|
||||
if (!req.body.otp) {
|
||||
throw new InvalidPayloadException(`"otp" is required`);
|
||||
}
|
||||
if (!req.body.otp) {
|
||||
throw new InvalidPayloadException(`"otp" is required`);
|
||||
}
|
||||
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
const authService = new AuthService({ accountability: req.accountability });
|
||||
const service = new UsersService({ accountability: req.accountability });
|
||||
const authService = new AuthService({ accountability: req.accountability });
|
||||
|
||||
const otpValid = await authService.verifyOTP(req.accountability.user, req.body.otp);
|
||||
const otpValid = await authService.verifyOTP(req.accountability.user, req.body.otp);
|
||||
|
||||
if (otpValid === false) {
|
||||
throw new InvalidPayloadException(`"otp" is invalid`);
|
||||
}
|
||||
if (otpValid === false) {
|
||||
throw new InvalidPayloadException(`"otp" is invalid`);
|
||||
}
|
||||
|
||||
await service.disableTFA(req.accountability.user);
|
||||
await service.disableTFA(req.accountability.user);
|
||||
|
||||
return res.status(200).end();
|
||||
}));
|
||||
return res.status(200).end();
|
||||
})
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user