pixabay sourcer download text file with source

This commit is contained in:
2023-05-05 21:19:38 -06:00
parent 9843113e1e
commit af34e94d50
5 changed files with 26 additions and 14 deletions

View File

@@ -4,6 +4,9 @@ import kiss.Prelude;
import kiss_firefox.API; import kiss_firefox.API;
import haxe.Constraints; import haxe.Constraints;
import pixabay_sourcer.Message; import pixabay_sourcer.Message;
import haxe.io.Path;
import js.html.File;
import js.html.URL;
@:build(kiss.Kiss.build()) @:build(kiss.Kiss.build())
class Background { class Background {

View File

@@ -2,8 +2,18 @@
(API.browser.runtime.onMessage.addListener ->[:Message message sender sendResponse] (API.browser.runtime.onMessage.addListener ->[:Message message sender sendResponse]
(let [:Function sendResponse sendResponse] (let [:Function sendResponse sendResponse]
(case message (case message
((object type "download" data [url]) ((object type "download" data [imageInfo])
// TODO awaitLet the DownloadItem and send a nativemessage with the path and credit info // awaitLet the DownloadItem and make an object url with the source info
(API.browser.downloads.download (objectWith [saveAs true] url))) (awaitLet [dlItemId (API.browser.downloads.download (object saveAs true url imageInfo.largeImageURL))
dlItems (API.browser.downloads.search (object id dlItemId))]
(let [dlItem (first dlItems)
fileName dlItem.filename
txtFileName "$(Path.withoutDirectory (Path.withoutExtension fileName)).txt"
txtContent "${imageInfo.pageURL}\t${imageInfo.user}\t${imageInfo.user_id}"
file (new File [txtContent] txtFileName)
txtUrl (URL.createObjectURL file)]
(awaitLet [txtDownloadId (API.browser.downloads.download (object url txtUrl filename txtFileName))]
(catch [e] (sendResponse e))
(API.browser.downloads.show txtDownloadId)))))
(never otherwise)) (never otherwise))
true))) true)))

View File

@@ -29,7 +29,8 @@
(request.send))) (request.send)))
(function handleInfo [:Dynamic info] (function handleInfo [:Dynamic info]
(API.browser.runtime.sendMessage (object type "download" data [.largeImageURL (first info.hits)]))) (awaitLet [response (API.browser.runtime.sendMessage (object type "download" data [(first info.hits)]))]
(print response)))
(window.addEventListener "load" (window.addEventListener "load"
->:Void ->:Void

View File

@@ -2,5 +2,5 @@ package pixabay_sourcer;
typedef Message = { typedef Message = {
type:String, type:String,
data:Array<String> data:Array<Dynamic>
}; };

View File

@@ -1,12 +1,10 @@
# @install: lix --silent download "gh://github.com/kiss-lang/kiss#a6c0cf88c6a02aa7845dca7c5c5025b915b78fbc" into kiss/0.0.1/github/a6c0cf88c6a02aa7845dca7c5c5025b915b78fbc
# @run: haxelib run-dir kiss "${HAXE_LIBCACHE}/kiss/0.0.1/github/a6c0cf88c6a02aa7845dca7c5c5025b915b78fbc"
-lib haxe-strings
-lib hscript -lib hscript
-lib tink_json
-lib tink_macro
-lib tink_syntaxhub
-lib uuid -lib uuid
-cp ${HAXE_LIBCACHE}/kiss/0.0.1/github/a6c0cf88c6a02aa7845dca7c5c5025b915b78fbc/src/ -lib tink_macro
-lib tink_json
-lib tink_syntaxhub
-lib haxe-strings
-cp C:/Users/natqu/repos/kiss/src/
-D kiss=0.0.1 -D kiss=0.0.1
-w -WUnusedPattern C:/Users/natqu/repos/kiss/extraParams.hxml
--macro kiss.KissFrontend.use() --macro Sys.println("haxe_libraries/kiss.hxml:8: [Warning] Using dev version of library kiss")