mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-09 15:57:05 +02:00
22 lines
657 B
Ruby
22 lines
657 B
Ruby
class ApiController < ApplicationController
|
|
def tree
|
|
render json: Treeview.tree(params[:path])
|
|
end
|
|
|
|
def file_preview
|
|
return empty_json unless params[:file]
|
|
return empty_json unless File.exists? params[:file]
|
|
file = params[:file]
|
|
sample = File.read(file, 1024) || ""
|
|
sample2 = sample.force_encoding('ascii-8bit').encode('us-ascii', :undef => :replace, :invalid => :replace, :replace => "")
|
|
return empty_json if sample != sample2 # maybe binary file
|
|
|
|
reader = FileReverseReader.new(File.open(file))
|
|
render json: reader.enum_for(:each_line).to_a.first(10).reverse
|
|
end
|
|
|
|
def empty_json
|
|
render json: []
|
|
end
|
|
end
|