mirror of
https://github.com/hkalexling/Mango.git
synced 2026-04-25 00:00:52 -04:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d2f95e5970 | |||
| 82bcd03f15 | |||
| fe799f30c8 | |||
| 54123917af |
@@ -50,7 +50,7 @@ The official docker images are available on [Dockerhub](https://hub.docker.com/r
|
|||||||
### CLI
|
### CLI
|
||||||
|
|
||||||
```
|
```
|
||||||
Mango - Manga Server and Web Reader. Version 0.5.0
|
Mango - Manga Server and Web Reader. Version 0.5.1
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: mango
|
name: mango
|
||||||
version: 0.5.0
|
version: 0.5.1
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- Alex Ling <hkalexling@gmail.com>
|
- Alex Ling <hkalexling@gmail.com>
|
||||||
|
|||||||
+4
-2
@@ -4,7 +4,7 @@ require "./mangadex/*"
|
|||||||
require "option_parser"
|
require "option_parser"
|
||||||
require "clim"
|
require "clim"
|
||||||
|
|
||||||
MANGO_VERSION = "0.5.0"
|
MANGO_VERSION = "0.5.1"
|
||||||
|
|
||||||
macro common_option
|
macro common_option
|
||||||
option "-c PATH", "--config=PATH", type: String,
|
option "-c PATH", "--config=PATH", type: String,
|
||||||
@@ -29,6 +29,8 @@ class CLI < Clim
|
|||||||
Config.load(opts.config).set_current
|
Config.load(opts.config).set_current
|
||||||
MangaDex::Downloader.default
|
MangaDex::Downloader.default
|
||||||
|
|
||||||
|
# empty ARGV so it won't be passed to Kemal
|
||||||
|
ARGV.clear
|
||||||
server = Server.new
|
server = Server.new
|
||||||
server.start
|
server.start
|
||||||
end
|
end
|
||||||
@@ -75,7 +77,7 @@ class CLI < Clim
|
|||||||
password.not_nil!, opts.admin
|
password.not_nil!, opts.admin
|
||||||
when "list"
|
when "list"
|
||||||
users = storage.list_users
|
users = storage.list_users
|
||||||
name_length = users.map(&.[0].size).max
|
name_length = users.map(&.[0].size).max? || 0
|
||||||
l_cell_width = ["username".size, name_length].max
|
l_cell_width = ["username".size, name_length].max
|
||||||
r_cell_width = "admin access".size
|
r_cell_width = "admin access".size
|
||||||
header = " #{"username".ljust l_cell_width} | admin access "
|
header = " #{"username".ljust l_cell_width} | admin access "
|
||||||
|
|||||||
+15
-8
@@ -47,23 +47,30 @@ class Storage
|
|||||||
Logger.fatal "Error when checking tables in DB: #{e}"
|
Logger.fatal "Error when checking tables in DB: #{e}"
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If the DB is initialized through CLI but no user is added, we need
|
||||||
|
# to create the admin user when first starting the app
|
||||||
|
user_count = db.query_one "select count(*) from users", as: Int32
|
||||||
|
init_admin if init_user && user_count == 0
|
||||||
else
|
else
|
||||||
Logger.debug "Creating DB file at #{@path}"
|
Logger.debug "Creating DB file at #{@path}"
|
||||||
db.exec "create unique index username_idx on users (username)"
|
db.exec "create unique index username_idx on users (username)"
|
||||||
db.exec "create unique index token_idx on users (token)"
|
db.exec "create unique index token_idx on users (token)"
|
||||||
|
|
||||||
if init_user
|
init_admin if init_user
|
||||||
random_pw = random_str
|
|
||||||
hash = hash_password random_pw
|
|
||||||
db.exec "insert into users values (?, ?, ?, ?)",
|
|
||||||
"admin", hash, nil, 1
|
|
||||||
Logger.log "Initial user created. You can log in with " \
|
|
||||||
"#{{"username" => "admin", "password" => random_pw}}"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
macro init_admin
|
||||||
|
random_pw = random_str
|
||||||
|
hash = hash_password random_pw
|
||||||
|
db.exec "insert into users values (?, ?, ?, ?)",
|
||||||
|
"admin", hash, nil, 1
|
||||||
|
Logger.log "Initial user created. You can log in with " \
|
||||||
|
"#{{"username" => "admin", "password" => random_pw}}"
|
||||||
|
end
|
||||||
|
|
||||||
def verify_user(username, password)
|
def verify_user(username, password)
|
||||||
DB.open "sqlite3://#{@path}" do |db|
|
DB.open "sqlite3://#{@path}" do |db|
|
||||||
begin
|
begin
|
||||||
|
|||||||
Reference in New Issue
Block a user