braidfs 0.0.64 → 0.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.sh +91 -0
  2. package/package.json +3 -2
package/index.sh ADDED
@@ -0,0 +1,91 @@
1
+ #!/bin/bash
2
+
3
+ # Function to calculate Base64-encoded SHA256 hash
4
+ calculate_sha256() {
5
+ if command -v shasum > /dev/null; then
6
+ cat | shasum -a 256 | cut -d ' ' -f 1 | xxd -r -p | base64
7
+ elif command -v sha256sum > /dev/null; then
8
+ cat | sha256sum | cut -d ' ' -f 1 | xxd -r -p | base64
9
+ else
10
+ echo "Error: Neither shasum nor sha256sum is available." >&2
11
+ exit 1
12
+ fi
13
+ }
14
+
15
+ # URL encoding function
16
+ urlencode() {
17
+ local string="$1"
18
+ local length="${#string}"
19
+ local encoded=""
20
+ local pos c o
21
+
22
+ for (( pos=0; pos<length; pos++ )); do
23
+ c="${string:$pos:1}"
24
+ case "$c" in
25
+ [-_.~a-zA-Z0-9])
26
+ encoded+="$c"
27
+ ;;
28
+ *)
29
+ printf -v o '%%%02x' "'$c"
30
+ encoded+="$o"
31
+ ;;
32
+ esac
33
+ done
34
+
35
+ echo "$encoded"
36
+ }
37
+
38
+ # Get the configuration file to read the port
39
+ CONFIG_FILE="${HOME}/http/.braidfs/config"
40
+ if [ -f "$CONFIG_FILE" ]; then
41
+ PORT=$(grep -o '"port":[^,}]*' "$CONFIG_FILE" | sed 's/"port"://; s/ //g')
42
+ if [ -z "$PORT" ]; then
43
+ PORT=45678 # Default port if not found in config
44
+ fi
45
+ else
46
+ PORT=45678 # Default port if config file doesn't exist
47
+ fi
48
+
49
+ # Check if the first argument is "editing"
50
+ if [ "$1" = "editing" ]; then
51
+ FILENAME="$2"
52
+ # Convert to absolute path if needed
53
+ if [[ ! "$FILENAME" = /* ]]; then
54
+ FILENAME="$(pwd)/$FILENAME"
55
+ fi
56
+
57
+ # Calculate SHA256 hash directly from stdin
58
+ HASH=$(calculate_sha256)
59
+
60
+ # Make HTTP request
61
+ RESPONSE=$(curl -s "http://localhost:${PORT}/.braidfs/get_version/$(urlencode "$FILENAME")/$(urlencode "$HASH")")
62
+ echo "$RESPONSE"
63
+ exit 0
64
+
65
+ # Check if the first argument is "edited"
66
+ elif [ "$1" = "edited" ]; then
67
+ FILENAME="$2"
68
+ # Convert to absolute path if needed
69
+ if [[ ! "$FILENAME" = /* ]]; then
70
+ FILENAME="$(pwd)/$FILENAME"
71
+ fi
72
+
73
+ PARENT_VERSION="$3"
74
+
75
+ # Make HTTP request (getting body from stdin)
76
+ curl -s -X PUT --data-binary @- "http://localhost:${PORT}/.braidfs/set_version/$(urlencode "$FILENAME")/$(urlencode "$PARENT_VERSION")"
77
+
78
+ # For all other commands, pass through to the Node.js script
79
+ else
80
+ # Resolve the actual path of the script, even if it's a symlink
81
+ SOURCE="${BASH_SOURCE[0]}"
82
+ while [ -h "$SOURCE" ]; do # Resolve $SOURCE until it's no longer a symlink
83
+ DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
84
+ SOURCE="$(readlink "$SOURCE")"
85
+ # If $SOURCE was a relative symlink, resolve it relative to the symlink's directory
86
+ [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
87
+ done
88
+ SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
89
+
90
+ node "$SCRIPT_DIR/index.js" "$@"
91
+ fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braidfs",
3
- "version": "0.0.64",
3
+ "version": "0.0.66",
4
4
  "description": "braid technology synchronizing files and webpages",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidfs",
@@ -11,9 +11,10 @@
11
11
  "chokidar": "^3.6.0"
12
12
  },
13
13
  "bin": {
14
- "braidfs": "./index.js"
14
+ "braidfs": "./index.sh"
15
15
  },
16
16
  "files": [
17
+ "index.sh",
17
18
  "index.js",
18
19
  "editor.html",
19
20
  "diff.js"