Really fix the directory listing for a user's root
This commit is contained in:
parent
6430a4b605
commit
2a4d148cbb
@ -85,7 +85,7 @@ module RemoteStorage
|
|||||||
return directory_listing([]).to_json if response.code == 404
|
return directory_listing([]).to_json if response.code == 404
|
||||||
|
|
||||||
if is_root_listing
|
if is_root_listing
|
||||||
get_response = do_get_request("#{container_url_for(user)}/?format=json")
|
get_response = do_get_request("#{container_url_for(user)}/?format=json&path=")
|
||||||
etag = etag_for(get_response.body)
|
etag = etag_for(get_response.body)
|
||||||
else
|
else
|
||||||
get_response = do_get_request("#{container_url_for(user)}/?format=json&path=#{escape(directory)}/")
|
get_response = do_get_request("#{container_url_for(user)}/?format=json&path=#{escape(directory)}/")
|
||||||
@ -99,7 +99,7 @@ module RemoteStorage
|
|||||||
server.headers["ETag"] = %Q("#{etag}")
|
server.headers["ETag"] = %Q("#{etag}")
|
||||||
|
|
||||||
if body = JSON.parse(get_response.body)
|
if body = JSON.parse(get_response.body)
|
||||||
listing = directory_listing(body, is_root_listing)
|
listing = directory_listing(body)
|
||||||
else
|
else
|
||||||
puts "listing not JSON"
|
puts "listing not JSON"
|
||||||
end
|
end
|
||||||
@ -187,7 +187,7 @@ module RemoteStorage
|
|||||||
permission
|
permission
|
||||||
end
|
end
|
||||||
|
|
||||||
def directory_listing(res_body, is_root_listing = false)
|
def directory_listing(res_body)
|
||||||
listing = {
|
listing = {
|
||||||
"@context" => "http://remotestorage.io/spec/folder-description",
|
"@context" => "http://remotestorage.io/spec/folder-description",
|
||||||
"items" => {}
|
"items" => {}
|
||||||
@ -195,14 +195,14 @@ module RemoteStorage
|
|||||||
|
|
||||||
res_body.each do |entry|
|
res_body.each do |entry|
|
||||||
name = entry["name"]
|
name = entry["name"]
|
||||||
name.sub!("#{File.dirname(entry["name"])}/", '') unless is_root_listing
|
name.sub!("#{File.dirname(entry["name"])}/", '')
|
||||||
if name[-1] == "/"
|
if name[-1] == "/" # It's a directory
|
||||||
listing["items"].merge!({
|
listing["items"].merge!({
|
||||||
name => {
|
name => {
|
||||||
"ETag" => entry["hash"],
|
"ETag" => entry["hash"],
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
else
|
else # It's a file
|
||||||
listing["items"].merge!({
|
listing["items"].merge!({
|
||||||
name => {
|
name => {
|
||||||
"ETag" => entry["hash"],
|
"ETag" => entry["hash"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user