-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload
executable file
·139 lines (118 loc) · 3.86 KB
/
upload
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env sh
# Function to upload a file
upload_file() {
local filename="$1"
local filetype="$2"
local filesize=$(stat -c%s "$filename")
if [[ "$filesize" -gt 500000000 ]]; then
echo "Skipping file $filename: File size exceeds 500 MB." >> "$log_file"
return
fi
local filelink=$(curl -sf -F "file=@$filename" 0x0.st)
if [[ -z "$filelink" ]]; then
echo "Failed to upload file $filename. Skipping." >> "$log_file"
return
fi
if [[ $filelink == *"http"* ]]; then
filelink="${filelink/http:/https:}"
fi
echo "{filename:\"${filename##*/}\", filetype:\"$filetype\", filelink:\"$filelink\"}"
}
# Function to remove all .json and .txt files
remove_files() {
find . -maxdepth 1 -type f \( -name '*.json' -o -name '*.txt' \) -delete
echo "ALL JSON and TXT files removed from current directory."
}
# Function to upload a single file and echo the link in green
upload_singlefile() {
local filename="$1"
local filetype="$2"
local filesize=$(stat -c%s "$filename")
if [[ "$filesize" -gt 500000000 ]]; then
echo "Skipping file $filename: File size exceeds 500 MB." >> "$log_file"
return
fi
local filelink=$(curl -sf -F "file=@$filename" 0x0.st)
if [[ -z "$filelink" ]]; then
echo "Failed to upload file $filename. Skipping." >> "$log_file"
return
fi
if [[ $filelink == *"http"* ]]; then
filelink="${filelink/http:/https:}"
fi
echo -e "\e[32m$filelink\e[0m"
echo "{filename:\"${filename##*/}\", filetype:\"$filetype\", filelink:\"$filelink\"}"
}
# Function to process files of specified types
process_files() {
local filetypes=("$@")
local output_file="${timestamp}-links.json"
local log_file="upload-logs${timestamp}.txt"
touch "$output_file" "$log_file"
echo "[" >> "$output_file"
for filetype in "${filetypes[@]}"; do
files=$(find . -maxdepth 1 -type f -name "*.$filetype")
if [[ -z "$files" ]]; then
echo "No files found with $filetype extension. Skipping."
echo "No files found with $filetype extension. Skipping." >> "$log_file"
continue
fi
for file in $files; do
upload_file "$file" "$filetype" >> "$output_file"
done
done
echo "]" >> "$output_file"
}
# Function to display usage information
show_usage() {
script_name=$(basename "$0")
echo "Usage:"
echo " $script_name -f <filetype1> [<filetype2> ...] Process specific file types"
echo " $script_name -j Upload all files from the current directory with JSON data"
echo " $script_name -d Delete all .json and .txt files from the current directory"
echo " $script_name <filepath> Upload a specific file"
echo " $script_name -u Update the script"
echo " $script_name -h Show this usage information"
}
# Function to update the script
updatescript() {
curl -LSs "https://raw.githubusercontent.com/ALEX5402/Q-shere/main/setup.sh" | bash -
}
# Main script execution
if [[ $# -eq 0 ]]; then
echo "No arguments provided."
show_usage
exit 1
fi
timestamp=$(date +"%Y%m%d%H%M%S")
case "$1" in
-f)
if [[ "$#" -eq 1 ]]; then
echo "Usage: $0 -f <filetype1> [<filetype2> ...]"
exit 1
fi
filetypes=("${@:2}")
process_files "${filetypes[@]}"
;;
-j)
process_files "all"
;;
-d)
remove_files
;;
-u)
updatescript
;;
-h)
show_usage
;;
*)
if [[ -f $1 ]]; then
upload_singlefile "$1" "${1##*.}"
else
echo "Invalid option or file not found."
show_usage
exit 1
fi
;;
esac