mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2026-01-08 10:10:16 +00:00
🛠️ Simplify route definition and update JS for Nostr profile handling
This commit is contained in:
@@ -24,8 +24,14 @@ class GetProfile extends Controller
|
||||
'npub' => (new Key)->convertPublicKeyToBech32($key),
|
||||
]);
|
||||
|
||||
return Profile::query()
|
||||
$profile = Profile::query()
|
||||
->where('pubkey', $key)
|
||||
->first();
|
||||
|
||||
if (!$profile) {
|
||||
return response()->json(['message' => 'Profile not found'], 200);
|
||||
}
|
||||
|
||||
return $profile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,11 +40,10 @@ trait NostrFetcherTrait
|
||||
$requestMessage = new RequestMessage($subscriptionId, $filters);
|
||||
|
||||
$relayUrls = [
|
||||
'wss://relay.nostr.band',
|
||||
'wss://relay.primal.net',
|
||||
'wss://purplepag.es',
|
||||
'wss://nostr.wine',
|
||||
'wss://relay.damus.io',
|
||||
'wss://nostr.einundzwanzig.space',
|
||||
];
|
||||
|
||||
$data = null;
|
||||
|
||||
2
public/dist/window.nostr.min.js.js
vendored
2
public/dist/window.nostr.min.js.js
vendored
File diff suppressed because one or more lines are too long
@@ -5,15 +5,43 @@ export default () => ({
|
||||
},
|
||||
|
||||
async openNostrLogin() {
|
||||
console.log('Starting Nostr login...');
|
||||
console.log('window.nostr available:', !!window.nostr);
|
||||
|
||||
const pubkey = await window.nostr.getPublicKey();
|
||||
console.log('Fetched pubkey:', pubkey);
|
||||
|
||||
// fetch profile from /api/nostr/profile/{publicKey}
|
||||
fetch('/api/nostr/profile/' + pubkey)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Profile fetched', data);
|
||||
// store the profile in AlpineJS store
|
||||
Alpine.store('nostr', {user: data});
|
||||
this.$dispatch('nostrLoggedIn', {pubkey: data.pubkey});
|
||||
const url = '/api/nostr/profile/' + pubkey;
|
||||
console.log('Fetching profile from:', url);
|
||||
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
console.log('Response status:', response.status);
|
||||
console.log('Response ok:', response.ok);
|
||||
console.log('Response headers:', response.headers);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return response.text();
|
||||
})
|
||||
.then(text => {
|
||||
console.log('Response text:', text);
|
||||
try {
|
||||
const data = JSON.parse(text);
|
||||
console.log('Profile fetched', data);
|
||||
// store the profile in AlpineJS store
|
||||
Alpine.store('nostr', {user: data});
|
||||
this.$dispatch('nostrLoggedIn', {pubkey: pubkey});
|
||||
} catch (e) {
|
||||
console.error('JSON parse error:', e);
|
||||
throw e;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during Nostr login:', error);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -470,8 +470,8 @@ $loadEvents = function () {
|
||||
<template x-if="$store.nostr.user">
|
||||
<div class="flex items">
|
||||
<img class="w-12 h-12 rounded-full"
|
||||
x-bind:src="$store.nostr.user.picture"
|
||||
alt="">
|
||||
x-bind:src="$store.nostr.user.picture || '{{ asset('apple-touch-icon.png') }}'"
|
||||
alt="Avatar">
|
||||
<div class="ml-4">
|
||||
<h3 class="w-48 sm:w-full truncate text-lg leading-snug text-[#1B1B1B] dark:text-gray-100 font-bold"
|
||||
x-text="$store.nostr.user.display_name"></h3>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\Api\Nostr\GetProfile;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/nostr/profile/{key}', \App\Http\Controllers\Api\Nostr\GetProfile::class);
|
||||
Route::get('/nostr/profile/{key}', GetProfile::class);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\Console\Commands\Nostr\SyncProfiles;
|
||||
use Illuminate\Support\Facades\Schedule;
|
||||
|
||||
Schedule::command('backup:clean')->daily()->at('01:00');
|
||||
Schedule::command('backup:run')->daily()->at('01:30');
|
||||
Schedule::command(SyncProfiles::class)->daily()->at('00:30');
|
||||
|
||||
Reference in New Issue
Block a user