A custom extension which tracks the aggegated filesize of all uploads by a user and allows to set an project-wide upload limit. Hooks into create and delete actions of directus_files and calculates the upload-size
❗️ This extension is still in beta and not prodution ready ❗️ Due to limitations in upload filters it already can track uploads / deletions but not prevent uploads that do not fit into the limit
- Count number of files per user
- Count aggregated filesizes of all existing files uploaded by a user
- Updates number of files and filesize on file-deletion
- Saves data on a user-level (directus_users >> directus_extension_upload_limiter)
- Limit uploads once a user-limit or a global limit is exceeded (Coming soon!)
Note: This extension works on a user level! If person A uploads a file and person B deletes it, the meta data of person A will be updated
Until directus provides a key-value store for extensions the configurations will be made through the projects environment variables. This might change in a future version!
Variable | example | description |
---|---|---|
DIRECTUS_EXTENSION_UPLOAD_LIMITER_GLOBAL_LIMIT |
100000000000 | Global upload limit for all tracked data in byte. Used to limit the project-wide uploads generated by all users together. |
- Files uploaded by public role (not related to any user) are not tracked
- File-transformations are not included in the data. (limitation of directus)
- File updates are not tracked (limitation of directus)
- Create a folder
directus-extension-upload-limiter
inside your projects extensions-folder- Example:
<your-directus-project>/extensions/hooks/directus-extension-upload-limiter
- See docs: (Deploying your Extension)[https://docs.directus.io/extensions/creating-extensions/#deploying-your-extension]
- Example:
- Build the extension and copy the output from the
dist
directory into the newly created folder - Copy the migrations from
src/_migrations
to your projects migration folder
- Run the migrations (See Docs)[https://docs.directus.io/extensions/migrations/#migrations-and-directus-schema]
- Start the application
- Go to the data-model settings, open the system collection
directus_users
and config the new field (should be recognised, but displayed with a warning: database only-field)- Recommended: set
Readonly
, as users shouldn't be able to update this field manually
- Recommended: set
- Upload a file and track the data inside the user-profile (column:
directus_extension_upload_limiter
)
Can this be used on existing projects?
Right know it won't work on existing projects where already user related files exists.This is based on the fact that we track file creattion and deletion. If there already exists files when the extension is installed and a user deletes a file he would get a negative amount of uploads. We do prevent this, as this wouldn't make any sense.
In a future version a re-calculation of existing files is planned. Once this is available it can be installed on existin projects.
** See issues tab **