Skip to content

Commit

Permalink
add user script
Browse files Browse the repository at this point in the history
  • Loading branch information
Eastern-Dream committed Oct 16, 2024
1 parent aff3e9a commit 4344b80
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ This repository holds the sourcecode for the TourForge web application.
```

## History

TourForge went through many changes during development. For those who are interested, below is a rough outline of the different stages.

1. Web app with Go backend and TypeScript/React frontend. Not too much time was spent on this iteration; it never became feature-complete.
2. Flutter desktop app. Lots of time was spent here, and this iteration eventually became feature-complete. A desktop app seemed likely to be the most low-maintenance option, and the mobile app was already being developed with Flutter, so it made sense to try the same framework for the desktop app.
3. Desktop app with Rust backend (Tauri) and TypeScript/React frontend. This was a full rewrite done to get away from the "jank" of Flutter desktop at the time. This version eventually became feature-complete.
4. Web app with Python/Django backend and TypeScript/Solid frontend. Frontend was switched from React to Solid to force a full pass over the UI code to fix some problems it had; since React and Solid are very similar, this was not a "full rewrite," but maybe a 50% rewrite. The switch from desktop to web was done with the goal of making TourForge easier for people to use, becoming a more all-encompassing solution for both building tours and acting as a tour content server. Though an official release was never made, this version was feature-complete by the time we moved on to stage 5.
5. (Now!) Web app with **NO** backend and TypeScript/Solid frontend. There were challenges in finding cloud hosting for the Django backend with all of the features we needed for maximum maintainability. Actually, this result was already forseen back when we chose to write a desktop app in stage 2 -- but something caused us to forget this and make a web app anyways in stage 4. In any case, we decided to simply get rid of the backend and keep the same frontend but have it interface with IndexedDB. It would have been an equal amount of work to go back to being a desktop app, but we think a fully client-side web app might be close to having the best of both worlds.

## User script
There are a few issues we have encountered with the creation of tour bundle, it works well as expected, but there were problems we had to solve with scripting. You can find all script named after its function in `user-script/` at the root of the repository.

### Image assets are too heavy
We were receiving full resolution images sometimes upward of 32MB and did not have formal procedure in place to make sure that the image is appropriately sized.

### Audio assets playback not working in iOS
The problem was that the backend audio library requires an appropriate filename e.g. ".mp3". The script renames all the audio file with the extension and modify the JSON to the new filename.
26 changes: 26 additions & 0 deletions user-script/rename-audio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Step 0: Check if 'tourforge.json' exists in the current directory
if [[ ! -f "tourforge.json" ]]; then
echo "'tourforge.json' not found in the current directory!"
exit 1
fi

# Step 1: Find all mp3 files without an extension and store their names
mp3_files=()
while IFS= read -r file; do
mp3_files+=("$file")
done < <(find . -type f -exec file --mime-type {} + | grep 'audio/mpeg' | cut -d: -f1)

# Step 2: Search the 'tourforge.json' file for mp3 filenames and append ".mp3" to them
for mp3 in "${mp3_files[@]}"; do
basename_mp3=$(basename "$mp3")
sed -i "s/\b$basename_mp3\b/$basename_mp3.mp3/g" "tourforge.json"
done

# Step 3: Rename files to append ".mp3" extension
for mp3 in "${mp3_files[@]}"; do
mv "$mp3" "$mp3.mp3"
done

echo "Operation completed successfully!"
17 changes: 17 additions & 0 deletions user-script/resize-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p imagemagick parallel

resize_percent=75 # Percentage to resize on each run
max_size=512 # Maximum file size in KB

# Find all files larger than max_size and check if they are images
files=$(find . -type f -size +${max_size}k | while read -r file; do
if file "$file" | grep -qE 'image|bitmap'; then
echo "$(realpath $file)"
fi
done)
# Process images in parallel
echo "Resizing all of the following image(s) ONCE, please run this script multiple times to bring it below ${max_size}KB"
echo "$files"
echo "$files" | parallel --no-notice magick {} -resize ${resize_percent}% {}

0 comments on commit 4344b80

Please sign in to comment.