-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcatbox
More file actions
executable file
·348 lines (313 loc) · 9.52 KB
/
catbox
File metadata and controls
executable file
·348 lines (313 loc) · 9.52 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#!/bin/bash
#
# Catbox v1.4
# A implelemtation of CatBox.moe API in Bash
# Author: MineBartekSA
# Gist: https://gist.github.com/MineBartekSA/1d42d6973ddafb82793fd49b4fb06591
#
curl --version &>/dev/null
if [ "$?" -ne 0 ]; then
echo -e "\e[91mcURL not found!\e[0m"
echo "Please check if you have installed cURL on your system"
exit 1
fi
usage() {
if [ -z "$1" ] || [ "$1" == "version" ]; then
echo -e "\e[1mCatBox\e[0m v1.4"
if [ -n "$1" ]; then exit; fi
echo "A CatBox.moe API implementation in Bash"
echo ""
elif [ "$1" != "\r" ]; then
echo -e "$1"
fi
echo -e "Usage: catbox <command> [arguments]\n"
echo "Commands:"
echo " user [userhash] - Gets or sets current userhash. If you pass 'off' then it will make you anonymous"
echo " file <filename(s)> - Uploads files to catbox.moe"
echo " url <url(s)> - Uploads files from URLs to catbox.moe"
echo " delete <filenames(s)> - Deletes files from catbox.moe. Requires userhash"
echo " album - Album Managment"
echo " usage, --usage, -h, --help - Prints this message"
echo " version, -v, --version - Prints version"
}
getHash() {
while read -r p; do
if [ "${p:0:1}" != "#" ]; then
echo "$p"
fi
done <"$HOME/.catbox"
}
checkUH() {
if ! [ -f "$HOME/.catbox" ]; then
echo -e "\e[91mNo userhash set! $1\e[0m"
echo "Use 'catbox user <hash>' first then try again!"
exit 1
fi
}
HOST="https://catbox.moe/user/api.php"
if [ $# -eq 0 ]; then
usage
elif [ "$1" == "usage" ] || [ "$1" == "--usage" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
usage
elif [ "$1" == "version" ] || [ "$1" == "-v" ] || [ "$1" == "--version" ]; then
usage "version"
elif [ "$1" == "user" ]; then
# User Command
if [ -z "$2" ]; then
if [ -f "$HOME/.catbox" ]; then
echo "Your current userhash is: $(getHash)"
else
echo "No userhash is currently set, so you are anonymous"
fi
else
if [ "$2" != "off" ]; then
echo -e "#CatBox.moe userhash file\n$2" >"$HOME/.catbox"
echo "Userhash $2 set in $HOME/.catbox"
else
rm "$HOME/.catbox"
echo "You are now Anonymous!"
fi
fi
elif [ "$1" == "file" ]; then
# File Commmand
if [ $# -eq 1 ]; then
echo "Usage: catbox file <filename> [<filename>...] - Uploads files to CatBox.moe"
exit 1
fi
if [ -f "$HOME/.catbox" ]; then
echo "Uploading with userhash..."
one=0
for file in "$@"; do
if [ $one -ne 1 ]; then
one=1
continue
fi
if [ -f "$file" ] || [ -L "$file" ]; then
name=$(basename -- "$file")
echo -en "\e[1m$name\e[0m:\n"
link=$(curl -F "reqtype=fileupload" -F "userhash=$(getHash)" -F "fileToUpload=@$file" $HOST)
echo -en "\n"
echo -en "Uploaded to: \e[1m$link\n"
echo -n $link | xclip -selection clipboard
else
echo -e "\e[91mFile $file dose not exists!\e[0m"
fi
done
else
echo "Uploading anonymously..."
one=0
for file in "$@"; do
if [ $one -ne 1 ]; then
one=1
continue
fi
if [ -f "$file" ] || [ -L "$file" ]; then
name=$(basename -- "$file")
echo -en "\e[1m$name\e[0m:\n"
link=$(curl -F "reqtype=fileupload" -F "fileToUpload=@$file" $HOST)
echo -en "\n"
echo -en "Uploaded to: \e[1m$link\n"
echo -n $link | xclip -selection clipboard
else
echo -e "\e[91mFile $file dose not exists!\e[0m"
fi
done
fi
elif [ "$1" == "url" ]; then
# Url Command
if [ $# -eq 1 ]; then
echo "Usage: catbox url <url> [<url>...] - Uploads files from urls to CatBox.moe"
exit 1
fi
if [ -f "$HOME/.catbox" ]; then
echo "Uploading with userhash..."
one=0
for url in "$@"; do
if [ $one -ne 1 ]; then
one=1
continue
fi
echo -en "\e[1m$url\e[0m: "
link=$(curl -F "reqtype=urlupload" -F "userhash=$(getHash)" -F "url=$url" $HOST)
echo -en "\n"
echo -en "Uploaded to: \e[1m$link\n"
echo -n $link | xclip -selection clipboard
done
else
echo "Uploading anonymously..."
one=0
for url in "$@"; do
if [ $one -ne 1 ]; then
one=1
continue
fi
echo -en "\e[1m$url\e[0m: "
link=$(curl -F "reqtype=urlupload" -F "url=$url" $HOST)
echo -en "\n"
echo -en "Uploaded to: \e[1m$link\n"
echo -n $link | xclip -selection clipboard
done
fi
elif [ "$1" == "delete" ]; then
# Delete Command
if [ $# -eq 1 ]; then
echo "Usage: catbox delete <filename> [<filename>...] - Deletes files from your CatBox.moe account"
exit 1
fi
checkUH "Can't delete files!"
echo "Deleting..."
one=0
files=""
for file in "$@"; do
if [ $one -ne 1 ]; then
one=1
continue
fi
echo -en "\e[1m$file\e[0m: "
curl -F "reqtype=deletefiles" -F "userhash=$(getHash)" -F "files=$file" $HOST
echo -en "\n"
done
echo "Finished deleting files!"
elif [ "$1" == "album" ]; then
#Album Managment
if [ $# -eq 1 ]; then
echo -e "Usage: catbox album <command> [arguments]\n"
echo "Every command here needs userhash so be sure you haveset it up!"
echo -e "\e[1;93mRemeber that every title or discription must written in \"\" if you want to write more than one word!\e[0m\n"
echo "Commands:"
echo " create <title> <description> <file(s)> - Create album"
echo " edit <short> <title> <description> [file(s)] - Edit album"
echo " add <short> <file(s)> - Add files to album"
echo " remove <short> <file(s)> - Remove files from album"
echo " delete <short> - Delete album"
exit 1
fi
if [ "$2" == "create" ]; then
if [ $# -lt 5 ]; then
echo "Usage: catbox album create <title> <description> <filename> [<filename> ...] - Careates an album with given title, discription and files"
echo -e "\e[1;93mRemeber that every title or discription must written in \"\" if you want to write more than one word!\e[0m"
exit 1
fi
checkUH "Can't create album!"
echo "Creating Album..."
echo "Title: $3"
echo "Description: $4"
echo -en "Files: "
one=0
files=""
for file in "$@"; do
if [ $one -ne 4 ]; then
one=$(($one + 1))
continue
fi
if [ "$files" == "" ]; then
files=$file
else
files=$files" "$file
fi
echo -en $file
done
echo -en "\n"
album=$(curl -F "reqtype=createalbum" -F "userhash=$(getHash)" -F "title=$3" -F "desc=$4" -F "files=$files" -# $HOST)
echo "Album short: ${album/"https://catbox.moe/c/"/""}"
echo "Album url: $album"
echo "Album creation successfull!"
elif [ "$2" == "edit" ]; then
if [ $# -lt 5 ]; then
echo "Usage: catbox album edit <short> <title> <description> [<filename> ...] - Edites album"
echo -e "\e[1;93mRemeber that every title or discription must written in \"\" if you want to write more than one word!"
echo -e "You don't have to give filenames but if you don't give any will render the album empty!\e[0m"
exit 1
fi
checkUH "Can't edit album!"
echo "Editing Album..."
echo "Album Short: $3"
echo "Title: $4"
echo "Description: $5"
echo -en "Files: "
one=0
files=""
for file in "$@"; do
if [ $one -ne 5 ]; then
one=$(($one + 1))
continue
fi
if [ "$files" == "" ]; then
files=$file
else
files=$files" "$file
fi
echo -en $file
done
echo -en "\n"
curl -F "reqtype=editalbum" -F "userhash=$(getHash)" -F "short=$3" -F "title=$4" -F "desc=$5" -F "files=$files" -# $HOST
echo -e "\nAlbum edition successfull!"
elif [ "$2" == "add" ]; then
if [ $# -lt 4 ]; then
echo "Usage: catbox album add <short> <filename> [<filename> ...] - Adds files to the specific album"
exit 1
fi
checkUH "Can't add files to album!"
echo -en "Files: "
one=0
files=""
for file in "$@"; do
if [ $one -ne 3 ]; then
one=$(($one + 1))
continue
fi
if [ "$files" == "" ]; then
files=$file
else
files=$files" "$file
fi
echo -en $file
done
echo -en "\n"
curl -F "reqtype=addtoalbum" -F "userhash=$(getHash)" -F "short=$3" -F "files=$files" $HOST
echo -e "\nAddition complete!"
elif [ "$2" == "remove" ]; then
if [ $# -lt 4 ]; then
echo "Usage: catbox album remove <short> <filename> [<filename> ...] - Removes files from the specific album"
exit 1
fi
checkUH "Can't remove files from album!"
echo -en "Files: "
one=0
files=""
for file in "$@"; do
if [ $one -ne 3 ]; then
one=$(($one + 1))
continue
fi
if [ "$files" == "" ]; then
files=$file
else
files=$files" "$file
fi
echo -en $file
done
echo -en "\n"
curl -F "reqtype=removefromalbum" -F "userhash=$(getHash)" -F "short=$3" -F "files=$files" $HOST
echo -e "\nRemoval complete!"
elif [ "$2" == "delete" ]; then
if [ $# -lt 3 ]; then
echo "Usage: catbox album delete <short> [<short> ...] - Deletes album"
exit 1
fi
checkUH "Can't delete album!"
one=0
for short in $@; do
if [ $one -ne 2 ]; then
one=$(($one + 1))
continue
fi
echo -en "\e[1m$short\e[0m: "
curl -F "reqtype=deletealbum" -F "userhash=$(getHash)" -F "short=$short" $HOST >>/dev/null
echo -en "Done!\n"
done
echo "Album deletion completed!"
fi
else
usage
fi