Skip to content
This repository has been archived by the owner on Jul 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from gazes-media/main
Browse files Browse the repository at this point in the history
Add Major updates (Video preview on Discord)
  • Loading branch information
exatombe authored Dec 4, 2023
2 parents 88a3fdb + 822ff8a commit ab16749
Show file tree
Hide file tree
Showing 29 changed files with 256 additions and 38 deletions.
45 changes: 45 additions & 0 deletions functions/cacheManager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package functions

import (
"os"
"sync"
"time"
)

type Cache struct {
data map[string]interface{}
mutex sync.RWMutex
}

func NewCache() *Cache {
return &Cache{
data: make(map[string]interface{}),
}
}

func (c *Cache) Set(key string, value interface{}) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.data[key] = value
// auto remove after 12 hours
go func() {
time.Sleep(12 * time.Hour)
e := os.Remove(value.(string))
if e == nil {
c.Remove(key)
}
}()
}

func (c *Cache) Get(key string) (interface{}, bool) {
c.mutex.RLock()
defer c.mutex.RUnlock()
value, found := c.data[key]
return value, found
}

func (c *Cache) Remove(key string) {
c.mutex.Lock()
defer c.mutex.Unlock()
delete(c.data, key)
}
24 changes: 24 additions & 0 deletions functions/httpClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package functions

import (
"net/http"
"crypto/tls"
)

type HttpClient struct {
client *http.Client
}

func NewHttpClient() *HttpClient {
return &HttpClient{
client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // ignore expired SSL certificates
},
},
}
}

func (c *HttpClient) Get(url string) (*http.Response, error) {
return c.client.Get(url)
}
2 changes: 2 additions & 0 deletions functions/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func metaVideo(url string) string {
<meta property="og:image:height" content="720">
<meta property="og:image:type" content="image/jpeg">
<meta property="twitter:player" content="` + url + `">
<meta name="twitter:player:stream" content="` + url + `/mp4" />
<meta name="twitter:player:stream:content_type" content="video/mp4" />
<meta property="twitter:player:width" content="1280">
<meta property="twitter:player:height" content="720">`
}
Expand Down
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package main

import (
"gazes_ssr/functions"
"gazes_ssr/routes"
"io/fs"
"log"
"net/http"
"os"

"github.com/gorilla/mux"
)

var fsys fs.FS
var static http.Handler
var port string = "5454"
var cache = functions.NewCache()

func init() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
Expand Down Expand Up @@ -83,6 +83,16 @@ func main() {
}
routes.EpisodeHandler(w, r, id, episode)
}))
router.Handle("/anime/{id}/episode/{episode}/mp4", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
id := mux.Vars(r)["id"]
episode := mux.Vars(r)["episode"]
if id == "" || episode == "" {
routes.NotFoundHandler(w, r)
return
}
routes.DownloadHandler(w, r, id, episode, cache)
}))

router.HandleFunc("/history", func(w http.ResponseWriter, r *http.Request) {
routes.HistoryHandler(w, r)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions public/assets/prod-127d96e2.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion public/assets/prod-c7a7ffcc.js.map

This file was deleted.

Loading

0 comments on commit ab16749

Please sign in to comment.