Skip to content

Commit

Permalink
allow models to be created that only contain images
Browse files Browse the repository at this point in the history
  • Loading branch information
Floppy committed Dec 3, 2021
1 parent b1d725a commit 1856972
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/jobs/library_scan_job.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class LibraryScanJob < ApplicationJob
queue_as :default

def self.model_pattern
lower = Rails.configuration.formats[:models].map(&:downcase)
upper = Rails.configuration.formats[:models].map(&:upcase)
def self.file_pattern
lower = Rails.configuration.formats[:models].map(&:downcase) + Rails.configuration.formats[:images].map(&:downcase)
upper = Rails.configuration.formats[:models].map(&:upcase) + Rails.configuration.formats[:images].map(&:upcase)
"*.{#{lower.zip(upper).flatten.join(",")}}"
end

def perform(library)
# For each directory in the library, create a model
all_3d_files = Dir.glob(File.join(library.path, "**", LibraryScanJob.model_pattern))
all_3d_files = Dir.glob(File.join(library.path, "**", LibraryScanJob.file_pattern))
model_folders = all_3d_files.map { |f| File.dirname(f) }.uniq
model_folders = model_folders.map { |f| f.gsub(/\/files$/, "").gsub(/\/images$/, "") }.uniq # Ignore thingiverse subfolders
model_folders.each do |path|
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/library_scan_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
create(:library, path: File.join(Rails.root, "spec", "fixtures", "library"))
end

it "generates a case-insensitive pattern for model files" do
expect(LibraryScanJob.model_pattern).to eq "*.{stl,STL,obj,OBJ,3mf,3MF,blend,BLEND,mix,MIX,ply,PLY}"
it "generates a case-insensitive pattern for files" do
expect(LibraryScanJob.file_pattern).to eq "*.{stl,STL,obj,OBJ,3mf,3MF,blend,BLEND,mix,MIX,ply,PLY,jpg,JPG,png,PNG}"
end

it "can scan a library directory" do
Expand Down

0 comments on commit 1856972

Please sign in to comment.