Skip to content

Commit

Permalink
fix playlist upload
Browse files Browse the repository at this point in the history
Signed-off-by: jbpratt <jbpratt78@gmail.com>
  • Loading branch information
jbpratt committed Mar 24, 2024
1 parent 0d881ac commit 32f7ec5
Showing 1 changed file with 14 additions and 29 deletions.
43 changes: 14 additions & 29 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var (
const (
hasteURL = "https://hastebin.com"
ytURLStart = "https://www.youtube.com/watch?v="
uguuURL = "https://uguu.se/api.php?d=upload-tool"
uploadURL = "https://st.pepog.com"
tmpFile = "tmp.txt"
)

Expand Down Expand Up @@ -249,7 +249,7 @@ func (c *controller) onPrivMessage(m dggchat.PrivateMessage, s *dggchat.Session)
return
}

c.sendMsg("unknown command", m.User.Nick)
c.sendMsg("unknown command: see https://github.com/SoMuchForSubtlety/strims-radio?tab=readme-ov-file#commands for help", m.User.Nick)
}

func onError(e string, s *dggchat.Session) {
Expand Down Expand Up @@ -479,35 +479,20 @@ func (c *controller) isMod(nick string) bool {

func (c *controller) uploadString(text string) (url string, err error) {
var file *os.File

type resp struct {
response *haste.Response
er error
err = os.WriteFile(tmpFile, []byte(text), 0o644)
if err != nil {
return url, err
}

c1 := make(chan resp)
go func() {
hasteResp, err := c.haste.UploadString(text)
c1 <- resp{response: hasteResp, er: err}
}()

select {
case res := <-c1:
err = res.er
url = hasteURL + "/raw/" + res.response.Key
case <-time.After(1 * time.Second):
// TODO: find a better way to do this
err = os.WriteFile(tmpFile, []byte(text), 0o644)
if err != nil {
return url, err
}
file, err = os.Open(tmpFile)
if err != nil {
return url, err
}
url, err = fileupload.UploadToHost(uguuURL, file)
file, err = os.Open(tmpFile)
if err != nil {
return url, err
}

url, err = fileupload.UploadToHost(uploadURL, file)
if err != nil {
return url, err
}
// st.pepog.com returns two urls, take the first one
url = strings.SplitAfter(url, "txt")[0]
return url, err
}

Expand Down

0 comments on commit 32f7ec5

Please sign in to comment.