mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
fixes for webdav
This commit is contained in:
parent
a81a708be5
commit
91055a2feb
3 changed files with 45 additions and 58 deletions
2
Gemfile
2
Gemfile
|
@ -16,7 +16,7 @@ gem 'erubi'
|
|||
gem 'stripe' #, source: 'https://code.stripe.com/'
|
||||
gem 'terrapin'
|
||||
gem 'sass', require: nil
|
||||
gem 'dav4rack', git: 'https://github.com/neocities/dav4rack.git', ref: '3ecde122a0b8bcc1d85581dc85ef3a7120b6a8f0'
|
||||
gem 'dav4rack', git: 'https://github.com/neocities/dav4rack.git', ref: '1bf1975c613d4f14d00f1e70ce7e0bb9e2e6cd9b'
|
||||
gem 'filesize'
|
||||
gem 'thread'
|
||||
gem 'rack-cache'
|
||||
|
|
15
Gemfile.lock
15
Gemfile.lock
|
@ -1,14 +1,13 @@
|
|||
GIT
|
||||
remote: https://github.com/neocities/dav4rack.git
|
||||
revision: 3ecde122a0b8bcc1d85581dc85ef3a7120b6a8f0
|
||||
ref: 3ecde122a0b8bcc1d85581dc85ef3a7120b6a8f0
|
||||
revision: 1bf1975c613d4f14d00f1e70ce7e0bb9e2e6cd9b
|
||||
ref: 1bf1975c613d4f14d00f1e70ce7e0bb9e2e6cd9b
|
||||
specs:
|
||||
dav4rack (1.1.0)
|
||||
addressable (>= 2.5.0)
|
||||
nokogiri (>= 1.6.0)
|
||||
ox (>= 2.1.0)
|
||||
rack (>= 1.6)
|
||||
dav4rack (0.3.0)
|
||||
nokogiri (>= 1.4.2)
|
||||
rack (~> 3.0)
|
||||
uuidtools (~> 2.1.1)
|
||||
webrick
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
|
@ -254,8 +253,6 @@ GEM
|
|||
nokogiri (1.18.2-x86_64-linux-musl)
|
||||
racc (~> 1.4)
|
||||
ostruct (0.6.1)
|
||||
ox (2.14.21)
|
||||
bigdecimal (>= 3.0)
|
||||
paypal-recurring (1.1.0)
|
||||
pg (1.5.9)
|
||||
phonelib (0.10.3)
|
||||
|
|
74
config.ru
74
config.ru
|
@ -16,73 +16,63 @@ end
|
|||
|
||||
map '/webdav' do
|
||||
use Rack::Auth::Basic do |username, password|
|
||||
@site = Site.get_site_from_login username, password
|
||||
@site = Site.get_site_from_login(username, password)
|
||||
@site ? true : false
|
||||
end
|
||||
|
||||
run lambda { |env|
|
||||
if env['REQUEST_METHOD'] == 'PUT'
|
||||
request_method = env['REQUEST_METHOD']
|
||||
path = env['PATH_INFO']
|
||||
tmpfile = Tempfile.new 'davfile', encoding: 'binary'
|
||||
tmpfile.write env['rack.input'].read
|
||||
|
||||
case request_method
|
||||
when 'OPTIONS'
|
||||
return [200, {'Allow' => 'OPTIONS, GET, HEAD, PUT, DELETE, PROPFIND, MKCOL, MOVE', 'DAV' => '1,2'}, ['']]
|
||||
|
||||
when 'PUT'
|
||||
tmpfile = Tempfile.new('davfile', encoding: 'binary')
|
||||
tmpfile.write(env['rack.input'].read)
|
||||
tmpfile.close
|
||||
|
||||
if @site.file_size_too_large? tmpfile.size
|
||||
return [507, {}, ['']]
|
||||
end
|
||||
return [507, {}, ['']] if @site.file_size_too_large?(tmpfile.size)
|
||||
|
||||
# if Site.valid_file_type?(filename: path, tempfile: tmpfile)
|
||||
if @site.okay_to_upload? filename: path, tempfile: tmpfile
|
||||
@site.store_files [{filename: path, tempfile: tmpfile}]
|
||||
if @site.okay_to_upload?(filename: path, tempfile: tmpfile)
|
||||
@site.store_files([{ filename: path, tempfile: tmpfile }])
|
||||
return [201, {}, ['']]
|
||||
else
|
||||
return [415, {}, ['']]
|
||||
end
|
||||
end
|
||||
|
||||
if env['REQUEST_METHOD'] == 'MKCOL'
|
||||
@site.create_directory env['PATH_INFO']
|
||||
when 'MKCOL'
|
||||
@site.create_directory(path)
|
||||
return [201, {}, ['']]
|
||||
end
|
||||
|
||||
if env['REQUEST_METHOD'] == 'MOVE'
|
||||
when 'MOVE'
|
||||
destination = env['HTTP_DESTINATION'][/\/webdav(.+)$/i, 1]
|
||||
return [400, {}, ['Bad Request']] unless destination
|
||||
|
||||
destination = env['HTTP_DESTINATION'].match(/^.+\/webdav(.+)$/i).captures.first
|
||||
|
||||
env['PATH_INFO'] = env['PATH_INFO'][1..env['PATH_INFO'].length] if env['PATH_INFO'][0] == '/'
|
||||
|
||||
site_file = @site.site_files.select {|s| s.path == env['PATH_INFO']}.first
|
||||
return [404, {}, ['']] if site_file.nil?
|
||||
res = site_file.rename destination
|
||||
path.sub!(/^\//, '') # Remove leading slash if present
|
||||
site_file = @site.site_files.find { |s| s.path == path }
|
||||
return [404, {}, ['']] unless site_file
|
||||
|
||||
site_file.rename(destination)
|
||||
return [201, {}, ['']]
|
||||
end
|
||||
|
||||
if env['REQUEST_METHOD'] == 'COPY'
|
||||
return [501, {}, ['']]
|
||||
end
|
||||
|
||||
if env['REQUEST_METHOD'] == 'LOCK'
|
||||
return [501, {}, ['']]
|
||||
end
|
||||
|
||||
if env['REQUEST_METHOD'] == 'UNLOCK'
|
||||
return [501, {}, ['']]
|
||||
end
|
||||
|
||||
if env['REQUEST_METHOD'] == 'PROPPATCH'
|
||||
return [501, {}, ['']]
|
||||
end
|
||||
|
||||
if env['REQUEST_METHOD'] == 'DELETE'
|
||||
@site.delete_file env['PATH_INFO']
|
||||
when 'DELETE'
|
||||
@site.delete_file(path)
|
||||
return [201, {}, ['']]
|
||||
|
||||
else
|
||||
unless ['PROPFIND', 'GET', 'HEAD'].include? request_method
|
||||
return [501, {}, ['Not Implemented']]
|
||||
end
|
||||
|
||||
res = DAV4Rack::Handler.new(
|
||||
env['PATH_INFO'] = "/#{@site.scrubbed_path(path)}" unless path.empty?
|
||||
|
||||
DAV4Rack::Handler.new(
|
||||
root: @site.files_path,
|
||||
root_uri_path: '/webdav'
|
||||
).call(env)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue