Skip to content

Instantly share code, notes, and snippets.

@joselcvarela
Created August 22, 2024 07:29
Show Gist options
  • Save joselcvarela/9d585fc4af56d9b1ba7ec339968e2821 to your computer and use it in GitHub Desktop.
Save joselcvarela/9d585fc4af56d9b1ba7ec339968e2821 to your computer and use it in GitHub Desktop.
Clear cache on a Directus custom extension
import type { Accountability } from '@directus/types';
export default defineEndpoint((router, context) => {
const { services, getSchema } = context;
const { UtilsService } = services;
router.get('/', async (req, res) => {
const utilsService = new UtilsService({
schema: await getSchema(),
accountability: createDefaultAccountability({admin: true})
});
await utilsService.clearCache({ system: false });
});
});
function createDefaultAccountability(overrides?: Partial<Accountability>): Accountability {
return {
role: null,
user: null,
roles: [],
admin: false,
app: false,
ip: null,
...overrides,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment