mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-22 11:42:19 -05:00
46 lines
1.7 KiB
Ruby
46 lines
1.7 KiB
Ruby
require "thor"
|
|
|
|
module Cli
|
|
class ModelsCommand < Thor
|
|
namespace :models
|
|
DESCRIPTION = "manage models"
|
|
|
|
desc "update_metadata", "reruns the metadata parser for all models"
|
|
option :search, required: false, type: :string
|
|
def update_metadata
|
|
Scan::CheckAllJob.perform_later({q: options[:search].presence}, nil)
|
|
end
|
|
|
|
desc "pregenerate_downloads", "generate downloadable ZIP files for all models"
|
|
option :search, required: false, type: :string
|
|
def pregenerate_downloads
|
|
if !SiteSettings.pregenerate_downloads
|
|
puts "ERROR: Enable proactive ZIP download creation in admin settings."
|
|
return
|
|
end
|
|
scope = Model
|
|
scope = Search::ModelSearchService.new(scope).search(options[:search]) if options[:search]
|
|
scope.find_each do
|
|
it.pregenerate_downloads delay: 5.seconds, queue: :low
|
|
print "."
|
|
sleep 0.01 # Slows down connections a bit so as not to saturate Redis
|
|
end
|
|
puts "\n#{scope.count} models queued for download creation" # rubocop:disable Pundit/UsePolicyScope
|
|
end
|
|
|
|
desc "set_permissions", "set permission preset for all models"
|
|
option :search, required: false, type: :string
|
|
option :preset, required: true, type: :string, enum: %w[private member public]
|
|
def set_permissions
|
|
scope = Model
|
|
scope = Search::ModelSearchService.new(scope).search(options[:search]) if options[:search]
|
|
scope.find_each do
|
|
it.update permission_preset: options[:preset].to_sym
|
|
print "."
|
|
sleep 0.01 # Slows down connections a bit so as not to saturate Redis
|
|
end
|
|
puts "\n#{scope.count} model permissions set to #{options[:preset]}" # rubocop:disable Pundit/UsePolicyScope
|
|
end
|
|
end
|
|
end
|