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

Run legacy API and new API at the same time. #648

Merged
merged 37 commits into from Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6d897b6
config: backwards comptabile dir
fmartingr Jul 18, 2023
fb81abd
remove duplicated frontend
fmartingr Jul 18, 2023
3a51281
frontend: move assets to assets folder
fmartingr Jul 18, 2023
4674916
legacy routes handler in gin
fmartingr Jul 18, 2023
f7be9f6
templates and asset in different embed
fmartingr Jul 18, 2023
6338edb
new routes
fmartingr Jul 18, 2023
285e0c2
frontend routes serve old views
fmartingr Jul 18, 2023
81c28a8
added DTO for account object
fmartingr Jul 18, 2023
e19cd7a
api auth calls legacy handler
fmartingr Jul 18, 2023
f410e19
frontend: handle new error messages
fmartingr Jul 18, 2023
44f8e17
frontend: update urls
fmartingr Jul 18, 2023
8475e84
frontend: login using new api
fmartingr Jul 18, 2023
1e73322
updated frontend tests
fmartingr Jul 18, 2023
ffd490b
chore: remove debug route
fmartingr Jul 18, 2023
f9667c0
create shiori/gopher user if no owner is present
fmartingr Jul 18, 2023
d2a5c7e
server as default command
fmartingr Jul 18, 2023
d9413e2
serve -> server
fmartingr Jul 19, 2023
5a3fd7c
refactored database logic, allow database url
fmartingr Jul 19, 2023
83bbb45
removed unused configuration
fmartingr Jul 19, 2023
2feeb19
storage docs
fmartingr Jul 19, 2023
b3d8c7f
refactor cli to use cfg and deps
fmartingr Jul 19, 2023
f6690d1
check errors only in server
fmartingr Jul 19, 2023
42a1e75
log fatal instead of os exit
fmartingr Jul 19, 2023
21222a8
dont default data directory to current dir
fmartingr Jul 19, 2023
127ff0b
fixed sqlite path
fmartingr Jul 19, 2023
65a66e8
trigger build on prs
fmartingr Jul 19, 2023
a2d2f0a
avoid releasing if lint/test fails
fmartingr Jul 19, 2023
8f19332
pull request condition
fmartingr Jul 19, 2023
c96a830
event -> event_name
fmartingr Jul 19, 2023
a4b9845
Get correct pull request number
fmartingr Jul 19, 2023
86cd9f2
added workflow to delete dangling tags
fmartingr Jul 19, 2023
cad4f7d
fix: nil error checking
fmartingr Jul 19, 2023
ae41b0f
set gin mode first
fmartingr Jul 19, 2023
479425f
set gin mode before initialization
fmartingr Jul 19, 2023
6ea3ca5
fix logger
fmartingr Jul 19, 2023
59f16a1
allow version bump from custom ref
fmartingr Jul 19, 2023
a1b71a1
Updated matrix link to workspace
fmartingr Jul 19, 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
22 changes: 18 additions & 4 deletions .github/workflows/_buildx.yml
Expand Up @@ -23,10 +23,10 @@ jobs:
mv binaries/shiori_linux_amd64_v1 binaries/shiori_linux_amd64
gzip -d -S binaries/.gz__ -r .
chmod 755 binaries/shiori_linux_*/shiori
- name: Buildx
working-directory: .github/workflows/docker
- name: Prepare master push tags
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u "${{ github.repository_owner }}" --password-stdin ghcr.io
echo "tag_flags=--tag ${{ github.ref }}" >> $GITHUB_ENV
REPO=ghcr.io/${{ github.repository }}
TAG=$(git describe --tags)
if [ -z "$(git tag --points-at HEAD)" ]
Expand All @@ -35,5 +35,19 @@ jobs:
else
TAG2="latest"
fi
echo "tag_flags=--tag $REPO:$TAG --tag $REPO:$TAG2" >> $GITHUB_ENV

- name: Prepare pull request tags
if: github.event_name == 'pull_request'
run: |
echo "tag_flags=--tag ${{ github.ref }}" >> $GITHUB_ENV
REPO=ghcr.io/${{ github.repository }}
echo "tag_flags=--tag $REPO:pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV

- name: Buildx
working-directory: .github/workflows/docker
run: |
set -x
echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u "${{ github.repository_owner }}" --password-stdin ghcr.io
docker buildx create --use --name builder
docker buildx build -f Dockerfile.ci --platform=linux/amd64,arm64,linux/arm/v7 --push --output=type=registry --tag $REPO:$TAG --tag $REPO:$TAG2 .
docker buildx build -f Dockerfile.ci --platform=linux/amd64,arm64,linux/arm/v7 --push ${{ env.tag_flags }} .
14 changes: 14 additions & 0 deletions .github/workflows/_delete-registry-tag.yml
@@ -0,0 +1,14 @@
name: Delete registry tag

on: workflow_call

jobs:
purge-image:
name: Delete tag
runs-on: ubuntu-latest
steps:
- uses: chipkent/action-cleanup-package@1316a66015b82d745b57acbb6c570f2bb1d108f9 # v1.0.3
with:
package-name: ${{ github.event.repository.name }}
tag: ${{ env.TAG_NAME }}
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/docker/Dockerfile.ci
Expand Up @@ -8,4 +8,4 @@ WORKDIR /shiori
EXPOSE 8080
ENV SHIORI_DIR=/shiori
ENTRYPOINT ["/usr/bin/shiori"]
CMD ["serve"]
CMD ["server"]
9 changes: 8 additions & 1 deletion .github/workflows/pull_request.yml
Expand Up @@ -2,7 +2,8 @@ name: 'Pull Request'

on:
pull_request:
branches: master
branches:
- master

concurrency:
group: ci-tests-${{ github.ref }}-1
Expand All @@ -13,3 +14,9 @@ jobs:
uses: ./.github/workflows/_golangci-lint.yml
call-test:
uses: ./.github/workflows/_test.yml
call-gorelease:
needs: [call-lint, call-test]
uses: ./.github/workflows/_gorelease.yml
call-buildx:
needs: call-gorelease
uses: ./.github/workflows/_buildx.yml
12 changes: 12 additions & 0 deletions .github/workflows/pull_request_closed.yml
@@ -0,0 +1,12 @@
name: 'Clean up Docker images from PR'

on:
pull_request:
types:
- closed

jobs:
delete-tag:
uses: ./.github/workflows/_delete-registry-tag.yml
with:
TAG_NAME: pr-${{ github.event.pull_request.number }}
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Expand Up @@ -15,6 +15,7 @@ jobs:
call-test:
uses: ./.github/workflows/_test.yml
call-gorelease:
needs: [call-lint, call-test]
uses: ./.github/workflows/_gorelease.yml
call-buildx:
needs: call-gorelease
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/version_bump.yml
Expand Up @@ -6,6 +6,11 @@ on:
version:
description: "Version to bump to, example: v1.5.2"
required: true
ref:
description: "Ref to release from"
required: true
type: string
default: master

jobs:
tag-release:
Expand All @@ -18,7 +23,7 @@ jobs:
uses: actions/checkout@24cb9080177205b6e8c946b17badbe402adc938f # v3.4.0
with:
fetch-depth: 0
ref: master
ref: ${{ inputs.ref }}
- name: Tag release
run: |
git config user.email "${{github.repository_owner}}@users.noreply.github.com"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -16,4 +16,4 @@ WORKDIR /shiori
EXPOSE 8080
ENV SHIORI_DIR /shiori/
ENTRYPOINT ["/usr/bin/shiori"]
CMD ["serve"]
CMD ["server"]
2 changes: 1 addition & 1 deletion Dockerfile.compose
Expand Up @@ -3,4 +3,4 @@ FROM docker.io/golang:1.19-alpine3.16
WORKDIR /src/shiori

ENTRYPOINT ["go", "run", "main.go"]
CMD ["serve"]
CMD ["server"]
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
[![IC](https://github.com/go-shiori/shiori/actions/workflows/push.yml/badge.svg?branch=master)](https://github.com/go-shiori/shiori/actions/workflows/push.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-shiori/shiori)](https://goreportcard.com/report/github.com/go-shiori/shiori)
[![#shiori@libera.chat](https://img.shields.io/badge/irc-%23shiori-orange)](https://web.libera.chat/#shiori)
[![#shiori-general:matrix.org](https://img.shields.io/badge/matrix-%23shiori-orange)](https://matrix.to/#/#shiori-general:matrix.org)
[![#shiori-general:matrix.org](https://img.shields.io/badge/matrix-%23shiori-orange)](https://matrix.to/#/#shiori:matrix.org)
[![Containers](https://img.shields.io/static/v1?label=Container&message=Images&color=1488C6&logo=docker)](https://github.com/go-shiori/shiori/pkgs/container/shiori)

**Check out our latest [Announcements](https://github.com/go-shiori/shiori/discussions/categories/announcements)**
Expand Down
14 changes: 14 additions & 0 deletions docs/Storage.md
@@ -0,0 +1,14 @@
# Storage

Shiori requires a folder to store several pieces of data, such as the bookmark archives, thumbnails, ebooks, and others. If the database engine used is sqlite, then the database file will also be stored in this folder.

You can specify the storage folder by using `--storage-dir` or `--portable` flags when running Shiori.

If none specified, Shiori will try to find the correct app folder for your OS.

For example:
- In Windows, Shiori will use `%APPDATA%`.
- In Linux, it will use `$XDG_CONFIG_HOME` or `$HOME/.local/share` if `$XDG_CONFIG_HOME` is not set.
- In macOS, it will use `$HOME/Library/Application Support`.

> For more and up to date information about app folder discovery check [muesli/go-app-paths](https://github.com/muesli/go-app-paths)
3 changes: 2 additions & 1 deletion docs/index.md
Expand Up @@ -4,11 +4,12 @@ Shiori is a simple bookmarks manager written in Go language. Intended as a simpl

## Resources

- [API](./API.md)
- [API](./API.md) (Deprecated)
- [APIv1](./APIv1.md) ([What is this?](https://github.com/go-shiori/shiori/issues/640))
- [Contributing](./Contribute.md)
- [Configuration](./Configuration.md)
- [FAQ](./Frequently-Asked-Question.md)
- [Installation](./Installation.md)
- [Screenshots](./screenshots/)
- [Storage](./Storage.md)
- [Usage](./Usage.md)
8 changes: 5 additions & 3 deletions internal/cmd/add.go
Expand Up @@ -29,6 +29,8 @@ func addCmd() *cobra.Command {
}

func addHandler(cmd *cobra.Command, args []string) {
cfg, deps := initShiori(cmd.Context(), cmd)

// Read flag and arguments
url := args[0]
title, _ := cmd.Flags().GetString("title")
Expand Down Expand Up @@ -70,7 +72,7 @@ func addHandler(cmd *cobra.Command, args []string) {
}

// Save bookmark to database
books, err := db.SaveBookmarks(cmd.Context(), true, book)
books, err := deps.Database.SaveBookmarks(cmd.Context(), true, book)
if err != nil {
cError.Printf("Failed to save bookmark: %v\n", err)
os.Exit(1)
Expand All @@ -90,7 +92,7 @@ func addHandler(cmd *cobra.Command, args []string) {

if err == nil && content != nil {
request := core.ProcessRequest{
DataDir: dataDir,
DataDir: cfg.Storage.DataDir,
Bookmark: book,
Content: content,
ContentType: contentType,
Expand All @@ -112,7 +114,7 @@ func addHandler(cmd *cobra.Command, args []string) {
}

// Save bookmark to database
_, err = db.SaveBookmarks(cmd.Context(), false, book)
_, err = deps.Database.SaveBookmarks(cmd.Context(), false, book)
if err != nil {
cError.Printf("Failed to save bookmark with content: %v\n", err)
os.Exit(1)
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/check.go
Expand Up @@ -29,6 +29,8 @@ func checkCmd() *cobra.Command {
}

func checkHandler(cmd *cobra.Command, args []string) {
_, deps := initShiori(cmd.Context(), cmd)

// Parse flags
skipConfirm, _ := cmd.Flags().GetBool("yes")

Expand All @@ -53,7 +55,7 @@ func checkHandler(cmd *cobra.Command, args []string) {

// Fetch bookmarks from database
filterOptions := database.GetBookmarksOptions{IDs: ids}
bookmarks, err := db.GetBookmarks(cmd.Context(), filterOptions)
bookmarks, err := deps.Database.GetBookmarks(cmd.Context(), filterOptions)
if err != nil {
cError.Printf("Failed to get bookmarks: %v\n", err)
os.Exit(1)
Expand Down
12 changes: 7 additions & 5 deletions internal/cmd/delete.go
Expand Up @@ -29,6 +29,8 @@ func deleteCmd() *cobra.Command {
}

func deleteHandler(cmd *cobra.Command, args []string) {
cfg, deps := initShiori(cmd.Context(), cmd)

// Parse flags
skipConfirm, _ := cmd.Flags().GetBool("yes")

Expand All @@ -52,23 +54,23 @@ func deleteHandler(cmd *cobra.Command, args []string) {
}

// Delete bookmarks from database
err = db.DeleteBookmarks(cmd.Context(), ids...)
err = deps.Database.DeleteBookmarks(cmd.Context(), ids...)
if err != nil {
cError.Printf("Failed to delete bookmarks: %v\n", err)
os.Exit(1)
}

// Delete thumbnail image and archives from local disk
if len(ids) == 0 {
thumbDir := fp.Join(dataDir, "thumb")
archiveDir := fp.Join(dataDir, "archive")
thumbDir := fp.Join(cfg.Storage.DataDir, "thumb")
archiveDir := fp.Join(cfg.Storage.DataDir, "archive")
os.RemoveAll(thumbDir)
os.RemoveAll(archiveDir)
} else {
for _, id := range ids {
strID := strconv.Itoa(id)
imgPath := fp.Join(dataDir, "thumb", strID)
archivePath := fp.Join(dataDir, "archive", strID)
imgPath := fp.Join(cfg.Storage.DataDir, "thumb", strID)
archivePath := fp.Join(cfg.Storage.DataDir, "archive", strID)

os.Remove(imgPath)
os.Remove(archivePath)
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/export.go
Expand Up @@ -24,8 +24,10 @@ func exportCmd() *cobra.Command {
}

func exportHandler(cmd *cobra.Command, args []string) {
_, deps := initShiori(cmd.Context(), cmd)

// Fetch bookmarks from database
bookmarks, err := db.GetBookmarks(cmd.Context(), database.GetBookmarksOptions{})
bookmarks, err := deps.Database.GetBookmarks(cmd.Context(), database.GetBookmarksOptions{})
if err != nil {
cError.Printf("Failed to get bookmarks: %v\n", err)
os.Exit(1)
Expand Down
6 changes: 4 additions & 2 deletions internal/cmd/import.go
Expand Up @@ -29,6 +29,8 @@ func importCmd() *cobra.Command {
}

func importHandler(cmd *cobra.Command, args []string) {
_, deps := initShiori(cmd.Context(), cmd)

// Parse flags
generateTag := cmd.Flags().Changed("generate-tag")

Expand Down Expand Up @@ -104,7 +106,7 @@ func importHandler(cmd *cobra.Command, args []string) {
return
}

_, exist, err := db.GetBookmark(cmd.Context(), 0, url)
_, exist, err := deps.Database.GetBookmark(cmd.Context(), 0, url)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
cError.Printf("Skip %s: Get Bookmark fail, %v", url, err)
return
Expand Down Expand Up @@ -145,7 +147,7 @@ func importHandler(cmd *cobra.Command, args []string) {
})

// Save bookmark to database
bookmarks, err = db.SaveBookmarks(cmd.Context(), true, bookmarks...)
bookmarks, err = deps.Database.SaveBookmarks(cmd.Context(), true, bookmarks...)
if err != nil {
cError.Printf("Failed to save bookmarks: %v\n", err)
os.Exit(1)
Expand Down
6 changes: 4 additions & 2 deletions internal/cmd/open.go
Expand Up @@ -36,6 +36,8 @@ func openCmd() *cobra.Command {
}

func openHandler(cmd *cobra.Command, args []string) {
cfg, deps := initShiori(cmd.Context(), cmd)

// Parse flags
skipConfirm, _ := cmd.Flags().GetBool("yes")
archiveMode, _ := cmd.Flags().GetBool("archive")
Expand Down Expand Up @@ -73,7 +75,7 @@ func openHandler(cmd *cobra.Command, args []string) {
WithContent: true,
}

bookmarks, err := db.GetBookmarks(cmd.Context(), getOptions)
bookmarks, err := deps.Database.GetBookmarks(cmd.Context(), getOptions)
if err != nil {
cError.Printf("Failed to get bookmarks: %v\n", err)
os.Exit(1)
Expand Down Expand Up @@ -130,7 +132,7 @@ func openHandler(cmd *cobra.Command, args []string) {

// Open archive
id := strconv.Itoa(bookmarks[0].ID)
archivePath := fp.Join(dataDir, "archive", id)
archivePath := fp.Join(cfg.Storage.DataDir, "archive", id)

archive, err := warc.Open(archivePath)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions internal/cmd/pocket.go
Expand Up @@ -25,6 +25,8 @@ func pocketCmd() *cobra.Command {
}

func pocketHandler(cmd *cobra.Command, args []string) {
_, deps := initShiori(cmd.Context(), cmd)

// Open pocket's file
srcFile, err := os.Open(args[0])
if err != nil {
Expand Down Expand Up @@ -70,7 +72,7 @@ func pocketHandler(cmd *cobra.Command, args []string) {
return
}

_, exist, err := db.GetBookmark(cmd.Context(), 0, url)
_, exist, err := deps.Database.GetBookmark(cmd.Context(), 0, url)
if err != nil {
cError.Printf("Skip %s: Get Bookmark fail, %v", url, err)
return
Expand Down Expand Up @@ -103,7 +105,7 @@ func pocketHandler(cmd *cobra.Command, args []string) {
})

// Save bookmark to database
bookmarks, err = db.SaveBookmarks(cmd.Context(), true, bookmarks...)
bookmarks, err = deps.Database.SaveBookmarks(cmd.Context(), true, bookmarks...)
if err != nil {
cError.Printf("Failed to save bookmarks: %v\n", err)
os.Exit(1)
Expand Down
4 changes: 3 additions & 1 deletion internal/cmd/print.go
Expand Up @@ -32,6 +32,8 @@ func printCmd() *cobra.Command {
}

func printHandler(cmd *cobra.Command, args []string) {
_, deps := initShiori(cmd.Context(), cmd)

// Read flags
tags, _ := cmd.Flags().GetStringSlice("tags")
keyword, _ := cmd.Flags().GetString("search")
Expand Down Expand Up @@ -61,7 +63,7 @@ func printHandler(cmd *cobra.Command, args []string) {
OrderMethod: orderMethod,
}

bookmarks, err := db.GetBookmarks(cmd.Context(), searchOptions)
bookmarks, err := deps.Database.GetBookmarks(cmd.Context(), searchOptions)
if err != nil {
cError.Printf("Failed to get bookmarks: %v\n", err)
return
Expand Down
7 changes: 0 additions & 7 deletions internal/cmd/root-dev.go

This file was deleted.