2025-01-26 00:07:44 +08:00
|
|
|
class SitemapsController < ApplicationController
|
|
|
|
def show
|
|
|
|
path = params[:path]
|
|
|
|
bucket_name =
|
|
|
|
Rails.env.production? ?
|
2025-02-19 11:31:57 +08:00
|
|
|
ENV.fetch("AWS_BUCKET", Rails.application.credentials.dig(:minio, :bucket)) :
|
|
|
|
ENV.fetch("AWS_DEV_BUCKET", Rails.application.credentials.dig(:minio_dev, :bucket))
|
2025-01-26 00:07:44 +08:00
|
|
|
Rails.logger.info "Sitemap: #{path}"
|
|
|
|
|
|
|
|
begin
|
|
|
|
s3_client = Aws::S3::Client.new
|
|
|
|
response = s3_client.get_object(
|
|
|
|
bucket: bucket_name,
|
|
|
|
key: "sitemaps/#{path}"
|
|
|
|
)
|
|
|
|
|
|
|
|
expires_in 12.hours, public: true
|
|
|
|
content_type = response.content_type || "application/xml"
|
|
|
|
|
|
|
|
send_data(
|
|
|
|
response.body.read,
|
|
|
|
filename: path,
|
|
|
|
type: content_type,
|
|
|
|
disposition: "inline"
|
|
|
|
)
|
|
|
|
rescue Aws::S3::Errors::NoSuchKey
|
|
|
|
render status: :not_found
|
|
|
|
rescue Aws::S3::Errors::ServiceError => e
|
|
|
|
Rails.logger.error "S3 Error: #{e.message}"
|
|
|
|
render status: :internal_server_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|