From c78dc87575effba1852493ada852777aac939e2b Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Wed, 29 Oct 2025 17:57:16 +0100 Subject: [PATCH] simplify hooks (wip) --- manyfold/cli/manyfold.sh | 16 +-- .../root/hook.d/daily/cleanup_taskspooler.sh | 3 + .../hook.d/datapackage_CREATE/placeholder.sh | 1 - .../cleanup_package.sh | 3 - .../hook.d/datapackage_MODIFY/10-reset-log.sh | 6 - .../datapackage_MODIFY/1000-scan-dir.sh | 7 -- manyfold/root/hook.d/datapackage_MOVED_TO | 1 - .../hook.d/experience_updated/10-reset-log.sh | 4 + .../experience_updated/1000-scan-dir.sh | 5 + .../300-package_experience_zip.sh | 3 +- .../300-package_godot_zip.sh | 3 +- .../300-package_janusxr.sh | 3 +- .../300-package_xrf.rb | 5 +- .../src/app/config/initializers/xrforge.rb | 28 +++-- .../usr/src/app/config/locales/models/en.yml | 105 ++++++++++++++++++ 15 files changed, 151 insertions(+), 42 deletions(-) create mode 100644 manyfold/root/hook.d/daily/cleanup_taskspooler.sh delete mode 120000 manyfold/root/hook.d/datapackage_CREATE/placeholder.sh delete mode 100644 manyfold/root/hook.d/datapackage_DELETE,ISDIR/cleanup_package.sh delete mode 100755 manyfold/root/hook.d/datapackage_MODIFY/10-reset-log.sh delete mode 100755 manyfold/root/hook.d/datapackage_MODIFY/1000-scan-dir.sh delete mode 120000 manyfold/root/hook.d/datapackage_MOVED_TO create mode 100755 manyfold/root/hook.d/experience_updated/10-reset-log.sh create mode 100755 manyfold/root/hook.d/experience_updated/1000-scan-dir.sh rename manyfold/root/hook.d/{datapackage_MODIFY => experience_updated}/300-package_experience_zip.sh (52%) rename manyfold/root/hook.d/{datapackage_MODIFY => experience_updated}/300-package_godot_zip.sh (78%) rename manyfold/root/hook.d/{datapackage_MODIFY => experience_updated}/300-package_janusxr.sh (85%) rename manyfold/root/hook.d/{datapackage_MODIFY => experience_updated}/300-package_xrf.rb (95%) create mode 100644 manyfold/usr/src/app/config/locales/models/en.yml diff --git a/manyfold/cli/manyfold.sh b/manyfold/cli/manyfold.sh index 573a57e..92db37b 100755 --- a/manyfold/cli/manyfold.sh +++ b/manyfold/cli/manyfold.sh @@ -84,15 +84,15 @@ start_hook_daemon(){ $0 infinite 86400 hook daily & $0 infinite 3600 hook hourly & # trigger hooks when files change in /mnt - find /mnt -type d -mindepth 1 -maxdepth 1 | while read dir; do - echocolor "[$APPNAME]" "listening to inotify events in $dir" - # scan for '/mnt/experiences/creatorname/#234/ MODIFY foo.glb' e.g. - # scan for '/mnt/experiences/creatorname/#234/ MOVED_TO foo.glb' e.g. - inotifywait -r -m $dir | awk '/.*/ { print $0 }; $2 ~ /(CREATE|MODIFY|MOVED_TO|DELETE)/ && $3 ~ /datapackage/ { system("'$0' hook datapackage_"$2" "$1""$3) }' & - done + #find /mnt -type d -mindepth 1 -maxdepth 1 | while read dir; do + # echocolor "[$APPNAME]" "listening to inotify events in $dir" + # # scan for '/mnt/experiences/creatorname/#234/ MODIFY foo.glb' e.g. + # # scan for '/mnt/experiences/creatorname/#234/ MOVED_TO foo.glb' e.g. + # inotifywait -r -m $dir | awk '/.*/ { print $0 }; $2 ~ /(CREATE|MODIFY|MOVED_TO|DELETE)/ && $3 ~ /datapackage/ { system("'$0' hook datapackage_"$2" "$1""$3) }' & + #done - # force-trigger processing hooks in /mnt - find /mnt | grep datapackage | xargs -n1 $0 hook inotify_MODIFY + ## force-trigger processing hooks in /mnt + #find /mnt | grep datapackage | xargs -n1 $0 hook inotify_MODIFY } diff --git a/manyfold/root/hook.d/daily/cleanup_taskspooler.sh b/manyfold/root/hook.d/daily/cleanup_taskspooler.sh new file mode 100644 index 0000000..353d2fa --- /dev/null +++ b/manyfold/root/hook.d/daily/cleanup_taskspooler.sh @@ -0,0 +1,3 @@ +#!/bin/sh +# remove succesful tasks +ts | awk '$4 == 0 { print $1 }' | xargs -n1 ts -r diff --git a/manyfold/root/hook.d/datapackage_CREATE/placeholder.sh b/manyfold/root/hook.d/datapackage_CREATE/placeholder.sh deleted file mode 120000 index d264ad3..0000000 --- a/manyfold/root/hook.d/datapackage_CREATE/placeholder.sh +++ /dev/null @@ -1 +0,0 @@ -../hourly/placeholder.sh \ No newline at end of file diff --git a/manyfold/root/hook.d/datapackage_DELETE,ISDIR/cleanup_package.sh b/manyfold/root/hook.d/datapackage_DELETE,ISDIR/cleanup_package.sh deleted file mode 100644 index 842d5a3..0000000 --- a/manyfold/root/hook.d/datapackage_DELETE,ISDIR/cleanup_package.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -test -f "$1".zip && rm "$1".zip -echo "[cleanup_package.sh] deleting $dir.zip" diff --git a/manyfold/root/hook.d/datapackage_MODIFY/10-reset-log.sh b/manyfold/root/hook.d/datapackage_MODIFY/10-reset-log.sh deleted file mode 100755 index 123f30c..0000000 --- a/manyfold/root/hook.d/datapackage_MODIFY/10-reset-log.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do -dir=$(dirname $1) -cd "$dir" -echo "[v] reset log.txt" -date > log.txt diff --git a/manyfold/root/hook.d/datapackage_MODIFY/1000-scan-dir.sh b/manyfold/root/hook.d/datapackage_MODIFY/1000-scan-dir.sh deleted file mode 100755 index 395ebf4..0000000 --- a/manyfold/root/hook.d/datapackage_MODIFY/1000-scan-dir.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh -echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do -dir=$(dirname $1) -cd "$dir" -echo "[v] scan (new) files of model" -id="$(basename "$dir" | sed 's/\#//g')" -echo "Model.find(id).add_new_files_later()" | /usr/src/app/bin/rails console diff --git a/manyfold/root/hook.d/datapackage_MOVED_TO b/manyfold/root/hook.d/datapackage_MOVED_TO deleted file mode 120000 index 1d1fb66..0000000 --- a/manyfold/root/hook.d/datapackage_MOVED_TO +++ /dev/null @@ -1 +0,0 @@ -datapackage_MODIFY \ No newline at end of file diff --git a/manyfold/root/hook.d/experience_updated/10-reset-log.sh b/manyfold/root/hook.d/experience_updated/10-reset-log.sh new file mode 100755 index 0000000..f55cbcb --- /dev/null +++ b/manyfold/root/hook.d/experience_updated/10-reset-log.sh @@ -0,0 +1,4 @@ +#!/bin/sh +cd "$1" +echo "[v] reset log.txt" +date > log.txt diff --git a/manyfold/root/hook.d/experience_updated/1000-scan-dir.sh b/manyfold/root/hook.d/experience_updated/1000-scan-dir.sh new file mode 100755 index 0000000..67c9f79 --- /dev/null +++ b/manyfold/root/hook.d/experience_updated/1000-scan-dir.sh @@ -0,0 +1,5 @@ +#!/bin/sh +cd "$1" +echo "[v] scan (new) files of model" +id="$(basename "$dir" | sed 's/\#//g')" +#echo "Model.find(id).add_new_files_later()" | /usr/src/app/bin/rails console diff --git a/manyfold/root/hook.d/datapackage_MODIFY/300-package_experience_zip.sh b/manyfold/root/hook.d/experience_updated/300-package_experience_zip.sh similarity index 52% rename from manyfold/root/hook.d/datapackage_MODIFY/300-package_experience_zip.sh rename to manyfold/root/hook.d/experience_updated/300-package_experience_zip.sh index 4594481..272c61c 100755 --- a/manyfold/root/hook.d/datapackage_MODIFY/300-package_experience_zip.sh +++ b/manyfold/root/hook.d/experience_updated/300-package_experience_zip.sh @@ -1,6 +1,5 @@ #!/bin/sh -echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do -dir=$(dirname $1) +dir="$1" cd "$dir" echo "[package_experience.sh] zipping $dir.zip" zip -r "$dir".zip $dir/* diff --git a/manyfold/root/hook.d/datapackage_MODIFY/300-package_godot_zip.sh b/manyfold/root/hook.d/experience_updated/300-package_godot_zip.sh similarity index 78% rename from manyfold/root/hook.d/datapackage_MODIFY/300-package_godot_zip.sh rename to manyfold/root/hook.d/experience_updated/300-package_godot_zip.sh index 76457db..e1566e6 100755 --- a/manyfold/root/hook.d/datapackage_MODIFY/300-package_godot_zip.sh +++ b/manyfold/root/hook.d/experience_updated/300-package_godot_zip.sh @@ -1,6 +1,5 @@ #!/bin/sh -echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do -dir=$(dirname $1) +dir="$1" cd "$dir" echo "[package_experience.sh] zipping $dir.zip" diff --git a/manyfold/root/hook.d/datapackage_MODIFY/300-package_janusxr.sh b/manyfold/root/hook.d/experience_updated/300-package_janusxr.sh similarity index 85% rename from manyfold/root/hook.d/datapackage_MODIFY/300-package_janusxr.sh rename to manyfold/root/hook.d/experience_updated/300-package_janusxr.sh index c80c987..29e10df 100755 --- a/manyfold/root/hook.d/datapackage_MODIFY/300-package_janusxr.sh +++ b/manyfold/root/hook.d/experience_updated/300-package_janusxr.sh @@ -1,6 +1,5 @@ #!/bin/sh -echo "$1" | grep -E 'datapackage|glb$' || exit 0 # nothing to do -dir=$(dirname $1) +dir="$1" cd "$dir" echo "[package_janusxr.sh] packing janusxr.html" diff --git a/manyfold/root/hook.d/datapackage_MODIFY/300-package_xrf.rb b/manyfold/root/hook.d/experience_updated/300-package_xrf.rb similarity index 95% rename from manyfold/root/hook.d/datapackage_MODIFY/300-package_xrf.rb rename to manyfold/root/hook.d/experience_updated/300-package_xrf.rb index 6c32188..c6b9bca 100755 --- a/manyfold/root/hook.d/datapackage_MODIFY/300-package_xrf.rb +++ b/manyfold/root/hook.d/experience_updated/300-package_xrf.rb @@ -5,11 +5,12 @@ require_relative './../../xrforge.rb' # Check if a filename is provided if ARGV.length != 1 - puts "Usage: #{$0} " + puts "Usage: #{$0} " exit 1 end -filename = ARGV[0] +dir = ARGV[0] +filename = "#{dir}/datapackage.json" begin # Read and parse the JSON file diff --git a/manyfold/usr/src/app/config/initializers/xrforge.rb b/manyfold/usr/src/app/config/initializers/xrforge.rb index f036aa8..1ea8729 100644 --- a/manyfold/usr/src/app/config/initializers/xrforge.rb +++ b/manyfold/usr/src/app/config/initializers/xrforge.rb @@ -6,21 +6,33 @@ Rails.application.config.to_prepare do # extend by adding listeners class Model - # The 'after_save' macro is now run within the context of the existing Model class. + + attr_accessor :last_action_execution_time + + # The macro is now run within the context of the existing Model class. after_commit :run_cli_hooks # Define the new method to be executed on save. def run_cli_hooks # Your custom logic to execute after Model.save or Model.update! goes here. - # 📝 Example Logic: - puts "\n-------- MODEL --------- #{self.id}\n\n" - pp self - puts "\n\n" - - command = "pwd" - system(command) + now = Time.current + rate_limit_seconds = 2.0 + last_run_time = @last_action_execution_time + + if self.path.match('#') + if last_run_time.nil? || (now - last_run_time) > rate_limit_seconds + self.last_action_execution_time = now + + # 📝 Example Logic: + puts "\n-------- MODEL --------- #{self.id} #{self.path}\n\n" + pp self + puts "\n\n" + command = "TS_SLOTS=5 ts /manyfold/cli/manyfold.sh hook experience_updated #{self.library.path}/#{self.path} &" + system(command) + end + end end end diff --git a/manyfold/usr/src/app/config/locales/models/en.yml b/manyfold/usr/src/app/config/locales/models/en.yml new file mode 100644 index 0000000..364a536 --- /dev/null +++ b/manyfold/usr/src/app/config/locales/models/en.yml @@ -0,0 +1,105 @@ +--- +en: + models: + bulk_edit: + description: 'Select models to change:' + form_subtitle: 'Select changes to make:' + merge: Merge selected models + needs_organizing: Needs organizing + remove_tags: Remove tags + select: Select model '%{name}' + select_all: Select all models + submit: Update Selected Experiences + title: Bulk Edit Experiences + update_all: Update All %{count} Experiences + bulk_fields: + add_tags: Add tags + bulk_update: + success: Experiences updated successfully. + configure_merge: + common_root: + description: The models will be combined into a single one in the shared root folder + title: New model in common root folder + description: Select one of the models to merge the others into, or create a new one. + heading: Merge models + new_model: + description: A new model will be created from the combined data, and automatically organised on disk. + title: New model + create: + success: File(s) uploaded successfully. + destroy: + confirm: This will delete associated files if they exist on disk. Are you sure you want to continue? + success: Model deleted! + file: + delete: Delete file + edit: Edit file + open_button: + label: View details for %{name} + text: Open + presupported: Presupported Version + set_as_preview: Set as preview + form: + notes: + help_html: You can use Markdown. + preview_file: + help: The file displayed as a model preview in library pages + tags: Tags + general: + edit: Edit Model + image_carousel: + next: Next + play_pause: Play or pause images + previous: Previous + select_slide: Choose image to display + slide_label: "%{name} (%{index} of %{count})" + list: + bulk_edit: Edit All Experiences + no_results_html: Sorry, we couldn't find anything to show you! Try changing your filters or search terms, or uploading some models. + no_results_signed_out_html: Sorry, we couldn't find anything to show you! There might be more to see if you sign in. + skip_models: Skip model list + merge: + success: Experiences merged successfully. + new: + description: Add new models by uploading files! If you upload a compressed archive, it will be extracted and become a single model containing all the files. If you upload individual files, they will each become a separate model. + files: + label: Select Files + free_space: "(%{available} free)" + library: + help: The library to upload to. + submit: Create models + title: Upload + problem: + merge_all: Merge all + scan: + success: Model scan started + show: + download_preparing: Download is being prepared, please wait. + download_requested: Download requested and will be ready soon, please wait. + files: Files + files_card: + bulk_edit: Edit all files + heading: Files + followers: Followers + license: License + merge: + heading: Merge + warning: Merging moves all files from this model to the target, and removes this model. File metadata is preserved, but any model metadata will be lost! + with: Merge with + model_details: Model Details + organize: + button_text: Organize files + confirm: + are_you_sure: Are you sure you want to do this? + 'no': No, cancel + summary_html: The folder and files that make up this model will be moved from:
%{from}
to
%{to} + 'yes': Yes, move the files + path: Path + preview: This is just a preview of the complete model, which contains %{count} more files. Contact the model owner to get full access. + rescan: Rescan files + search: Search the Internet for models with this name + submit: Upload Files + tags: Tags + upload_card: + heading: Upload + update: + success: Model details saved.