Rouji / single_php_filehost

Simple Filehosting Page in a Single PHP File (obvious 0x0 clone)
ISC License
235 stars 35 forks source link

Add-on for the context menu of your system #14

Closed MuratovAS closed 11 months ago

MuratovAS commented 2 years ago

good day I wrote a small config for WM (windows manager). It adds the ability to upload files to your server directly from the context menu. The code is attached below. I have not found a place for this in your repositories. So I'll leave it here :)

It needs to be slightly modified, or rather to add checks for the system clipboard and notifications. In my case, these are wl-copy and notify-send

~/.local/share/applications/x0-upload

[Desktop Entry]
Type=Application
Name=x0-upload
Icon=emblem-dropbox-infinite
Exec=sh -c "~/.local/bin/x0-upload %u"
Categories=Other;
NoDisplay=false
MimeType=application/zip
Terminal=false

~/.local/bin/x0-upload

#!/bin/bash

#urldecode
url_encoded=`echo "$1" | sed 's@.*://@@g'`
PATH_FILE=$(printf '%b' "${url_encoded//%/\\x}")

#upload
URL=$(curl -F "file=@\"$PATH_FILE\"" 'https://x0.at/')
echo $URL | wl-copy
notify-send " $URL"
Rouji commented 2 years ago

I have a similar, slightly outdated/crusty thing in my dotfiles: https://github.com/Rouji/dotfiles/blob/master/bin/upl Not really sure where to put stuff like that, so I haven't put mine anywhere else yet either :thinking:

Just out of curiosity: what's the urlencode-ish stuff for? and why application/zip?

MuratovAS commented 2 years ago

Users using languages other than English may have difficulties. On the way, there may be non-Latin characters, which will be converted by the system into codes. Example. This is how the path to the file in the FS looks like: /home/user/файл.txt the value that the script takes: file:///home/user/%D1%84%D0%B0%D0%B9%D0%BB.txt

Curl will not be able to find the file in that path. Therefore, you need to execute decode


Initially, I wanted to hide the application shortcut in the system. NoDisplay=true In order not to clog the startup menu. But at the same time, I wanted to preserve the ability to load the file through the "open with" menu, this requires the type association MimeType = application / zip. I mainly post zip files.

It turned out to be not very convenient and I changed the parameter NoDisplay = false. Now MimeType can be removed.

Rouji commented 2 years ago

I see. Why not just use %f instead and get rid of the url stuff?

MuratovAS commented 2 years ago

I see. Why not just use %f instead and get rid of the url stuff?

Really. I misinterpreted %f. I thought it was returning the filename, not the path. Thank you