mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
80 lines
2 KiB
Ruby
80 lines
2 KiB
Ruby
require 'rubygems'
|
|
require './app.rb'
|
|
require 'sidekiq/web'
|
|
|
|
map('/') do
|
|
use(Rack::Cache,
|
|
verbose: false,
|
|
metastore: 'file:/tmp/neocitiesrackcache/meta',
|
|
entitystore: 'file:/tmp/neocitiesrackcache/body'
|
|
)
|
|
run Sinatra::Application
|
|
end
|
|
|
|
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_files [{filename: path, tempfile: tmpfile}]
|
|
return [201, {}, ['']]
|
|
else
|
|
return [415, {}, ['']]
|
|
end
|
|
end
|
|
|
|
if env['REQUEST_METHOD'] == 'MKCOL'
|
|
site.create_directory env['PATH_INFO']
|
|
return [201, {}, ['']]
|
|
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_files [{filename: destination, tempfile: 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
|
|
use Rack::Auth::Basic, "Protected Area" do |username, password|
|
|
raise 'missing sidekiq auth' unless $config['sidekiq_user'] && $config['sidekiq_pass']
|
|
username == $config['sidekiq_user'] && password == $config['sidekiq_pass']
|
|
end
|
|
|
|
run Sidekiq::Web
|
|
end
|