From b8bec108a7fd625282407dec6e95075b3f5ca167 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 2 Sep 2024 18:16:00 +0200 Subject: [PATCH] public chat bot log --- app/Http/Controllers/ChatBotLogController.php | 15 +++++ app/Http/Controllers/SitemapXmlController.php | 7 ++ app/Models/ChatBotLog.php | 11 ++++ resources/js/app/Routes.js | 7 ++ resources/js/components/channel/Link.js | 29 +++++++++ resources/js/components/chat-bot-logs/Item.js | 9 ++- resources/js/components/chat-bot-logs/List.js | 33 ++++++++-- resources/js/components/episodes/Channel.js | 13 +--- resources/js/pages/HorstieLog.js | 64 +++++++++++++++++++ routes/api.php | 2 + 10 files changed, 172 insertions(+), 18 deletions(-) create mode 100644 app/Http/Controllers/ChatBotLogController.php create mode 100644 resources/js/components/channel/Link.js create mode 100644 resources/js/pages/HorstieLog.js diff --git a/app/Http/Controllers/ChatBotLogController.php b/app/Http/Controllers/ChatBotLogController.php new file mode 100644 index 0000000..86bb690 --- /dev/null +++ b/app/Http/Controllers/ChatBotLogController.php @@ -0,0 +1,15 @@ +orderBy('created_at', 'DESC')->limit(50); + return $logs->get()->toJson(); + } + +} diff --git a/app/Http/Controllers/SitemapXmlController.php b/app/Http/Controllers/SitemapXmlController.php index c538bc4..f85e40e 100644 --- a/app/Http/Controllers/SitemapXmlController.php +++ b/app/Http/Controllers/SitemapXmlController.php @@ -76,6 +76,13 @@ class SitemapXmlController extends Controller $urls[] = $url; } + $url = new SitemapUrl(); + $url->path = '/horstielog'; + $url->lastmod = ChatBotLog::latest()->first()->created_at; + $url->changefreq = 'daily'; + $url->priority = 0.5; + $urls[] = $url; + return response()->view('sitemap', [ 'urls' => $urls, ])->header('Content-Type', 'text/xml'); diff --git a/app/Models/ChatBotLog.php b/app/Models/ChatBotLog.php index a4f1f93..2819ee0 100644 --- a/app/Models/ChatBotLog.php +++ b/app/Models/ChatBotLog.php @@ -2,13 +2,24 @@ namespace App\Models; +use Illuminate\Broadcasting\Channel as PublicChannel; +use Illuminate\Database\Eloquent\BroadcastsEvents; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ChatBotLog extends Model { + use BroadcastsEvents; use HasFactory; + public function broadcastOn($event) { + return new PublicChannel('ChatBotLog'); + } + + public function broadcastWith($event) { + $this->load(['channel', 'origin', 'user']); + } + public function channel() { return $this->belongsTo(Channel::class); } diff --git a/resources/js/app/Routes.js b/resources/js/app/Routes.js index 0e35ddb..5e12004 100644 --- a/resources/js/app/Routes.js +++ b/resources/js/app/Routes.js @@ -53,6 +53,13 @@ const router = createBrowserRouter( '../pages/AlttpSeed' )} /> + import( + /* webpackChunkName: "horstie" */ + '../pages/HorstieLog' + )} + /> } diff --git a/resources/js/components/channel/Link.js b/resources/js/components/channel/Link.js new file mode 100644 index 0000000..cb6cb79 --- /dev/null +++ b/resources/js/components/channel/Link.js @@ -0,0 +1,29 @@ +import PropTypes from 'prop-types'; +import React from 'react'; +import { Button } from 'react-bootstrap'; + +import Icon from '../common/Icon'; + +const Link = ({ channel }) => { + return ; +}; + +Link.propTypes = { + channel: PropTypes.shape({ + short_name: PropTypes.string, + stream_link: PropTypes.string, + title: PropTypes.string, + }), +}; + +export default Link; diff --git a/resources/js/components/chat-bot-logs/Item.js b/resources/js/components/chat-bot-logs/Item.js index 4c55c59..9b4cfcb 100644 --- a/resources/js/components/chat-bot-logs/Item.js +++ b/resources/js/components/chat-bot-logs/Item.js @@ -4,6 +4,7 @@ import React from 'react'; import { ListGroup } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; +import ChannelLink from '../channel/Link'; import { getUserName } from '../../helpers/User'; const getEntryDate = entry => moment(entry.created_at).fromNow(); @@ -42,7 +43,7 @@ const getEntryInfo = (entry, t) => { const Item = ({ entry = {} }) => { const { t } = useTranslation(); - return + return
{entry.text} @@ -61,11 +62,17 @@ const Item = ({ entry = {} }) => { {getEntryInfo(entry, t)}
+ {entry.channel ? +
+ +
+ : null}
; }; Item.propTypes = { entry: PropTypes.shape({ + channel: PropTypes.shape({}), created_at: PropTypes.string, origin: PropTypes.shape({}), text: PropTypes.string, diff --git a/resources/js/components/chat-bot-logs/List.js b/resources/js/components/chat-bot-logs/List.js index 0411299..52a4de8 100644 --- a/resources/js/components/chat-bot-logs/List.js +++ b/resources/js/components/chat-bot-logs/List.js @@ -4,16 +4,37 @@ import { ListGroup } from 'react-bootstrap'; import Item from './Item'; -const List = ({ log = [] }) => - - {log ? log.map(entry => - - ) : null} - ; +class List extends React.Component { + + componentDidMount() { + this.timer = setInterval(() => { + this.forceUpdate(); + }, 30000); + } + + componentWillUnmount() { + clearInterval(this.timer); + } + + render() { + const { log } = this.props; + + return + {log ? log.map(entry => + + ) : null} + ; + } + +} List.propTypes = { log: PropTypes.arrayOf(PropTypes.shape({ })), }; +List.defaultProps = { + log: [], +}; + export default List; diff --git a/resources/js/components/episodes/Channel.js b/resources/js/components/episodes/Channel.js index e2d25d7..24569be 100644 --- a/resources/js/components/episodes/Channel.js +++ b/resources/js/components/episodes/Channel.js @@ -2,6 +2,7 @@ import PropTypes from 'prop-types'; import React from 'react'; import { Button } from 'react-bootstrap'; +import Link from '../channel/Link'; import Icon from '../common/Icon'; import { mayEditRestream } from '../../helpers/permissions'; import { useUser } from '../../hooks/user'; @@ -10,17 +11,7 @@ const Channel = ({ channel, episode, onEditRestream }) => { const { user } = useUser(); return
- + {onEditRestream && mayEditRestream(user, episode, channel) ?