mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-22 19:52:18 -05:00
Allow requesting files by their original filename
Allows links between files, like texture loading from glTF
This commit is contained in:
3 files changed
+25
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in new issue
Block a user