fix: issues with default player
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"backend/pkg/consts"
|
||||
"backend/pkg/errorx"
|
||||
|
||||
@@ -17,7 +19,12 @@ func (f *Middlewares) ParseJWT(c fiber.Ctx) error {
|
||||
token := tokens[0]
|
||||
claim, err := f.jwt.Parse(token)
|
||||
if err != nil {
|
||||
c.ClearCookie("token")
|
||||
c.Cookie(&fiber.Cookie{
|
||||
Name: "token",
|
||||
Value: "",
|
||||
Expires: time.Now().Add(-1 * time.Hour),
|
||||
HTTPOnly: true,
|
||||
})
|
||||
log.Errorf("failed to parse jwt from token: %s", token)
|
||||
return errorx.RequestUnAuthorized
|
||||
}
|
||||
@@ -26,14 +33,24 @@ func (f *Middlewares) ParseJWT(c fiber.Ctx) error {
|
||||
_, err = f.userSvc.GetByOpenID(c.Context(), claim.OpenID)
|
||||
if err != nil {
|
||||
log.Errorf("failed to get user by open id(%s) from token: %s", claim.OpenID, token)
|
||||
c.ClearCookie("token")
|
||||
c.Cookie(&fiber.Cookie{
|
||||
Name: "token",
|
||||
Value: "",
|
||||
Expires: time.Now().Add(-1 * time.Hour),
|
||||
HTTPOnly: true,
|
||||
})
|
||||
return errorx.RequestUnAuthorized
|
||||
}
|
||||
|
||||
_, err = f.userSvc.GetTenantBySlug(c.Context(), claim.Tenant)
|
||||
if err != nil {
|
||||
log.Errorf("failed to get tenant(%s) by from token: %s", claim.Tenant, token)
|
||||
c.ClearCookie("token")
|
||||
c.Cookie(&fiber.Cookie{
|
||||
Name: "token",
|
||||
Value: "",
|
||||
Expires: time.Now().Add(-1 * time.Hour),
|
||||
HTTPOnly: true,
|
||||
})
|
||||
return errorx.RequestUnAuthorized
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,12 @@ func (f *Middlewares) WeChatAuth(c fiber.Ctx) error {
|
||||
if _, err := f.jwt.Parse(jwtToken); err != nil {
|
||||
log.WithError(err).Error("failed to parse jwt token")
|
||||
|
||||
c.ClearCookie("token")
|
||||
c.Cookie(&fiber.Cookie{
|
||||
Name: "token",
|
||||
Value: "",
|
||||
Expires: time.Now().Add(-1 * time.Hour),
|
||||
HTTPOnly: true,
|
||||
})
|
||||
return c.Redirect().To(c.Path())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"backend/modules/users"
|
||||
"backend/pkg/pg"
|
||||
@@ -78,6 +79,7 @@ func (c *Controller) Render(ctx fiber.Ctx) error {
|
||||
ctx.Cookie(&fiber.Cookie{
|
||||
Name: "token",
|
||||
Value: jwtToken,
|
||||
Expires: time.Now().Add(6 * time.Hour),
|
||||
HTTPOnly: true,
|
||||
})
|
||||
|
||||
|
||||
@@ -142,10 +142,19 @@ const play = (hash, type) => {
|
||||
player.play();
|
||||
});
|
||||
} else if (player.canPlayType("application/vnd.apple.mpegurl")) {
|
||||
player.src = source;
|
||||
player.addEventListener("loadedmetadata", function () {
|
||||
player.play();
|
||||
});
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', source, true);
|
||||
xhr.setRequestHeader("Authorization", "Bearer " + __GA);
|
||||
xhr.responseType = 'blob';
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
player.src = URL.createObjectURL(xhr.response);
|
||||
player.addEventListener("loadedmetadata", function () {
|
||||
player.play();
|
||||
});
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user