braidfs 0.0.65 → 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 +16 -24
  2. package/package.json +1 -1
package/index.sh CHANGED
@@ -1,21 +1,11 @@
1
1
  #!/bin/bash
2
2
 
3
- # Resolve the actual path of the script, even if it's a symlink
4
- SOURCE="${BASH_SOURCE[0]}"
5
- while [ -h "$SOURCE" ]; do # Resolve $SOURCE until it's no longer a symlink
6
- DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
7
- SOURCE="$(readlink "$SOURCE")"
8
- # If $SOURCE was a relative symlink, resolve it relative to the symlink's directory
9
- [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
10
- done
11
- SCRIPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
12
-
13
3
  # Function to calculate Base64-encoded SHA256 hash
14
4
  calculate_sha256() {
15
5
  if command -v shasum > /dev/null; then
16
- echo -n "$1" | shasum -a 256 | cut -d ' ' -f 1 | xxd -r -p | base64
6
+ cat | shasum -a 256 | cut -d ' ' -f 1 | xxd -r -p | base64
17
7
  elif command -v sha256sum > /dev/null; then
18
- echo -n "$1" | sha256sum | cut -d ' ' -f 1 | xxd -r -p | base64
8
+ cat | sha256sum | cut -d ' ' -f 1 | xxd -r -p | base64
19
9
  else
20
10
  echo "Error: Neither shasum nor sha256sum is available." >&2
21
11
  exit 1
@@ -64,11 +54,8 @@ if [ "$1" = "editing" ]; then
64
54
  FILENAME="$(pwd)/$FILENAME"
65
55
  fi
66
56
 
67
- # Read input from stdin
68
- INPUT=$(cat)
69
-
70
- # Calculate SHA256 hash
71
- HASH=$(calculate_sha256 "$INPUT")
57
+ # Calculate SHA256 hash directly from stdin
58
+ HASH=$(calculate_sha256)
72
59
 
73
60
  # Make HTTP request
74
61
  RESPONSE=$(curl -s "http://localhost:${PORT}/.braidfs/get_version/$(urlencode "$FILENAME")/$(urlencode "$HASH")")
@@ -85,15 +72,20 @@ elif [ "$1" = "edited" ]; then
85
72
 
86
73
  PARENT_VERSION="$3"
87
74
 
88
- # Read input from stdin
89
- INPUT=$(cat)
90
-
91
- # Make HTTP request
92
- RESPONSE=$(curl -s -X PUT -d "$INPUT" "http://localhost:${PORT}/.braidfs/set_version/$(urlencode "$FILENAME")/$(urlencode "$PARENT_VERSION")")
93
- echo "$RESPONSE"
94
- exit 0
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")"
95
77
 
96
78
  # For all other commands, pass through to the Node.js script
97
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
+
98
90
  node "$SCRIPT_DIR/index.js" "$@"
99
91
  fi
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braidfs",
3
- "version": "0.0.65",
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",