Skip to content

utomic-media/directus-extension-upload-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Directus extension: Upload Limiter & User-files calculator

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

The tracked data by the extension

Functions

  • 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

Configuration

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.

Limitations

  • 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)

Installation

Copy files

  • Create a folder directus-extension-upload-limiter inside your projects extensions-folder
  • 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

Init

Test

  • Upload a file and track the data inside the user-profile (column: directus_extension_upload_limiter)

FAQ

Can this be used on existing projects? Right know it won't work on existing projects where already user related files exists.

Background

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.

ToDos

** See issues tab **

Releases

No releases published

Packages

No packages published