Let viewers set a per-streamer display name
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 29s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 29s
Viewers can type a custom name shown to the streamer instead of their Google account name. It's saved per (streamer, viewer) pair in SQLite and pre-filled on future visits to the same send link. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
ed2b051c91
commit
fab55cde1d
4 changed files with 76 additions and 5 deletions
25
db.js
25
db.js
|
|
@ -20,6 +20,14 @@ db.exec(`
|
|||
tts_voice TEXT NOT NULL DEFAULT 'ru-RU-DmitryNeural',
|
||||
created_at INTEGER NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS viewer_names (
|
||||
streamer_id INTEGER NOT NULL,
|
||||
google_id TEXT NOT NULL,
|
||||
display_name TEXT NOT NULL,
|
||||
updated_at INTEGER NOT NULL,
|
||||
PRIMARY KEY (streamer_id, google_id)
|
||||
);
|
||||
`);
|
||||
|
||||
function generateToken() {
|
||||
|
|
@ -52,8 +60,25 @@ function getOrCreateStreamerByGoogle({ googleId, email, name, picture }) {
|
|||
return findStreamerByGoogleId(googleId) || createStreamer({ googleId, email, name, picture });
|
||||
}
|
||||
|
||||
function getViewerName(streamerId, googleId) {
|
||||
const row = db
|
||||
.prepare('SELECT display_name FROM viewer_names WHERE streamer_id = ? AND google_id = ?')
|
||||
.get(streamerId, googleId);
|
||||
return row ? row.display_name : null;
|
||||
}
|
||||
|
||||
function setViewerName(streamerId, googleId, displayName) {
|
||||
db.prepare(
|
||||
`INSERT INTO viewer_names (streamer_id, google_id, display_name, updated_at)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(streamer_id, google_id) DO UPDATE SET display_name = excluded.display_name, updated_at = excluded.updated_at`
|
||||
).run(streamerId, googleId, displayName, Date.now());
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
findStreamerByOverlayToken,
|
||||
findStreamerBySenderToken,
|
||||
getOrCreateStreamerByGoogle,
|
||||
getViewerName,
|
||||
setViewerName,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue