Merge branch 'main' into resusbscribe_on_add
This commit is contained in:
commit
a37b4f01d5
8 changed files with 46 additions and 29 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
from starlette.staticfiles import StaticFiles
|
||||||
|
|
||||||
from lnbits.db import Database
|
from lnbits.db import Database
|
||||||
from lnbits.helpers import template_renderer
|
from lnbits.helpers import template_renderer
|
||||||
from lnbits.tasks import catch_everything_and_restart
|
from lnbits.tasks import catch_everything_and_restart
|
||||||
from starlette.staticfiles import StaticFiles
|
|
||||||
|
|
||||||
db = Database("ext_nostrclient")
|
db = Database("ext_nostrclient")
|
||||||
|
|
||||||
|
|
|
||||||
1
crud.py
1
crud.py
|
|
@ -1,6 +1,7 @@
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
import shortuuid
|
import shortuuid
|
||||||
|
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ from typing import Dict, List, Optional
|
||||||
|
|
||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
from fastapi.param_functions import Query
|
from fastapi.param_functions import Query
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
|
|
||||||
|
|
||||||
class Relay(BaseModel):
|
class Relay(BaseModel):
|
||||||
id: Optional[str] = None
|
id: Optional[str] = None
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,16 @@ import json
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
from fastapi import WebSocket, WebSocketDisconnect
|
from fastapi import WebSocket, WebSocketDisconnect
|
||||||
|
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
from .nostr.client.client import NostrClient as NostrClientLib
|
|
||||||
|
|
||||||
from .models import Event, Filter, Filters, Relay, RelayList
|
from .models import Event, Filter, Filters, Relay, RelayList
|
||||||
|
from .nostr.client.client import NostrClient as NostrClientLib
|
||||||
from .nostr.event import Event as NostrEvent
|
from .nostr.event import Event as NostrEvent
|
||||||
from .nostr.filter import Filter as NostrFilter
|
from .nostr.filter import Filter as NostrFilter
|
||||||
from .nostr.filter import Filters as NostrFilters
|
from .nostr.filter import Filters as NostrFilters
|
||||||
from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage
|
from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage
|
||||||
|
|
||||||
|
|
||||||
received_subscription_events: dict[str, list[Event]] = {}
|
received_subscription_events: dict[str, list[Event]] = {}
|
||||||
received_subscription_notices: dict[str, list[NoticeMessage]] = {}
|
received_subscription_notices: dict[str, list[NoticeMessage]] = {}
|
||||||
received_subscription_eosenotices: dict[str, EndOfStoredEventsMessage] = {}
|
received_subscription_eosenotices: dict[str, EndOfStoredEventsMessage] = {}
|
||||||
|
|
|
||||||
6
tasks.py
6
tasks.py
|
|
@ -3,20 +3,18 @@ import ssl
|
||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
from .crud import get_relays
|
||||||
from .nostr.event import Event
|
from .nostr.event import Event
|
||||||
from .nostr.key import PublicKey
|
from .nostr.key import PublicKey
|
||||||
from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage
|
from .nostr.message_pool import EndOfStoredEventsMessage, EventMessage, NoticeMessage
|
||||||
from .nostr.relay_manager import RelayManager
|
from .nostr.relay_manager import RelayManager
|
||||||
from .services import (
|
from .services import (
|
||||||
nostr,
|
nostr,
|
||||||
received_subscription_events,
|
|
||||||
received_subscription_eosenotices,
|
received_subscription_eosenotices,
|
||||||
|
received_subscription_events,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
from .crud import get_relays
|
|
||||||
|
|
||||||
|
|
||||||
async def init_relays():
|
async def init_relays():
|
||||||
# we save any subscriptions teporarily to re-add them after reinitializing the client
|
# we save any subscriptions teporarily to re-add them after reinitializing the client
|
||||||
subscriptions = {}
|
subscriptions = {}
|
||||||
|
|
|
||||||
|
|
@ -75,12 +75,17 @@
|
||||||
</q-tr>
|
</q-tr>
|
||||||
</template>
|
</template>
|
||||||
</q-table>
|
</q-table>
|
||||||
|
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<div class="text-weight-bold"> Your endpoint:
|
<div class="text-weight-bold">
|
||||||
<q-badge outline class="q-ml-sm text-subtitle2" color="primary" :label="`wss://${host}/nostrclient/api/v1/relay`" />
|
Your endpoint:
|
||||||
</div>
|
<q-badge
|
||||||
|
outline
|
||||||
|
class="q-ml-sm text-subtitle2"
|
||||||
|
color="primary"
|
||||||
|
:label="`wss://${host}/nostrclient/api/v1/relay`"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
<q-card>
|
<q-card>
|
||||||
|
|
@ -88,7 +93,13 @@
|
||||||
<q-form class="q-gutter-md q-y-md" @submit="addRelay">
|
<q-form class="q-gutter-md q-y-md" @submit="addRelay">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col q-mx-md q-my-sm">
|
<div class="col q-mx-md q-my-sm">
|
||||||
<q-input outlined v-model="relayToAdd" dense filled label="Relay URL"></q-input>
|
<q-input
|
||||||
|
outlined
|
||||||
|
v-model="relayToAdd"
|
||||||
|
dense
|
||||||
|
filled
|
||||||
|
label="Relay URL"
|
||||||
|
></q-input>
|
||||||
</div>
|
</div>
|
||||||
<div class="col q-mx-md items-align flex items-center justify-right">
|
<div class="col q-mx-md items-align flex items-center justify-right">
|
||||||
<q-btn unelevated color="primary" type="submit">Add relay </q-btn>
|
<q-btn unelevated color="primary" type="submit">Add relay </q-btn>
|
||||||
|
|
@ -104,17 +115,20 @@
|
||||||
<h6 class="text-subtitle1 q-my-none">Nostrclient Extension</h6>
|
<h6 class="text-subtitle1 q-my-none">Nostrclient Extension</h6>
|
||||||
<p>
|
<p>
|
||||||
This extension is a always-on nostr client that other extensions can
|
This extension is a always-on nostr client that other extensions can
|
||||||
use to send and receive events on nostr.
|
use to send and receive events on nostr. Add multiple nostr relays to
|
||||||
|
connect to. The extension then opens a websocket for you to use at
|
||||||
Add multiple nostr relays to connect to. The extension then opens a websocket for you to use
|
|
||||||
at
|
|
||||||
<p>
|
|
||||||
<!-- wss://{{host}}nostrclient/api/v1/relay -->
|
|
||||||
<q-badge outline class="q-ml-sm text-subtitle2" color="primary" :label="`wss://${host}/nostrclient/api/v1/relay`" />
|
|
||||||
</p>
|
|
||||||
Only Admin users can manage
|
|
||||||
this extension.
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<!-- wss://{{host}}nostrclient/api/v1/relay -->
|
||||||
|
<q-badge
|
||||||
|
outline
|
||||||
|
class="q-ml-sm text-subtitle2"
|
||||||
|
color="primary"
|
||||||
|
:label="`wss://${host}/nostrclient/api/v1/relay`"
|
||||||
|
/>
|
||||||
|
</p>
|
||||||
|
Only Admin users can manage this extension.
|
||||||
<q-card-section></q-card-section>
|
<q-card-section></q-card-section>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
@ -217,7 +231,7 @@
|
||||||
message: `Invalid relay URL.`,
|
message: `Invalid relay URL.`,
|
||||||
caption: "Should start with 'wss://'' or 'ws://'"
|
caption: "Should start with 'wss://'' or 'ws://'"
|
||||||
})
|
})
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
console.log('ADD RELAY ' + this.relayToAdd)
|
console.log('ADD RELAY ' + this.relayToAdd)
|
||||||
let that = this
|
let that = this
|
||||||
|
|
@ -229,7 +243,7 @@
|
||||||
{url: this.relayToAdd}
|
{url: this.relayToAdd}
|
||||||
)
|
)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
console.log("response:", response)
|
console.log('response:', response)
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
response.data.map(maplrelays)
|
response.data.map(maplrelays)
|
||||||
that.nostrrelayLinks = response.data
|
that.nostrrelayLinks = response.data
|
||||||
|
|
@ -239,7 +253,7 @@
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
})
|
})
|
||||||
return false;
|
return false
|
||||||
},
|
},
|
||||||
deleteRelay(url) {
|
deleteRelay(url) {
|
||||||
console.log('DELETE RELAY ' + url)
|
console.log('DELETE RELAY ' + url)
|
||||||
|
|
|
||||||
3
views.py
3
views.py
|
|
@ -6,11 +6,12 @@ from fastapi import Request
|
||||||
from fastapi.param_functions import Query
|
from fastapi.param_functions import Query
|
||||||
from fastapi.params import Depends
|
from fastapi.params import Depends
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
from starlette.responses import HTMLResponse
|
||||||
|
|
||||||
from lnbits.core.crud import update_payment_status
|
from lnbits.core.crud import update_payment_status
|
||||||
from lnbits.core.models import User
|
from lnbits.core.models import User
|
||||||
from lnbits.core.views.api import api_payment
|
from lnbits.core.views.api import api_payment
|
||||||
from lnbits.decorators import check_admin, check_user_exists
|
from lnbits.decorators import check_admin, check_user_exists
|
||||||
from starlette.responses import HTMLResponse
|
|
||||||
|
|
||||||
from . import nostr_renderer, nostrclient_ext
|
from . import nostr_renderer, nostrclient_ext
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,12 @@ from http import HTTPStatus
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from fastapi import Depends, WebSocket
|
from fastapi import Depends, WebSocket
|
||||||
from lnbits.decorators import check_admin
|
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
from starlette.exceptions import HTTPException
|
from starlette.exceptions import HTTPException
|
||||||
|
|
||||||
|
from lnbits.decorators import check_admin
|
||||||
|
from lnbits.helpers import urlsafe_short_hash
|
||||||
|
|
||||||
from . import nostrclient_ext
|
from . import nostrclient_ext
|
||||||
from .crud import add_relay, delete_relay, get_relays
|
from .crud import add_relay, delete_relay, get_relays
|
||||||
from .models import Relay, RelayList
|
from .models import Relay, RelayList
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue