mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
implement WebDAV mount support
This commit is contained in:
parent
b2906808d1
commit
7520bc70b8
5 changed files with 67 additions and 4 deletions
1
Gemfile
1
Gemfile
|
@ -21,6 +21,7 @@ gem 'cocaine'
|
||||||
gem 'zipruby'
|
gem 'zipruby'
|
||||||
gem 'always_verify_ssl_certificates'
|
gem 'always_verify_ssl_certificates'
|
||||||
gem 'sass', require: nil
|
gem 'sass', require: nil
|
||||||
|
gem 'dav4rack'
|
||||||
|
|
||||||
platform :mri do
|
platform :mri do
|
||||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||||
|
|
|
@ -43,16 +43,20 @@ GEM
|
||||||
cocaine (0.5.4)
|
cocaine (0.5.4)
|
||||||
climate_control (>= 0.0.3, < 1.0)
|
climate_control (>= 0.0.3, < 1.0)
|
||||||
coderay (1.1.0)
|
coderay (1.1.0)
|
||||||
columnize (0.3.6)
|
columnize (0.8.9)
|
||||||
connection_pool (2.0.0)
|
connection_pool (2.0.0)
|
||||||
crack (0.4.2)
|
crack (0.4.2)
|
||||||
safe_yaml (~> 1.0.0)
|
safe_yaml (~> 1.0.0)
|
||||||
|
dav4rack (0.3.0)
|
||||||
|
nokogiri (>= 1.4.2)
|
||||||
|
rack (>= 1.1.0)
|
||||||
|
uuidtools (~> 2.1.1)
|
||||||
debugger (1.6.6)
|
debugger (1.6.6)
|
||||||
columnize (>= 0.3.1)
|
columnize (>= 0.3.1)
|
||||||
debugger-linecache (~> 1.2.0)
|
debugger-linecache (~> 1.2.0)
|
||||||
debugger-ruby_core_source (~> 1.3.2)
|
debugger-ruby_core_source (~> 1.3.2)
|
||||||
debugger-linecache (1.2.0)
|
debugger-linecache (1.2.0)
|
||||||
debugger-ruby_core_source (1.3.2)
|
debugger-ruby_core_source (1.3.5)
|
||||||
docile (1.1.3)
|
docile (1.1.3)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
extlib (0.9.16)
|
extlib (0.9.16)
|
||||||
|
@ -211,6 +215,7 @@ DEPENDENCIES
|
||||||
bcrypt
|
bcrypt
|
||||||
capybara_minitest_spec
|
capybara_minitest_spec
|
||||||
cocaine
|
cocaine
|
||||||
|
dav4rack
|
||||||
erubis
|
erubis
|
||||||
fabrication
|
fabrication
|
||||||
faker
|
faker
|
||||||
|
|
1
app.rb
1
app.rb
|
@ -692,7 +692,6 @@ post '/site_files/upload' do
|
||||||
params[:files].each do |file|
|
params[:files].each do |file|
|
||||||
results << current_site.store_file(file[:filename], file[:tempfile])
|
results << current_site.store_file(file[:filename], file[:tempfile])
|
||||||
end
|
end
|
||||||
|
|
||||||
current_site.increment_changed_count if results.include?(true)
|
current_site.increment_changed_count if results.include?(true)
|
||||||
|
|
||||||
file_upload_response
|
file_upload_response
|
||||||
|
|
58
config.ru
58
config.ru
|
@ -1,8 +1,64 @@
|
||||||
|
require 'rubygems'
|
||||||
require './app.rb'
|
require './app.rb'
|
||||||
require 'sidekiq/web'
|
require 'sidekiq/web'
|
||||||
|
|
||||||
map('/') { run Sinatra::Application }
|
map('/') { run Sinatra::Application }
|
||||||
|
|
||||||
|
map '/webdav' do
|
||||||
|
|
||||||
|
use Rack::Auth::Basic do |username, password|
|
||||||
|
Site.valid_login? username, password
|
||||||
|
end
|
||||||
|
|
||||||
|
run lambda {|env|
|
||||||
|
site = Site[username: env['REMOTE_USER']]
|
||||||
|
|
||||||
|
if env['REQUEST_METHOD'] == 'PUT'
|
||||||
|
path = env['PATH_INFO']
|
||||||
|
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
|
||||||
|
|
||||||
|
if Site.valid_file_type?(filename: path, tempfile: tmpfile)
|
||||||
|
site.store_file path, tmpfile
|
||||||
|
return [201, {}, ['']]
|
||||||
|
else
|
||||||
|
return [415, {}, ['']]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if env['REQUEST_METHOD'] == 'MOVE'
|
||||||
|
tmpfile = Tempfile.new 'moved_file'
|
||||||
|
tmpfile.close
|
||||||
|
|
||||||
|
destination = env['HTTP_DESTINATION'].match(/^.+\/webdav(.+)$/i).captures.first
|
||||||
|
|
||||||
|
FileUtils.cp site.files_path(env['PATH_INFO']), tmpfile.path
|
||||||
|
|
||||||
|
DB.transaction do
|
||||||
|
site.store_file destination, tmpfile
|
||||||
|
site.delete_file env['PATH_INFO']
|
||||||
|
end
|
||||||
|
|
||||||
|
return [201, {}, ['']]
|
||||||
|
end
|
||||||
|
|
||||||
|
if env['REQUEST_METHOD'] == 'DELETE'
|
||||||
|
site.delete_file env['PATH_INFO']
|
||||||
|
return [201, {}, ['']]
|
||||||
|
end
|
||||||
|
|
||||||
|
res = DAV4Rack::Handler.new(
|
||||||
|
root: Site.select(:username).where(username: env['REMOTE_USER']).first.files_path,
|
||||||
|
root_uri_path: '/webdav'
|
||||||
|
).call(env)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
map '/sidekiq' do
|
map '/sidekiq' do
|
||||||
use Rack::Auth::Basic, "Protected Area" do |username, password|
|
use Rack::Auth::Basic, "Protected Area" do |username, password|
|
||||||
raise 'missing sidekiq auth' unless $config['sidekiq_user'] && $config['sidekiq_pass']
|
raise 'missing sidekiq auth' unless $config['sidekiq_user'] && $config['sidekiq_pass']
|
||||||
|
@ -10,4 +66,4 @@ map '/sidekiq' do
|
||||||
end
|
end
|
||||||
|
|
||||||
run Sidekiq::Web
|
run Sidekiq::Web
|
||||||
end
|
end
|
|
@ -439,6 +439,8 @@ class Site < Sequel::Model
|
||||||
screenshots_delete(path) if ext.match HTML_REGEX
|
screenshots_delete(path) if ext.match HTML_REGEX
|
||||||
thumbnails_delete(path) if ext.match IMAGE_REGEX
|
thumbnails_delete(path) if ext.match IMAGE_REGEX
|
||||||
|
|
||||||
|
path = path[1..path.length] if path[0] == '/'
|
||||||
|
|
||||||
SiteChangeFile.filter(site_id: self.id, filename: path).delete
|
SiteChangeFile.filter(site_id: self.id, filename: path).delete
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
Loading…
Add table
Reference in a new issue