Skip to content

Commit

Permalink
Don't accept folders for uploading
Browse files Browse the repository at this point in the history
Put a note into the clipboard that UploadIt only works with files,
if the user tries to send a folder.

Update catkeys.
  • Loading branch information
Humdinger committed Sep 3, 2018
1 parent 8eca070 commit 95b446e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
3 changes: 2 additions & 1 deletion locales/de.catkeys
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1 English application/x-vnd.humdinger-UploadIt 1837252867
1 German application/x-vnd.humdinger-UploadIt 496113555
UploadIt can only be used as a Tracker add-on.\n Add-On UploadIt can nur als Tracker Add-on benutzt werden.\n
Online upload service not available Add-On Online Upload-Dienst nicht verfügbar
UploadIt only works on a single file, no folders Add-On UploadIt verarbeitet nur eine einzelne Datei, keine Ordner
3 changes: 2 additions & 1 deletion locales/en.catkeys
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1 English application/x-vnd.humdinger-UploadIt 1837252867
1 English application/x-vnd.humdinger-UploadIt 496113555
UploadIt can only be used as a Tracker add-on.\n Add-On UploadIt can only be used as a Tracker add-on.\n
Online upload service not available Add-On Online upload service not available
UploadIt only works on a single file, no folders Add-On UploadIt only works on a single file, no folders
45 changes: 32 additions & 13 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,39 @@ process_refs(entry_ref directoryRef, BMessage* msg, void*)
{
BPath path;
entry_ref file_ref;

if (msg->FindRef("refs", &file_ref) == B_NO_ERROR) {
BEntry(&file_ref).GetPath(&path);
BString command(
"stat=$(curl -m 2 -s -I http://google.com | grep HTTP/1 | awk {'print $2'}) ; "
"if [ -z \"$stat\" ] ; then " // network up in general?
"clipboard -c \"%ERROR%\" ; "
"else "
"curl -F'file=@'\"%FILENAME%\" https://0x0.st | clipboard -i ; "
"fi ; "
"exit");
command.ReplaceAll("%ERROR%",
B_TRANSLATE("Online upload service not available"));
command.ReplaceAll("%FILENAME%", path.Path());
system(command.String());
BEntry entry(&file_ref);
if (entry.IsDirectory()) {
BString text(B_TRANSLATE(
"UploadIt only works on a single file, no folders"));
ssize_t textLen = text.Length();
BMessage* message = (BMessage *)NULL;

if (be_clipboard->Lock()) {
be_clipboard->Clear();
if ((message = be_clipboard->Data())) {
message->AddData("text/plain", B_MIME_TYPE, text.String(),
textLen);
be_clipboard->Commit();
}
be_clipboard->Unlock();
}
} else {
entry.GetPath(&path);
BString command(
"stat=$(curl -m 2 -s -I http://google.com | grep HTTP/1 | awk {'print $2'}) ; "
"if [ -z \"$stat\" ] ; then " // network up in general?
"clipboard -c \"%ERROR%\" ; "
"else "
"curl -F'file=@'\"%FILENAME%\" https://0x0.st | clipboard -i ; "
"fi ; "
"exit");
command.ReplaceAll("%ERROR%",
B_TRANSLATE("Online upload service not available"));
command.ReplaceAll("%FILENAME%", path.Path());
system(command.String());
}
}
}

Expand Down

0 comments on commit 95b446e

Please sign in to comment.