show download link and admin token

master
Chakib Benziane 5 years ago
parent 0f5075acab
commit e97dc51f8d

@ -53,20 +53,25 @@ func CheckInvoice(id string) (*Invoice, error) {
// This will watch on the pubsub for paid invoices given an invoice id
func PollPaidInvoice(invoiceId string, invoicePaidChan chan<- *Invoice, errorChan chan<- error) {
defer func() {
log.Printf("quitting poller %s", invoiceId)
}()
watchPaidChannel := make(chan radix.PubSubMessage)
busName := fmt.Sprintf("%s:*", bus.InvoicePaidChannelPrefix)
busName := fmt.Sprintf("%s:%s", bus.InvoicePaidChannelPrefix, invoiceId)
err := db.DB.RedisPubSub.PSubscribe(watchPaidChannel, busName)
err := db.DB.RedisPubSub.Subscribe(watchPaidChannel, busName)
if err != nil {
log.Printf("error in poll invoice: %s", err)
errorChan <- err
return
}
for {
msg := <-watchPaidChannel
log.Printf("received message on %s", msg.Channel)
log.Printf("poller: %s, listening to watchPaidChannel", invoiceId)
for msg := range watchPaidChannel {
log.Printf("poller received message on %s", msg.Channel)
split := strings.Split(msg.Channel, ":")
if len(split) != 2 {
@ -85,12 +90,11 @@ func PollPaidInvoice(invoiceId string, invoicePaidChan chan<- *Invoice, errorCha
}
invoicePaidChan <- &invoice
close(invoicePaidChan)
return
}
}
}
func PollPaidInvoiceTMP(invoiceId string, invoiceChan chan<- *Invoice, errorChan chan<- error) {

@ -276,6 +276,7 @@ func (ctrl UploadCtrl) PollStatus(c *gin.Context) {
// Block until payment done or error
log.Println("blocking")
select {
case invoice := <-invoiceChan:
log.Printf("poll: received invoice notif %s", invoice.RHash)
@ -320,7 +321,7 @@ func (ctrl UploadCtrl) PollStatus(c *gin.Context) {
return
}
err = SetUploadAdminToken(uploadId, invoice.PreImage)
err = SetUploadAdminToken(uploadId, adminToken)
if err != nil {
utils.JSONErrPriv(c, http.StatusInternalServerError, err)
return

@ -255,9 +255,9 @@ func GetDownloadId(uploadId string) (string, error) {
//if !exists get from sql and store in redis
if !exists {
log.Printf("download id not found for %s, trying form db")
log.Printf("download id not found for %s, trying form db", uploadId)
query := `SELECT download_id from uploads WHERE upload_id = $1`
err = DB.Sql.Get(&downloadId, query)
err = DB.Sql.Get(&downloadId, query, uploadId)
if err != nil {
return "", err
}

@ -47,6 +47,8 @@ func WatchInvoice() {
// Get the last invoice index cursor
cursor := getLastSettledInvoiceIndex()
log.Printf("watching settled from index %d", cursor)
ctxb := context.Background()
client, cleanUp := lndrpc.GetClient()
defer cleanUp()
@ -71,7 +73,7 @@ func WatchInvoice() {
break
}
log.Printf("Received invoice \n%s\n", invoice)
log.Printf("watcher, received invoice \n%s\n", invoice)
// We are only interested in settled invoices
if !invoice.Settled {

@ -1,5 +1,5 @@
#172.29.195.31
localhost
0.0.0.0
root dist
ext .html

@ -15,7 +15,7 @@
<div v-if="showTimer" class="payreq-wrapper bg-washed-yellow flex justify-center">
<div class="payreq b f6 tc courier gray">
<p>
<p id="payreq" @click="selectCopy">
{{invoice.payreq}}
</p>
</div>
@ -33,7 +33,7 @@
<timer v-if="showTimer" :expires="expires" :expired="expired"></timer>
<div class="paid-date f6 mid-gray" v-if="paid">on &nbsp;{{paidAt}}</div>
</div>
<span class="b f5 mid-gray">{{invoice.msatoshi / 1000}} Satoshi</span>
<span v-if="unpaid" class="b f5 mid-gray">{{invoice.msatoshi / 1000}} Satoshi</span>
<canvas id="canvas" hidden>
</div>
@ -77,6 +77,11 @@ export default {
.catch(err =>{
console.error(err);
})
},
selectCopy(ev){
//ev.target.select()
//document.execCommand('copy')
console.log("TODO: select and copy to clipboard")
}
},

@ -1,5 +1,5 @@
<template>
<div @dragenter.stop.prevent @dragover.stop.prevent @drop.stop.prevent="drop" id="upload" class="flex flex-column ph4 pv4 ba b--dashed bw2 b--light-red br4 bg-near-white mid-gray">
<div @dragenter.stop.prevent @dragover.stop.prevent @drop.stop.prevent="drop" id="upload" class="flex flex-column ph4 pv4 ba b--dashed bw2 b--orange br4 bg-near-white mid-gray">
<div class="title f6 b lh-title ttu tc">drop files here</div>

@ -1,7 +1,22 @@
<template>
<div class="flex flex-column items-center justify-center" id="upload-view">
<div id="upload-view" class="flex flex-column items-center justify-center">
<pay :uploadId="uploadId" :status="status" :invoice="invoice"></pay>
<div class="hr"></div>
<form id="accepted" class="flex flex-column mt5 w-100" v-if="accepted" >
<label for="adminToken" class="f7 db mb2">
<span class="normal b orange">Your admin token:</span>
</label>
<input class="input-reset f6 b ba b--black-20 pa2 mb2 db w-100 mid-gray" @click="selectItem" id="adminToken" type="text" v-model="adminToken">
<label for="adminToken" class="f7 db mb2 mt3">
<span class="normal b blue">Download link:</span>
</label>
<input class="input-reset f6 b ba b--black-20 pa2 mb2 db w-100 mid-gray" @click="selectItem" id="downloadLink" type="text" v-model="downloadLink">
</form>
<!--<upload></upload>-->
<!--<download-link v-if="uploadId && paid" :id="uploadId"></download-link>-->
@ -25,6 +40,9 @@ export default {
name: 'UploadView',
data() {
return {
accepted: false,
adminToken: "",
downloadId: "",
}
},
props: ['uploadId'],
@ -49,6 +67,14 @@ export default {
this.$store.commit('setInvoice', data.invoice)
this.$store.commit('setStatus', data.status)
// if paid we get the admin/dl link
if (data.status.pay_status == 'paid' ){
this.accepted = true;
({ admin_token: this.adminToken,
download_id: this.downloadId } = data);
}
})
}
@ -59,12 +85,22 @@ export default {
})
},
methods:{
selectItem(ev){
ev.target.select()
document.execCommand('copy');
}
},
computed: {
...mapState({
status: state => state.upload.status,
invoice: state => state.upload.invoice,
}),
downloadLink(){
let loc = window.location;
return loc.host + '/d/' + this.downloadId
},
},
components: {
Upload,
@ -75,4 +111,20 @@ export default {
</script>
<style>
#upload-view{
min-width: var(--qrcode-width);
}
#accepted input:focus {
background: #fffceb;
}
input#adminToken::selection {
color: #ff6300;
}
input#downloadLink::selection {
color: #357Edd;;
}
</style>

@ -10,7 +10,7 @@ const upload ={
status: {},
options: {
request_payment: true,
request_payment_amount: 100,
request_payment_amount: 10,
payment_currency: 'SAT'
},
},

Loading…
Cancel
Save