Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Dev #22

Merged
merged 4 commits into from
Sep 1, 2022
Merged

Dev #22

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions html/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
"shiftChannel": {
"label": "Shift Channels",
"title": "Shift existing channels up by 1 channel number if moving a channel to an already used channel number"
},
"badLogos": {
"label": "Show Bad Logos",
"title": ""
}
},
"filter": {
Expand Down
3 changes: 0 additions & 3 deletions src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ func Init() (err error) {
System.File.ServerCert = getPlatformFile(fmt.Sprintf("%sxteve.crt", System.Folder.Certificates))
System.File.ServerCertPrivKey = getPlatformFile(fmt.Sprintf("%sxteve.key", System.Folder.Certificates))
System.File.XML = getPlatformFile(fmt.Sprintf("%s%s.xml", System.Folder.Data, System.AppName))
System.File.XMLUploaded = getPlatformFile(fmt.Sprintf("%s%s_uploaded.xml", System.Folder.Data, System.AppName))
System.File.M3U = getPlatformFile(fmt.Sprintf("%s%s.m3u", System.Folder.Data, System.AppName))
System.File.M3UUploaded = getPlatformFile(fmt.Sprintf("%s%s_uploaded.m3u", System.Folder.Data, System.AppName))

System.Compressed.GZxml = getPlatformFile(fmt.Sprintf("%s%s.xml.gz", System.Folder.Data, System.AppName))

err = activatedSystemAuthentication()
Expand Down
2 changes: 0 additions & 2 deletions src/struct-system.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ type SystemStruct struct {
File struct {
Authentication string
M3U string
M3UUploaded string
PMS string
ServerCert string
ServerCertPrivKey string
Settings string
URLS string
XEPG string
XML string
XMLUploaded string
TVLogos string
}

Expand Down
6 changes: 3 additions & 3 deletions src/webUI.go

Large diffs are not rendered by default.

32 changes: 25 additions & 7 deletions src/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"io/ioutil"
"net/http"
"os"
"regexp"
"strconv"
"strings"
"time"

"xteve/src/internal/authentication"

"github.com/gorilla/websocket"
Expand Down Expand Up @@ -776,6 +776,12 @@ func WS(w http.ResponseWriter, r *http.Request) {

}

var nonAlphanumericRegex = regexp.MustCompile(`[^a-zA-Z0-9-. ]+`)

func clearString(str string) string {
return nonAlphanumericRegex.ReplaceAllString(str, "")
}

func uploadM3U(input, filename string) (m3uURL string, err error) {

b64data := input[strings.IndexByte(input, ',')+1:]
Expand All @@ -786,13 +792,19 @@ func uploadM3U(input, filename string) (m3uURL string, err error) {
return
}

err = writeByteToFile(System.File.M3UUploaded, sDec)
filename = clearString(filename)

if strings.HasSuffix(filename, ".m3u") {
m3uURL = getPlatformFile(fmt.Sprintf("%s%s", System.Folder.Data, filename))
} else {
m3uURL = getPlatformFile(fmt.Sprintf("%s%s.m3u", System.Folder.Data, filename))
}

err = writeByteToFile(m3uURL, sDec)
if err != nil {
return
}

m3uURL = System.File.M3UUploaded

return

}
Expand All @@ -807,13 +819,19 @@ func uploadXML(input, filename string) (xmlURL string, err error) {
return
}

err = writeByteToFile(System.File.XMLUploaded, sDec)
filename = clearString(filename)

if strings.HasSuffix(filename, ".xml") {
xmlURL = getPlatformFile(fmt.Sprintf("%s%s", System.Folder.Data, filename))
} else {
xmlURL = getPlatformFile(fmt.Sprintf("%s%s.xml", System.Folder.Data, filename))
}

err = writeByteToFile(xmlURL, sDec)
if err != nil {
return
}

xmlURL = System.File.XMLUploaded

return

}
Expand Down
20 changes: 20 additions & 0 deletions ts/base_ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,26 @@ function createSearchObj() {
return
}


function searchBadLogos(isChecked: boolean) {

var trs = document.getElementById("content_table").getElementsByTagName("TR")

for (var i = 1; i < trs.length; ++i) {
let element = (trs[i] as HTMLElement)
let nameElement = (trs[i].childNodes[3].firstChild as HTMLElement)

if (!isChecked || nameElement.style.color === "red") {
element.style.display = ""
} else {
element.style.display = "none"
}

}

return
}

function searchInMapping() {

var searchValue = (document.getElementById("searchMapping") as HTMLInputElement).value
Expand Down
61 changes: 49 additions & 12 deletions ts/menu_ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ class Content {
cell.childType = "IMG"
cell.value = data[key]["x-name"]
cell.imageURL = data[key]["tvg-logo"]
cell.id = "cell" + key
var td = cell.createCell()
td.setAttribute('onclick', 'javascript: openPopUp("mapping", this)')
td.id = key
Expand All @@ -438,6 +439,7 @@ class Content {
cell.childType = "P"
cell.className = data[key]["x-category"]
cell.value = data[key]["x-name"]
cell.id = "cell" + key
var td = cell.createCell()
td.setAttribute('onclick', 'javascript: openPopUp("mapping", this)')
td.id = key
Expand Down Expand Up @@ -544,6 +546,7 @@ class Cell {
imageURL: string
onclick: boolean
onclickFunction: string
id: string

createCell(): any {
let td = document.createElement("TD")
Expand All @@ -557,6 +560,7 @@ class Cell {
element = document.createElement(this.childType);
element.innerHTML = this.value
element.className = this.className
element.id = this.id
break

case "INPUT":
Expand Down Expand Up @@ -590,15 +594,21 @@ class Cell {
case "IMG":
element = document.createElement(this.childType);
element.setAttribute("alt", this.value);
element.onerror = function () {
element.setAttribute("channelID", this.id)

element.onerror = function (this: HTMLImageElement) {
showWarning(this.alt + " has a bad logo URL")
var channelNameID = this.attributes["channelID"].value;
document.getElementById(channelNameID).style.color = "red";
this.src = getDefaultLogo()
this.onerror = null
};
if (this.imageURL === "") {

if (!this.imageURL) {
this.imageURL = getDefaultLogo()
}

element.setAttribute("src", this.imageURL)

}

td.appendChild(element)
Expand All @@ -619,9 +629,10 @@ class Cell {
return td
}

return

}


class ShowContent extends Content {
menuID: number

Expand Down Expand Up @@ -714,6 +725,19 @@ class ShowContent extends Content {
label.innerHTML = "{{.checkbox.shiftChannel.label}}"
interaction.appendChild(label)

var input = this.createInput("checkbox", menuKey, "")
input.setAttribute("id", "badChannels")
input.checked = false
input.setAttribute("title", "{{.checkbox.badLogos.title}}")
input.setAttribute("onchange", 'javascript: searchBadLogos(this.checked)')
interaction.appendChild(input)

var label = document.createElement("label")
label.setAttribute("for", "badLogos")
label.setAttribute("class", "shiftChannelLabel")
label.innerHTML = "{{.checkbox.badLogos.label}}"
interaction.appendChild(label)

var input = this.createInput("search", "search", "")
input.setAttribute("id", "searchMapping")
input.setAttribute("placeholder", "{{.button.search}}")
Expand Down Expand Up @@ -1690,7 +1714,7 @@ function openPopUp(dataType, element) {
currentLogoUrl = data[dbKey]
var input = content.createInput("text", dbKey, data[dbKey])
input.setAttribute("onchange", "javascript: this.className = 'changed'; previewChannelLogo(this.value)")
input.setAttribute("id", "channel-icon")
input.setAttribute("id", "station-logo-picker-input")
content.appendRow("{{.mapping.channelLogo.title}}", input)
}

Expand All @@ -1703,10 +1727,14 @@ function openPopUp(dataType, element) {

// Channel logo update
var dbKey: string = "x-update-channel-icon"
var input = content.createCheckbox(dbKey)
input.checked = data[dbKey]
if (BULK_EDIT) {
var input = content.createCheckbox(dbKey)
input.checked = data[dbKey]
} else {
var input = content.createInput("button", "Use M3U Logo", "Use M3U Logo")
}
input.setAttribute("id", "update-icon")
input.setAttribute("onchange", "javascript: this.className = 'changed'; changeChannelLogo('" + id + "');")
input.setAttribute("onclick", "javascript: this.className = 'changed'; changeChannelLogo('" + id + "');")
content.appendRow("{{.mapping.updateChannelLogo.title}}", input)

// Expand EPG category
Expand Down Expand Up @@ -2004,7 +2032,7 @@ function changeChannelLogo(epgMapId: string) {
const xmlTvIdInput = document.getElementById('xmltv-id-picker-input') as HTMLInputElement;
const newXmlTvId = xmlTvIdInput.value;

const updateLogo = (document.getElementById('update-icon') as HTMLInputElement).checked;
const updateLogo = !BULK_EDIT || (document.getElementById('update-icon') as HTMLInputElement).checked;

let logo: string;

Expand All @@ -2016,7 +2044,7 @@ function changeChannelLogo(epgMapId: string) {
logo = channel['tvg-logo'];
}

var logoInput = (document.getElementById('channel-icon') as HTMLInputElement);
var logoInput = (document.getElementById('station-logo-picker-input') as HTMLInputElement);
logoInput.value = logo;

if (BULK_EDIT == false) {
Expand Down Expand Up @@ -2278,7 +2306,14 @@ function donePopupData(dataType: string, idsStr: string) {


case "tvg-logo":
//(document.getElementById(id).childNodes[2].firstChild as HTMLElement).setAttribute("src", value)
let element = (document.getElementById(id).childNodes[3].firstChild as HTMLElement)
if (!ImageExist(input["tvg-logo"])) {
element.style.color = "red";
showWarning(element.innerText + " has a bad logo URL")
input["tvg-logo"] = getDefaultLogo()
} else {
element.style.color = "white";
}
break

case "x-name":
Expand Down Expand Up @@ -2343,7 +2378,9 @@ function donePopupData(dataType: string, idsStr: string) {
});

showElement("popup", false);

if ((document.getElementById("badChannels") as HTMLInputElement).checked) {
searchBadLogos(true)
}
return
}

Expand Down
12 changes: 0 additions & 12 deletions xteve.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ var h = flag.Bool("h", false, ": Show help")

// Activates Development Mode. The local Files are then used for the Webserver.
var dev = flag.Bool("dev", false, ": Activates the developer mode, the source code must be available. The local files for the web interface are used.")
var buildwebui = flag.Bool("buildwebui", false, ": Builds webUI.go and exits.")

func main() {

Expand Down Expand Up @@ -118,17 +117,6 @@ func main() {
return
}

if *buildwebui {
src.HTMLInit("webUI", "src", "html"+string(os.PathSeparator), "src"+string(os.PathSeparator)+"webUI.go")
err := src.BuildGoFile()
if err != nil {
src.ShowError(err, 0)
} else {
fmt.Println("webUI.go built successfully")
}
os.Exit(0)
}

system.Dev = *dev

// Display System Information
Expand Down