- update, files and the 6 /api catalog controllers now live in the engine on a new WarpEngine::ApiController base (same rescue/mime behavior as host) - engine routes serve /update, /file/*path, /api/software*, /api/builds*, /api/image/:id, /api/download at unchanged public paths via the root mount; host routes keep only TTG endpoints (events, members, wiki, rss, swagger) - /update secret comes from WarpEngine.config.update_secret and an unconfigured secret now rejects every request (previously an empty UPDATE_SECRET env accepted empty secrets) - apipie-rails is an engine dependency (DSL in engine controllers); dummy app configures apipie with validation off, mirroring the host - engine request specs: catalog controller specs moved from host plus new /update auth contract spec Verified: engine suite 53 green, host suite 6 green, /api/software and /api/builds byte-identical to baselines, /update 401/400 behavior intact, admin and TTG endpoints OK. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
32 lines
957 B
Ruby
32 lines
957 B
Ruby
module WarpEngine
|
|
class Api::DownloadsController < ApiController
|
|
resource_description do
|
|
short "File downloads"
|
|
formats [ "binary" ]
|
|
end
|
|
|
|
api :GET, "/api/download", "Download a file by path"
|
|
param :path, String, required: true, desc: "File path to download"
|
|
returns code: 200, desc: "File binary data"
|
|
error code: 400, desc: "Path is blank"
|
|
error code: 404, desc: "File not found"
|
|
def show
|
|
path = params[:path]
|
|
return render(json: { error: "Path is required" }, status: :bad_request) if path.blank?
|
|
|
|
full_path = WarpEngine::DownloadService.new.create(
|
|
path: path,
|
|
ip: request.remote_ip,
|
|
user_agent: request.user_agent,
|
|
referer: request.referer
|
|
)
|
|
|
|
if full_path
|
|
send_file full_path, disposition: "attachment", type: resolve_mime(full_path)
|
|
else
|
|
render json: { error: "Not found" }, status: :not_found
|
|
end
|
|
end
|
|
end
|
|
end
|