Skip to content

Commit

Permalink
refactor: migrate ebook routes to new http server (#742)
Browse files Browse the repository at this point in the history
* add new api

* UI use new API

* remove legacy route

* fix request to new api destination and read that response

* feat: allow authentication using cookies

* fix: return proper error on validatesession

* typo: secret key envionment variable in makefile

* serve ebook file with new api

* cache update use new api path

* add skipexist and batch download use same route as cache

* fix bug - update hasebook status

* remove unneeded part of code

* add swagger documentation

* fix swagger documentation

* fix swagger response

* better statuscode

* fix swagger documentation

* covert to snake_case

* recover coverage.txt that remove

---------

Co-authored-by: Felipe M <me@fmartingr.com>
Co-authored-by: Felipe Martin <812088+fmartingr@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 29, 2023
1 parent 29b1d97 commit 5e9847a
Show file tree
Hide file tree
Showing 18 changed files with 610 additions and 295 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -44,7 +44,7 @@ serve:
## Runs server for local development
.PHONY: run-server
run-server:
GIN_MODE=$(GIN_MODE) SHIORI_DEVELOPMENT=$(SHIORI_DEVELOPMENT) SHIORI_DIR=$(SHIORI_DIR) SHIORI_SECRET_KEY=shiori go run main.go server
GIN_MODE=$(GIN_MODE) SHIORI_DEVELOPMENT=$(SHIORI_DEVELOPMENT) SHIORI_DIR=$(SHIORI_DIR) SHIORI_HTTP_SECRET_KEY=shiori go run main.go server

## Generate swagger docs
.PHONY: swagger
Expand Down
112 changes: 112 additions & 0 deletions docs/swagger/docs.go
Expand Up @@ -126,6 +126,39 @@ const docTemplate = `{
}
}
},
"/api/v1/bookmaeks/cache": {
"put": {
"produces": [
"application/json"
],
"tags": [
"Auth"
],
"summary": "Update Cache and Ebook on server.",
"parameters": [
{
"description": "Update Cache Payload",
"name": "payload",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api_v1.updateCachePayload"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.Bookmark"
}
},
"403": {
"description": "Token not provided/invalid"
}
}
}
},
"/api/v1/tags": {
"get": {
"produces": [
Expand Down Expand Up @@ -215,6 +248,32 @@ const docTemplate = `{
}
}
},
"api_v1.updateCachePayload": {
"type": "object",
"required": [
"ids"
],
"properties": {
"create_archive": {
"type": "boolean"
},
"create_ebook": {
"type": "boolean"
},
"ids": {
"type": "array",
"items": {
"type": "integer"
}
},
"keep_metadata": {
"type": "boolean"
},
"skip_exist": {
"type": "boolean"
}
}
},
"model.Account": {
"type": "object",
"properties": {
Expand All @@ -235,6 +294,59 @@ const docTemplate = `{
}
}
},
"model.Bookmark": {
"type": "object",
"properties": {
"author": {
"type": "string"
},
"create_archive": {
"type": "boolean"
},
"create_ebook": {
"type": "boolean"
},
"excerpt": {
"type": "string"
},
"hasArchive": {
"type": "boolean"
},
"hasContent": {
"type": "boolean"
},
"hasEbook": {
"type": "boolean"
},
"html": {
"type": "string"
},
"id": {
"type": "integer"
},
"imageURL": {
"type": "string"
},
"modified": {
"type": "string"
},
"public": {
"type": "integer"
},
"tags": {
"type": "array",
"items": {
"$ref": "#/definitions/model.Tag"
}
},
"title": {
"type": "string"
},
"url": {
"type": "string"
}
}
},
"model.Tag": {
"type": "object",
"properties": {
Expand Down
112 changes: 112 additions & 0 deletions docs/swagger/swagger.json
Expand Up @@ -115,6 +115,39 @@
}
}
},
"/api/v1/bookmaeks/cache": {
"put": {
"produces": [
"application/json"
],
"tags": [
"Auth"
],
"summary": "Update Cache and Ebook on server.",
"parameters": [
{
"description": "Update Cache Payload",
"name": "payload",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api_v1.updateCachePayload"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/model.Bookmark"
}
},
"403": {
"description": "Token not provided/invalid"
}
}
}
},
"/api/v1/tags": {
"get": {
"produces": [
Expand Down Expand Up @@ -204,6 +237,32 @@
}
}
},
"api_v1.updateCachePayload": {
"type": "object",
"required": [
"ids"
],
"properties": {
"create_archive": {
"type": "boolean"
},
"create_ebook": {
"type": "boolean"
},
"ids": {
"type": "array",
"items": {
"type": "integer"
}
},
"keep_metadata": {
"type": "boolean"
},
"skip_exist": {
"type": "boolean"
}
}
},
"model.Account": {
"type": "object",
"properties": {
Expand All @@ -224,6 +283,59 @@
}
}
},
"model.Bookmark": {
"type": "object",
"properties": {
"author": {
"type": "string"
},
"create_archive": {
"type": "boolean"
},
"create_ebook": {
"type": "boolean"
},
"excerpt": {
"type": "string"
},
"hasArchive": {
"type": "boolean"
},
"hasContent": {
"type": "boolean"
},
"hasEbook": {
"type": "boolean"
},
"html": {
"type": "string"
},
"id": {
"type": "integer"
},
"imageURL": {
"type": "string"
},
"modified": {
"type": "string"
},
"public": {
"type": "integer"
},
"tags": {
"type": "array",
"items": {
"$ref": "#/definitions/model.Tag"
}
},
"title": {
"type": "string"
},
"url": {
"type": "string"
}
}
},
"model.Tag": {
"type": "object",
"properties": {
Expand Down
73 changes: 73 additions & 0 deletions docs/swagger/swagger.yaml
Expand Up @@ -27,6 +27,23 @@ definitions:
config:
$ref: '#/definitions/model.UserConfig'
type: object
api_v1.updateCachePayload:
properties:
create_archive:
type: boolean
create_ebook:
type: boolean
ids:
items:
type: integer
type: array
keep_metadata:
type: boolean
skip_exist:
type: boolean
required:
- ids
type: object
model.Account:
properties:
config:
Expand All @@ -40,6 +57,41 @@ definitions:
username:
type: string
type: object
model.Bookmark:
properties:
author:
type: string
create_archive:
type: boolean
create_ebook:
type: boolean
excerpt:
type: string
hasArchive:
type: boolean
hasContent:
type: boolean
hasEbook:
type: boolean
html:
type: string
id:
type: integer
imageURL:
type: string
modified:
type: string
public:
type: integer
tags:
items:
$ref: '#/definitions/model.Tag'
type: array
title:
type: string
url:
type: string
type: object
model.Tag:
properties:
id:
Expand Down Expand Up @@ -143,6 +195,27 @@ paths:
summary: Refresh a token for an account
tags:
- Auth
/api/v1/bookmaeks/cache:
put:
parameters:
- description: Update Cache Payload
in: body
name: payload
required: true
schema:
$ref: '#/definitions/api_v1.updateCachePayload'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/model.Bookmark'
"403":
description: Token not provided/invalid
summary: Update Cache and Ebook on server.
tags:
- Auth
/api/v1/tags:
get:
produces:
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/update.go
Expand Up @@ -52,7 +52,7 @@ func updateHandler(cmd *cobra.Command, args []string) {
skipConfirm, _ := cmd.Flags().GetBool("yes")
noArchival, _ := cmd.Flags().GetBool("no-archival")
logArchival, _ := cmd.Flags().GetBool("log-archival")
keepMetadata := cmd.Flags().Changed("keep-metadata")
keep_metadata := cmd.Flags().Changed("keep-metadata")

// If no arguments (i.e all bookmarks going to be updated), confirm to user
if len(args) == 0 && !skipConfirm {
Expand Down Expand Up @@ -170,8 +170,8 @@ func updateHandler(cmd *cobra.Command, args []string) {
Bookmark: book,
Content: content,
ContentType: contentType,
KeepTitle: keepMetadata,
KeepExcerpt: keepMetadata,
KeepTitle: keep_metadata,
KeepExcerpt: keep_metadata,
LogArchival: logArchival,
}

Expand Down

0 comments on commit 5e9847a

Please sign in to comment.