This commit is contained in:
mm 2024-10-30 01:38:57 +05:00
parent 4201a3d23b
commit 8471ee3649
2 changed files with 34 additions and 11 deletions

View File

@ -37,6 +37,15 @@ func CreateWidget(widgetService model.WidgetService, authClient model.AuthClient
return request.JSON(http.StatusInternalServerError, err.Error())
}
if authData.StreamerID == 0 {
slog.Error("Unauthorized account")
return request.JSON(http.StatusUnauthorized, "Unauthorized")
}
if authData.StreamerID == -1 {
slog.Error("Expired token")
return request.JSON(http.StatusUnauthorized, "Expired token")
}
widgetID, err := widgetService.CreateWidget(
ctx,
model.StreamerID(authData.StreamerID),

View File

@ -41,16 +41,17 @@ func GetTemplate1(
`, backgroundUrl)
script := fmt.Sprintf(`
let baseUrl = 'http://147.45.237.174:8002/api'
let widgetUrl = 'http://147.45.237.174:8002/api/widget'
let ttsUrl = 'http://147.45.237.174:8005/api/tts'
async function getDonatInfo(streamerID) {
let response = await fetch(baseUrl + '/widget/donat/get/' + String(streamerID));
let response = await fetch(widgetUrl + '/donat/get/' + String(streamerID));
let donat = await response.json();
return donat
}
async function getWidgetInfo(widgetID) {
let response = await fetch(baseUrl + '/widget/info/' + widgetID);
let response = await fetch(widgetUrl + '/info/' + widgetID);
let widget = await response.json();
return widget
}
@ -67,12 +68,22 @@ function addText(text) {
contentDiv.appendChild(p);
}
function addAudio(audioUrl) {
audio = document.createElement('audio');
audio.src = audioUrl;
audio.autoplay = true;
audio.controls = false;
contentDiv.appendChild(audio);
function playAudio(audioUrl) {
const audio = new Audio(audioUrl);
audio.play()
await delay(5000);
audio.pause();
audio.remove();
}
function playSpeech(text) {
const audio = new Audio(ttsUrl + '/generate, {
method: 'POST',
body: JSON.stringify({
text: text,
}),
});
audio.play()
}
function delay(ms) {
@ -87,7 +98,7 @@ async function endDonat(donatID) {
while (contentDiv.firstChild) {
contentDiv.removeChild(contentDiv.firstChild);
}
let response = await fetch(baseUrl + '/widget/donat/view/' + String(donatID), {method: 'POST'});
let response = await fetch(widgetUrl + '/donat/view/' + String(donatID), {method: 'POST'});
}
let audio;
@ -114,8 +125,11 @@ async function widgetView() {
if (widget.ImageUrl != "") {
addImage(widget.ImageUrl)
}
if (widget.AudioUrl) {
playAudio(widget.AudioUrl)
}
addAudio(widget.AudioUrl)
addText(donat.Text + " " + donat.Amount)
await delay(widget.Duration * 1000);