diff --git a/ui/noogle/src/components/ImageGeneration.vue b/ui/noogle/src/components/ImageGeneration.vue index 0829c7f..0217628 100644 --- a/ui/noogle/src/components/ImageGeneration.vue +++ b/ui/noogle/src/components/ImageGeneration.vue @@ -22,94 +22,18 @@ import {data} from "autoprefixer"; import {requestProvider} from "webln"; import Newnote from "@/components/Newnote.vue"; import amberSignerService from "./android-signer/AndroidSigner"; +import { ref } from "vue"; +import ModalComponent from "../components/Newnote.vue"; +import VueDatePicker from "@vuepic/vue-datepicker"; +import {timestamp} from "@vueuse/core"; +import {post_note, schedule, copyinvoice, copyurl, sleep, nextInput} from "../components/helper/Helper.vue" + + let dvms =[] -let searching = false - - - -let listener = false - let hasmultipleinputs = false -function showDetails(user) { - this.$bvModal.show("modal-details"); - this.modalData = user; -} - -const sleep = (ms) => { - return new Promise(resolve => setTimeout(resolve, ms)) -} - - -async function post_note(note){ - let client = store.state.client - let tags = [] - - if (localStorage.getItem('nostr-key-method') === 'android-signer') { - const draft = { - content: note, - kind: 1, - pubkey: store.state.pubkey.toHex(), - tags: tags, - createdAt: Date.now() - }; - const eventJson = await amberSignerService.signEvent(draft); - await client.sendEvent(Event.fromJson(JSON.stringify(eventJson))); - } - else - { - await client.publishTextNote(note, tags); - } -} - -async function schedule(note) { - - - let schedule = Timestamp.fromSecs(datetopost.value/1000) - let humandatetime = schedule.toHumanDatetime() - let time = humandatetime.split("T")[1].split("Z")[0].trim() - let date = humandatetime.split("T")[0].split("-")[2].trim() + "." + humandatetime.split("T")[0].split("-")[1].trim() + "." + humandatetime.split("T")[0].split("-")[0].trim().slice(2) - - console.log("Date: " + date + " Time: "+ time ) - - let client = store.state.client - let signer = store.state.signer - - let noteevent = EventBuilder.textNote(note, []).customCreatedAt(schedule).toUnsignedEvent(store.state.pubkey) - let signedEvent = await signer.signEvent(noteevent) - - let stringifiedevent = signedEvent.asJson() - - let tags_str = [] - let tag = Tag.parse(["i", stringifiedevent, "text"]) - tags_str.push(tag.asVec()) - let tags_as_str = JSON.stringify(tags_str) - - - let content = await signer.nip04Encrypt(PublicKey.parse("85c20d3760ef4e1976071a569fb363f4ff086ca907669fb95167cdc5305934d1"), tags_as_str) - - let tags_t = [] - tags_t.push(Tag.parse(["p", "85c20d3760ef4e1976071a569fb363f4ff086ca907669fb95167cdc5305934d1"])) - tags_t.push(Tag.parse(["encrypted"])) - tags_t.push(Tag.parse(["client", "noogle"])) - - - let evt = new EventBuilder(5905, content, tags_t) - console.log(evt) - let res = await client.sendEventBuilder(evt); - console.log(res) - miniToastr.showMessage("Note scheduled for " + ("Date: " + date + " Time: "+ time )) - - - - -} - - - async function generate_image(message) { - try { if (message === undefined){ message = "A purple Ostrich" @@ -138,8 +62,6 @@ async function generate_image(message) { console.log(urlinput.value) } - - let res; let requestid; @@ -155,7 +77,6 @@ async function generate_image(message) { res = await amberSignerService.signEvent(draft) await client.sendEvent(Event.fromJson(JSON.stringify(res))) requestid = res.id; - res = res.id; } else { @@ -170,10 +91,6 @@ async function generate_image(message) { } store.commit('set_current_request_id_image', requestid) - //console.log("IMAGE EVENT SENT: " + res.toHex()) - - //miniToastr.showMessage("Sent Request to DVMs", "Awaiting results", VueNotifications.types.warn) - searching = true if (!store.state.imagehasEventListener){ listen() store.commit('set_imagehasEventListener', true) @@ -188,8 +105,6 @@ async function generate_image(message) { } async function listen() { - listener = true - let client = store.state.client let pubkey = store.state.pubkey @@ -224,7 +139,6 @@ async function listen() { try { console.log("7000: ", event.content); console.log("DVM: " + event.author.toHex()) - searching = false //miniToastr.showMessage("DVM: " + dvmname, event.content, VueNotifications.types.info) let status = "unknown" @@ -301,7 +215,7 @@ async function listen() { } }) }, - // Handle relay message + handleMsg: async (relayUrl, message) => { //console.log("Received message from", relayUrl, message.asJson()); } @@ -313,25 +227,6 @@ async function listen() { const urlinput = ref(""); -function nextInput(e) { - const next = e.currentTarget.nextElementSibling; - if (next) { - next.focus(); - - } -} - - - async function copyinvoice(invoice){ - await navigator.clipboard.writeText(invoice) - window.open("lightning:" + invoice,"_blank") - miniToastr.showMessage("", "Copied Invoice to clipboard", VueNotifications.types.info) - } - - async function copyurl(url){ - await navigator.clipboard.writeText(url) - miniToastr.showMessage("", "Copied link to clipboard", VueNotifications.types.info) - } async function zap(invoice) { @@ -358,44 +253,11 @@ function nextInput(e) { await copyinvoice(invoice) } - - //console.log(response) - //for (const dvm of dvms){ - // console.log(dvm.bolt11 + " " + invoice) - //} - - } } - async function createBolt11Lud16(lud16, amount) { - let url; - if (lud16.includes('@')) { // LNaddress - const parts = lud16.split('@'); - url = `https://${parts[1]}/.well-known/lnurlp/${parts[0]}`; - } else { // No lud16 set or format invalid - return null; - } - - try { - console.log(url); - const response = await fetch(url); - const ob = await response.json(); - const callback = ob.callback; - const amountInSats = parseInt(amount) * 1000; - const callbackResponse = await fetch(`${callback}?amount=${amountInSats}`); - const obCallback = await callbackResponse.json(); - return obCallback.pr; - } - catch (e) { - console.log(`LUD16: ${e}`); - return null; - } - - } - defineProps({ msg: { @@ -404,10 +266,7 @@ defineProps({ }, }) -import { ref } from "vue"; -import ModalComponent from "../components/Newnote.vue"; -import VueDatePicker from "@vuepic/vue-datepicker"; -import {timestamp} from "@vueuse/core"; + const isModalOpened = ref(false); const modalcontent = ref(""); @@ -425,17 +284,10 @@ const closeModal = () => { }; const submitHandler = async () => { - - // await post_note(modalcontent) - await schedule(modalcontent, Timestamp.now()) } - - - -