Skip to content

Commit

Permalink
update: add configuration for auto fill metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijit-hota committed May 1, 2022
1 parent f2e2c9c commit db0646d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions api/bingo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
DatabasePath = "../links.db"
ShouldSaveOffline = true
AutofillURLData = true
16 changes: 13 additions & 3 deletions api/handlers/save_bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
DB "bingo/api/db"
"bingo/api/utils"
"database/sql"
"fmt"
"log"
"net/http"
"time"
Expand All @@ -14,16 +15,25 @@ import (

var db *sql.DB = DB.GetDB()

var config utils.Config

func init() {
config = utils.GetConfig()
}

func AddBookmark(ctx *gin.Context) {
var json DB.Bookmark

if err := ctx.ShouldBindJSON(&json); err != nil {
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
if err := common.GetMetadata(json.URL, &json.Meta); err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
fmt.Println(config)
if config.AutofillURLData {
if err := common.GetMetadata(json.URL, &json.Meta); err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
}

statement, err := db.Prepare("INSERT INTO meta (title, description, favicon) VALUES (?, ?, ?)")
Expand Down
1 change: 1 addition & 0 deletions api/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
type Config struct {
DatabasePath string
ShouldSaveOffline bool
AutofillURLData bool
}

var config Config
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

## Todo

- [] Update /add route to support title, meta data, etc, auto fill missing data[1]
- [] 1) Auto fill missing data configuration
- [x] Update /add route to support title, meta data, etc, auto fill missing data[1]
- [x] 1) Auto fill missing data configuration
- [] Add support for tags
- [] tags table?
- [] Add /get route
Expand Down

0 comments on commit db0646d

Please sign in to comment.