package model import "fmt" func GetTemplate1( streamerID StreamerID, backgroundUrl MediaUrl, ) WidgetHTML { style := fmt.Sprintf(`body { margin: 0; padding: 0; height: 100vh; display: flex; justify-content: center; align-items: flex-start; background-image: url('%s'); background-repeat: no-repeat; background-size: cover; } #content { display: flex; flex-direction: column; align-items: center; margin-top: 100px } #content img { width: 50vw; height: 50vh; object-fit: cover; } #content audio { display: none; } #content p { font-size: 60px; } `, backgroundUrl) script := fmt.Sprintf(` let baseUrl = 'http://147.45.237.174:8002/api' async function getDonatInfo(streamerID) { let response = await fetch(baseUrl + '/widget/donat/get/' + String(streamerID)); let donat = await response.json(); return donat } async function getWidgetInfo(widgetID) { let response = await fetch(baseUrl + '/widget/info/' + widgetID); let widget = await response.json(); return widget } function addImage(imageUrl) { img = document.createElement('img'); img.src = imageUrl + '?t=' + new Date().getTime(); contentDiv.appendChild(img); } function addText(text) { p = document.createElement('p'); p.innerHTML = text; contentDiv.appendChild(p); } function addAudio(audioUrl) { audio = document.createElement('audio'); audio.src = audioUrl; audio.autoplay = true; audio.controls = false; contentDiv.appendChild(audio); } function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function endDonat(donatID) { if (audio) { audio.pause(); audio.remove(); } while (contentDiv.firstChild) { contentDiv.removeChild(contentDiv.firstChild); } let response = await fetch(baseUrl + '/widget/donat/view/' + String(donatID), {method: 'POST'}); } let audio; const contentDiv = document.getElementById('content'); async function widgetView() { let streamerID = '%v' while (true) { let donat = await getDonatInfo(streamerID); if (!donat) { await delay(5 * 1000); continue } donat = donat[0] widgetID = donat.WidgetID let widget = await getWidgetInfo(widgetID) widget = widhet[0] console.log(donat); console.log(widget); if (widget.ImageUrl != "") { addImage(widget.ImageUrl) } addAudio(widget.AudioUrl) addText(donat.Text + " " + donat.Amount) await delay(widget.Duration * 1000); await endDonat(donat.ID) } } widgetView()`, streamerID) template1 := fmt.Sprintf(`