mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 21:52:01 +08:00
remove confirmation on prefetch
This commit is contained in:
parent
e1c4738b1d
commit
72dda9a1a6
51
prefetch.go
51
prefetch.go
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -13,40 +12,34 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func PrefetchImages(confImgPath string, ExhaustPath string, QUALITY string) {
|
func PrefetchImages(confImgPath string, ExhaustPath string, QUALITY string) {
|
||||||
fmt.Println(`Prefetch will convert all your images to webp,
|
|
||||||
it may take some time and consume a lot of CPU resource. Do you want to proceed(Y/n)`)
|
|
||||||
|
|
||||||
reader := bufio.NewReader(os.Stdin)
|
|
||||||
char, _, _ := reader.ReadRune() //y Y enter
|
|
||||||
// maximum ongoing prefetch is depending on your core of CPU
|
// maximum ongoing prefetch is depending on your core of CPU
|
||||||
log.Infof("Prefetching using %d cores", jobs)
|
log.Infof("Prefetching using %d cores", jobs)
|
||||||
var finishChan = make(chan int, jobs)
|
var finishChan = make(chan int, jobs)
|
||||||
for i := 0; i < jobs; i++ {
|
for i := 0; i < jobs; i++ {
|
||||||
finishChan <- 0
|
finishChan <- 0
|
||||||
}
|
}
|
||||||
if char == 121 || char == 10 || char == 89 {
|
|
||||||
//prefetch, recursive through the dir
|
//prefetch, recursive through the dir
|
||||||
all := FileCount(confImgPath)
|
all := FileCount(confImgPath)
|
||||||
count := 0
|
count := 0
|
||||||
err := filepath.Walk(confImgPath,
|
err := filepath.Walk(confImgPath,
|
||||||
func(picAbsPath string, info os.FileInfo, err error) error {
|
func(picAbsPath string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// RawImagePath string, ImgFilename string, reqURI string
|
// RawImagePath string, ImgFilename string, reqURI string
|
||||||
proposedURI := strings.Replace(picAbsPath, confImgPath, "", 1)
|
proposedURI := strings.Replace(picAbsPath, confImgPath, "", 1)
|
||||||
_, p2 := GenWebpAbs(picAbsPath, ExhaustPath, info.Name(), proposedURI)
|
_, p2 := GenWebpAbs(picAbsPath, ExhaustPath, info.Name(), proposedURI)
|
||||||
q, _ := strconv.ParseFloat(QUALITY, 32)
|
q, _ := strconv.ParseFloat(QUALITY, 32)
|
||||||
_ = os.MkdirAll(path.Dir(p2), 0755)
|
_ = os.MkdirAll(path.Dir(p2), 0755)
|
||||||
go WebpEncoder(picAbsPath, p2, float32(q), false, finishChan)
|
go WebpEncoder(picAbsPath, p2, float32(q), false, finishChan)
|
||||||
count += <-finishChan
|
count += <-finishChan
|
||||||
//progress bar
|
//progress bar
|
||||||
_, _ = fmt.Fprintf(os.Stdout, "[Webp Server started] - convert in progress: %d/%d\r", count, all)
|
_, _ = fmt.Fprintf(os.Stdout, "[Webp Server started] - convert in progress: %d/%d\r", count, all)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug(err)
|
log.Debug(err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = fmt.Fprintf(os.Stdout, "Prefetch completeY(^_^)Y\n\n")
|
_, _ = fmt.Fprintf(os.Stdout, "Prefetch completeY(^_^)Y\n\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user