Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate bookmark static pages to new http server #775

Merged
merged 27 commits into from Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e08a22c
migrate bookmark content route to new http server
fmartingr Nov 11, 2023
4159d5e
new archive page
fmartingr Nov 12, 2023
776b86b
Merge remote-tracking branch 'origin/master' into feat/bookmark-http-new
fmartingr Nov 12, 2023
46f5645
Merge remote-tracking branch 'origin/master' into feat/bookmark-http-new
fmartingr Nov 12, 2023
1b49d90
remove unused go generate comment
fmartingr Nov 18, 2023
bb84c19
database mock
fmartingr Nov 18, 2023
600e741
utils cleanup
fmartingr Nov 18, 2023
887d23f
unused var
fmartingr Nov 18, 2023
68f12ef
domains refactor and tests
fmartingr Nov 18, 2023
7a2ad09
Merge remote-tracking branch 'origin/master' into feat/bookmark-http-new
fmartingr Nov 18, 2023
939f394
fixed secret key type
fmartingr Dec 10, 2023
336528d
redirect to login on ui errors
fmartingr Dec 10, 2023
bb64c1e
fixed archive folder with storage domain
fmartingr Dec 10, 2023
0e971a7
webroot documentation
fmartingr Dec 10, 2023
f32035b
some bookmark route tests
fmartingr Dec 10, 2023
d64b2b4
fixed error in bookmark domain for non existant bookmarks
fmartingr Dec 10, 2023
0f9eb6c
centralice errors
fmartingr Dec 10, 2023
9953175
Merge remote-tracking branch 'origin/master' into feat/bookmark-http-new
fmartingr Dec 10, 2023
0bcf5d9
add coverage data to unittests
fmartingr Dec 10, 2023
76dccde
Merge remote-tracking branch 'origin/master' into feat/bookmark-http-new
fmartingr Dec 10, 2023
f1a1305
added tests, refactor storage to use afero
fmartingr Dec 17, 2023
692b157
removed mock to avoid increasing complexity
fmartingr Dec 25, 2023
467e296
using deps to copy files around
fmartingr Dec 25, 2023
230fab4
remove config usage (to deps)
fmartingr Dec 25, 2023
dc1ee48
remove handler-ui file
fmartingr Dec 25, 2023
c5fbc1d
Merge branch 'master' into feat/bookmark-http-new
fmartingr Dec 27, 2023
15c19df
Merge remote-tracking branch 'origin/master' into feat/bookmark-http-new
fmartingr Dec 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/cmd/add.go
Expand Up @@ -45,7 +45,7 @@ func addHandler(cmd *cobra.Command, args []string) {
excerpt = normalizeSpace(excerpt)

// Create bookmark item
book := model.Bookmark{
book := model.BookmarkDTO{
URL: url,
Title: title,
Excerpt: excerpt,
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/check.go
Expand Up @@ -76,7 +76,7 @@ func checkHandler(cmd *cobra.Command, args []string) {
for i, book := range bookmarks {
wg.Add(1)

go func(i int, book model.Bookmark) {
go func(i int, book model.BookmarkDTO) {
// Make sure to finish the WG
defer wg.Done()

Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/import.go
Expand Up @@ -52,7 +52,7 @@ func importHandler(cmd *cobra.Command, args []string) {
defer srcFile.Close()

// Parse bookmark's file
bookmarks := []model.Bookmark{}
bookmarks := []model.BookmarkDTO{}
mapURL := make(map[string]struct{})

doc, err := goquery.NewDocumentFromReader(srcFile)
Expand Down Expand Up @@ -135,7 +135,7 @@ func importHandler(cmd *cobra.Command, args []string) {
}

// Add item to list
bookmark := model.Bookmark{
bookmark := model.BookmarkDTO{
URL: url,
Title: title,
Tags: tags,
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/pocket.go
Expand Up @@ -36,7 +36,7 @@ func pocketHandler(cmd *cobra.Command, args []string) {
defer srcFile.Close()

// Parse pocket's file
bookmarks := []model.Bookmark{}
bookmarks := []model.BookmarkDTO{}
mapURL := make(map[string]struct{})

doc, err := goquery.NewDocumentFromReader(srcFile)
Expand Down Expand Up @@ -93,7 +93,7 @@ func pocketHandler(cmd *cobra.Command, args []string) {
}

// Add item to list
bookmark := model.Bookmark{
bookmark := model.BookmarkDTO{
URL: url,
Title: title,
Modified: modified.Format(model.DatabaseDateFormat),
Expand Down
6 changes: 4 additions & 2 deletions internal/cmd/root.go
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/go-shiori/shiori/internal/config"
"github.com/go-shiori/shiori/internal/database"
"github.com/go-shiori/shiori/internal/dependencies"
"github.com/go-shiori/shiori/internal/domains"
"github.com/go-shiori/shiori/internal/model"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -47,7 +48,7 @@ func ShioriCmd() *cobra.Command {
return rootCmd
}

func initShiori(ctx context.Context, cmd *cobra.Command) (*config.Config, *config.Dependencies) {
func initShiori(ctx context.Context, cmd *cobra.Command) (*config.Config, *dependencies.Dependencies) {
logger := logrus.New()

portableMode, _ := cmd.Flags().GetBool("portable")
Expand Down Expand Up @@ -96,9 +97,10 @@ func initShiori(ctx context.Context, cmd *cobra.Command) (*config.Config, *confi
logger.Warn("Development mode is ENABLED, this will enable some helpers for local development, unsuitable for production environments")
}

dependencies := config.NewDependencies(logger, db, cfg)
dependencies := dependencies.NewDependencies(logger, db, cfg)
dependencies.Domains.Auth = domains.NewAccountsDomain(logger, cfg.Http.SecretKey, db)
dependencies.Domains.Archiver = domains.NewArchiverDomain(logger, cfg.Storage.DataDir)
dependencies.Domains.Bookmarks = domains.NewBookmarksDomain(logger, db, cfg)

// Workaround: Get accounts to make sure at least one is present in the database.
// If there's no accounts in the database, create the shiori/gopher account the legacy api
Expand Down
5 changes: 4 additions & 1 deletion internal/cmd/server.go
Expand Up @@ -66,7 +66,10 @@ func newServerCommandHandler() func(cmd *cobra.Command, args []string) {

dependencies.Log.Infof("Starting Shiori v%s", model.BuildVersion)

server := http.NewHttpServer(dependencies.Log).Setup(cfg, dependencies)
server, err := http.NewHttpServer(dependencies.Log).Setup(cfg, dependencies)
if err != nil {
dependencies.Log.WithError(err).Fatal("error setting up server")
}

if err := server.Start(ctx); err != nil {
dependencies.Log.WithError(err).Fatal("error starting server")
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/update.go
Expand Up @@ -147,7 +147,7 @@ func updateHandler(cmd *cobra.Command, args []string) {
book.URL = url
}

go func(i int, book model.Bookmark) {
go func(i int, book model.BookmarkDTO) {
// Make sure to finish the WG
defer wg.Done()

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/utils.go
Expand Up @@ -41,7 +41,7 @@ func isURLValid(s string) bool {
return err == nil && tmp.Scheme != "" && tmp.Hostname() != ""
}

func printBookmarks(bookmarks ...model.Bookmark) {
func printBookmarks(bookmarks ...model.BookmarkDTO) {
for _, bookmark := range bookmarks {
// Create bookmark index
strBookmarkIndex := fmt.Sprintf("%d. ", bookmark.ID)
Expand Down
2 changes: 1 addition & 1 deletion internal/core/ebook.go
Expand Up @@ -15,7 +15,7 @@ import (
// GenerateEbook receives a `ProcessRequest` and generates an ebook file in the destination path specified.
// The destination path `dstPath` should include file name with ".epub" extension
// The bookmark model will be used to update the UI based on whether this function is successful or not.
func GenerateEbook(req ProcessRequest, dstPath string) (book model.Bookmark, err error) {
func GenerateEbook(req ProcessRequest, dstPath string) (book model.BookmarkDTO, err error) {

book = req.Bookmark

Expand Down
14 changes: 7 additions & 7 deletions internal/core/ebook_test.go
Expand Up @@ -19,7 +19,7 @@ func TestGenerateEbook(t *testing.T) {
dstDir := t.TempDir()

mockRequest := core.ProcessRequest{
Bookmark: model.Bookmark{
Bookmark: model.BookmarkDTO{
ID: 1,
Title: "Example Bookmark",
HTML: "<html><body>Example HTML</body></html>",
Expand All @@ -39,7 +39,7 @@ func TestGenerateEbook(t *testing.T) {
dstDir := t.TempDir()

mockRequest := core.ProcessRequest{
Bookmark: model.Bookmark{
Bookmark: model.BookmarkDTO{
ID: 1,
HasEbook: false,
},
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestGenerateEbook(t *testing.T) {
dstDir := t.TempDir()

mockRequest := core.ProcessRequest{
Bookmark: model.Bookmark{
Bookmark: model.BookmarkDTO{
ID: 1,
HasEbook: false,
},
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestGenerateEbook(t *testing.T) {
t.Run("invalid bookmarkId that return Error", func(t *testing.T) {
tempDir := t.TempDir()
mockRequest := core.ProcessRequest{
Bookmark: model.Bookmark{
Bookmark: model.BookmarkDTO{
ID: 0,
HasEbook: false,
},
Expand All @@ -114,7 +114,7 @@ func TestGenerateEbook(t *testing.T) {

bookmark, err := core.GenerateEbook(mockRequest, tempDir)

assert.Equal(t, model.Bookmark{
assert.Equal(t, model.BookmarkDTO{
ID: 0,
HasEbook: false,
}, bookmark)
Expand All @@ -125,7 +125,7 @@ func TestGenerateEbook(t *testing.T) {
dstDir := t.TempDir()

mockRequest := core.ProcessRequest{
Bookmark: model.Bookmark{
Bookmark: model.BookmarkDTO{
ID: 1,
HasEbook: false,
},
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestGenerateEbook(t *testing.T) {
tempDir := t.TempDir()

mockRequest := core.ProcessRequest{
Bookmark: model.Bookmark{
Bookmark: model.BookmarkDTO{
ID: 1,
HasEbook: false,
},
Expand Down
4 changes: 2 additions & 2 deletions internal/core/processing.go
Expand Up @@ -30,7 +30,7 @@ import (
// ProcessRequest is the request for processing bookmark.
type ProcessRequest struct {
DataDir string
Bookmark model.Bookmark
Bookmark model.BookmarkDTO
Content io.Reader
ContentType string
KeepTitle bool
Expand All @@ -42,7 +42,7 @@ var ErrNoSupportedImageType = errors.New("unsupported image type")

// ProcessBookmark process the bookmark and archive it if needed.
// Return three values, is error fatal, and error value.
func ProcessBookmark(req ProcessRequest) (book model.Bookmark, isFatalErr bool, err error) {
func ProcessBookmark(req ProcessRequest) (book model.BookmarkDTO, isFatalErr bool, err error) {
book = req.Bookmark
contentType := req.ContentType

Expand Down
14 changes: 7 additions & 7 deletions internal/core/processing_test.go
Expand Up @@ -104,7 +104,7 @@ func TestDownloadBookImage(t *testing.T) {
func TestProcessBookmark(t *testing.T) {
t.Run("ProcessRequest with sucssesful result", func(t *testing.T) {
t.Run("Normal without image", func(t *testing.T) {
bookmark := model.Bookmark{
bookmark := model.BookmarkDTO{
ID: 1,
URL: "https://example.com",
Title: "Example",
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestProcessBookmark(t *testing.T) {
<p>This is an example article</p>
</body>
</html>`
bookmark := model.Bookmark{
bookmark := model.BookmarkDTO{
ID: 1,
URL: "https://example.com",
Title: "Example",
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestProcessBookmark(t *testing.T) {
<p>This is an example article</p>
</body>
</html>`
bookmark := model.Bookmark{
bookmark := model.BookmarkDTO{
ID: 1,
URL: "https://example.com",
Title: "Example",
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestProcessBookmark(t *testing.T) {
}
})
t.Run("ProcessRequest sucssesful with empty title ", func(t *testing.T) {
bookmark := model.Bookmark{
bookmark := model.BookmarkDTO{
ID: 1,
URL: "https://example.com",
Title: "",
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestProcessBookmark(t *testing.T) {
}
})
t.Run("ProcessRequest sucssesful with empty Excerpt", func(t *testing.T) {
bookmark := model.Bookmark{
bookmark := model.BookmarkDTO{
ID: 1,
URL: "https://example.com",
Title: "",
Expand Down Expand Up @@ -299,7 +299,7 @@ func TestProcessBookmark(t *testing.T) {
t.Run("Specific case", func(t *testing.T) {
t.Run("ProcessRequest with ID zero", func(t *testing.T) {

bookmark := model.Bookmark{
bookmark := model.BookmarkDTO{
ID: 0,
URL: "https://example.com",
Title: "Example",
Expand All @@ -324,7 +324,7 @@ func TestProcessBookmark(t *testing.T) {

t.Run("ProcessRequest that content type not zero", func(t *testing.T) {

bookmark := model.Bookmark{
bookmark := model.BookmarkDTO{
ID: 1,
URL: "https://example.com",
Title: "Example",
Expand Down
6 changes: 3 additions & 3 deletions internal/database/database.go
Expand Up @@ -72,10 +72,10 @@ type DB interface {
Migrate() error

// SaveBookmarks saves bookmarks data to database.
SaveBookmarks(ctx context.Context, create bool, bookmarks ...model.Bookmark) ([]model.Bookmark, error)
SaveBookmarks(ctx context.Context, create bool, bookmarks ...model.BookmarkDTO) ([]model.BookmarkDTO, error)

// GetBookmarks fetch list of bookmarks based on submitted options.
GetBookmarks(ctx context.Context, opts GetBookmarksOptions) ([]model.Bookmark, error)
GetBookmarks(ctx context.Context, opts GetBookmarksOptions) ([]model.BookmarkDTO, error)

// GetBookmarksCount get count of bookmarks in database.
GetBookmarksCount(ctx context.Context, opts GetBookmarksOptions) (int, error)
Expand All @@ -84,7 +84,7 @@ type DB interface {
DeleteBookmarks(ctx context.Context, ids ...int) error

// GetBookmark fetches bookmark based on its ID or URL.
GetBookmark(ctx context.Context, id int, url string) (model.Bookmark, bool, error)
GetBookmark(ctx context.Context, id int, url string) (model.BookmarkDTO, bool, error)

// SaveAccount saves new account in database
SaveAccount(ctx context.Context, a model.Account) error
Expand Down