braidfs 0.0.64 → 0.0.65
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.
- package/index.sh +99 -0
- package/package.json +3 -2
package/index.sh
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/bin/bash
|
|
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
|
+
# Function to calculate Base64-encoded SHA256 hash
|
|
14
|
+
calculate_sha256() {
|
|
15
|
+
if command -v shasum > /dev/null; then
|
|
16
|
+
echo -n "$1" | shasum -a 256 | cut -d ' ' -f 1 | xxd -r -p | base64
|
|
17
|
+
elif command -v sha256sum > /dev/null; then
|
|
18
|
+
echo -n "$1" | sha256sum | cut -d ' ' -f 1 | xxd -r -p | base64
|
|
19
|
+
else
|
|
20
|
+
echo "Error: Neither shasum nor sha256sum is available." >&2
|
|
21
|
+
exit 1
|
|
22
|
+
fi
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# URL encoding function
|
|
26
|
+
urlencode() {
|
|
27
|
+
local string="$1"
|
|
28
|
+
local length="${#string}"
|
|
29
|
+
local encoded=""
|
|
30
|
+
local pos c o
|
|
31
|
+
|
|
32
|
+
for (( pos=0; pos<length; pos++ )); do
|
|
33
|
+
c="${string:$pos:1}"
|
|
34
|
+
case "$c" in
|
|
35
|
+
[-_.~a-zA-Z0-9])
|
|
36
|
+
encoded+="$c"
|
|
37
|
+
;;
|
|
38
|
+
*)
|
|
39
|
+
printf -v o '%%%02x' "'$c"
|
|
40
|
+
encoded+="$o"
|
|
41
|
+
;;
|
|
42
|
+
esac
|
|
43
|
+
done
|
|
44
|
+
|
|
45
|
+
echo "$encoded"
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
# Get the configuration file to read the port
|
|
49
|
+
CONFIG_FILE="${HOME}/http/.braidfs/config"
|
|
50
|
+
if [ -f "$CONFIG_FILE" ]; then
|
|
51
|
+
PORT=$(grep -o '"port":[^,}]*' "$CONFIG_FILE" | sed 's/"port"://; s/ //g')
|
|
52
|
+
if [ -z "$PORT" ]; then
|
|
53
|
+
PORT=45678 # Default port if not found in config
|
|
54
|
+
fi
|
|
55
|
+
else
|
|
56
|
+
PORT=45678 # Default port if config file doesn't exist
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
# Check if the first argument is "editing"
|
|
60
|
+
if [ "$1" = "editing" ]; then
|
|
61
|
+
FILENAME="$2"
|
|
62
|
+
# Convert to absolute path if needed
|
|
63
|
+
if [[ ! "$FILENAME" = /* ]]; then
|
|
64
|
+
FILENAME="$(pwd)/$FILENAME"
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
# Read input from stdin
|
|
68
|
+
INPUT=$(cat)
|
|
69
|
+
|
|
70
|
+
# Calculate SHA256 hash
|
|
71
|
+
HASH=$(calculate_sha256 "$INPUT")
|
|
72
|
+
|
|
73
|
+
# Make HTTP request
|
|
74
|
+
RESPONSE=$(curl -s "http://localhost:${PORT}/.braidfs/get_version/$(urlencode "$FILENAME")/$(urlencode "$HASH")")
|
|
75
|
+
echo "$RESPONSE"
|
|
76
|
+
exit 0
|
|
77
|
+
|
|
78
|
+
# Check if the first argument is "edited"
|
|
79
|
+
elif [ "$1" = "edited" ]; then
|
|
80
|
+
FILENAME="$2"
|
|
81
|
+
# Convert to absolute path if needed
|
|
82
|
+
if [[ ! "$FILENAME" = /* ]]; then
|
|
83
|
+
FILENAME="$(pwd)/$FILENAME"
|
|
84
|
+
fi
|
|
85
|
+
|
|
86
|
+
PARENT_VERSION="$3"
|
|
87
|
+
|
|
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
|
|
95
|
+
|
|
96
|
+
# For all other commands, pass through to the Node.js script
|
|
97
|
+
else
|
|
98
|
+
node "$SCRIPT_DIR/index.js" "$@"
|
|
99
|
+
fi
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "braidfs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
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.
|
|
14
|
+
"braidfs": "./index.sh"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
|
+
"index.sh",
|
|
17
18
|
"index.js",
|
|
18
19
|
"editor.html",
|
|
19
20
|
"diff.js"
|