mirror of
https://github.com/neocities/neocities.git
synced 2025-07-19 17:16:05 +02:00
initial dashboard interface, uploading and deleting of files with validations
This commit is contained in:
parent
7dfc2407b9
commit
380a1253cc
16 changed files with 526 additions and 4 deletions
|
@ -1,4 +1,8 @@
|
|||
class Site < Sequel::Model
|
||||
# We might need to include fonts in here..
|
||||
VALID_MIME_TYPES = ['text/plain', 'text/html', 'text/css', 'application/javascript', 'image/png', 'image/jpeg', 'image/gif', 'image/svg+xml']
|
||||
VALID_EXTENSIONS = %w{ html htm txt text css js jpg jpeg png gif svg md markdown }
|
||||
MAX_SPACE = 5242880 # 5MB
|
||||
MINIMUM_PASSWORD_LENGTH = 5
|
||||
USERNAME_REGEX = /[^\w-]/i
|
||||
many_to_one :server
|
||||
|
@ -74,4 +78,18 @@ class Site < Sequel::Model
|
|||
errors.add :password, "Password must be at least #{MINIMUM_PASSWORD_LENGTH} characters."
|
||||
end
|
||||
end
|
||||
|
||||
def file_list
|
||||
Dir.glob(File.join(DIR_ROOT, 'public', 'sites', username, '*')).collect {|p| File.basename(p)}.sort.collect {|sitename| SiteFile.new sitename}
|
||||
end
|
||||
|
||||
def total_space
|
||||
space = Dir.glob(File.join(DIR_ROOT, 'public', 'sites', username, '*')).collect {|p| File.size(p)}.inject {|sum,x| sum += x}
|
||||
space.nil? ? 0 : space
|
||||
end
|
||||
|
||||
def available_space
|
||||
remaining = MAX_SPACE - total_space
|
||||
remaining < 0 ? 0 : remaining
|
||||
end
|
||||
end
|
8
models/site_file.rb
Normal file
8
models/site_file.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class SiteFile
|
||||
attr_reader :filename, :ext
|
||||
|
||||
def initialize(filename)
|
||||
@filename = filename
|
||||
@ext = File.extname(@filename).sub(/^./, '')
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue