From 185697248a864607774eb4063663c9e50d806a83 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 3 Dec 2021 22:36:21 +0000 Subject: [PATCH] allow models to be created that only contain images --- app/jobs/library_scan_job.rb | 8 ++++---- spec/jobs/library_scan_job_spec.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/jobs/library_scan_job.rb b/app/jobs/library_scan_job.rb index b45577522..10dc8f2c4 100644 --- a/app/jobs/library_scan_job.rb +++ b/app/jobs/library_scan_job.rb @@ -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| diff --git a/spec/jobs/library_scan_job_spec.rb b/spec/jobs/library_scan_job_spec.rb index b3982c748..24d66f5c5 100644 --- a/spec/jobs/library_scan_job_spec.rb +++ b/spec/jobs/library_scan_job_spec.rb @@ -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