mirror of
https://github.com/go-shiori/shiori.git
synced 2025-01-16 04:48:30 +08:00
6f19c12c95
* added 404 template * added auth domain * added embed file for frontend * added base config and dependencies * added basic new http server * added separated server command * updated go modules * removed modd file * Added shortcut to send internal server error response * Added JWT support to Auth Domain * Added JWT support to API * docs: added comments to response struct * naming * inline returns * updated dependencies * production logger * bookmarks endpoint * reverted old views api path * frontend for api v1 * proper 404 error (not working atm) * use response * removed 404 html * server error handler * login and basic auth * adjusted session duration * properly retrieve tags * properly delete bookmark * cleanup * archiver domain * debug routes * bookmark routes * expiration by parameter * move to logrus * logout * frontend cache * updated dependencies * http: migrated to gin * linted * Added version command * unit tests, docs * response test utils and tests * remove logout handler * auth * createtag * improved http test utilities * assert message equals * Remove 1.19 from test matrix * moved api to v1 folder * docs: contribute docs * updated makefile * updated usage docs * warn in server command * updaed docs with shiori version command * Updated documentation * deps: update
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package domains
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
|
|
"github.com/go-shiori/shiori/internal/core"
|
|
"github.com/go-shiori/shiori/internal/model"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type ArchiverDomain struct {
|
|
dataDir string
|
|
logger *logrus.Logger
|
|
}
|
|
|
|
func (d *ArchiverDomain) DownloadBookmarkArchive(book model.Bookmark) (*model.Bookmark, error) {
|
|
content, contentType, err := core.DownloadBookmark(book.URL)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error downloading url: %s", err)
|
|
}
|
|
|
|
processRequest := core.ProcessRequest{
|
|
DataDir: d.dataDir,
|
|
Bookmark: book,
|
|
Content: content,
|
|
ContentType: contentType,
|
|
}
|
|
|
|
result, isFatalErr, err := core.ProcessBookmark(processRequest)
|
|
content.Close()
|
|
|
|
if err != nil && isFatalErr {
|
|
return nil, fmt.Errorf("failed to process: %v", err)
|
|
}
|
|
|
|
return &result, nil
|
|
}
|
|
|
|
func (d *ArchiverDomain) GetBookmarkArchive(book model.Bookmark) error {
|
|
archivePath := filepath.Join(d.dataDir, "archive", strconv.Itoa(book.ID))
|
|
|
|
info, err := os.Stat(archivePath)
|
|
if !os.IsNotExist(err) && !info.IsDir() {
|
|
return fmt.Errorf("archive not found")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func NewArchiverDomain(logger *logrus.Logger, dataDir string) ArchiverDomain {
|
|
return ArchiverDomain{
|
|
dataDir: dataDir,
|
|
logger: logger,
|
|
}
|
|
}
|