Allow requesting files by their original filename

Allows links between files, like texture loading from glTF
This commit is contained in:
James Smith committed 2025-05-14 14:32:28 +01:00
1 parent c33b846237
commit 52776887a7
3 files changed
+25 -1

No files matched your search

+5 -1
View File
@@ -159,7 +159,11 @@ class ModelFilesController < ApplicationController
@file = @model.model_files.find_signed!(params[:id], purpose: "download")
skip_authorization
else
@file = @model.model_files.find_param(params[:id])
begin
@file = @model.model_files.find_param(params[:id])
rescue ActiveRecord::RecordNotFound
@file = @model.model_files.find_by!(filename: [params[:filename], params[:format]].join("."))
end
authorize @file
end
@title = @file.name
+3
View File
@@ -146,4 +146,7 @@ Rails.application.routes.draw do
skip_controllers :applications
end
resources :doorkeeper_applications, path: "/oauth/applications"
# Fallback route for filename matching
get "/models/:model_id/model_files/*filename" => "model_files#show", :as => "model_model_files_by_filename"
end
+17
View File
@@ -177,5 +177,22 @@ RSpec.describe "Model Files" do
expect(response).to redirect_to(model_path(model))
end
end
describe "GET /models/:model_id/model_files/:filename", :as_member do
describe "GET a model file from its filename" do
before do
create(:model_file, model: model, filename: "subfolder/test.stl")
get model_model_files_by_filename_path(model_id: model.to_param, filename: "subfolder/test", format: :stl)
end
it "returns http success" do
expect(response).to have_http_status(:success)
end
it "has correct MIME type" do
expect(response.media_type).to eq("model/stl")
end
end
end
end
end