5 Commits 85971693a9 ... b94b49229b

Author SHA1 Message Date
  Adam b94b49229b show latest episode in series 4 years ago
  Adam c80a59e916 cache series’ responses 4 years ago
  Adam a9944d1f7c cache films’ responses 4 years ago
  Adam 9b669cd219 specify custom port 4 years ago
  Adam 078eb2e533 add mk to container 4 years ago
10 changed files with 47 additions and 8 deletions
  1. 1 0
      .gitignore
  2. 2 2
      Dockerfile
  3. 1 0
      go.mod
  4. 2 0
      go.sum
  5. 1 0
      i18n/en-GB.toml
  6. 1 1
      libamuse/about.go
  7. 16 4
      libamuse/common.go
  8. 22 0
      libamuse/db.go
  9. 1 1
      libamuse/error.go
  10. 0 0
      libamuse/film.go

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
+amuse.db
 amuse
 tags
 *.webp

+ 2 - 2
Dockerfile

@@ -2,7 +2,7 @@ FROM ubuntu:latest
 
 RUN apt update && apt install -y software-properties-common curl
 RUN add-apt-repository -y ppa:longsleep/golang-backports && apt update && apt install -y golang-go
-RUN apt install -y python3.7 python3.7-dev python3-pip git
+RUN apt install -y python3.7 python3.7-dev python3-pip git 9base
 RUN sed 's/python3/python3.7/' /usr/bin/pip3 > pip3 && mv pip3 /usr/bin/pip3
 RUN chmod 755 /usr/bin/pip3
 
@@ -13,4 +13,4 @@ RUN go get github.com/go-python/gopy
 RUN ln -s /usr/bin/python3.7 /usr/bin/python
 RUN ln -s /usr/bin/python3.7-config /usr/bin/python-config
 
-ENV PATH="/root/go/bin:${PATH}"
+ENV PATH="/root/go/bin:${PATH}:/usr/lib/plan9/bin"

+ 1 - 0
go.mod

@@ -6,6 +6,7 @@ require (
 	github.com/BurntSushi/toml v0.3.1
 	github.com/bytesparadise/libasciidoc v0.2.0
 	github.com/go-python/gopy v0.3.1
+	github.com/mattn/go-sqlite3 v2.0.2+incompatible
 	github.com/onsi/ginkgo v1.10.3 // indirect
 	github.com/onsi/gomega v1.7.1 // indirect
 	github.com/sirupsen/logrus v1.4.2 // indirect

+ 2 - 0
go.sum

@@ -18,6 +18,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
 github.com/kuangchanglang/graceful v1.0.0 h1:EPcA4vV75CkLi9+tW1+cd6KpfULYRTxTm1MO8USa49k=
 github.com/kuangchanglang/graceful v1.0.0/go.mod h1:fQkb+p3PRjvdiAsa65Qv78lm9CsYc4M+yhiuU1rOVtg=
+github.com/mattn/go-sqlite3 v2.0.2+incompatible h1:qzw9c2GNT8UFrgWNDhCTqRqYUSmu/Dav/9Z58LGpk7U=
+github.com/mattn/go-sqlite3 v2.0.2+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
 github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
 github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY=
 github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=

+ 1 - 0
i18n/en-GB.toml

@@ -73,6 +73,7 @@ rating = "Rating"
 votes = "votes"
 genre = "Genre"
 status = "Status"
+latest_episode = "Latest episode"
 
 [person]
 cast = "Cast"

+ 1 - 1
libamuse/about.go

@@ -17,7 +17,7 @@ func renderAbout(args ...interface{}) interface{} {
 
 func ShowAbout(language, mimetype string) (string, error) {
 	result, err := gott.
-		NewResult(gott.Tuple{requestData{"", "", language, mimetype}, nil, nil, nil}).
+		NewResult(gott.Tuple{requestData{"", nil, language, mimetype}, nil, nil, nil}).
 		Bind(parseLanguage).
 		Bind(createRenderer).
 		Map(renderAbout).

+ 16 - 4
libamuse/common.go

@@ -5,6 +5,7 @@ import (
 
 	"notabug.org/apiote/gott"
 
+	"database/sql"
 	"golang.org/x/text/language"
 )
 
@@ -13,6 +14,17 @@ type data interface {
 	getMimeType() string
 }
 
+func createDbConnection(args ...interface{}) (interface{}, error) {
+	requestData := args[0].(requestData)
+	db, err := sql.Open("sqlite3", "./amuse.db")
+	if err != nil {
+		return gott.Tuple(args), err
+	}
+	*(requestData.connection) = *db
+	args[0] = requestData
+	return gott.Tuple(args), nil
+}
+
 func parseLanguage(args ...interface{}) (interface{}, error) {
 	data := args[0].(data)
 	tags, _, err := language.ParseAcceptLanguage(data.getLanguage())
@@ -34,10 +46,10 @@ func createRenderer(args ...interface{}) (interface{}, error) {
 }
 
 type requestData struct {
-	id       string
-	etag     string
-	language string
-	mimetype string
+	id         string
+	connection *sql.DB
+	language   string
+	mimetype   string
 }
 
 func (d requestData) getLanguage() string {

+ 22 - 0
libamuse/db.go

@@ -0,0 +1,22 @@
+package libamuse
+
+import (
+	"database/sql"
+	_ "github.com/mattn/go-sqlite3"
+)
+
+func InitDB() error {
+	db, err := sql.Open("sqlite3", "./amuse.db")
+	if err != nil {
+		return err
+	}
+
+	db.Exec(`create table cache(uri text primary key, etag text, date date, response blob)`)
+
+	err = db.Close()
+	if err != nil {
+		return err
+	}
+
+	return nil
+}

+ 1 - 1
libamuse/error.go

@@ -18,7 +18,7 @@ func renderErrorPage(args ...interface{}) interface{} {
 
 func ShowErrorPage(code int, language, mimetype string) (string, error){
 	result, err := gott.
-		NewResult(gott.Tuple{requestData{"", "", language, mimetype}, code, nil, nil}).
+		NewResult(gott.Tuple{requestData{"", nil, language, mimetype}, code, nil, nil}).
 		Bind(parseLanguage).
 		Bind(createRenderer).
 		Map(renderErrorPage).

+ 0 - 0
libamuse/film.go


Some files were not shown because too many files changed in this diff