📜 ⬆️ ⬇️

Script Automator, loading images on Habrastorage: the second coming

Some time ago I made a script that uploads images to Habrastorage directly from the file manager. But the trouble is: after the upgrade, it stopped working.

image

But yesterday I still got tired of uploading photos via the web interface, and I went to fix the script.
For the decision, you have to put the pluses in karma to the avalak user, who told how to do this in my question on the toaster. Toaster - cake!
')
So how to upload images now?

Previously, this command was used to upload images:
curl -F "Filedata=@/Users/vvzvlad/Documents/REVIEWS/003.jpg" "http://habrastorage.org/uploadController/?username=vvzvlad&userkey=7a25d94cde460365b6f7ce137675c623ec"

With the new version of HS, it took this form:
curl --cookie "habrastorage_sid= fs5csqksk0hdm5mq3o91cmdm97" --form "files[]=@/Users/vvzvlad/Documents/REVIEWS/003.jpg --header "X-Requested-With: XMLHttpRequest" --header "Referer: habrastorage.org" --request POST habrastorage.org/main/upload

Authorization now occurs not by code, but by the contents of the cookie. To find it, you need to go to Habrastorej, click (in chrome) on the empty sheet in front of the address and select "Show cookie and site data":
image
Then find it in the list and copy the contents:
image
And paste it into the script:
image

By the way, the previous version of the script had certain problems with the names of folders and files containing spaces. To avoid this, do this:
image
We move the file to a temporary folder, rename it to remove spaces in the name and load. And after loading - we delete: rm "$FILE"

Another of the new - my picture is inserted into the text of the draft automatically. This is done by the following construction:
set the clipboard to "<img src=\"" & input & "\" alt=\"image\"/>"
display notification input with title " "
tell application "Google Chrome" to activate
tell application "System Events" to key code 9 using command down


The first line - forms an image tag from the image address, the second shows a notification, the third - makes the Chrome application active, and the fourth one virtually presses the cmd + v button.

As usual, the file with the service is here . It is necessary to unpack the archive and its contents move to / Users / User / Library / Services /. Open it by double-clicking on the file, and paste your cookie inward.

True, what to do with a sweat in a few days a cookie - I do not know yet. While I will copy manually.

Source: https://habr.com/ru/post/214347/


All Articles