add defined file and path length limits

This commit is contained in:
Kyle Drake 2024-01-15 08:59:57 -06:00
parent 1870286f2a
commit a1cb3c6a11
3 changed files with 43 additions and 1 deletions

View file

@ -5,10 +5,22 @@ require 'sanitize'
class SiteFile < Sequel::Model
CLASSIFIER_LIMIT = 1_000_000
CLASSIFIER_WORD_LIMIT = 25
FILE_PATH_CHARACTER_LIMIT = 300
FILE_NAME_CHARACTER_LIMIT = 100
unrestrict_primary_key
plugin :update_primary_key
many_to_one :site
def self.path_too_long?(filename)
return true if filename.length > FILE_PATH_CHARACTER_LIMIT
false
end
def self.name_too_long?(filename)
return true if filename.length > FILE_NAME_CHARACTER_LIMIT
false
end
def before_destroy
if is_directory
site.site_files_dataset.where(path: /^#{Regexp.quote path}\//, is_directory: true).all.each do |site_file|