diff options
| author | realtradam <[email protected]> | 2024-05-16 22:10:46 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2024-05-16 22:10:46 -0400 |
| commit | 98571b599449bfd7497c9b098a07b376da670319 (patch) | |
| tree | 7fc85863cd7d8406dc0c537dd893111f662d8938 /app/controllers/api | |
| parent | 43237d776e311ebd00b36c0048ec339a4da5b15b (diff) | |
| download | gameHolster-98571b599449bfd7497c9b098a07b376da670319.tar.gz gameHolster-98571b599449bfd7497c9b098a07b376da670319.zip | |
implement uploading and serving web games
Diffstat (limited to 'app/controllers/api')
| -rw-r--r-- | app/controllers/api/v1/games_controller.rb | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/app/controllers/api/v1/games_controller.rb b/app/controllers/api/v1/games_controller.rb index 67bc947..7b033df 100644 --- a/app/controllers/api/v1/games_controller.rb +++ b/app/controllers/api/v1/games_controller.rb @@ -33,12 +33,33 @@ class Api::V1::GamesController < ApplicationController return end - render html: game.game_file.download.html_safe #Game.first.game_file.download.html_safe + filename = params[:file] + if !params[:format].nil? + filename = "#{filename}.#{params[:format]}" + end + + result = game.game_files.blobs.find_by(filename: filename) + + if(result.nil?) + game = Game.all.order(created_at: :desc) + render json: game + return + end + + if params[:format] == "html" + render html: result.download.html_safe + elsif params[:format] == "js" + render js: result.download.html_safe + else + render plain: result.download + end + + #render html: game.game_files.first.download.html_safe #Game.first.game_file.download.html_safe end private def games_params - params.require(:game).permit(:title, :game_file, :titleSlug) + params.require(:game).permit(:title, :titleSlug, game_files: []) end end |
