Created
August 22, 2024 07:29
-
-
Save joselcvarela/9d585fc4af56d9b1ba7ec339968e2821 to your computer and use it in GitHub Desktop.
Clear cache on a Directus custom extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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