MCPcopy Index your code
hub / github.com/TruthHun/BookStack / RenderCoverByBookIdentify

Function RenderCoverByBookIdentify

utils/util.go:221–253  ·  view source on GitHub ↗

生成

(identify string)

Source from the content-addressed store, hash-verified

219
220// 生成
221func RenderCoverByBookIdentify(identify string) (err error) {
222 var args []string
223 shotJS := "cover.js"
224 if _, err = os.Stat(shotJS); err != nil {
225 err = ioutil.WriteFile(shotJS, []byte(screenshotCoverJS), os.ModePerm)
226 }
227 if err != nil {
228 return
229 }
230
231 //使用chromium-browser
232 // chromium-browser --headless --disable-gpu --screenshot --no-sandbox --window-size=320,480 http://www.bookstack.cn
233 link := "http://localhost:" + beego.AppConfig.DefaultString("httpport", "8181") + "/local-render-cover?id=" + identify
234 name := "node"
235 if ok := beego.AppConfig.DefaultBool("puppeteer", false); ok {
236 args = []string{shotJS, "--identify", identify, "--url", link}
237 } else {
238 err = errors.New("请安装并启用puppeteer")
239 return
240 }
241 cmd := exec.Command(name, args...)
242 beego.Info("render cover by book id:", cmd.Args)
243 // 超过30秒,杀掉进程,避免长期占用
244 time.AfterFunc(httpTimeout, func() {
245 if cmd.Process != nil && cmd.Process.Pid != 0 {
246 cmd.Process.Kill()
247 }
248 })
249 if err = cmd.Run(); err != nil {
250 beego.Error(err)
251 }
252 return
253}
254
255// 使用chrome采集网页HTML
256func CrawlByChrome(urlStr string, bookIdentify string) (cont string, err error) {

Callers 2

GenerateBookMethod · 0.92
generateMethod · 0.92

Calls 1

RunMethod · 0.80

Tested by

no test coverage detected