Skip to content

Commit

Permalink
lazy react components
Browse files Browse the repository at this point in the history
  • Loading branch information
gaohan085 committed Nov 4, 2024
1 parent 7a43eb5 commit 63e0638
Show file tree
Hide file tree
Showing 30 changed files with 591 additions and 516 deletions.
1 change: 1 addition & 0 deletions database/video-convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (v *VideoConvert) ReadProgress(chInter <-chan int, chDone <-chan int) error
}

func (v *VideoConvert) DownloadConverted() error {
fiberlog.Info("Downloading Converted Video " + v.FileName)
downloadLink := os.Getenv("FFMPEG_DOWNLOAD_ADDR")
rootDir := os.Getenv("ROOT_DIR")
var script = fmt.Sprintf(`wget -nc %s -P %s%s/`, downloadLink+v.OutputName, rootDir, v.Path)
Expand Down
5 changes: 5 additions & 0 deletions database/video_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

"github.com/PuerkitoBio/goquery"
"gorm.io/gorm"

fiberlog "github.com/gofiber/fiber/v2/log"
)

var (
Expand Down Expand Up @@ -56,6 +58,7 @@ func (v *VideoInf) QueryByVideoName(n string) error {
}

func (v *VideoInf) GetDetailInfo() error {
fiberlog.Info("Getting Video " + v.SerialNumber + " Info.")
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://javdb.com/search?q="+v.SerialNumber+"&f=all", nil)
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
Expand Down Expand Up @@ -123,6 +126,7 @@ func (v *VideoInf) DownloadPoster() error {
}

//下载封面文件
fiberlog.Info("Downloading Video " + v.SerialNumber + " Poster.")
client := &http.Client{}
req, _ := http.NewRequest("GET", v.SourcePosterUrl, nil)
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36")
Expand All @@ -140,6 +144,7 @@ func (v *VideoInf) DownloadPoster() error {
}

func (v *VideoInf) GetActress() error {
fiberlog.Info("Getting Actress for " + v.SerialNumber)
v.Actress = strings.Split(v.PlaySrc, "/")[4]
return v.Update()
}
3 changes: 1 addition & 2 deletions handlers/delete-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ func DeleteHandler(c *fiber.Ctx) error {

c.BodyParser(&fileinfo)

err := os.RemoveAll(rootDir + fileinfo.CurrentPath + "/" + fileinfo.Name)
if err != nil {
if err := os.RemoveAll(rootDir + fileinfo.CurrentPath + "/" + fileinfo.Name); err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(&RespBody{
StatusCode: 500,
Data: err.Error(),
Expand Down
2 changes: 1 addition & 1 deletion handlers/file-reader-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func FileReaderHandler(c *fiber.Ctx) error {
currentPath = path
}

time.Sleep(250 * time.Millisecond)
time.Sleep(500 * time.Millisecond)
return c.Status(fiber.StatusOK).JSON(&RespBody{
StatusCode: 200,
Data: &Folder{
Expand Down
26 changes: 26 additions & 0 deletions lib/schedule/operate-video-info.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package schedule

import (
"fmt"
"go-fiber-react-ts/database"
"go-fiber-react-ts/lib"
"net/http"
"strings"

fiberlog "github.com/gofiber/fiber/v2/log"
)

func QueryVideoInfo() error {
Expand Down Expand Up @@ -74,3 +78,25 @@ func DownloadConvertedVideo() error {

return nil
}

func CheckVideoExists() error {
var videos = []database.VideoInf{}
fiberlog.Info("Check videos exists")

if err := database.Db.Model(&database.VideoInf{}).Order("ID").Find(&videos).Error; err != nil {
return err
}

for _, video := range videos {
fiberlog.Info(fmt.Sprintf("Checking video %s exists or not", video.SerialNumber))
client := http.Client{}
req, _ := http.NewRequest("GET", video.PlaySrc, nil)
res, _ := client.Do(req)

if res.StatusCode == 403 {
return video.Delete()
}
continue
}
return nil
}
12 changes: 5 additions & 7 deletions lib/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/go-co-op/gocron/v2"
fiberlog "github.com/gofiber/fiber/v2/log"
)

func Schedule() error {
Expand All @@ -20,46 +19,45 @@ func Schedule() error {
schedule.NewJob(
gocron.DurationJob(1*time.Minute),
gocron.NewTask(func() {
fiberlog.Info("Start task 'QueryVideoInfo'")
QueryVideoInfo()
}),
)
schedule.NewJob(
gocron.DurationRandomJob(30*time.Second, 3*time.Minute),
gocron.NewTask(func() {
fiberlog.Info("Start task 'DownloadVideoPoster'")
DownloadVideoPoster()
}),
)
schedule.NewJob(
gocron.DurationJob(5*time.Second),
gocron.NewTask(func() {
fiberlog.Info("Start task 'GetActress'")
GetActress()
}),
)

schedule.NewJob(
gocron.DurationJob(1*time.Minute),
gocron.NewTask(func() {
fiberlog.Info("Start task 'RemoveErrorSerialNum'")
RemoveErrorSerialNum()
}),
)

schedule.NewJob(
gocron.DurationJob(60*time.Second),
gocron.NewTask(func() {
fiberlog.Info("Start task 'DownloadConvertedVideo'")
DownloadConvertedVideo()
}),
)

schedule.NewJob(
gocron.DailyJob(1, gocron.NewAtTimes(gocron.NewAtTime(0, 0, 0))),
gocron.NewTask(CheckVideoExists),
)

case "ffmpeg":
schedule.NewJob(
gocron.DurationJob(30*time.Second),
gocron.NewTask(func() {
fiberlog.Info("Start task 'database.StartConvert'")
database.StartConvert()
}),
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:dev": "webpack --mode=development",
"build:watch": "webpack --mode=production --node-env=production --watch",
"watch": "webpack --watch",
"serve": "webpack serve"
"serve": "webpack serve --node-env=development"
},
"keywords": [],
"author": "",
Expand Down
Loading

0 comments on commit 63e0638

Please sign in to comment.