Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Oct 24, 2024
1 parent 731b3a9 commit 8375f37
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 62 deletions.
5 changes: 1 addition & 4 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ async def get_producer(producer_id: str) -> Optional[Producer]:

async def get_producers(livestream: str) -> list[Producer]:
return await db.fetchall(
"""
SELECT id, "user", wallet, name
FROM livestream.producers WHERE livestream = :livestream
""",
"SELECT * FROM livestream.producers WHERE livestream = :livestream",
{"livestream": livestream},
Producer,
)
7 changes: 7 additions & 0 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,10 @@ class Producer(BaseModel):
user: str
wallet: str
name: str


class LivestreamOverview(BaseModel):
lnurl: str
livestream: Livestream
tracks: list[Track]
producers: list[Producer]
30 changes: 14 additions & 16 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ window.app = Vue.createApp({
)
}
},
watch: {
selectedWallet() {
this.loadLivestream()
this.startPaymentNotifier()
}
},
methods: {
getTrackLabel(trackId) {
if (!trackId) return
Expand All @@ -45,11 +51,6 @@ window.app = Vue.createApp({
this.trackDialog.data.producer.length === 0
)
},
changedWallet(wallet) {
this.selectedWallet = wallet
this.loadLivestream()
this.startPaymentNotifier()
},
loadLivestream() {
LNbits.api
.request(
Expand All @@ -59,7 +60,7 @@ window.app = Vue.createApp({
)
.then(response => {
this.livestream = response.data
this.nextCurrentTrack = this.livestream.current_track
this.nextCurrentTrack = this.livestream.livestream.current_track
})
.catch(err => {
LNbits.utils.notifyApiError(err)
Expand Down Expand Up @@ -97,7 +98,7 @@ window.app = Vue.createApp({
: ['POST', '/livestream/api/v1/livestream/track']

LNbits.api
.request(method, path, this.selectedWallet.inkey, {
.request(method, path, this.selectedWallet.adminkey, {
download_url:
download_url && download_url.length > 0 ? download_url : undefined,
name,
Expand Down Expand Up @@ -141,7 +142,7 @@ window.app = Vue.createApp({
.request(
'DELETE',
'/livestream/api/v1/livestream/tracks/' + trackId,
this.selectedWallet.inkey
this.selectedWallet.adminkey
)
.then(response => {
Quasar.Notify.create({
Expand All @@ -159,8 +160,7 @@ window.app = Vue.createApp({
})
},
updateCurrentTrack(track) {
console.log(this.nextCurrentTrack, this.livestream)
if (this.livestream.current_track === track) {
if (this.livestream.livestream.current_track === track) {
// if clicking the same, stop it
track = 0
}
Expand All @@ -169,10 +169,10 @@ window.app = Vue.createApp({
.request(
'PUT',
'/livestream/api/v1/livestream/track/' + track,
this.selectedWallet.inkey
this.selectedWallet.adminkey
)
.then(() => {
this.livestream.current_track = track
this.livestream.livestream.current_track = track
this.nextCurrentTrack = track
Quasar.Notify.create({
message: `Current track updated.`,
Expand All @@ -187,8 +187,8 @@ window.app = Vue.createApp({
LNbits.api
.request(
'PUT',
'/livestream/api/v1/livestream/fee/' + this.livestream.fee_pct,
this.selectedWallet.inkey
'/livestream/api/v1/livestream/fee/' + this.livestream.livestream.fee_pct,
this.selectedWallet.adminkey
)
.then(() => {
Quasar.Notify.create({
Expand All @@ -206,7 +206,5 @@ window.app = Vue.createApp({
},
created() {
this.selectedWallet = this.g.user.wallets[0]
this.loadLivestream()
this.startPaymentNotifier()
}
})
34 changes: 15 additions & 19 deletions templates/livestream/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ <h5 class="text-subtitle1 q-my-none">Tracks</h5>
<q-th auto-width>Producer</q-th>
<q-th auto-width>Price</q-th>
<q-th auto-width>Download URL</q-th>
<q-th auto-width></q-th>
</q-tr>
</template>
<template v-slot:body="props">
Expand All @@ -96,23 +95,6 @@ <h5 class="text-subtitle1 q-my-none">Tracks</h5>
@click="updateCurrentTrack(props.row.id)"
target="_blank"
></q-btn>
</q-td>
<q-td auto-width v-text="props.row.name"></q-td>
<q-td
auto-width
v-text="producersMap[props.row.producer].name"
></q-td>
<q-td
class="text-right"
auto-width
v-tex="Math.round(props.row.price_msat / 1000)"
></q-td>
<q-td
class="text-center"
auto-width
v-text="props.row.download_url"
></q-td>
<q-td auto-width>
<q-btn
flat
dense
Expand All @@ -132,6 +114,21 @@ <h5 class="text-subtitle1 q-my-none">Tracks</h5>
target="_blank"
></q-btn>
</q-td>
<q-td auto-width v-text="props.row.name"></q-td>
<q-td
auto-width
v-text="producersMap[props.row.producer].name"
></q-td>
<q-td
class="text-right"
auto-width
v-tex="Math.round(props.row.price_msat / 1000)"
></q-td>
<q-td
class="text-center"
auto-width
v-text="props.row.download_url"
></q-td>
</q-tr>
</template>
</q-table>
Expand Down Expand Up @@ -186,7 +183,6 @@ <h5 class="text-subtitle1 q-my-none">Producers</h5>
v-model="selectedWallet"
label="Using wallet:"
option-label="name"
@input="changedWallet"
>
</q-select>
</q-form>
Expand Down
32 changes: 9 additions & 23 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,25 @@
update_livestream_fee,
update_track,
)
from .models import CreateTrack
from .models import CreateTrack, LivestreamOverview

livestream_api_router = APIRouter()


@livestream_api_router.get("/api/v1/livestream")
async def api_livestream_from_wallet(
req: Request, key_info: WalletTypeInfo = Depends(require_invoice_key)
):
) -> LivestreamOverview:
ls = await get_or_create_livestream_by_wallet(key_info.wallet.id)
tracks = await get_tracks(ls.id)
producers = await get_producers(ls.id)

try:
return {
**ls.dict(),
**{
"lnurl": ls.lnurl(request=req),
"tracks": [
dict(lnurl=track.lnurl(request=req), **track.dict())
for track in tracks
],
"producers": [producer.dict() for producer in producers],
},
}
except LnurlInvalidUrl as exc:
raise HTTPException(
status_code=HTTPStatus.UPGRADE_REQUIRED,
detail=(
"LNURLs need to be delivered over a publically "
"accessible `https` domain or Tor."
),
) from exc
overview = LivestreamOverview(
lnurl=str(ls.lnurl(request=req)),
livestream=ls,
tracks=tracks,
producers=producers
)
return overview


@livestream_api_router.put("/api/v1/livestream/track/{track_id}")
Expand Down

0 comments on commit 8375f37

Please sign in to comment.