mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +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 'stripe' #, source: 'https://code.stripe.com/'
|
||||||
gem 'terrapin'
|
gem 'terrapin'
|
||||||
gem 'sass', require: nil
|
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 'filesize'
|
||||||
gem 'thread'
|
gem 'thread'
|
||||||
gem 'rack-cache'
|
gem 'rack-cache'
|
||||||
|
|
15
Gemfile.lock
15
Gemfile.lock
|
@ -1,14 +1,13 @@
|
||||||
GIT
|
GIT
|
||||||
remote: https://github.com/neocities/dav4rack.git
|
remote: https://github.com/neocities/dav4rack.git
|
||||||
revision: 3ecde122a0b8bcc1d85581dc85ef3a7120b6a8f0
|
revision: 1bf1975c613d4f14d00f1e70ce7e0bb9e2e6cd9b
|
||||||
ref: 3ecde122a0b8bcc1d85581dc85ef3a7120b6a8f0
|
ref: 1bf1975c613d4f14d00f1e70ce7e0bb9e2e6cd9b
|
||||||
specs:
|
specs:
|
||||||
dav4rack (1.1.0)
|
dav4rack (0.3.0)
|
||||||
addressable (>= 2.5.0)
|
nokogiri (>= 1.4.2)
|
||||||
nokogiri (>= 1.6.0)
|
rack (~> 3.0)
|
||||||
ox (>= 2.1.0)
|
|
||||||
rack (>= 1.6)
|
|
||||||
uuidtools (~> 2.1.1)
|
uuidtools (~> 2.1.1)
|
||||||
|
webrick
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
|
@ -254,8 +253,6 @@ GEM
|
||||||
nokogiri (1.18.2-x86_64-linux-musl)
|
nokogiri (1.18.2-x86_64-linux-musl)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
ostruct (0.6.1)
|
ostruct (0.6.1)
|
||||||
ox (2.14.21)
|
|
||||||
bigdecimal (>= 3.0)
|
|
||||||
paypal-recurring (1.1.0)
|
paypal-recurring (1.1.0)
|
||||||
pg (1.5.9)
|
pg (1.5.9)
|
||||||
phonelib (0.10.3)
|
phonelib (0.10.3)
|
||||||
|
|
74
config.ru
74
config.ru
|
@ -16,73 +16,63 @@ end
|
||||||
|
|
||||||
map '/webdav' do
|
map '/webdav' do
|
||||||
use Rack::Auth::Basic do |username, password|
|
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
|
@site ? true : false
|
||||||
end
|
end
|
||||||
|
|
||||||
run lambda { |env|
|
run lambda { |env|
|
||||||
if env['REQUEST_METHOD'] == 'PUT'
|
request_method = env['REQUEST_METHOD']
|
||||||
path = env['PATH_INFO']
|
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
|
tmpfile.close
|
||||||
|
|
||||||
if @site.file_size_too_large? tmpfile.size
|
return [507, {}, ['']] if @site.file_size_too_large?(tmpfile.size)
|
||||||
return [507, {}, ['']]
|
|
||||||
end
|
|
||||||
|
|
||||||
# if Site.valid_file_type?(filename: path, tempfile: tmpfile)
|
if @site.okay_to_upload?(filename: path, tempfile: tmpfile)
|
||||||
if @site.okay_to_upload? filename: path, tempfile: tmpfile
|
@site.store_files([{ filename: path, tempfile: tmpfile }])
|
||||||
@site.store_files [{filename: path, tempfile: tmpfile}]
|
|
||||||
return [201, {}, ['']]
|
return [201, {}, ['']]
|
||||||
else
|
else
|
||||||
return [415, {}, ['']]
|
return [415, {}, ['']]
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if env['REQUEST_METHOD'] == 'MKCOL'
|
when 'MKCOL'
|
||||||
@site.create_directory env['PATH_INFO']
|
@site.create_directory(path)
|
||||||
return [201, {}, ['']]
|
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
|
path.sub!(/^\//, '') # Remove leading slash if present
|
||||||
|
site_file = @site.site_files.find { |s| s.path == path }
|
||||||
env['PATH_INFO'] = env['PATH_INFO'][1..env['PATH_INFO'].length] if env['PATH_INFO'][0] == '/'
|
return [404, {}, ['']] unless site_file
|
||||||
|
|
||||||
site_file = @site.site_files.select {|s| s.path == env['PATH_INFO']}.first
|
|
||||||
return [404, {}, ['']] if site_file.nil?
|
|
||||||
res = site_file.rename destination
|
|
||||||
|
|
||||||
|
site_file.rename(destination)
|
||||||
return [201, {}, ['']]
|
return [201, {}, ['']]
|
||||||
end
|
|
||||||
|
|
||||||
if env['REQUEST_METHOD'] == 'COPY'
|
when 'DELETE'
|
||||||
return [501, {}, ['']]
|
@site.delete_file(path)
|
||||||
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']
|
|
||||||
return [201, {}, ['']]
|
return [201, {}, ['']]
|
||||||
|
|
||||||
|
else
|
||||||
|
unless ['PROPFIND', 'GET', 'HEAD'].include? request_method
|
||||||
|
return [501, {}, ['Not Implemented']]
|
||||||
end
|
end
|
||||||
|
|
||||||
res = DAV4Rack::Handler.new(
|
env['PATH_INFO'] = "/#{@site.scrubbed_path(path)}" unless path.empty?
|
||||||
|
|
||||||
|
DAV4Rack::Handler.new(
|
||||||
root: @site.files_path,
|
root: @site.files_path,
|
||||||
root_uri_path: '/webdav'
|
root_uri_path: '/webdav'
|
||||||
).call(env)
|
).call(env)
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue