mirror of
https://github.com/neocities/neocities.git
synced 2025-08-05 01:01:30 +02:00
New API method: /api/list
This commit is contained in:
parent
6ba8efaa11
commit
bbe57750da
3 changed files with 119 additions and 1 deletions
25
app/api.rb
25
app/api.rb
|
@ -5,6 +5,31 @@ get '/api' do
|
|||
erb :'api'
|
||||
end
|
||||
|
||||
get '/api/list' do
|
||||
require_api_credentials
|
||||
|
||||
files = []
|
||||
|
||||
if params[:path].nil? || params[:path].empty?
|
||||
file_list = current_site.site_files
|
||||
else
|
||||
file_list = current_site.file_list params[:path]
|
||||
end
|
||||
|
||||
file_list.each do |file|
|
||||
new_file = {}
|
||||
new_file[:path] = file[:path]
|
||||
new_file[:is_directory] = file[:is_directory]
|
||||
new_file[:size] = file[:size] unless file[:is_directory]
|
||||
new_file[:updated_at] = file[:updated_at].rfc2822
|
||||
files << new_file
|
||||
end
|
||||
|
||||
files.each {|f| f[:path].sub!(/^\//, '')}
|
||||
|
||||
api_success files: files
|
||||
end
|
||||
|
||||
post '/api/upload' do
|
||||
require_api_credentials
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue