Skip to content

Commit

Permalink
Preparing first public release
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas Aaberg <[email protected]>
  • Loading branch information
gmelchett committed Dec 23, 2021
1 parent 0ef5abc commit 23d9f63
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 20 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Jonas Aaberg

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Jomics

Jomics is a simple comic reader server. It supports cbz and cbr and can handle folders.
It has some basic `ComicInfo.xml` support. (Probably it can be developed further.)

![jomics](jomics.png "Jomics screenshot")

## Installation

You need a go compiler, probably a pretty new version. Clone the repo, and run

`go get && go build`

All data will be embedded into the `jomics` binary.

## Usage
```
Usage of ./jomics:
-addr string
Server address. (default ":8080")
-root string
Comic collection root. (default ".")
-th int
Front page thumb nail size. (default 400)
```
And point your favorite browser to `localhost:8080` if you are using the address.

## Security
There is none. It is just a comics reader server.

## Third party packages
* The folder icon is taken from http://www.clker.com/clipart-simple-file-folder.html (resized & included)
* The CSS framework used https://picocss.com/ (included)
* http://github.com/OpenPeeDeeP/xdg for cache directory.
* http://github.com/disintegration/imaging is used to resize images.
* http://github.com/gen2brain/go-unarr for uncompressing zip and rar archives.

## TODO
Currently jomics is feature complete. I have no plans to add any features, but it might change once I've used jomics for some time.

## License
MIT

3 changes: 0 additions & 3 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
TODO:

- progress bar when loading new albums
- Remove ([text]) hooks at end
- json file as config
- alpha channel broken for folders
- folder.jpg embedd in folder icon
Binary file added jomics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 37 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
//
// SPDX-FileCopyrightText: 2021 Jonas Aaberg
//
// SPDX-License-Identifier: MIT
//

package main

import (
"bytes"
"container/list"
"embed"
"encoding/xml"
"flag"
"fmt"
"hash/crc32"
"image"
_ "image/gif"
"image/jpeg"
_ "image/jpeg"
"image/png"
_ "image/png"
"io"
"io/fs"
Expand Down Expand Up @@ -50,7 +57,6 @@ type comic struct {
mimeType string
frontPage []byte

files *list.List
comicInfo *ComicInfo
}

Expand Down Expand Up @@ -192,13 +198,20 @@ func (jomics *jomics) saveToCache(hash uint32, data []byte) error {

func (jomics *jomics) prepareAlbums() {

resizeAndSave := func(h uint32, m image.Image) []byte {
resizeAndSave := func(h uint32, m image.Image, toPng bool) []byte {
img := imaging.Resize(m, 0, jomics.thumbHeight, imaging.Lanczos)

b := new(bytes.Buffer)
if err := jpeg.Encode(b, img, nil); err != nil {
log.Fatalf("Failed to encode jpeg: %v\n", err)
var err error
if !toPng {
err = jpeg.Encode(b, img, nil)
} else {
err = png.Encode(b, img)
}
if err != nil {
log.Fatalf("Failed to encode image: %v\n", err)
}

data := b.Bytes()
jomics.saveToCache(h, data)
return data
Expand All @@ -216,7 +229,7 @@ func (jomics *jomics) prepareAlbums() {
log.Fatal("Can't decode folder.png - corrupt? ", err)
}

jomics.folder = resizeAndSave(FOLDER_PNG_HASH, m)
jomics.folder = resizeAndSave(FOLDER_PNG_HASH, m, true)
}

firstResize := false
Expand Down Expand Up @@ -271,7 +284,7 @@ func (jomics *jomics) prepareAlbums() {
}

if !firstResize {
fmt.Printf("Loading & resizing front page: ")
fmt.Printf("Load & resize front pages")
}
firstResize = true

Expand All @@ -285,7 +298,7 @@ func (jomics *jomics) prepareAlbums() {
}

if m, _, err := image.Decode(bytes.NewReader(data)); err == nil {
jomics.comics[i][j].frontPage = resizeAndSave(jomics.comics[i][j].hash, m)
jomics.comics[i][j].frontPage = resizeAndSave(jomics.comics[i][j].hash, m, false)
} else {
fmt.Printf("Failed to decode image %s in zip: %s Error: %v\n",
imgs[0], jomics.comics[i][j].fname, err)
Expand Down Expand Up @@ -478,8 +491,19 @@ func createDir(dir string) (err error) {
}

func main() {

var thumbHeight = flag.Int("th", THUMB_HEIGHT, "Front page thumb nail size.")
var root = flag.String("root", ".", "Comic collection root.")
var addr = flag.String("addr", ":8080", "Server address.")

flag.Parse()

if *thumbHeight < 100 || *thumbHeight > 2000 {
log.Fatal("Invalid thumbnail height")
}

jomics := jomics{
thumbHeight: THUMB_HEIGHT,
thumbHeight: *thumbHeight,
}

var err error
Expand All @@ -489,11 +513,7 @@ func main() {
log.Fatal("Failed to create cache directory", err)
}

if err = createDir(jomics.xdg.DataHome()); err != nil {
log.Fatal("Failed to create data directory", err)
}

jomics.listComics("/data/books/Serier/Disney/")
jomics.listComics(*root)

jomics.prepareAlbums()

Expand All @@ -515,5 +535,7 @@ func main() {

http.Handle(STATIC_PATH, http.StripPrefix(STATIC_PATH, http.FileServer(http.FS(sub))))

http.ListenAndServe(":8080", nil)
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatal("Failed to start server. Probably faulty address", err)
}
}
Binary file added static/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tmpl/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<div><form action="{{ .Last }}" method="post"><input type="submit" value="Last"/></form></div>
</div>

<img src="{{.PageImageUrl}}" style="display:block;margin-left:auto;margin-right:auto;width:80%;object-fit:cover;">

<img src="{{.PageImageUrl}}" style="display:block;margin-left:auto;margin-right:auto;width:100%;object-fit:cover;">
<br/>
<div class="grid">
<div>
{{ if .HasPrev }}
Expand Down

0 comments on commit 23d9f63

Please sign in to comment.