Skip to content

Commit

Permalink
api fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyun8023 committed Aug 4, 2024
1 parent a40440f commit 3785504
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ ENV CALIBRE_STATIC_DIR=/app/static

WORKDIR /app
COPY --from=build /calibre-api ./calibre-api
COPY config.yaml ./
COPY config.yaml ./config-example.yaml

COPY --from=app /app/dist/ ./templates
COPY --from=app /app/dist/ /app/static


EXPOSE 8080
Expand Down
35 changes: 30 additions & 5 deletions app/calibre-pages/src/views/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@

<el-button text bg @click="copyToClipboard(book.id)">{{ book.id }}📋</el-button>
</el-descriptions-item>
<el-descriptions-item label="Authors">
<el-descriptions-item>
<template #label>
<div class="cell-item">
<el-icon :style="iconStyle">
<user />
</el-icon>
Authors
</div>
</template>
<el-tag
class="tag-spacing"
v-for="item in book.authors"
Expand All @@ -43,11 +51,27 @@
{{ item }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item label="Publisher">
<el-descriptions-item>
<template #label>
<div class="cell-item">
<el-icon :style="iconStyle">
<Discount />
</el-icon>
Publisher
</div>
</template>
<span @click="searchByPublisher" >{{ book.publisher }}</span>
</el-descriptions-item>
<el-descriptions-item label="ISBN">{{ book.isbn }}</el-descriptions-item>
<el-descriptions-item label="Published Date">
<el-descriptions-item>
<template #label>
<div class="cell-item">
<el-icon :style="iconStyle">
<Timer />
</el-icon>
Published Date
</div>
</template>
<span class="tag-spacing">{{ new Date(book.pubdate).toLocaleDateString() }}</span>
</el-descriptions-item>
<el-descriptions-item v-if="book.tags && book.tags.length" label="Tags">
Expand All @@ -61,8 +85,9 @@
</el-descriptions>
<el-row class="book-buttons">
<el-button
type="primary"
color="#626aef"
:xs="24"
:icon="Download"
plain
:disabled="!book.file_path"
@click="redirectToDownload(book.file_path)"
Expand All @@ -72,7 +97,7 @@
</el-button>
<el-popconfirm title="确定删除?" @confirm="deleteBook(book.id)">
<template #reference>
<el-button :xs="24" class="delete-button">删除书籍</el-button>
<el-button :icon="Delete" :xs="24" class="delete-button">删除书籍</el-button>
</template>
</el-popconfirm>
</el-row>
Expand Down
13 changes: 6 additions & 7 deletions internal/calibre/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ type BookRaw struct {
}

type Config struct {
Address string `mapstructure:"address"`
Debug bool `mapstructure:"debug"`
StaticDir string `mapstructure:"static_dir"`
TemplateDir string `mapstructure:"template_dir"`
Content Content `mapstructure:"content"`
Search Search `mapstructure:"search"`
Storage Storage `mapstructure:"storage"`
Address string `mapstructure:"address"`
Debug bool `mapstructure:"debug"`
StaticDir string `mapstructure:"staticDir"`
Content Content `mapstructure:"content"`
Search Search `mapstructure:"search"`
Storage Storage `mapstructure:"storage"`
}

type Content struct {
Expand Down
17 changes: 6 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ func main() {
r := gin.Default()
setPages(r, conf)
calibre.NewClient(conf).SetupRouter(r)
//if l, err := lanzou.NewClient(); err == nil {
// l.SetupRouter(r)
//}
// print router
for _, route := range r.Routes() {
log.Infof("route: %s %s", route.Method, route.Path)
}
Expand All @@ -34,26 +30,26 @@ func main() {

func setPages(r *gin.Engine, conf *calibre.Config) {
// 配置静态文件目录
r.Static("/assets", conf.TemplateDir+"/assets")
r.Static("/assets", conf.StaticDir+"/assets")

// 配置模板目录
//r.LoadHTMLGlob(conf.TemplateDir + "/*")
r.GET("/", func(c *gin.Context) {
//c.HTML(http.StatusOK, "index.html", nil)
c.File(conf.TemplateDir + "/index.html")
c.File(conf.StaticDir + "/index.html")
})
r.GET("/index", func(c *gin.Context) {
//c.HTML(http.StatusOK, "index.html", nil)
c.File(conf.TemplateDir + "/index.html")
c.File(conf.StaticDir + "/index.html")
})
r.GET("/favico.ico", func(c *gin.Context) {
//c.HTML(http.StatusOK, "index.html", nil)
c.File(conf.TemplateDir + "/favico.ico")
c.File(conf.StaticDir + "/favico.ico")
})

// Serve the index.html file for all other routes
r.NoRoute(func(c *gin.Context) {
c.File(conf.TemplateDir + "/index.html")
c.File(conf.StaticDir + "/index.html")
})

//// Serve the settings page
Expand Down Expand Up @@ -83,8 +79,7 @@ func initConfig() *calibre.Config {
viper.AddConfigPath("$HOME/.calibre-api")
viper.AddConfigPath(".")
viper.SetDefault("address", ":8080")
viper.SetDefault("static_dir", "./pages/static")
viper.SetDefault("template_dir", "./pages/templates")
viper.SetDefault("staticDir", "./static")
viper.SetEnvPrefix("CALIBRE")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
Expand Down

0 comments on commit 3785504

Please sign in to comment.