mirror of
https://github.com/hkalexling/Mango.git
synced 2026-01-24 00:03:14 -05:00
Compare commits
134 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5e6f42fc2 | ||
|
|
3ca6d3d338 | ||
|
|
750a28eccb | ||
|
|
88b16445e2 | ||
|
|
7774efa471 | ||
|
|
4aeda53806 | ||
|
|
5d62a87720 | ||
|
|
e902e1dff0 | ||
|
|
9fe32b5011 | ||
|
|
e65d701e0a | ||
|
|
5a500364fc | ||
|
|
3e42266955 | ||
|
|
6407cea7bf | ||
|
|
7e22cc5f57 | ||
|
|
e68678f2fb | ||
|
|
82fb45b242 | ||
|
|
46dfc2f712 | ||
|
|
79aa816ca8 | ||
|
|
e35cf2ce0c | ||
|
|
47ba0e39af | ||
|
|
aedb13ac92 | ||
|
|
d1c0e52f90 | ||
|
|
173ff2d2e6 | ||
|
|
ae281e2e21 | ||
|
|
2c10623731 | ||
|
|
31da5acdc5 | ||
|
|
77237a274a | ||
|
|
318501bc9b | ||
|
|
dc5284968d | ||
|
|
01216d806c | ||
|
|
c4ffb5cd59 | ||
|
|
50ce0e2b54 | ||
|
|
8b8967de26 | ||
|
|
335fb45de6 | ||
|
|
8c7ced87f1 | ||
|
|
00d2540b95 | ||
|
|
d120433525 | ||
|
|
9536ce62e6 | ||
|
|
4ba81b9ffe | ||
|
|
c355c67415 | ||
|
|
4def23a5cf | ||
|
|
943076ccf7 | ||
|
|
36034042f2 | ||
|
|
36e2b2bfaf | ||
|
|
c6c908953b | ||
|
|
3ae0ad6348 | ||
|
|
7ca40215b6 | ||
|
|
54206bc6ac | ||
|
|
1abdac2fdd | ||
|
|
9ffe896705 | ||
|
|
7a7c855ce4 | ||
|
|
e2d01f7eb9 | ||
|
|
7575785c1c | ||
|
|
dfd53bc51d | ||
|
|
f140ffa4b2 | ||
|
|
589483cd75 | ||
|
|
306edc3c77 | ||
|
|
30af64e9ca | ||
|
|
fecb96c91b | ||
|
|
4f01aba3e1 | ||
|
|
f13f7989d5 | ||
|
|
1ce553f541 | ||
|
|
c4253db572 | ||
|
|
db6d33eae1 | ||
|
|
8fbc5528a8 | ||
|
|
d50804830d | ||
|
|
5d7bbc7c9b | ||
|
|
0b463539c9 | ||
|
|
7f0088f45a | ||
|
|
5645f272df | ||
|
|
dc3bbd10d6 | ||
|
|
c89c74c71b | ||
|
|
cb76a96126 | ||
|
|
73b38492ba | ||
|
|
bf37c4aa10 | ||
|
|
f837be0718 | ||
|
|
8c47d50291 | ||
|
|
4ca8daca29 | ||
|
|
d3d8dff6d2 | ||
|
|
f11a5cd608 | ||
|
|
6bccba16da | ||
|
|
28ac5c7a00 | ||
|
|
f8e0c6d795 | ||
|
|
e3d505d62b | ||
|
|
77864afa67 | ||
|
|
5abdca24c2 | ||
|
|
e8c365b7a1 | ||
|
|
6659041631 | ||
|
|
fa50f4cb88 | ||
|
|
c39a1ddbaf | ||
|
|
7de01991a0 | ||
|
|
319967438b | ||
|
|
1bbb08eede | ||
|
|
d9d1dbc26f | ||
|
|
c33884ea29 | ||
|
|
2dd980b92c | ||
|
|
89e747d3ee | ||
|
|
468f109776 | ||
|
|
905d02e911 | ||
|
|
bb00c2e77f | ||
|
|
bc75f4d336 | ||
|
|
98baf63b0c | ||
|
|
46b36860d1 | ||
|
|
9f6261e02d | ||
|
|
d782995bac | ||
|
|
b264f7dd76 | ||
|
|
59622930c7 | ||
|
|
e90b97ca43 | ||
|
|
b58d2e3620 | ||
|
|
a507e3be7a | ||
|
|
bf0f5270f0 | ||
|
|
ac620e1f2a | ||
|
|
a7519a791e | ||
|
|
7a21f4dc9b | ||
|
|
650ebc7f9d | ||
|
|
5b34c05243 | ||
|
|
803fc8c44b | ||
|
|
67d3d2bd55 | ||
|
|
5ec35f3af6 | ||
|
|
dd49f75079 | ||
|
|
6be9c3eac6 | ||
|
|
0fa95959a7 | ||
|
|
83597e7f84 | ||
|
|
c893135ec6 | ||
|
|
5a2f80b5e1 | ||
|
|
5b4d79220c | ||
|
|
a3356344fa | ||
|
|
aecac748dc | ||
|
|
c449a1e9b1 | ||
|
|
f9a4698fca | ||
|
|
676f2ae032 | ||
|
|
fd342fe1ee | ||
|
|
1649f286aa | ||
|
|
60a1032f71 |
32
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
32
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: I found a bug in Mango!
|
||||
title: "[Bug Report]"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Environment (please complete the following information):**
|
||||
- OS: [e.g. Ubuntu 18.04]
|
||||
- Browser [e.g. chrome, safari, if applicable]
|
||||
- Mango Version [e.g. v0.1.0]
|
||||
|
||||
**Docker (if you are running Mango in a Docker container)**
|
||||
- The `docker-compose.yml` file you are using
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here. Add screenshots if applicable.
|
||||
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest a feature for Mango
|
||||
title: "[Feature Request]"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
10
.github/ISSUE_TEMPLATE/general-question.md
vendored
Normal file
10
.github/ISSUE_TEMPLATE/general-question.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
name: General Question
|
||||
about: I have a question about Mango
|
||||
title: "[Question]"
|
||||
labels: general question
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
||||
BIN
.github/screenshots/dark.png
vendored
Normal file
BIN
.github/screenshots/dark.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 598 KiB |
6
Makefile
6
Makefile
@@ -10,12 +10,18 @@ uglify:
|
||||
build: libs
|
||||
crystal build src/mango.cr --release --progress
|
||||
|
||||
static: uglify | libs
|
||||
crystal build src/mango.cr --release --progress --static
|
||||
|
||||
libs:
|
||||
shards install
|
||||
|
||||
run:
|
||||
crystal run src/mango.cr --error-trace
|
||||
|
||||
test:
|
||||
crystal spec
|
||||
|
||||
install:
|
||||
cp mango $(INSTALL_DIR)/mango
|
||||
|
||||
|
||||
49
README.md
49
README.md
@@ -1,17 +1,29 @@
|
||||
# Mango
|
||||
|
||||
|
||||
|
||||

|
||||
|
||||
# Mango
|
||||
|
||||
[](https://gitter.im/mango-cr/mango?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
|
||||
Mango is a self-hosted manga server and reader. Its features include
|
||||
|
||||
- Multi-user support
|
||||
- Dark/light mode switch
|
||||
- Supports both `.zip` and `.cbz` formats
|
||||
- Supports nested folders in library
|
||||
- Automatically stores reading progress
|
||||
- Built-in [MangaDex](https://mangadex.org/) downloader
|
||||
- The web reader is responsive and works well on mobile, so there is no need for a mobile app
|
||||
- All the static files are embedded in the binary, so the deployment process is easy and painless
|
||||
|
||||
## Installation
|
||||
|
||||
### Pre-built Binary
|
||||
|
||||
1. Simply download the pre-built binary file `mango` for the latest [release](https://github.com/hkalexling/Mango/releases). All the dependencies are statically linked, and it should work with most Linux systems on amd64.
|
||||
|
||||
### Docker
|
||||
|
||||
1. Make sure you have docker installed and running. You will also need `docker-compose`
|
||||
@@ -21,10 +33,9 @@ Mango is a self-hosted manga server and reader. Its features include
|
||||
5. Run `docker-compose up`. This should build the docker image and start the container with Mango running inside
|
||||
6. Head over to `localhost:9000` to log in
|
||||
|
||||
|
||||
### Build from source
|
||||
|
||||
1. Make sure you have Crystal, Node and Yarn installed
|
||||
1. Make sure you have Crystal, Node and Yarn installed. You might also need to install the development headers for `libsqlite3` and `libyaml`.
|
||||
2. Clone the repository
|
||||
3. `make && sudo make install`
|
||||
4. Start Mango by running the command `mango`
|
||||
@@ -35,7 +46,7 @@ Mango is a self-hosted manga server and reader. Its features include
|
||||
### CLI
|
||||
|
||||
```
|
||||
Mango e-manga server/reader. Version 0.1.0
|
||||
Mango e-manga server/reader. Version 0.2.0
|
||||
|
||||
-v, --version Show version
|
||||
-h, --help Show help
|
||||
@@ -53,27 +64,17 @@ library_path: ~/mango/library
|
||||
db_path: ~/mango/mango.db
|
||||
scan_interval_minutes: 5
|
||||
log_level: info
|
||||
mangadex:
|
||||
base_url: https://mangadex.org
|
||||
api_url: https://mangadex.org/api
|
||||
download_wait_seconds: 5
|
||||
download_retries: 4
|
||||
download_queue_db_path: ~/mango/queue.db
|
||||
```
|
||||
|
||||
- `scan_interval_minutes` can be any non-negative integer. Setting it to `0` disables the periodic scan
|
||||
- `log_level` can be `debug`, `info`, `warn`, `error`, `fatal` or `off`. Setting it to `off` disables the logging
|
||||
|
||||
### Required Library Structure
|
||||
|
||||
Please make sure that your library directory has the following structure:
|
||||
|
||||
```
|
||||
.
|
||||
├── Manga 1
|
||||
│  └── Manga 1.cbz
|
||||
└── Manga 2
|
||||
├── Vol 0001.zip
|
||||
├── Vol 0002.zip
|
||||
├── Vol 0003.zip
|
||||
├── Vol 0004.zip
|
||||
└── Vol 0005.zip
|
||||
```
|
||||
|
||||
### Initial Login
|
||||
|
||||
On the first run, Mango would log the default username and a randomly generated password to STDOUT. You are advised to immediately change the password.
|
||||
@@ -88,6 +89,10 @@ Title:
|
||||
|
||||

|
||||
|
||||
Dark mode:
|
||||
|
||||

|
||||
|
||||
Reader:
|
||||
|
||||

|
||||
@@ -95,3 +100,7 @@ Reader:
|
||||
Mobile UI:
|
||||
|
||||

|
||||
|
||||
## Contributors
|
||||
|
||||
[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/0)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/1)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/2)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/3)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/4)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/5)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/6)[](https://sourcerer.io/fame/hkalexling/hkalexling/Mango/links/7)
|
||||
|
||||
@@ -11,5 +11,5 @@ services:
|
||||
ports:
|
||||
- 9000:9000
|
||||
volumes:
|
||||
- ./mango:/root/mango
|
||||
- ./config:/root/.config/mango
|
||||
- ~/mango:/root/mango
|
||||
- ~/.config/mango:/root/.config/mango
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
const gulp = require('gulp');
|
||||
const uglify = require('gulp-uglify');
|
||||
const minify = require("gulp-babel-minify");
|
||||
const minifyCss = require('gulp-minify-css');
|
||||
|
||||
gulp.task('minify-js', () => {
|
||||
return gulp.src('public/js/*.js')
|
||||
.pipe(uglify())
|
||||
.pipe(minify({
|
||||
removeConsole: true
|
||||
}))
|
||||
.pipe(gulp.dest('dist/js'));
|
||||
});
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-minify-css": "^1.2.4",
|
||||
"gulp-uglify": "^3.0.2"
|
||||
"gulp-babel-minify": "^0.5.1",
|
||||
"gulp-minify-css": "^1.2.4"
|
||||
},
|
||||
"scripts": {
|
||||
"uglify": "gulp"
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
.uk-alert-close {
|
||||
color: black !important;
|
||||
}
|
||||
.uk-card-body {
|
||||
padding: 20px;
|
||||
}
|
||||
@@ -17,7 +20,7 @@
|
||||
#scan-status {
|
||||
cursor: auto;
|
||||
}
|
||||
.uk-card-title {
|
||||
.break-word {
|
||||
word-wrap: break-word;
|
||||
}
|
||||
.uk-logo > img {
|
||||
@@ -26,3 +29,18 @@
|
||||
.uk-search {
|
||||
width: 100%;
|
||||
}
|
||||
#selectable .ui-selecting {
|
||||
background: #EEE6B9;
|
||||
}
|
||||
#selectable .ui-selected {
|
||||
background: #F4E487;
|
||||
}
|
||||
#selectable .ui-selecting.dark {
|
||||
background: #5E5731;
|
||||
}
|
||||
#selectable .ui-selected.dark {
|
||||
background: #9D9252;
|
||||
}
|
||||
td > .uk-dropdown {
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
6
public/js/alert.js
Normal file
6
public/js/alert.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const alert = (level, text) => {
|
||||
$('#alert').empty();
|
||||
const html = `<div class="uk-alert-${level}" uk-alert><a class="uk-alert-close" uk-close></a><p>${text}</p></div>`;
|
||||
$('#alert').append(html);
|
||||
$("html, body").animate({ scrollTop: 0 });
|
||||
};
|
||||
138
public/js/download-manager.js
Normal file
138
public/js/download-manager.js
Normal file
@@ -0,0 +1,138 @@
|
||||
$(() => {
|
||||
$('input.uk-checkbox').each((i, e) => {
|
||||
$(e).change(() => {
|
||||
loadConfig();
|
||||
});
|
||||
});
|
||||
loadConfig();
|
||||
load();
|
||||
|
||||
const intervalMS = 5000;
|
||||
setTimeout(() => {
|
||||
setInterval(() => {
|
||||
if (globalConfig.autoRefresh !== true) return;
|
||||
load();
|
||||
}, intervalMS);
|
||||
}, intervalMS);
|
||||
});
|
||||
var globalConfig = {};
|
||||
var loading = false;
|
||||
|
||||
const loadConfig = () => {
|
||||
globalConfig.autoRefresh = $('#auto-refresh').prop('checked');
|
||||
};
|
||||
const remove = (id) => {
|
||||
var url = '/api/admin/mangadex/queue/delete';
|
||||
if (id !== undefined)
|
||||
url += '?' + $.param({id: id});
|
||||
console.log(url);
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
dataType: 'json'
|
||||
})
|
||||
.done(data => {
|
||||
if (!data.success && data.error) {
|
||||
alert('danger', `Failed to remove job from download queue. Error: ${data.error}`);
|
||||
return;
|
||||
}
|
||||
load();
|
||||
})
|
||||
.fail((jqXHR, status) => {
|
||||
alert('danger', `Failed to remove job from download queue. Error: [${jqXHR.status}] ${jqXHR.statusText}`);
|
||||
});
|
||||
};
|
||||
const refresh = (id) => {
|
||||
var url = '/api/admin/mangadex/queue/retry';
|
||||
if (id !== undefined)
|
||||
url += '?' + $.param({id: id});
|
||||
console.log(url);
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
dataType: 'json'
|
||||
})
|
||||
.done(data => {
|
||||
if (!data.success && data.error) {
|
||||
alert('danger', `Failed to restart download job. Error: ${data.error}`);
|
||||
return;
|
||||
}
|
||||
load();
|
||||
})
|
||||
.fail((jqXHR, status) => {
|
||||
alert('danger', `Failed to restart download job. Error: [${jqXHR.status}] ${jqXHR.statusText}`);
|
||||
});
|
||||
};
|
||||
const toggle = () => {
|
||||
$('#pause-resume-btn').attr('disabled', '');
|
||||
const paused = $('#pause-resume-btn').text() === 'Resume download';
|
||||
const action = paused ? 'resume' : 'pause';
|
||||
const url = `/api/admin/mangadex/queue/${action}`;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: url,
|
||||
dataType: 'json'
|
||||
})
|
||||
.fail((jqXHR, status) => {
|
||||
alert('danger', `Failed to ${action} download queue. Error: [${jqXHR.status}] ${jqXHR.statusText}`);
|
||||
})
|
||||
.always(() => {
|
||||
load();
|
||||
$('#pause-resume-btn').removeAttr('disabled');
|
||||
});
|
||||
};
|
||||
const load = () => {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
console.log('fetching');
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/api/admin/mangadex/queue',
|
||||
dataType: 'json'
|
||||
})
|
||||
.done(data => {
|
||||
if (!data.success && data.error) {
|
||||
alert('danger', `Failed to fetch download queue. Error: ${data.error}`);
|
||||
return;
|
||||
}
|
||||
console.log(data);
|
||||
const btnText = data.paused ? "Resume download" : "Pause download";
|
||||
$('#pause-resume-btn').text(btnText);
|
||||
$('#pause-resume-btn').removeAttr('hidden');
|
||||
const rows = data.jobs.map(obj => {
|
||||
var cls = 'uk-label ';
|
||||
if (obj.status === 'Completed')
|
||||
cls += 'uk-label-success';
|
||||
if (obj.status === 'Error')
|
||||
cls += 'uk-label-danger';
|
||||
if (obj.status === 'MissingPages')
|
||||
cls += 'uk-label-warning';
|
||||
|
||||
const info = obj.status_message.length > 0 ? '<span uk-icon="info"></span>' : '';
|
||||
const statusSpan = `<span class="${cls}">${obj.status} ${info}</span>`;
|
||||
const dropdown = obj.status_message.length > 0 ? `<div uk-dropdown>${obj.status_message}</div>` : '';
|
||||
const retryBtn = obj.status_message.length > 0 ? `<a onclick="refresh('${obj.id}')" uk-icon="refresh"></a>` : '';
|
||||
return `<tr id="chapter-${obj.id}">
|
||||
<td><a href="${baseURL}/chapter/${obj.id}">${obj.title}</a></td>
|
||||
<td><a href="${baseURL}/manga/${obj.manga_id}">${obj.manga_title}</a></td>
|
||||
<td>${obj.success_count}/${obj.pages}</td>
|
||||
<td>${moment(obj.time).fromNow()}</td>
|
||||
<td>${statusSpan} ${dropdown}</td>
|
||||
<td>
|
||||
<a onclick="remove('${obj.id}')" uk-icon="trash"></a>
|
||||
${retryBtn}
|
||||
</td>
|
||||
</tr>`;
|
||||
});
|
||||
|
||||
const tbody = `<tbody>${rows.join('')}</tbody>`;
|
||||
$('tbody').remove();
|
||||
$('table').append(tbody);
|
||||
})
|
||||
.fail((jqXHR, status) => {
|
||||
alert('danger', `Failed to fetch download queue. Error: [${jqXHR.status}] ${jqXHR.statusText}`);
|
||||
})
|
||||
.always(() => {
|
||||
loading = false;
|
||||
});
|
||||
};
|
||||
299
public/js/download.js
Normal file
299
public/js/download.js
Normal file
@@ -0,0 +1,299 @@
|
||||
$(() => {
|
||||
$('#search-input').keypress(event => {
|
||||
if (event.which === 13) {
|
||||
search();
|
||||
}
|
||||
});
|
||||
$('.filter-field').each((i, ele) => {
|
||||
$(ele).change(() => {
|
||||
buildTable();
|
||||
});
|
||||
});
|
||||
});
|
||||
const selectAll = () => {
|
||||
$('tbody > tr').each((i, e) => {
|
||||
$(e).addClass('ui-selected');
|
||||
});
|
||||
};
|
||||
const unselect = () => {
|
||||
$('tbody > tr').each((i, e) => {
|
||||
$(e).removeClass('ui-selected');
|
||||
});
|
||||
};
|
||||
const download = () => {
|
||||
const selected = $('tbody > tr.ui-selected');
|
||||
if (selected.length === 0) return;
|
||||
UIkit.modal.confirm(`Download ${selected.length} selected chapters?`).then(() => {
|
||||
$('#download-btn').attr('hidden', '');
|
||||
$('#download-spinner').removeAttr('hidden');
|
||||
const ids = selected.map((i, e) => {
|
||||
return $(e).find('td').first().text();
|
||||
}).get();
|
||||
const chapters = globalChapters.filter(c => ids.indexOf(c.id) >= 0);
|
||||
console.log(ids);
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/api/admin/mangadex/download',
|
||||
data: JSON.stringify({chapters: chapters}),
|
||||
contentType: "application/json",
|
||||
dataType: 'json'
|
||||
})
|
||||
.done(data => {
|
||||
console.log(data);
|
||||
if (data.error) {
|
||||
alert('danger', `Failed to add chapters to the download queue. Error: ${data.error}`);
|
||||
return;
|
||||
}
|
||||
const successCount = parseInt(data.success);
|
||||
const failCount = parseInt(data.fail);
|
||||
UIkit.modal.confirm(`${successCount} of ${successCount + failCount} chapters added to the download queue. Proceed to the download manager?`).then(() => {
|
||||
window.location.href = '/admin/downloads';
|
||||
});
|
||||
styleModal();
|
||||
})
|
||||
.fail((jqXHR, status) => {
|
||||
alert('danger', `Failed to add chapters to the download queue. Error: [${jqXHR.status}] ${jqXHR.statusText}`);
|
||||
})
|
||||
.always(() => {
|
||||
$('#download-spinner').attr('hidden', '');
|
||||
$('#download-btn').removeAttr('hidden');
|
||||
});
|
||||
});
|
||||
styleModal();
|
||||
};
|
||||
const toggleSpinner = () => {
|
||||
var attr = $('#spinner').attr('hidden');
|
||||
if (attr) {
|
||||
$('#spinner').removeAttr('hidden');
|
||||
$('#search-btn').attr('hidden', '');
|
||||
}
|
||||
else {
|
||||
$('#search-btn').removeAttr('hidden');
|
||||
$('#spinner').attr('hidden', '');
|
||||
}
|
||||
searching = !searching;
|
||||
};
|
||||
var searching = false;
|
||||
var globalChapters;
|
||||
const search = () => {
|
||||
if (searching) {
|
||||
return;
|
||||
}
|
||||
$('#manga-details').attr('hidden', '');
|
||||
$('#filter-form').attr('hidden', '');
|
||||
$('table').attr('hidden', '');
|
||||
$('#selection-controls').attr('hidden', '');
|
||||
$('#filter-notification').attr('hidden', '');
|
||||
toggleSpinner();
|
||||
const input = $('input').val();
|
||||
|
||||
if (input === "") {
|
||||
toggleSpinner();
|
||||
return;
|
||||
}
|
||||
|
||||
var int_id = -1;
|
||||
|
||||
try {
|
||||
const path = new URL(input).pathname;
|
||||
const match = /\/title\/([0-9]+)/.exec(path);
|
||||
int_id = parseInt(match[1]);
|
||||
}
|
||||
catch(e) {
|
||||
int_id = parseInt(input);
|
||||
}
|
||||
|
||||
if (int_id <= 0 || isNaN(int_id)) {
|
||||
alert('danger', 'Please make sure you are using a valid manga ID or manga URL from Mangadex.');
|
||||
toggleSpinner();
|
||||
return;
|
||||
}
|
||||
|
||||
$.getJSON("/api/admin/mangadex/manga/" + int_id)
|
||||
.done((data) => {
|
||||
if (data.error) {
|
||||
alert('danger', 'Failed to get manga info. Error: ' + data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
const cover = baseURL + data.cover_url;
|
||||
$('#cover').attr("src", cover);
|
||||
$('#title').text("Title: " + data.title);
|
||||
$('#artist').text("Artist: " + data.artist);
|
||||
$('#author').text("Author: " + data.author);
|
||||
|
||||
$('#manga-details').removeAttr('hidden');
|
||||
|
||||
console.log(data.chapters);
|
||||
globalChapters = data.chapters;
|
||||
|
||||
let langs = new Set();
|
||||
let group_names = new Set();
|
||||
data.chapters.forEach(chp => {
|
||||
Object.entries(chp.groups).forEach(([k, v]) => {
|
||||
group_names.add(k);
|
||||
});
|
||||
langs.add(chp.language);
|
||||
});
|
||||
|
||||
const comp = (a, b) => {
|
||||
var ai;
|
||||
var bi;
|
||||
try {ai = parseFloat(a);} catch(e) {}
|
||||
try {bi = parseFloat(b);} catch(e) {}
|
||||
if (typeof ai === 'undefined') return -1;
|
||||
if (typeof bi === 'undefined') return 1;
|
||||
if (ai < bi) return 1;
|
||||
if (ai > bi) return -1;
|
||||
return 0;
|
||||
};
|
||||
|
||||
langs = [...langs].sort();
|
||||
group_names = [...group_names].sort();
|
||||
|
||||
langs.unshift('All');
|
||||
group_names.unshift('All');
|
||||
|
||||
$('select#lang-select').append(langs.map(e => `<option>${e}</option>`).join(''));
|
||||
$('select#group-select').append(group_names.map(e => `<option>${e}</option>`).join(''));
|
||||
|
||||
$('#filter-form').removeAttr('hidden');
|
||||
|
||||
buildTable();
|
||||
})
|
||||
.fail((jqXHR, status) => {
|
||||
alert('danger', `Failed to get manga info. Error: [${jqXHR.status}] ${jqXHR.statusText}`);
|
||||
})
|
||||
.always(() => {
|
||||
toggleSpinner();
|
||||
});
|
||||
};
|
||||
const parseRange = str => {
|
||||
const regex = /^[\t ]*(?:(?:(<|<=|>|>=)[\t ]*([0-9]+))|(?:([0-9]+))|(?:([0-9]+)[\t ]*-[\t ]*([0-9]+))|(?:[\t ]*))[\t ]*$/m;
|
||||
const matches = str.match(regex);
|
||||
var num;
|
||||
|
||||
if (!matches) {
|
||||
alert('danger', `Failed to parse filter input ${str}`);
|
||||
return [null, null];
|
||||
}
|
||||
else if (typeof matches[1] !== 'undefined' && typeof matches[2] !== 'undefined') {
|
||||
// e.g., <= 30
|
||||
num = parseInt(matches[2]);
|
||||
if (isNaN(num)) {
|
||||
alert('danger', `Failed to parse filter input ${str}`);
|
||||
return [null, null];
|
||||
}
|
||||
switch (matches[1]) {
|
||||
case '<':
|
||||
return [null, num - 1];
|
||||
case '<=':
|
||||
return [null, num];
|
||||
case '>':
|
||||
return [num + 1, null];
|
||||
case '>=':
|
||||
return [num, null];
|
||||
}
|
||||
}
|
||||
else if (typeof matches[3] !== 'undefined') {
|
||||
// a single number
|
||||
num = parseInt(matches[3]);
|
||||
if (isNaN(num)) {
|
||||
alert('danger', `Failed to parse filter input ${str}`);
|
||||
return [null, null];
|
||||
}
|
||||
return [num, num];
|
||||
}
|
||||
else if (typeof matches[4] !== 'undefined' && typeof matches[5] !== 'undefined') {
|
||||
// e.g., 10 - 23
|
||||
num = parseInt(matches[4]);
|
||||
const n2 = parseInt(matches[5]);
|
||||
if (isNaN(num) || isNaN(n2) || num > n2) {
|
||||
alert('danger', `Failed to parse filter input ${str}`);
|
||||
return [null, null];
|
||||
}
|
||||
return [num, n2];
|
||||
}
|
||||
else {
|
||||
// empty or space only
|
||||
return [null, null];
|
||||
}
|
||||
};
|
||||
const getFilters = () => {
|
||||
const filters = {};
|
||||
$('.uk-select').each((i, ele) => {
|
||||
const id = $(ele).attr('id');
|
||||
const by = id.split('-')[0];
|
||||
const choice = $(ele).val();
|
||||
filters[by] = choice;
|
||||
});
|
||||
filters.volume = parseRange($('#volume-range').val());
|
||||
filters.chapter = parseRange($('#chapter-range').val());
|
||||
return filters;
|
||||
};
|
||||
const buildTable = () => {
|
||||
$('table').attr('hidden', '');
|
||||
$('#selection-controls').attr('hidden', '');
|
||||
$('#filter-notification').attr('hidden', '');
|
||||
console.log('rebuilding table');
|
||||
const filters = getFilters();
|
||||
console.log('filters:', filters);
|
||||
var chapters = globalChapters.slice();
|
||||
Object.entries(filters).forEach(([k, v]) => {
|
||||
if (v === 'All') return;
|
||||
if (k === 'group') {
|
||||
chapters = chapters.filter(c => v in c.groups);
|
||||
return;
|
||||
}
|
||||
if (k === 'lang') {
|
||||
chapters = chapters.filter(c => c.language === v);
|
||||
return;
|
||||
}
|
||||
const lb = parseFloat(v[0]);
|
||||
const ub = parseFloat(v[1]);
|
||||
if (isNaN(lb) && isNaN(ub)) return;
|
||||
chapters = chapters.filter(c => {
|
||||
const val = parseFloat(c[k]);
|
||||
if (isNaN(val)) return false;
|
||||
if (isNaN(lb))
|
||||
return val <= ub;
|
||||
else if (isNaN(ub))
|
||||
return val >= lb;
|
||||
else
|
||||
return val >= lb && val <= ub;
|
||||
});
|
||||
});
|
||||
console.log('filtered chapters:', chapters);
|
||||
$('#count-text').text(`${chapters.length} chapters found`);
|
||||
|
||||
const chaptersLimit = 1000;
|
||||
if (chapters.length > chaptersLimit) {
|
||||
$('#filter-notification').text(`Mango can only list ${chaptersLimit} chapters, but we found ${chapters.length} chapters in this manga. Please use the filter options above to narrow down your search.`);
|
||||
$('#filter-notification').removeAttr('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
const inner = chapters.map(chp => {
|
||||
const group_str = Object.entries(chp.groups).map(([k, v]) => {
|
||||
return `<a href="${baseURL }/group/${v}">${k}</a>`;
|
||||
}).join(' | ');
|
||||
const dark = getTheme() === 'dark' ? 'dark' : '';
|
||||
return `<tr class="ui-widget-content ${dark}">
|
||||
<td><a href="${baseURL}/chapter/${chp.id}">${chp.id}</a></td>
|
||||
<td>${chp.title}</td>
|
||||
<td>${chp.language}</td>
|
||||
<td>${group_str}</td>
|
||||
<td>${chp.volume}</td>
|
||||
<td>${chp.chapter}</td>
|
||||
<td>${moment.unix(chp.time).fromNow()}</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
const tbody = `<tbody id="selectable">${inner}</tbody>`;
|
||||
$('tbody').remove();
|
||||
$('table').append(tbody);
|
||||
$('table').removeAttr('hidden');
|
||||
$("#selectable").selectable({
|
||||
filter: 'tr'
|
||||
});
|
||||
$('#selection-controls').removeAttr('hidden');
|
||||
};
|
||||
5
public/js/fontawesome.min.js
vendored
Normal file
5
public/js/fontawesome.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -58,8 +58,12 @@ $('#page-select').change(function(){
|
||||
jumpTo(parseInt($('#page-select').val()));
|
||||
});
|
||||
function showControl(idx) {
|
||||
const pageCount = $('#page-select > option').length;
|
||||
const progressText = `Progress: ${idx}/${pageCount} (${(idx/pageCount * 100).toFixed(1)}%)`;
|
||||
$('#progress-label').text(progressText);
|
||||
$('#page-select').val(idx);
|
||||
UIkit.modal($('#modal-sections')).show();
|
||||
styleModal();
|
||||
}
|
||||
function jumpTo(page) {
|
||||
var ary = window.location.pathname.split('/');
|
||||
|
||||
5
public/js/solid.min.js
vendored
Normal file
5
public/js/solid.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
124
public/js/sort-items.js
Normal file
124
public/js/sort-items.js
Normal file
@@ -0,0 +1,124 @@
|
||||
$(() => {
|
||||
const sortItems = () => {
|
||||
const sort = $('#sort-select').find(':selected').attr('id');
|
||||
const ary = sort.split('-');
|
||||
const by = ary[0];
|
||||
const dir = ary[1];
|
||||
|
||||
let items = $('.item');
|
||||
items.remove();
|
||||
|
||||
const ctxAry = [];
|
||||
const keyRange = {};
|
||||
if (by === 'auto') {
|
||||
// intelligent sorting
|
||||
items.each((i, item) => {
|
||||
const name = $(item).find('.uk-card-title').text();
|
||||
const regex = /([^0-9\n\r\ ]*)[ ]*([0-9]*\.*[0-9]+)/g;
|
||||
|
||||
const numbers = {};
|
||||
let match = regex.exec(name);
|
||||
while (match) {
|
||||
const key = match[1];
|
||||
const num = parseFloat(match[2]);
|
||||
numbers[key] = num;
|
||||
|
||||
if (!keyRange[key]) {
|
||||
keyRange[key] = [num, num, 1];
|
||||
}
|
||||
else {
|
||||
keyRange[key][2] += 1;
|
||||
if (num < keyRange[key][0]) {
|
||||
keyRange[key][0] = num;
|
||||
}
|
||||
else if (num > keyRange[key][1]) {
|
||||
keyRange[key][1] = num;
|
||||
}
|
||||
}
|
||||
|
||||
match = regex.exec(name);
|
||||
}
|
||||
ctxAry.push({index: i, numbers: numbers});
|
||||
});
|
||||
|
||||
console.log(keyRange);
|
||||
|
||||
const sortedKeys = Object.keys(keyRange).filter(k => {
|
||||
return keyRange[k][2] >= items.length / 2;
|
||||
});
|
||||
|
||||
sortedKeys.sort((a, b) => {
|
||||
// sort by frequency of the key first
|
||||
if (keyRange[a][2] !== keyRange[b][2]) {
|
||||
return keyRange[a][2] < keyRange[b][2];
|
||||
}
|
||||
// then sort by range of the key
|
||||
return (keyRange[a][1] - keyRange[a][0]) < (keyRange[b][1] - keyRange[b][0]);
|
||||
});
|
||||
|
||||
console.log(sortedKeys);
|
||||
|
||||
ctxAry.sort((a, b) => {
|
||||
for (let i = 0; i < sortedKeys.length; i++) {
|
||||
const key = sortedKeys[i];
|
||||
|
||||
if (a.numbers[key] === undefined && b.numbers[key] === undefined)
|
||||
continue;
|
||||
if (a.numbers[key] === undefined)
|
||||
return 1;
|
||||
if (b.numbers[key] === undefined)
|
||||
return -1;
|
||||
if (a.numbers[key] === b.numbers[key])
|
||||
continue;
|
||||
return a.numbers[key] > b.numbers[key];
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
const sortedItems = [];
|
||||
ctxAry.forEach(ctx => {
|
||||
sortedItems.push(items[ctx.index]);
|
||||
});
|
||||
items = sortedItems;
|
||||
|
||||
if (dir === 'down') {
|
||||
items.reverse();
|
||||
}
|
||||
}
|
||||
else {
|
||||
items.sort((a, b) => {
|
||||
var res;
|
||||
if (by === 'name')
|
||||
res = $(a).find('.uk-card-title').text() > $(b).find('.uk-card-title').text();
|
||||
else if (by === 'date')
|
||||
res = $(a).attr('data-mtime') > $(b).attr('data-mtime');
|
||||
else if (by === 'progress') {
|
||||
const ap = parseFloat($(a).attr('data-progress'));
|
||||
const bp = parseFloat($(b).attr('data-progress'));
|
||||
if (ap === bp)
|
||||
// if progress is the same, we compare by name
|
||||
res = $(a).find('.uk-card-title').text() > $(b).find('.uk-card-title').text();
|
||||
else
|
||||
res = ap > bp;
|
||||
}
|
||||
if (dir === 'up')
|
||||
return res;
|
||||
else
|
||||
return !res;
|
||||
});
|
||||
}
|
||||
var html = '';
|
||||
$('#item-container').append(items);
|
||||
};
|
||||
|
||||
$('#sort-select').change(() => {
|
||||
sortItems();
|
||||
});
|
||||
|
||||
if ($('option#auto-up').length > 0)
|
||||
$('option#auto-up').attr('selected', '');
|
||||
else
|
||||
$('option#name-up').attr('selected', '');
|
||||
|
||||
sortItems();
|
||||
});
|
||||
78
public/js/theme.js
Normal file
78
public/js/theme.js
Normal file
@@ -0,0 +1,78 @@
|
||||
const getTheme = () => {
|
||||
var theme = localStorage.getItem('theme');
|
||||
if (!theme) theme = 'light';
|
||||
return theme;
|
||||
};
|
||||
|
||||
const saveTheme = theme => {
|
||||
localStorage.setItem('theme', theme);
|
||||
};
|
||||
|
||||
const toggleTheme = () => {
|
||||
const theme = getTheme();
|
||||
const newTheme = theme === 'dark' ? 'light' : 'dark';
|
||||
setTheme(newTheme);
|
||||
saveTheme(newTheme);
|
||||
};
|
||||
|
||||
// https://stackoverflow.com/a/28344281
|
||||
const hasClass = (ele,cls) => {
|
||||
return !!ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
|
||||
};
|
||||
const addClass = (ele,cls) => {
|
||||
if (!hasClass(ele,cls)) ele.className += " "+cls;
|
||||
};
|
||||
const removeClass = (ele,cls) => {
|
||||
if (hasClass(ele,cls)) {
|
||||
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
|
||||
ele.className=ele.className.replace(reg,' ');
|
||||
}
|
||||
};
|
||||
|
||||
const addClassToClass = (targetCls, newCls) => {
|
||||
const elements = document.getElementsByClassName(targetCls);
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
addClass(elements[i], newCls);
|
||||
}
|
||||
};
|
||||
|
||||
const removeClassFromClass = (targetCls, newCls) => {
|
||||
const elements = document.getElementsByClassName(targetCls);
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
removeClass(elements[i], newCls);
|
||||
}
|
||||
};
|
||||
|
||||
const setTheme = themeStr => {
|
||||
if (themeStr === 'dark') {
|
||||
document.getElementsByTagName('html')[0].style.background = 'rgb(20, 20, 20)';
|
||||
addClass(document.getElementsByTagName('body')[0], 'uk-light');
|
||||
addClassToClass('uk-card', 'uk-card-secondary');
|
||||
removeClassFromClass('uk-card', 'uk-card-default');
|
||||
addClassToClass('ui-widget-content', 'dark');
|
||||
}
|
||||
else {
|
||||
document.getElementsByTagName('html')[0].style.background = '';
|
||||
removeClass(document.getElementsByTagName('body')[0], 'uk-light');
|
||||
removeClassFromClass('uk-card', 'uk-card-secondary');
|
||||
addClassToClass('uk-card', 'uk-card-default');
|
||||
removeClassFromClass('ui-widget-content', 'dark');
|
||||
}
|
||||
};
|
||||
|
||||
const styleModal = () => {
|
||||
const color = getTheme() === 'dark' ? '#222' : '';
|
||||
$('.uk-modal-header').css('background', color);
|
||||
$('.uk-modal-body').css('background', color);
|
||||
$('.uk-modal-footer').css('background', color);
|
||||
};
|
||||
|
||||
// do it before document is ready to prevent the initial flash of white
|
||||
setTheme(getTheme());
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// because this script is attached at the top of HTML, the style on uk-card
|
||||
// won't be applied because the elements are not available yet. We have to
|
||||
// apply the theme again for it to take effect
|
||||
setTheme(getTheme());
|
||||
}, false);
|
||||
@@ -1,4 +1,7 @@
|
||||
function showModal(title, zipPath, pages, percentage, title, entry) {
|
||||
function showModal(encodedPath, pages, percentage, encodedeTitle, encodedEntryTitle, titleID, entryID) {
|
||||
const zipPath = decodeURIComponent(encodedPath);
|
||||
const title = decodeURIComponent(encodedeTitle);
|
||||
const entry = decodeURIComponent(encodedEntryTitle);
|
||||
$('#modal button, #modal a').each(function(){
|
||||
$(this).removeAttr('hidden');
|
||||
});
|
||||
@@ -12,24 +15,25 @@ function showModal(title, zipPath, pages, percentage, title, entry) {
|
||||
if (percentage === 100) {
|
||||
$('#read-btn').attr('hidden', '');
|
||||
}
|
||||
$('#modal-title').text(title);
|
||||
$('#modal-title').text(entry);
|
||||
$('#path-text').text(zipPath);
|
||||
$('#pages-text').text(pages + ' pages');
|
||||
|
||||
$('#beginning-btn').attr('href', '/reader/' + title + '/' + entry + '/1');
|
||||
$('#continue-btn').attr('href', '/reader/' + title + '/' + entry);
|
||||
$('#beginning-btn').attr('href', '/reader/' + titleID + '/' + entryID + '/1');
|
||||
$('#continue-btn').attr('href', '/reader/' + titleID + '/' + entryID);
|
||||
|
||||
$('#read-btn').click(function(){
|
||||
updateProgress(title, entry, pages);
|
||||
updateProgress(titleID, entryID, pages);
|
||||
});
|
||||
$('#unread-btn').click(function(){
|
||||
updateProgress(title, entry, 0);
|
||||
updateProgress(titleID, entryID, 0);
|
||||
});
|
||||
|
||||
UIkit.modal($('#modal')).show();
|
||||
styleModal();
|
||||
}
|
||||
function updateProgress(title, entry, page) {
|
||||
$.post('/api/progress/' + title + '/' + entry + '/' + page, function(data) {
|
||||
function updateProgress(titleID, entryID, page) {
|
||||
$.post('/api/progress/' + titleID + '/' + entryID + '/' + page, function(data) {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
}
|
||||
@@ -39,11 +43,3 @@ function updateProgress(title, entry, page) {
|
||||
}
|
||||
});
|
||||
}
|
||||
function alert(level, text) {
|
||||
hideAlert();
|
||||
var html = '<div class="uk-alert-' + level + '" uk-alert><a class="uk-alert-close" uk-close></a><p>' + text + '</p></div>';
|
||||
$('#alert').append(html);
|
||||
}
|
||||
function hideAlert() {
|
||||
$('#alert').empty();
|
||||
}
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
$(function(){
|
||||
$(() => {
|
||||
var target = '/admin/user/edit';
|
||||
if (username) target += username;
|
||||
$('form').attr('action', target);
|
||||
|
||||
function alert(level, text) {
|
||||
hideAlert();
|
||||
var html = '<div class="uk-alert-' + level + '" uk-alert><a class="uk-alert-close" uk-close></a><p>' + text + '</p></div>';
|
||||
$('#alert').append(html);
|
||||
}
|
||||
function hideAlert() {
|
||||
$('#alert').empty();
|
||||
}
|
||||
|
||||
if (error) alert('danger', error);
|
||||
});
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
function alert(level, text) {
|
||||
hideAlert();
|
||||
var html = '<div class="uk-alert-' + level + '" uk-alert><a class="uk-alert-close" uk-close></a><p>' + text + '</p></div>';
|
||||
$('#alert').append(html);
|
||||
}
|
||||
function hideAlert() {
|
||||
$('#alert').empty();
|
||||
}
|
||||
function remove(username) {
|
||||
$.post('/api/admin/user/delete/' + username, function(data) {
|
||||
if (data.success) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: mango
|
||||
version: 0.1.0
|
||||
version: 0.2.1
|
||||
|
||||
authors:
|
||||
- Alex Ling <hkalexling@gmail.com>
|
||||
|
||||
2
spec/asset/test-config.yml
Normal file
2
spec/asset/test-config.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
port: 3000
|
||||
14
spec/config_spec.cr
Normal file
14
spec/config_spec.cr
Normal file
@@ -0,0 +1,14 @@
|
||||
require "./spec_helper"
|
||||
|
||||
describe Config do
|
||||
it "creates config if it does not exist" do
|
||||
with_default_config do |config, logger, path|
|
||||
File.exists?(path).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "correctly loads config" do
|
||||
config = Config.load "spec/asset/test-config.yml"
|
||||
config.port.should eq 3000
|
||||
end
|
||||
end
|
||||
105
spec/mangadex_spec.cr
Normal file
105
spec/mangadex_spec.cr
Normal file
@@ -0,0 +1,105 @@
|
||||
require "./spec_helper"
|
||||
|
||||
include MangaDex
|
||||
|
||||
describe Queue do
|
||||
it "creates DB at given path" do
|
||||
with_queue do |queue, path|
|
||||
File.exists?(path).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "pops nil when empty" do
|
||||
with_queue do |queue|
|
||||
queue.pop.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it "inserts multiple jobs" do
|
||||
with_queue do |queue|
|
||||
j1 = Job.new "1", "1", "title", "manga_title", JobStatus::Error,
|
||||
Time.utc
|
||||
j2 = Job.new "2", "2", "title", "manga_title", JobStatus::Completed,
|
||||
Time.utc
|
||||
j3 = Job.new "3", "3", "title", "manga_title", JobStatus::Pending,
|
||||
Time.utc
|
||||
j4 = Job.new "4", "4", "title", "manga_title",
|
||||
JobStatus::Downloading, Time.utc
|
||||
count = queue.push [j1, j2, j3, j4]
|
||||
count.should eq 4
|
||||
end
|
||||
end
|
||||
|
||||
it "pops pending job" do
|
||||
with_queue do |queue|
|
||||
job = queue.pop
|
||||
job.should_not be_nil
|
||||
job.not_nil!.id.should eq "3"
|
||||
end
|
||||
end
|
||||
|
||||
it "correctly counts jobs" do
|
||||
with_queue do |queue|
|
||||
queue.count.should eq 4
|
||||
end
|
||||
end
|
||||
|
||||
it "deletes job" do
|
||||
with_queue do |queue|
|
||||
queue.delete "4"
|
||||
queue.count.should eq 3
|
||||
end
|
||||
end
|
||||
|
||||
it "sets status" do
|
||||
with_queue do |queue|
|
||||
job = queue.pop.not_nil!
|
||||
queue.set_status JobStatus::Downloading, job
|
||||
job = queue.pop
|
||||
job.should_not be_nil
|
||||
job.not_nil!.status.should eq JobStatus::Downloading
|
||||
end
|
||||
end
|
||||
|
||||
it "sets number of pages" do
|
||||
with_queue do |queue|
|
||||
job = queue.pop.not_nil!
|
||||
queue.set_pages 100, job
|
||||
job = queue.pop
|
||||
job.should_not be_nil
|
||||
job.not_nil!.pages.should eq 100
|
||||
end
|
||||
end
|
||||
|
||||
it "adds fail/success counts" do
|
||||
with_queue do |queue|
|
||||
job = queue.pop.not_nil!
|
||||
queue.add_success job
|
||||
queue.add_success job
|
||||
queue.add_fail job
|
||||
job = queue.pop
|
||||
job.should_not be_nil
|
||||
job.not_nil!.success_count.should eq 2
|
||||
job.not_nil!.fail_count.should eq 1
|
||||
end
|
||||
end
|
||||
|
||||
it "appends status message" do
|
||||
with_queue do |queue|
|
||||
job = queue.pop.not_nil!
|
||||
queue.add_message "hello", job
|
||||
queue.add_message "world", job
|
||||
job = queue.pop
|
||||
job.should_not be_nil
|
||||
job.not_nil!.status_message.should eq "\nhello\nworld"
|
||||
end
|
||||
end
|
||||
|
||||
it "cleans up" do
|
||||
with_queue do
|
||||
true
|
||||
end
|
||||
State.reset
|
||||
end
|
||||
end
|
||||
|
||||
65
spec/spec_helper.cr
Normal file
65
spec/spec_helper.cr
Normal file
@@ -0,0 +1,65 @@
|
||||
require "spec"
|
||||
require "../src/context"
|
||||
require "../src/server"
|
||||
|
||||
class State
|
||||
@@hash = {} of String => String
|
||||
|
||||
def self.get(key)
|
||||
@@hash[key]?
|
||||
end
|
||||
|
||||
def self.get!(key)
|
||||
@@hash[key]
|
||||
end
|
||||
|
||||
def self.set(key, value)
|
||||
return if value.nil?
|
||||
@@hash[key] = value
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@@hash.clear
|
||||
end
|
||||
end
|
||||
|
||||
def get_tempfile(name)
|
||||
path = State.get name
|
||||
if path.nil? || !File.exists? path
|
||||
file = File.tempfile name
|
||||
State.set name, file.path
|
||||
return file
|
||||
else
|
||||
return File.new path
|
||||
end
|
||||
end
|
||||
|
||||
def with_default_config
|
||||
temp_config = get_tempfile "mango-test-config"
|
||||
config = Config.load temp_config.path
|
||||
logger = MLogger.new config
|
||||
yield config, logger, temp_config.path
|
||||
temp_config.delete
|
||||
end
|
||||
|
||||
def with_storage
|
||||
with_default_config do |config, logger|
|
||||
temp_db = get_tempfile "mango-test-db"
|
||||
storage = Storage.new temp_db.path, logger
|
||||
clear = yield storage, temp_db.path
|
||||
if clear == true
|
||||
temp_db.delete
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def with_queue
|
||||
with_default_config do |config, logger|
|
||||
temp_queue_db = get_tempfile "mango-test-queue-db"
|
||||
queue = MangaDex::Queue.new temp_queue_db.path, logger
|
||||
clear = yield queue, temp_queue_db.path
|
||||
if clear == true
|
||||
temp_queue_db.delete
|
||||
end
|
||||
end
|
||||
end
|
||||
91
spec/storage_spec.cr
Normal file
91
spec/storage_spec.cr
Normal file
@@ -0,0 +1,91 @@
|
||||
require "./spec_helper"
|
||||
|
||||
describe Storage do
|
||||
it "creates DB at given path" do
|
||||
with_storage do |storage, path|
|
||||
File.exists?(path).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "deletes user" do
|
||||
with_storage do |storage|
|
||||
storage.delete_user "admin"
|
||||
end
|
||||
end
|
||||
|
||||
it "creates new user" do
|
||||
with_storage do |storage|
|
||||
storage.new_user "user", "123456", false
|
||||
storage.new_user "admin", "123456", true
|
||||
end
|
||||
end
|
||||
|
||||
it "verifies username/password combination" do
|
||||
with_storage do |storage|
|
||||
user_token = storage.verify_user "user", "123456"
|
||||
admin_token = storage.verify_user "admin", "123456"
|
||||
user_token.should_not be_nil
|
||||
admin_token.should_not be_nil
|
||||
State.set "user_token", user_token
|
||||
State.set "admin_token", admin_token
|
||||
end
|
||||
end
|
||||
|
||||
it "rejects duplicate username" do
|
||||
with_storage do |storage|
|
||||
expect_raises SQLite3::Exception,
|
||||
"UNIQUE constraint failed: users.username" do
|
||||
storage.new_user "admin", "123456", true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "verifies token" do
|
||||
with_storage do |storage|
|
||||
user_token = State.get! "user_token"
|
||||
user = storage.verify_token user_token
|
||||
user.should eq "user"
|
||||
end
|
||||
end
|
||||
|
||||
it "verfies admin token" do
|
||||
with_storage do |storage|
|
||||
admin_token = State.get! "admin_token"
|
||||
storage.verify_admin(admin_token).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "rejects non-admin token" do
|
||||
with_storage do |storage|
|
||||
user_token = State.get! "user_token"
|
||||
storage.verify_admin(user_token).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
it "updates user" do
|
||||
with_storage do |storage|
|
||||
storage.update_user "admin", "admin", "654321", true
|
||||
token = storage.verify_user "admin", "654321"
|
||||
admin_token = State.get! "admin_token"
|
||||
token.should eq admin_token
|
||||
end
|
||||
end
|
||||
|
||||
it "logs user out" do
|
||||
with_storage do |storage|
|
||||
user_token = State.get! "user_token"
|
||||
admin_token = State.get! "admin_token"
|
||||
storage.logout user_token
|
||||
storage.logout admin_token
|
||||
storage.verify_token(user_token).should be_nil
|
||||
storage.verify_token(admin_token).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it "cleans up" do
|
||||
with_storage do
|
||||
true
|
||||
end
|
||||
State.reset
|
||||
end
|
||||
end
|
||||
28
spec/util_spec.cr
Normal file
28
spec/util_spec.cr
Normal file
@@ -0,0 +1,28 @@
|
||||
require "./spec_helper"
|
||||
|
||||
describe "compare_alphanumerically" do
|
||||
it "sorts filenames with leading zeros correctly" do
|
||||
ary = ["010.jpg", "001.jpg", "002.png"]
|
||||
ary.sort! {|a, b|
|
||||
compare_alphanumerically a, b
|
||||
}
|
||||
ary.should eq ["001.jpg", "002.png", "010.jpg"]
|
||||
end
|
||||
|
||||
it "sorts filenames without leading zeros correctly" do
|
||||
ary = ["10.jpg", "1.jpg", "0.png", "0100.jpg"]
|
||||
ary.sort! {|a, b|
|
||||
compare_alphanumerically a, b
|
||||
}
|
||||
ary.should eq ["0.png", "1.jpg", "10.jpg", "0100.jpg"]
|
||||
end
|
||||
|
||||
# https://ux.stackexchange.com/a/95441
|
||||
it "sorts like the stack exchange post" do
|
||||
ary = ["2", "12", "200000", "1000000", "a", "a12", "b2", "text2",
|
||||
"text2a", "text2a2", "text2a12", "text2ab", "text12", "text12a"]
|
||||
ary.reverse.sort {|a, b|
|
||||
compare_alphanumerically a, b
|
||||
}.should eq ary
|
||||
end
|
||||
end
|
||||
41
src/assets/lang_codes.csv
Normal file
41
src/assets/lang_codes.csv
Normal file
@@ -0,0 +1,41 @@
|
||||
Arabic,sa
|
||||
Bengali,bd
|
||||
Bulgarian,bg
|
||||
Burmese,mm
|
||||
Catalan,ct
|
||||
Chinese (Simp),cn
|
||||
Chinese (Trad),hk
|
||||
Czech,cz
|
||||
Danish,dk
|
||||
Dutch,nl
|
||||
English,gb
|
||||
Filipino,ph
|
||||
Finnish,fi
|
||||
French,fr
|
||||
German,de
|
||||
Greek,gr
|
||||
Hebrew,il
|
||||
Hindi,in
|
||||
Hungarian,hu
|
||||
Indonesian,id
|
||||
Italian,it
|
||||
Japanese,jp
|
||||
Korean,kr
|
||||
Lithuanian,lt
|
||||
Malay,my
|
||||
Mongolian,mn
|
||||
Other,
|
||||
Persian,ir
|
||||
Polish,pl
|
||||
Portuguese (Br),br
|
||||
Portuguese (Pt),pt
|
||||
Romanian,ro
|
||||
Russian,ru
|
||||
Serbo-Croatian,rs
|
||||
Spanish (Es),es
|
||||
Spanish (LATAM),mx
|
||||
Swedish,se
|
||||
Thai,th
|
||||
Turkish,tr
|
||||
Ukrainian,ua
|
||||
Vietnames,vn
|
||||
|
@@ -15,7 +15,7 @@ class AuthHandler < Kemal::Handler
|
||||
return env.redirect "/login"
|
||||
end
|
||||
|
||||
if request_path_startswith env, ["/admin", "/api/admin"]
|
||||
if request_path_startswith env, ["/admin", "/api/admin", "/download"]
|
||||
unless @storage.verify_admin cookie.value
|
||||
env.response.status_code = 403
|
||||
end
|
||||
|
||||
@@ -3,28 +3,33 @@ require "yaml"
|
||||
class Config
|
||||
include YAML::Serializable
|
||||
|
||||
@[YAML::Field(key: "port")]
|
||||
property port : Int32 = 9000
|
||||
|
||||
@[YAML::Field(key: "library_path")]
|
||||
property library_path : String = \
|
||||
File.expand_path "~/mango/library", home: true
|
||||
|
||||
@[YAML::Field(key: "db_path")]
|
||||
property db_path : String = \
|
||||
File.expand_path "~/mango/mango.db", home: true
|
||||
|
||||
@[YAML::Field(key: "scan_interval_minutes")]
|
||||
property scan_interval : Int32 = 5
|
||||
|
||||
@[YAML::Field(key: "log_level")]
|
||||
property log_level : String = "info"
|
||||
property mangadex = Hash(String, String|Int32).new
|
||||
|
||||
@[YAML::Field(ignore: true)]
|
||||
@mangadex_defaults = {
|
||||
"base_url" => "https://mangadex.org",
|
||||
"api_url" => "https://mangadex.org/api",
|
||||
"download_wait_seconds" => 5,
|
||||
"download_retries" => 4,
|
||||
"download_queue_db_path" => File.expand_path "~/mango/queue.db",
|
||||
home: true
|
||||
}
|
||||
|
||||
def self.load(path : String?)
|
||||
path = "~/.config/mango/config.yml" if path.nil?
|
||||
cfg_path = File.expand_path path, home: true
|
||||
if File.exists? cfg_path
|
||||
return self.from_yaml File.read cfg_path
|
||||
config = self.from_yaml File.read cfg_path
|
||||
config.fill_defaults
|
||||
return config
|
||||
end
|
||||
puts "The config file #{cfg_path} does not exist." \
|
||||
" Do you want mango to dump the default config there? [Y/n]"
|
||||
@@ -33,6 +38,7 @@ class Config
|
||||
abort "Aborting..."
|
||||
end
|
||||
default = self.allocate
|
||||
default.fill_defaults
|
||||
cfg_dir = File.dirname cfg_path
|
||||
unless Dir.exists? cfg_dir
|
||||
Dir.mkdir_p cfg_dir
|
||||
@@ -41,4 +47,14 @@ class Config
|
||||
puts "The config file has been created at #{cfg_path}."
|
||||
default
|
||||
end
|
||||
|
||||
def fill_defaults
|
||||
{% for hash_name in ["mangadex"] %}
|
||||
@{{hash_name.id}}_defaults.map do |k, v|
|
||||
if @{{hash_name.id}}[k]?.nil?
|
||||
@{{hash_name.id}}[k] = v
|
||||
end
|
||||
end
|
||||
{% end %}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,8 +8,9 @@ class Context
|
||||
property library : Library
|
||||
property storage : Storage
|
||||
property logger : MLogger
|
||||
property queue : MangaDex::Queue
|
||||
|
||||
def initialize(@config, @logger, @library, @storage)
|
||||
def initialize(@config, @logger, @library, @storage, @queue)
|
||||
end
|
||||
|
||||
{% for lvl in LEVELS %}
|
||||
|
||||
204
src/library.cr
204
src/library.cr
@@ -1,6 +1,8 @@
|
||||
require "zip"
|
||||
require "mime"
|
||||
require "json"
|
||||
require "uri"
|
||||
require "./util"
|
||||
|
||||
struct Image
|
||||
property data : Bytes
|
||||
@@ -13,21 +15,42 @@ struct Image
|
||||
end
|
||||
|
||||
class Entry
|
||||
JSON.mapping zip_path: String, book_title: String, title: String, \
|
||||
size: String, pages: Int32, cover_url: String
|
||||
property zip_path : String, book_title : String, title : String,
|
||||
size : String, pages : Int32, cover_url : String, id : String,
|
||||
title_id : String, encoded_path : String, encoded_title : String,
|
||||
mtime : Time
|
||||
|
||||
def initialize(path, @book_title)
|
||||
def initialize(path, @book_title, @title_id, storage)
|
||||
@zip_path = path
|
||||
@encoded_path = URI.encode path
|
||||
@title = File.basename path, File.extname path
|
||||
@encoded_title = URI.encode @title
|
||||
@size = (File.size path).humanize_bytes
|
||||
@pages = Zip::File.new(path).entries
|
||||
file = Zip::File.new path
|
||||
@pages = file.entries
|
||||
.select { |e|
|
||||
["image/jpeg", "image/png"].includes? \
|
||||
MIME.from_filename? e.filename
|
||||
}
|
||||
.size
|
||||
@cover_url = "/api/page/#{@book_title}/#{title}/1"
|
||||
file.close
|
||||
@id = storage.get_id @zip_path, false
|
||||
@cover_url = "/api/page/#{@title_id}/#{@id}/1"
|
||||
@mtime = File.info(@zip_path).modification_time
|
||||
end
|
||||
|
||||
def to_json(json : JSON::Builder)
|
||||
json.object do
|
||||
{% for str in ["zip_path", "book_title", "title", "size",
|
||||
"cover_url", "id", "title_id", "encoded_path",
|
||||
"encoded_title"] %}
|
||||
json.field {{str}}, @{{str.id}}
|
||||
{% end %}
|
||||
json.field "pages" {json.number @pages}
|
||||
json.field "mtime" {json.number @mtime.to_unix}
|
||||
end
|
||||
end
|
||||
|
||||
def read_page(page_num)
|
||||
Zip::File.open @zip_path do |file|
|
||||
page = file.entries
|
||||
@@ -35,7 +58,9 @@ class Entry
|
||||
["image/jpeg", "image/png"].includes? \
|
||||
MIME.from_filename? e.filename
|
||||
}
|
||||
.sort { |a, b| a.filename <=> b.filename }
|
||||
.sort { |a, b|
|
||||
compare_alphanumerically a.filename, b.filename
|
||||
}
|
||||
.[page_num - 1]
|
||||
page.open do |io|
|
||||
slice = Bytes.new page.uncompressed_size
|
||||
@@ -51,20 +76,114 @@ class Entry
|
||||
end
|
||||
|
||||
class Title
|
||||
JSON.mapping dir: String, entries: Array(Entry), title: String
|
||||
property dir : String, parent_id : String, title_ids : Array(String),
|
||||
entries : Array(Entry), title : String, id : String,
|
||||
encoded_title : String, mtime : Time
|
||||
|
||||
def initialize(dir : String)
|
||||
def initialize(dir : String, @parent_id, storage,
|
||||
@logger : MLogger, @library : Library)
|
||||
@dir = dir
|
||||
@id = storage.get_id @dir, true
|
||||
@title = File.basename dir
|
||||
@entries = (Dir.entries dir)
|
||||
.select { |path| [".zip", ".cbz"].includes? File.extname path }
|
||||
.map { |path| Entry.new File.join(dir, path), @title }
|
||||
.select { |e| e.pages > 0 }
|
||||
.sort { |a, b| a.title <=> b.title }
|
||||
@encoded_title = URI.encode @title
|
||||
@title_ids = [] of String
|
||||
@entries = [] of Entry
|
||||
|
||||
Dir.entries(dir).each do |fn|
|
||||
next if fn.starts_with? "."
|
||||
path = File.join dir, fn
|
||||
if File.directory? path
|
||||
title = Title.new path, @id, storage, @logger, library
|
||||
next if title.entries.size == 0 && title.titles.size == 0
|
||||
@library.title_hash[title.id] = title
|
||||
@title_ids << title.id
|
||||
next
|
||||
end
|
||||
if [".zip", ".cbz"].includes? File.extname path
|
||||
next if !valid_zip path
|
||||
entry = Entry.new path, @title, @id, storage
|
||||
@entries << entry if entry.pages > 0
|
||||
end
|
||||
end
|
||||
|
||||
@title_ids.sort! do |a, b|
|
||||
compare_alphanumerically @library.title_hash[a].title,
|
||||
@library.title_hash[b].title
|
||||
end
|
||||
@entries.sort! do |a, b|
|
||||
compare_alphanumerically a.title, b.title
|
||||
end
|
||||
|
||||
mtimes = [File.info(dir).modification_time]
|
||||
mtimes += @title_ids.map{|e| @library.title_hash[e].mtime}
|
||||
mtimes += @entries.map{|e| e.mtime}
|
||||
@mtime = mtimes.max
|
||||
end
|
||||
def get_entry(name)
|
||||
@entries.find { |e| e.title == name }
|
||||
|
||||
def to_json(json : JSON::Builder)
|
||||
json.object do
|
||||
{% for str in ["dir", "title", "id", "encoded_title"] %}
|
||||
json.field {{str}}, @{{str.id}}
|
||||
{% end %}
|
||||
json.field "mtime" {json.number @mtime.to_unix}
|
||||
json.field "titles" do
|
||||
json.raw self.titles.to_json
|
||||
end
|
||||
json.field "entries" do
|
||||
json.raw @entries.to_json
|
||||
end
|
||||
json.field "parents" do
|
||||
json.array do
|
||||
self.parents.each do |title|
|
||||
json.object do
|
||||
json.field "title", title.title
|
||||
json.field "id", title.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def titles
|
||||
@title_ids.map {|tid| @library.get_title! tid}
|
||||
end
|
||||
|
||||
def parents
|
||||
ary = [] of Title
|
||||
tid = @parent_id
|
||||
while !tid.empty?
|
||||
title = @library.get_title! tid
|
||||
ary << title
|
||||
tid = title.parent_id
|
||||
end
|
||||
ary
|
||||
end
|
||||
|
||||
def size
|
||||
@entries.size + @title_ids.size
|
||||
end
|
||||
|
||||
# When downloading from MangaDex, the zip/cbz file would not be valid
|
||||
# before the download is completed. If we scan the zip file,
|
||||
# Entry.new would throw, so we use this method to check before
|
||||
# constructing Entry
|
||||
private def valid_zip(path : String)
|
||||
begin
|
||||
file = Zip::File.new path
|
||||
file.close
|
||||
return true
|
||||
rescue
|
||||
@logger.warn "File #{path} is corrupted or is not a valid zip "\
|
||||
"archive. Ignoring it."
|
||||
return false
|
||||
end
|
||||
end
|
||||
def get_entry(eid)
|
||||
@entries.find { |e| e.id == eid }
|
||||
end
|
||||
# For backward backward compatibility with v0.1.0, we save entry titles
|
||||
# instead of IDs in info.json
|
||||
def save_progress(username, entry, page)
|
||||
info = TitleInfo.new @dir
|
||||
if info.progress[username]?.nil?
|
||||
@@ -75,7 +194,7 @@ class Title
|
||||
info.progress[username][entry] = page
|
||||
info.save @dir
|
||||
end
|
||||
def load_progress(username, entry : String)
|
||||
def load_progress(username, entry)
|
||||
info = TitleInfo.new @dir
|
||||
if info.progress[username]?.nil?
|
||||
return 0
|
||||
@@ -85,14 +204,15 @@ class Title
|
||||
end
|
||||
info.progress[username][entry]
|
||||
end
|
||||
def load_percetage(username, entry : String)
|
||||
def load_percetage(username, entry)
|
||||
info = TitleInfo.new @dir
|
||||
page = load_progress username, entry
|
||||
entry_obj = get_entry entry
|
||||
entry_obj = @entries.find{|e| e.title == entry}
|
||||
return 0 if entry_obj.nil?
|
||||
page / entry_obj.pages
|
||||
end
|
||||
def load_percetage(username)
|
||||
return 0 if @entries.empty?
|
||||
read_pages = total_pages = 0
|
||||
@entries.each do |e|
|
||||
read_pages += load_progress username, e.title
|
||||
@@ -111,10 +231,7 @@ class TitleInfo
|
||||
# { user1: { entry1: 10, entry2: 0 } }
|
||||
include JSON::Serializable
|
||||
|
||||
@[JSON::Field(key: "comment")]
|
||||
property comment = "Generated by Mango. DO NOT EDIT!"
|
||||
|
||||
@[JSON::Field(key: "progress")]
|
||||
property progress : Hash(String, Hash(String, Int32))
|
||||
|
||||
def initialize(title_dir)
|
||||
@@ -136,12 +253,14 @@ class TitleInfo
|
||||
end
|
||||
|
||||
class Library
|
||||
JSON.mapping dir: String, titles: Array(Title), scan_interval: Int32, logger: MLogger
|
||||
property dir : String, title_ids : Array(String), scan_interval : Int32,
|
||||
logger : MLogger, storage : Storage, title_hash : Hash(String, Title)
|
||||
|
||||
def initialize(@dir, @scan_interval, @logger)
|
||||
def initialize(@dir, @scan_interval, @logger, @storage)
|
||||
# explicitly initialize @titles to bypass the compiler check. it will
|
||||
# be filled with actual Titles in the `scan` call below
|
||||
@titles = [] of Title
|
||||
@title_ids = [] of String
|
||||
@title_hash = {} of String => Title
|
||||
|
||||
return scan if @scan_interval < 1
|
||||
spawn do
|
||||
@@ -149,13 +268,27 @@ class Library
|
||||
start = Time.local
|
||||
scan
|
||||
ms = (Time.local - start).total_milliseconds
|
||||
@logger.info "Scanned #{@titles.size} titles in #{ms}ms"
|
||||
@logger.info "Scanned #{@title_ids.size} titles in #{ms}ms"
|
||||
sleep @scan_interval * 60
|
||||
end
|
||||
end
|
||||
end
|
||||
def get_title(name)
|
||||
@titles.find { |t| t.title == name }
|
||||
def titles
|
||||
@title_ids.map {|tid| self.get_title!(tid) }
|
||||
end
|
||||
def to_json(json : JSON::Builder)
|
||||
json.object do
|
||||
json.field "dir", @dir
|
||||
json.field "titles" do
|
||||
json.raw self.titles.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
def get_title(tid)
|
||||
@title_hash[tid]?
|
||||
end
|
||||
def get_title!(tid)
|
||||
@title_hash[tid]
|
||||
end
|
||||
def scan
|
||||
unless Dir.exists? @dir
|
||||
@@ -163,11 +296,18 @@ class Library
|
||||
"Attempting to create it"
|
||||
Dir.mkdir_p @dir
|
||||
end
|
||||
@titles = (Dir.entries @dir)
|
||||
.select { |path| File.directory? File.join @dir, path }
|
||||
.map { |path| Title.new File.join @dir, path }
|
||||
.select { |title| !title.entries.empty? }
|
||||
@title_ids.clear
|
||||
(Dir.entries @dir)
|
||||
.select { |fn| !fn.starts_with? "." }
|
||||
.map { |fn| File.join @dir, fn }
|
||||
.select { |path| File.directory? path }
|
||||
.map { |path| Title.new path, "", @storage, @logger, self }
|
||||
.select { |title| !(title.entries.empty? && title.titles.empty?) }
|
||||
.sort { |a, b| a.title <=> b.title }
|
||||
.each do |title|
|
||||
@title_hash[title.id] = title
|
||||
@title_ids << title.id
|
||||
end
|
||||
@logger.debug "Scan completed"
|
||||
@logger.debug "Scanned library: \n#{self.to_pretty_json}"
|
||||
end
|
||||
end
|
||||
|
||||
203
src/mangadex/api.cr
Normal file
203
src/mangadex/api.cr
Normal file
@@ -0,0 +1,203 @@
|
||||
require "http/client"
|
||||
require "json"
|
||||
require "csv"
|
||||
|
||||
macro string_properties (names)
|
||||
{% for name in names %}
|
||||
property {{name.id}} = ""
|
||||
{% end %}
|
||||
end
|
||||
|
||||
macro parse_strings_from_json (names)
|
||||
{% for name in names %}
|
||||
@{{name.id}} = obj[{{name}}].as_s
|
||||
{% end %}
|
||||
end
|
||||
|
||||
module MangaDex
|
||||
class Chapter
|
||||
string_properties ["lang_code", "title", "volume", "chapter"]
|
||||
property manga : Manga
|
||||
property time = Time.local
|
||||
property id : String
|
||||
property full_title = ""
|
||||
property language = ""
|
||||
property pages = [] of {String, String} # filename, url
|
||||
property groups = [] of {Int32, String} # group_id, group_name
|
||||
|
||||
def initialize(@id, json_obj : JSON::Any, @manga, lang :
|
||||
Hash(String, String))
|
||||
self.parse_json json_obj, lang
|
||||
end
|
||||
|
||||
def to_info_json
|
||||
JSON.build do |json|
|
||||
json.object do
|
||||
{% for name in ["id", "title", "volume", "chapter",
|
||||
"language", "full_title"] %}
|
||||
json.field {{name}}, @{{name.id}}
|
||||
{% end %}
|
||||
json.field "time", @time.to_unix.to_s
|
||||
json.field "manga_title", @manga.title
|
||||
json.field "manga_id", @manga.id
|
||||
json.field "groups" do
|
||||
json.object do
|
||||
@groups.each do |gid, gname|
|
||||
json.field gname, gid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parse_json(obj, lang)
|
||||
begin
|
||||
parse_strings_from_json ["lang_code", "title", "volume",
|
||||
"chapter"]
|
||||
language = lang[@lang_code]?
|
||||
@language = language if language
|
||||
@time = Time.unix obj["timestamp"].as_i
|
||||
suffixes = ["", "_2", "_3"]
|
||||
suffixes.each do |s|
|
||||
gid = obj["group_id#{s}"].as_i
|
||||
next if gid == 0
|
||||
gname = obj["group_name#{s}"].as_s
|
||||
@groups << {gid, gname}
|
||||
end
|
||||
@full_title = @title
|
||||
unless @chapter.empty?
|
||||
@full_title = "Ch.#{@chapter} " + @full_title
|
||||
end
|
||||
unless @volume.empty?
|
||||
@full_title = "Vol.#{@volume} " + @full_title
|
||||
end
|
||||
rescue e
|
||||
raise "failed to parse json: #{e}"
|
||||
end
|
||||
end
|
||||
end
|
||||
class Manga
|
||||
string_properties ["cover_url", "description", "title", "author",
|
||||
"artist"]
|
||||
property chapters = [] of Chapter
|
||||
property id : String
|
||||
|
||||
def initialize(@id, json_obj : JSON::Any)
|
||||
self.parse_json json_obj
|
||||
end
|
||||
|
||||
def to_info_json(with_chapters = true)
|
||||
JSON.build do |json|
|
||||
json.object do
|
||||
{% for name in ["id", "title", "description",
|
||||
"author", "artist", "cover_url"] %}
|
||||
json.field {{name}}, @{{name.id}}
|
||||
{% end %}
|
||||
if with_chapters
|
||||
json.field "chapters" do
|
||||
json.array do
|
||||
@chapters.each do |c|
|
||||
json.raw c.to_info_json
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parse_json(obj)
|
||||
begin
|
||||
parse_strings_from_json ["cover_url", "description", "title",
|
||||
"author", "artist"]
|
||||
rescue e
|
||||
raise "failed to parse json: #{e}"
|
||||
end
|
||||
end
|
||||
end
|
||||
class API
|
||||
def initialize(@base_url = "https://mangadex.org/api/")
|
||||
@lang = {} of String => String
|
||||
CSV.each_row {{read_file "src/assets/lang_codes.csv"}} do |row|
|
||||
@lang[row[1]] = row[0]
|
||||
end
|
||||
end
|
||||
|
||||
def get(url)
|
||||
headers = HTTP::Headers {
|
||||
"User-agent" => "Mangadex.cr"
|
||||
}
|
||||
res = HTTP::Client.get url, headers
|
||||
raise "Failed to get #{url}. [#{res.status_code}] "\
|
||||
"#{res.status_message}" if !res.success?
|
||||
JSON.parse res.body
|
||||
end
|
||||
|
||||
def get_manga(id)
|
||||
obj = self.get File.join @base_url, "manga/#{id}"
|
||||
if obj["status"]? != "OK"
|
||||
raise "Expecting `OK` in the `status` field. " \
|
||||
"Got `#{obj["status"]?}`"
|
||||
end
|
||||
begin
|
||||
manga = Manga.new id, obj["manga"]
|
||||
obj["chapter"].as_h.map do |k, v|
|
||||
chapter = Chapter.new k, v, manga, @lang
|
||||
manga.chapters << chapter
|
||||
end
|
||||
return manga
|
||||
rescue
|
||||
raise "Failed to parse JSON"
|
||||
end
|
||||
end
|
||||
|
||||
def get_chapter(chapter : Chapter)
|
||||
obj = self.get File.join @base_url, "chapter/#{chapter.id}"
|
||||
if obj["status"]? == "external"
|
||||
raise "This chapter is hosted on an external site " \
|
||||
"#{obj["external"]?}, and Mango does not support " \
|
||||
"external chapters."
|
||||
end
|
||||
if obj["status"]? != "OK"
|
||||
raise "Expecting `OK` in the `status` field. " \
|
||||
"Got `#{obj["status"]?}`"
|
||||
end
|
||||
begin
|
||||
server = obj["server"].as_s
|
||||
hash = obj["hash"].as_s
|
||||
chapter.pages = obj["page_array"].as_a.map do |fn|
|
||||
{
|
||||
fn.as_s,
|
||||
"#{server}#{hash}/#{fn.as_s}"
|
||||
}
|
||||
end
|
||||
rescue
|
||||
raise "Failed to parse JSON"
|
||||
end
|
||||
end
|
||||
|
||||
def get_chapter(id : String)
|
||||
obj = self.get File.join @base_url, "chapter/#{id}"
|
||||
if obj["status"]? == "external"
|
||||
raise "This chapter is hosted on an external site " \
|
||||
"#{obj["external"]?}, and Mango does not support " \
|
||||
"external chapters."
|
||||
end
|
||||
if obj["status"]? != "OK"
|
||||
raise "Expecting `OK` in the `status` field. " \
|
||||
"Got `#{obj["status"]?}`"
|
||||
end
|
||||
manga_id = ""
|
||||
begin
|
||||
manga_id = obj["manga_id"].as_i.to_s
|
||||
rescue
|
||||
raise "Failed to parse JSON"
|
||||
end
|
||||
manga = self.get_manga manga_id
|
||||
chapter = manga.chapters.find {|c| c.id == id}.not_nil!
|
||||
self.get_chapter chapter
|
||||
return chapter
|
||||
end
|
||||
end
|
||||
end
|
||||
373
src/mangadex/downloader.cr
Normal file
373
src/mangadex/downloader.cr
Normal file
@@ -0,0 +1,373 @@
|
||||
require "./api"
|
||||
require "sqlite3"
|
||||
|
||||
module MangaDex
|
||||
class PageJob
|
||||
property success = false
|
||||
property url : String
|
||||
property filename : String
|
||||
property writer : Zip::Writer
|
||||
property tries_remaning : Int32
|
||||
def initialize(@url, @filename, @writer, @tries_remaning)
|
||||
end
|
||||
end
|
||||
|
||||
enum JobStatus
|
||||
Pending # 0
|
||||
Downloading # 1
|
||||
Error # 2
|
||||
Completed # 3
|
||||
MissingPages # 4
|
||||
end
|
||||
|
||||
struct Job
|
||||
property id : String
|
||||
property manga_id : String
|
||||
property title : String
|
||||
property manga_title : String
|
||||
property status : JobStatus
|
||||
property status_message : String = ""
|
||||
property pages : Int32 = 0
|
||||
property success_count : Int32 = 0
|
||||
property fail_count : Int32 = 0
|
||||
property time : Time
|
||||
|
||||
def parse_query_result(res : DB::ResultSet)
|
||||
@id = res.read String
|
||||
@manga_id = res.read String
|
||||
@title = res.read String
|
||||
@manga_title = res.read String
|
||||
status = res.read Int32
|
||||
@status_message = res.read String
|
||||
@pages = res.read Int32
|
||||
@success_count = res.read Int32
|
||||
@fail_count = res.read Int32
|
||||
time = res.read Int64
|
||||
@status = JobStatus.new status
|
||||
@time = Time.unix_ms time
|
||||
end
|
||||
|
||||
# Raises if the result set does not contain the correct set of columns
|
||||
def self.from_query_result(res : DB::ResultSet)
|
||||
job = Job.allocate
|
||||
job.parse_query_result res
|
||||
return job
|
||||
end
|
||||
|
||||
def initialize(@id, @manga_id, @title, @manga_title, @status, @time)
|
||||
end
|
||||
|
||||
def to_json(json)
|
||||
json.object do
|
||||
{% for name in ["id", "manga_id", "title", "manga_title",
|
||||
"status_message"] %}
|
||||
json.field {{name}}, @{{name.id}}
|
||||
{% end %}
|
||||
{% for name in ["pages", "success_count", "fail_count"] %}
|
||||
json.field {{name}} do
|
||||
json.number @{{name.id}}
|
||||
end
|
||||
{% end %}
|
||||
json.field "status", @status.to_s
|
||||
json.field "time" do
|
||||
json.number @time.to_unix_ms
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Queue
|
||||
property downloader : Downloader?
|
||||
|
||||
def initialize(@path : String, @logger : MLogger)
|
||||
dir = File.dirname path
|
||||
unless Dir.exists? dir
|
||||
@logger.info "The queue DB directory #{dir} does not exist. " \
|
||||
"Attepmting to create it"
|
||||
Dir.mkdir_p dir
|
||||
end
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
begin
|
||||
db.exec "create table if not exists queue " \
|
||||
"(id text, manga_id text, title text, manga_title " \
|
||||
"text, status integer, status_message text, " \
|
||||
"pages integer, success_count integer, " \
|
||||
"fail_count integer, time integer)"
|
||||
db.exec "create unique index if not exists id_idx " \
|
||||
"on queue (id)"
|
||||
db.exec "create index if not exists manga_id_idx " \
|
||||
"on queue (manga_id)"
|
||||
db.exec "create index if not exists status_idx " \
|
||||
"on queue (status)"
|
||||
rescue e
|
||||
@logger.error "Error when checking tables in DB: #{e}"
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the earliest job in queue or nil if the job cannot be parsed.
|
||||
# Returns nil if queue is empty
|
||||
def pop
|
||||
job = nil
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
begin
|
||||
db.query_one "select * from queue where status = 0 "\
|
||||
"or status = 1 order by time limit 1" do |res|
|
||||
job = Job.from_query_result res
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
return job
|
||||
end
|
||||
|
||||
# Push an array of jobs into the queue, and return the number of jobs
|
||||
# inserted. Any job already exists in the queue will be ignored.
|
||||
def push(jobs : Array(Job))
|
||||
start_count = self.count
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
jobs.each do |job|
|
||||
db.exec "insert or ignore into queue values "\
|
||||
"(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
job.id, job.manga_id, job.title, job.manga_title,
|
||||
job.status.to_i, job.status_message, job.pages,
|
||||
job.success_count, job.fail_count, job.time.to_unix_ms
|
||||
end
|
||||
end
|
||||
self.count - start_count
|
||||
end
|
||||
|
||||
def reset(id : String)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
db.exec "update queue set status = 0, status_message = '', " \
|
||||
"pages = 0, success_count = 0, fail_count = 0 " \
|
||||
"where id = (?)", id
|
||||
end
|
||||
end
|
||||
|
||||
def reset (job : Job)
|
||||
self.reset job.id
|
||||
end
|
||||
|
||||
# Reset all failed tasks (missing pages and error)
|
||||
def reset
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
db.exec "update queue set status = 0, status_message = '', " \
|
||||
"pages = 0, success_count = 0, fail_count = 0 " \
|
||||
"where status = 2 or status = 4"
|
||||
end
|
||||
end
|
||||
|
||||
def delete(id : String)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
db.exec "delete from queue where id = (?)", id
|
||||
end
|
||||
end
|
||||
|
||||
def delete(job : Job)
|
||||
self.delete job.id
|
||||
end
|
||||
|
||||
def delete_status(status : JobStatus)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
db.exec "delete from queue where status = (?)", status.to_i
|
||||
end
|
||||
end
|
||||
|
||||
def count_status(status : JobStatus)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
return db.query_one "select count(*) from queue where "\
|
||||
"status = (?)", status.to_i, as: Int32
|
||||
end
|
||||
end
|
||||
|
||||
def count
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
return db.query_one "select count(*) from queue", as: Int32
|
||||
end
|
||||
end
|
||||
|
||||
def set_status(status : JobStatus, job : Job)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
db.exec "update queue set status = (?) where id = (?)",
|
||||
status.to_i, job.id
|
||||
end
|
||||
end
|
||||
|
||||
def get_all
|
||||
jobs = [] of Job
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
jobs = db.query_all "select * from queue order by time", do |rs|
|
||||
Job.from_query_result rs
|
||||
end
|
||||
end
|
||||
return jobs
|
||||
end
|
||||
|
||||
def add_success(job : Job)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
db.exec "update queue set success_count = success_count + 1 " \
|
||||
"where id = (?)", job.id
|
||||
end
|
||||
end
|
||||
|
||||
def add_fail(job : Job)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
db.exec "update queue set fail_count = fail_count + 1 " \
|
||||
"where id = (?)", job.id
|
||||
end
|
||||
end
|
||||
|
||||
def set_pages(pages : Int32, job : Job)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
db.exec "update queue set pages = (?), success_count = 0, " \
|
||||
"fail_count = 0 where id = (?)", pages, job.id
|
||||
end
|
||||
end
|
||||
|
||||
def add_message(msg : String, job : Job)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
db.exec "update queue set status_message = " \
|
||||
"status_message || (?) || (?) where id = (?)",
|
||||
"\n", msg, job.id
|
||||
end
|
||||
end
|
||||
|
||||
def pause
|
||||
@downloader.not_nil!.stopped = true
|
||||
end
|
||||
|
||||
def resume
|
||||
@downloader.not_nil!.stopped = false
|
||||
end
|
||||
|
||||
def paused?
|
||||
@downloader.not_nil!.stopped
|
||||
end
|
||||
end
|
||||
|
||||
class Downloader
|
||||
property stopped = false
|
||||
|
||||
def initialize(@queue : Queue, @api : API, @library_path : String,
|
||||
@wait_seconds : Int32, @retries : Int32,
|
||||
@logger : MLogger)
|
||||
@queue.downloader = self
|
||||
|
||||
spawn do
|
||||
loop do
|
||||
sleep 1.second
|
||||
next if @stopped
|
||||
begin
|
||||
job = @queue.pop
|
||||
next if job.nil?
|
||||
download job
|
||||
rescue e
|
||||
@logger.error e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private def download(job : Job)
|
||||
@stopped = true
|
||||
@queue.set_status JobStatus::Downloading, job
|
||||
begin
|
||||
chapter = @api.get_chapter(job.id)
|
||||
rescue e
|
||||
@logger.error e
|
||||
@queue.set_status JobStatus::Error, job
|
||||
unless e.message.nil?
|
||||
@queue.add_message e.message.not_nil!, job
|
||||
end
|
||||
@stopped = false
|
||||
return
|
||||
end
|
||||
@queue.set_pages chapter.pages.size, job
|
||||
lib_dir = @library_path
|
||||
manga_dir = File.join lib_dir, chapter.manga.title
|
||||
unless File.exists? manga_dir
|
||||
Dir.mkdir_p manga_dir
|
||||
end
|
||||
zip_path = File.join manga_dir, "#{job.title}.cbz"
|
||||
|
||||
# Find the number of digits needed to store the number of pages
|
||||
len = Math.log10(chapter.pages.size).to_i + 1
|
||||
|
||||
writer = Zip::Writer.new zip_path
|
||||
# Create a buffered channel. It works as an FIFO queue
|
||||
channel = Channel(PageJob).new chapter.pages.size
|
||||
spawn do
|
||||
chapter.pages.each_with_index do |tuple, i|
|
||||
fn, url = tuple
|
||||
ext = File.extname fn
|
||||
fn = "#{i.to_s.rjust len, '0'}#{ext}"
|
||||
page_job = PageJob.new url, fn, writer, @retries
|
||||
@logger.debug "Downloading #{url}"
|
||||
loop do
|
||||
sleep @wait_seconds.seconds
|
||||
download_page page_job
|
||||
break if page_job.success ||
|
||||
page_job.tries_remaning <= 0
|
||||
page_job.tries_remaning -= 1
|
||||
@logger.warn "Failed to download page #{url}. " \
|
||||
"Retrying... Remaining retries: " \
|
||||
"#{page_job.tries_remaning}"
|
||||
end
|
||||
|
||||
channel.send page_job
|
||||
end
|
||||
end
|
||||
|
||||
spawn do
|
||||
page_jobs = [] of PageJob
|
||||
chapter.pages.size.times do
|
||||
page_job = channel.receive
|
||||
@logger.debug "[#{page_job.success ? "success" : "failed"}] " \
|
||||
"#{page_job.url}"
|
||||
page_jobs << page_job
|
||||
if page_job.success
|
||||
@queue.add_success job
|
||||
else
|
||||
@queue.add_fail job
|
||||
msg = "Failed to download page #{page_job.url}"
|
||||
@queue.add_message msg, job
|
||||
@logger.error msg
|
||||
end
|
||||
end
|
||||
fail_count = page_jobs.select{|j| !j.success}.size
|
||||
@logger.debug "Download completed. "\
|
||||
"#{fail_count}/#{page_jobs.size} failed"
|
||||
writer.close
|
||||
@logger.debug "cbz File created at #{zip_path}"
|
||||
if fail_count == 0
|
||||
@queue.set_status JobStatus::Completed, job
|
||||
else
|
||||
@queue.set_status JobStatus::MissingPages, job
|
||||
end
|
||||
@stopped = false
|
||||
end
|
||||
end
|
||||
|
||||
private def download_page(job : PageJob)
|
||||
@logger.debug "downloading #{job.url}"
|
||||
headers = HTTP::Headers {
|
||||
"User-agent" => "Mangadex.cr"
|
||||
}
|
||||
begin
|
||||
HTTP::Client.get job.url, headers do |res|
|
||||
unless res.success?
|
||||
raise "Failed to download page #{job.url}. " \
|
||||
"[#{res.status_code}] #{res.status_message}"
|
||||
end
|
||||
job.writer.add job.filename, res.body_io
|
||||
end
|
||||
job.success = true
|
||||
rescue e
|
||||
@logger.error e
|
||||
job.success = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
13
src/mango.cr
13
src/mango.cr
@@ -1,8 +1,9 @@
|
||||
require "./server"
|
||||
require "./context"
|
||||
require "./mangadex/*"
|
||||
require "option_parser"
|
||||
|
||||
VERSION = "0.1.0"
|
||||
VERSION = "0.2.1"
|
||||
|
||||
config_path = nil
|
||||
|
||||
@@ -25,10 +26,16 @@ end
|
||||
|
||||
config = Config.load config_path
|
||||
logger = MLogger.new config
|
||||
library = Library.new config.library_path, config.scan_interval, logger
|
||||
storage = Storage.new config.db_path, logger
|
||||
library = Library.new config.library_path, config.scan_interval, logger, storage
|
||||
queue = MangaDex::Queue.new config.mangadex["download_queue_db_path"].to_s,
|
||||
logger
|
||||
api = MangaDex::API.new config.mangadex["api_url"].to_s
|
||||
downloader = MangaDex::Downloader.new queue, api, config.library_path,
|
||||
config.mangadex["download_wait_seconds"].to_i,
|
||||
config.mangadex["download_retries"].to_i, logger
|
||||
|
||||
context = Context.new config, logger, library, storage
|
||||
context = Context.new config, logger, library, storage, queue
|
||||
|
||||
server = Server.new context
|
||||
server.start
|
||||
|
||||
108
src/routes/admin.cr
Normal file
108
src/routes/admin.cr
Normal file
@@ -0,0 +1,108 @@
|
||||
require "./router"
|
||||
|
||||
class AdminRouter < Router
|
||||
def setup
|
||||
get "/admin" do |env|
|
||||
layout "admin"
|
||||
end
|
||||
|
||||
get "/admin/user" do |env|
|
||||
users = @context.storage.list_users
|
||||
username = get_username env
|
||||
layout "user"
|
||||
end
|
||||
|
||||
get "/admin/user/edit" do |env|
|
||||
username = env.params.query["username"]?
|
||||
admin = env.params.query["admin"]?
|
||||
if admin
|
||||
admin = admin == "true"
|
||||
end
|
||||
error = env.params.query["error"]?
|
||||
current_user = get_username env
|
||||
new_user = username.nil? && admin.nil?
|
||||
layout "user-edit"
|
||||
end
|
||||
|
||||
post "/admin/user/edit" do |env|
|
||||
# creating new user
|
||||
begin
|
||||
username = env.params.body["username"]
|
||||
password = env.params.body["password"]
|
||||
# if `admin` is unchecked, the body hash
|
||||
# would not contain `admin`
|
||||
admin = !env.params.body["admin"]?.nil?
|
||||
|
||||
if username.size < 3
|
||||
raise "Username should contain at least 3 characters"
|
||||
end
|
||||
if (username =~ /^[A-Za-z0-9_]+$/).nil?
|
||||
raise "Username should contain alphanumeric characters "\
|
||||
"and underscores only"
|
||||
end
|
||||
if password.size < 6
|
||||
raise "Password should contain at least 6 characters"
|
||||
end
|
||||
if (password =~ /^[[:ascii:]]+$/).nil?
|
||||
raise "password should contain ASCII characters only"
|
||||
end
|
||||
|
||||
@context.storage.new_user username, password, admin
|
||||
|
||||
env.redirect "/admin/user"
|
||||
rescue e
|
||||
@context.error e
|
||||
redirect_url = URI.new \
|
||||
path: "/admin/user/edit",\
|
||||
query: hash_to_query({"error" => e.message})
|
||||
env.redirect redirect_url.to_s
|
||||
end
|
||||
end
|
||||
|
||||
post "/admin/user/edit/:original_username" do |env|
|
||||
# editing existing user
|
||||
begin
|
||||
username = env.params.body["username"]
|
||||
password = env.params.body["password"]
|
||||
# if `admin` is unchecked, the body
|
||||
# hash would not contain `admin`
|
||||
admin = !env.params.body["admin"]?.nil?
|
||||
original_username = env.params.url["original_username"]
|
||||
|
||||
if username.size < 3
|
||||
raise "Username should contain at least 3 characters"
|
||||
end
|
||||
if (username =~ /^[A-Za-z0-9_]+$/).nil?
|
||||
raise "Username should contain alphanumeric characters "\
|
||||
"and underscores only"
|
||||
end
|
||||
|
||||
if password.size != 0
|
||||
if password.size < 6
|
||||
raise "Password should contain at least 6 characters"
|
||||
end
|
||||
if (password =~ /^[[:ascii:]]+$/).nil?
|
||||
raise "password should contain ASCII characters only"
|
||||
end
|
||||
end
|
||||
|
||||
@context.storage.update_user \
|
||||
original_username, username, password, admin
|
||||
|
||||
env.redirect "/admin/user"
|
||||
rescue e
|
||||
@context.error e
|
||||
redirect_url = URI.new \
|
||||
path: "/admin/user/edit",\
|
||||
query: hash_to_query({"username" => original_username, \
|
||||
"admin" => admin, "error" => e.message})
|
||||
env.redirect redirect_url.to_s
|
||||
end
|
||||
end
|
||||
|
||||
get "/admin/downloads" do |env|
|
||||
base_url = @context.config.mangadex["base_url"];
|
||||
layout "download-manager"
|
||||
end
|
||||
end
|
||||
end
|
||||
180
src/routes/api.cr
Normal file
180
src/routes/api.cr
Normal file
@@ -0,0 +1,180 @@
|
||||
require "./router"
|
||||
require "../mangadex/*"
|
||||
|
||||
class APIRouter < Router
|
||||
def setup
|
||||
get "/api/page/:tid/:eid/:page" do |env|
|
||||
begin
|
||||
tid = env.params.url["tid"]
|
||||
eid = env.params.url["eid"]
|
||||
page = env.params.url["page"].to_i
|
||||
|
||||
title = @context.library.get_title tid
|
||||
raise "Title ID `#{tid}` not found" if title.nil?
|
||||
entry = title.get_entry eid
|
||||
raise "Entry ID `#{eid}` of `#{title.title}` not found" if \
|
||||
entry.nil?
|
||||
img = entry.read_page page
|
||||
raise "Failed to load page #{page} of " \
|
||||
"`#{title.title}/#{entry.title}`" if img.nil?
|
||||
|
||||
send_img env, img
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 500
|
||||
e.message
|
||||
end
|
||||
end
|
||||
|
||||
get "/api/book/:tid" do |env|
|
||||
begin
|
||||
tid = env.params.url["tid"]
|
||||
title = @context.library.get_title tid
|
||||
raise "Title ID `#{tid}` not found" if title.nil?
|
||||
|
||||
send_json env, title.to_json
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 500
|
||||
e.message
|
||||
end
|
||||
end
|
||||
|
||||
get "/api/book" do |env|
|
||||
send_json env, @context.library.to_json
|
||||
end
|
||||
|
||||
post "/api/admin/scan" do |env|
|
||||
start = Time.utc
|
||||
@context.library.scan
|
||||
ms = (Time.utc - start).total_milliseconds
|
||||
send_json env, {
|
||||
"milliseconds" => ms,
|
||||
"titles" => @context.library.titles.size
|
||||
}.to_json
|
||||
end
|
||||
|
||||
post "/api/admin/user/delete/:username" do |env|
|
||||
begin
|
||||
username = env.params.url["username"]
|
||||
@context.storage.delete_user username
|
||||
rescue e
|
||||
@context.error e
|
||||
send_json env, {
|
||||
"success" => false,
|
||||
"error" => e.message
|
||||
}.to_json
|
||||
else
|
||||
send_json env, {"success" => true}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
post "/api/progress/:title/:entry/:page" do |env|
|
||||
begin
|
||||
username = get_username env
|
||||
title = (@context.library.get_title env.params.url["title"])
|
||||
.not_nil!
|
||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||
page = env.params.url["page"].to_i
|
||||
|
||||
raise "incorrect page value" if page < 0 || page > entry.pages
|
||||
title.save_progress username, entry.title, page
|
||||
rescue e
|
||||
@context.error e
|
||||
send_json env, {
|
||||
"success" => false,
|
||||
"error" => e.message
|
||||
}.to_json
|
||||
else
|
||||
send_json env, {"success" => true}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
get "/api/admin/mangadex/manga/:id" do |env|
|
||||
begin
|
||||
id = env.params.url["id"]
|
||||
api = MangaDex::API.new \
|
||||
@context.config.mangadex["api_url"].to_s
|
||||
manga = api.get_manga id
|
||||
send_json env, manga.to_info_json
|
||||
rescue e
|
||||
@context.error e
|
||||
send_json env, {"error" => e.message}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
post "/api/admin/mangadex/download" do |env|
|
||||
begin
|
||||
chapters = env.params.json["chapters"].as(Array).map{|c| c.as_h}
|
||||
jobs = chapters.map {|chapter|
|
||||
MangaDex::Job.new(
|
||||
chapter["id"].as_s,
|
||||
chapter["manga_id"].as_s,
|
||||
chapter["full_title"].as_s,
|
||||
chapter["manga_title"].as_s,
|
||||
MangaDex::JobStatus::Pending,
|
||||
Time.unix chapter["time"].as_s.to_i
|
||||
)
|
||||
}
|
||||
inserted_count = @context.queue.push jobs
|
||||
send_json env, {
|
||||
"success": inserted_count,
|
||||
"fail": jobs.size - inserted_count
|
||||
}.to_json
|
||||
rescue e
|
||||
@context.error e
|
||||
send_json env, {"error" => e.message}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
get "/api/admin/mangadex/queue" do |env|
|
||||
begin
|
||||
jobs = @context.queue.get_all
|
||||
send_json env, {
|
||||
"jobs" => jobs,
|
||||
"paused" => @context.queue.paused?,
|
||||
"success" => true
|
||||
}.to_json
|
||||
rescue e
|
||||
send_json env, {
|
||||
"success" => false,
|
||||
"error" => e.message
|
||||
}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
post "/api/admin/mangadex/queue/:action" do |env|
|
||||
begin
|
||||
action = env.params.url["action"]
|
||||
id = env.params.query["id"]?
|
||||
case action
|
||||
when "delete"
|
||||
if id.nil?
|
||||
@context.queue.delete_status MangaDex::JobStatus::Completed
|
||||
else
|
||||
@context.queue.delete id
|
||||
end
|
||||
when "retry"
|
||||
if id.nil?
|
||||
@context.queue.reset
|
||||
else
|
||||
@context.queue.reset id
|
||||
end
|
||||
when "pause"
|
||||
@context.queue.pause
|
||||
when "resume"
|
||||
@context.queue.resume
|
||||
else
|
||||
raise "Unknown queue action #{action}"
|
||||
end
|
||||
|
||||
send_json env, {"success" => true}.to_json
|
||||
rescue e
|
||||
send_json env, {
|
||||
"success" => false,
|
||||
"error" => e.message
|
||||
}.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
64
src/routes/main.cr
Normal file
64
src/routes/main.cr
Normal file
@@ -0,0 +1,64 @@
|
||||
require "./router"
|
||||
|
||||
class MainRouter < Router
|
||||
def setup
|
||||
get "/login" do |env|
|
||||
render "src/views/login.ecr"
|
||||
end
|
||||
|
||||
get "/logout" do |env|
|
||||
begin
|
||||
cookie = env.request.cookies
|
||||
.find { |c| c.name == "token" }.not_nil!
|
||||
@context.storage.logout cookie.value
|
||||
rescue e
|
||||
@context.error "Error when attempting to log out: #{e}"
|
||||
ensure
|
||||
env.redirect "/login"
|
||||
end
|
||||
end
|
||||
|
||||
post "/login" do |env|
|
||||
begin
|
||||
username = env.params.body["username"]
|
||||
password = env.params.body["password"]
|
||||
token = @context.storage.verify_user(username, password)
|
||||
.not_nil!
|
||||
|
||||
cookie = HTTP::Cookie.new "token", token
|
||||
cookie.expires = Time.local.shift years: 1
|
||||
env.response.cookies << cookie
|
||||
env.redirect "/"
|
||||
rescue
|
||||
env.redirect "/login"
|
||||
end
|
||||
end
|
||||
get "/" do |env|
|
||||
titles = @context.library.titles
|
||||
username = get_username env
|
||||
percentage = titles.map &.load_percetage username
|
||||
layout "index"
|
||||
end
|
||||
|
||||
get "/book/:title" do |env|
|
||||
begin
|
||||
title = (@context.library.get_title env.params.url["title"])
|
||||
.not_nil!
|
||||
username = get_username env
|
||||
percentage = title.entries.map { |e|
|
||||
title.load_percetage username, e.title }
|
||||
titles_percentage = title.titles.map { |t|
|
||||
title.load_percetage username, t.title }
|
||||
layout "title"
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 404
|
||||
end
|
||||
end
|
||||
|
||||
get "/download" do |env|
|
||||
base_url = @context.config.mangadex["base_url"];
|
||||
layout "download"
|
||||
end
|
||||
end
|
||||
end
|
||||
58
src/routes/reader.cr
Normal file
58
src/routes/reader.cr
Normal file
@@ -0,0 +1,58 @@
|
||||
require "./router"
|
||||
|
||||
class ReaderRouter < Router
|
||||
def setup
|
||||
get "/reader/:title/:entry" do |env|
|
||||
begin
|
||||
title = (@context.library.get_title env.params.url["title"])
|
||||
.not_nil!
|
||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||
|
||||
# load progress
|
||||
username = get_username env
|
||||
page = title.load_progress username, entry.title
|
||||
# we go back 2 * `IMGS_PER_PAGE` pages. the infinite scroll
|
||||
# library perloads a few pages in advance, and the user
|
||||
# might not have actually read them
|
||||
page = [page - 2 * IMGS_PER_PAGE, 1].max
|
||||
|
||||
env.redirect "/reader/#{title.id}/#{entry.id}/#{page}"
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 404
|
||||
end
|
||||
end
|
||||
|
||||
get "/reader/:title/:entry/:page" do |env|
|
||||
begin
|
||||
title = (@context.library.get_title env.params.url["title"])
|
||||
.not_nil!
|
||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||
page = env.params.url["page"].to_i
|
||||
raise "" if page > entry.pages || page <= 0
|
||||
|
||||
# save progress
|
||||
username = get_username env
|
||||
title.save_progress username, entry.title, page
|
||||
|
||||
pages = (page...[entry.pages + 1, page + IMGS_PER_PAGE].min)
|
||||
urls = pages.map { |idx|
|
||||
"/api/page/#{title.id}/#{entry.id}/#{idx}" }
|
||||
reader_urls = pages.map { |idx|
|
||||
"/reader/#{title.id}/#{entry.id}/#{idx}" }
|
||||
next_page = page + IMGS_PER_PAGE
|
||||
next_url = next_page > entry.pages ? nil :
|
||||
"/reader/#{title.id}/#{entry.id}/#{next_page}"
|
||||
exit_url = "/book/#{title.id}"
|
||||
next_entry = title.next_entry entry
|
||||
next_entry_url = next_entry.nil? ? nil : \
|
||||
"/reader/#{title.id}/#{next_entry.id}"
|
||||
|
||||
render "src/views/reader.ecr"
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 404
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
6
src/routes/router.cr
Normal file
6
src/routes/router.cr
Normal file
@@ -0,0 +1,6 @@
|
||||
require "../context"
|
||||
|
||||
class Router
|
||||
def initialize(@context : Context)
|
||||
end
|
||||
end
|
||||
308
src/server.cr
308
src/server.cr
@@ -4,312 +4,36 @@ require "./auth_handler"
|
||||
require "./static_handler"
|
||||
require "./log_handler"
|
||||
require "./util"
|
||||
require "./routes/*"
|
||||
|
||||
class Server
|
||||
def initialize(@context : Context)
|
||||
|
||||
error 403 do |env|
|
||||
message = "You are not authorized to visit #{env.request.path}"
|
||||
message = "HTTP 403: You are not authorized to visit " \
|
||||
"#{env.request.path}"
|
||||
layout "message"
|
||||
end
|
||||
error 404 do |env|
|
||||
message = "HTTP 404: Mango cannot find the page #{env.request.path}"
|
||||
layout "message"
|
||||
end
|
||||
error 500 do |env|
|
||||
message = "HTTP 500: Internal server error. Please try again later."
|
||||
layout "message"
|
||||
end
|
||||
|
||||
get "/" do |env|
|
||||
titles = @context.library.titles
|
||||
username = get_username env
|
||||
percentage = titles.map &.load_percetage username
|
||||
layout "index"
|
||||
end
|
||||
|
||||
get "/book/:title" do |env|
|
||||
begin
|
||||
title = (@context.library.get_title env.params.url["title"])
|
||||
.not_nil!
|
||||
username = get_username env
|
||||
percentage = title.entries.map { |e|
|
||||
title.load_percetage username, e.title }
|
||||
layout "title"
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 404
|
||||
end
|
||||
end
|
||||
|
||||
get "/admin" do |env|
|
||||
layout "admin"
|
||||
end
|
||||
|
||||
get "/admin/user" do |env|
|
||||
users = @context.storage.list_users
|
||||
username = get_username env
|
||||
layout "user"
|
||||
end
|
||||
|
||||
get "/admin/user/edit" do |env|
|
||||
username = env.params.query["username"]?
|
||||
admin = env.params.query["admin"]?
|
||||
if admin
|
||||
admin = admin == "true"
|
||||
end
|
||||
error = env.params.query["error"]?
|
||||
current_user = get_username env
|
||||
new_user = username.nil? && admin.nil?
|
||||
layout "user-edit"
|
||||
end
|
||||
|
||||
post "/admin/user/edit" do |env|
|
||||
# creating new user
|
||||
begin
|
||||
username = env.params.body["username"]
|
||||
password = env.params.body["password"]
|
||||
# if `admin` is unchecked, the body hash
|
||||
# would not contain `admin`
|
||||
admin = !env.params.body["admin"]?.nil?
|
||||
|
||||
if username.size < 3
|
||||
raise "Username should contain at least 3 characters"
|
||||
end
|
||||
if (username =~ /^[A-Za-z0-9_]+$/).nil?
|
||||
raise "Username should contain alphanumeric characters "\
|
||||
"and underscores only"
|
||||
end
|
||||
if password.size < 6
|
||||
raise "Password should contain at least 6 characters"
|
||||
end
|
||||
if (password =~ /^[[:ascii:]]+$/).nil?
|
||||
raise "password should contain ASCII characters only"
|
||||
end
|
||||
|
||||
@context.storage.new_user username, password, admin
|
||||
|
||||
env.redirect "/admin/user"
|
||||
rescue e
|
||||
@context.error e
|
||||
redirect_url = URI.new \
|
||||
path: "/admin/user/edit",\
|
||||
query: hash_to_query({"error" => e.message})
|
||||
env.redirect redirect_url.to_s
|
||||
end
|
||||
end
|
||||
|
||||
post "/admin/user/edit/:original_username" do |env|
|
||||
# editing existing user
|
||||
begin
|
||||
username = env.params.body["username"]
|
||||
password = env.params.body["password"]
|
||||
# if `admin` is unchecked, the body
|
||||
# hash would not contain `admin`
|
||||
admin = !env.params.body["admin"]?.nil?
|
||||
original_username = env.params.url["original_username"]
|
||||
|
||||
if username.size < 3
|
||||
raise "Username should contain at least 3 characters"
|
||||
end
|
||||
if (username =~ /^[A-Za-z0-9_]+$/).nil?
|
||||
raise "Username should contain alphanumeric characters "\
|
||||
"and underscores only"
|
||||
end
|
||||
|
||||
if password.size != 0
|
||||
if password.size < 6
|
||||
raise "Password should contain at least 6 characters"
|
||||
end
|
||||
if (password =~ /^[[:ascii:]]+$/).nil?
|
||||
raise "password should contain ASCII characters only"
|
||||
end
|
||||
end
|
||||
|
||||
@context.storage.update_user \
|
||||
original_username, username, password, admin
|
||||
|
||||
env.redirect "/admin/user"
|
||||
rescue e
|
||||
@context.error e
|
||||
redirect_url = URI.new \
|
||||
path: "/admin/user/edit",\
|
||||
query: hash_to_query({"username" => original_username, \
|
||||
"admin" => admin, "error" => e.message})
|
||||
env.redirect redirect_url.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
get "/reader/:title/:entry" do |env|
|
||||
begin
|
||||
title = (@context.library.get_title env.params.url["title"])
|
||||
.not_nil!
|
||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||
|
||||
# load progress
|
||||
username = get_username env
|
||||
page = title.load_progress username, entry.title
|
||||
# we go back 2 * `IMGS_PER_PAGE` pages. the infinite scroll
|
||||
# library perloads a few pages in advance, and the user
|
||||
# might not have actually read them
|
||||
page = [page - 2 * IMGS_PER_PAGE, 1].max
|
||||
|
||||
env.redirect "/reader/#{title.title}/#{entry.title}/#{page}"
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 404
|
||||
end
|
||||
end
|
||||
|
||||
get "/reader/:title/:entry/:page" do |env|
|
||||
begin
|
||||
title = (@context.library.get_title env.params.url["title"])
|
||||
.not_nil!
|
||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||
page = env.params.url["page"].to_i
|
||||
raise "" if page > entry.pages || page <= 0
|
||||
|
||||
# save progress
|
||||
username = get_username env
|
||||
title.save_progress username, entry.title, page
|
||||
|
||||
pages = (page...[entry.pages + 1, page + IMGS_PER_PAGE].min)
|
||||
urls = pages.map { |idx|
|
||||
"/api/page/#{title.title}/#{entry.title}/#{idx}" }
|
||||
reader_urls = pages.map { |idx|
|
||||
"/reader/#{title.title}/#{entry.title}/#{idx}" }
|
||||
next_page = page + IMGS_PER_PAGE
|
||||
next_url = next_page > entry.pages ? nil :
|
||||
"/reader/#{title.title}/#{entry.title}/#{next_page}"
|
||||
exit_url = "/book/#{title.title}"
|
||||
next_entry = title.next_entry entry
|
||||
next_entry_url = next_entry.nil? ? nil : \
|
||||
"/reader/#{title.title}/#{next_entry.title}"
|
||||
|
||||
render "src/views/reader.ecr"
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 404
|
||||
end
|
||||
end
|
||||
|
||||
get "/login" do |env|
|
||||
render "src/views/login.ecr"
|
||||
end
|
||||
|
||||
get "/logout" do |env|
|
||||
begin
|
||||
cookie = env.request.cookies
|
||||
.find { |c| c.name == "token" }.not_nil!
|
||||
@context.storage.logout cookie.value
|
||||
rescue e
|
||||
@context.error "Error when attempting to log out: #{e}"
|
||||
ensure
|
||||
env.redirect "/login"
|
||||
end
|
||||
end
|
||||
|
||||
post "/login" do |env|
|
||||
begin
|
||||
username = env.params.body["username"]
|
||||
password = env.params.body["password"]
|
||||
token = @context.storage.verify_user(username, password)
|
||||
.not_nil!
|
||||
|
||||
cookie = HTTP::Cookie.new "token", token
|
||||
env.response.cookies << cookie
|
||||
env.redirect "/"
|
||||
rescue
|
||||
env.redirect "/login"
|
||||
end
|
||||
end
|
||||
|
||||
get "/api/page/:title/:entry/:page" do |env|
|
||||
begin
|
||||
title = env.params.url["title"]
|
||||
entry = env.params.url["entry"]
|
||||
page = env.params.url["page"].to_i
|
||||
|
||||
t = @context.library.get_title title
|
||||
raise "Title `#{title}` not found" if t.nil?
|
||||
e = t.get_entry entry
|
||||
raise "Entry `#{entry}` of `#{title}` not found" if e.nil?
|
||||
img = e.read_page page
|
||||
raise "Failed to load page #{page} of `#{title}/#{entry}`"\
|
||||
if img.nil?
|
||||
|
||||
send_img env, img
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 500
|
||||
e.message
|
||||
end
|
||||
end
|
||||
|
||||
get "/api/book/:title" do |env|
|
||||
begin
|
||||
title = env.params.url["title"]
|
||||
|
||||
t = @context.library.get_title title
|
||||
raise "Title `#{title}` not found" if t.nil?
|
||||
|
||||
send_json env, t.to_json
|
||||
rescue e
|
||||
@context.error e
|
||||
env.response.status_code = 500
|
||||
e.message
|
||||
end
|
||||
end
|
||||
|
||||
get "/api/book" do |env|
|
||||
send_json env, @context.library.to_json
|
||||
end
|
||||
|
||||
post "/api/admin/scan" do |env|
|
||||
start = Time.utc
|
||||
@context.library.scan
|
||||
ms = (Time.utc - start).total_milliseconds
|
||||
send_json env, {
|
||||
"milliseconds" => ms,
|
||||
"titles" => @context.library.titles.size
|
||||
}.to_json
|
||||
end
|
||||
|
||||
post "/api/admin/user/delete/:username" do |env|
|
||||
begin
|
||||
username = env.params.url["username"]
|
||||
@context.storage.delete_user username
|
||||
rescue e
|
||||
@context.error e
|
||||
send_json env, {
|
||||
"success" => false,
|
||||
"error" => e.message
|
||||
}.to_json
|
||||
else
|
||||
send_json env, {"success" => true}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
post "/api/progress/:title/:entry/:page" do |env|
|
||||
begin
|
||||
username = get_username env
|
||||
title = (@context.library.get_title env.params.url["title"])
|
||||
.not_nil!
|
||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||
page = env.params.url["page"].to_i
|
||||
|
||||
raise "incorrect page value" if page < 0 || page > entry.pages
|
||||
title.save_progress username, entry.title, page
|
||||
rescue e
|
||||
@context.error e
|
||||
send_json env, {
|
||||
"success" => false,
|
||||
"error" => e.message
|
||||
}.to_json
|
||||
else
|
||||
send_json env, {"success" => true}.to_json
|
||||
end
|
||||
end
|
||||
MainRouter.new(@context).setup
|
||||
AdminRouter.new(@context).setup
|
||||
ReaderRouter.new(@context).setup
|
||||
APIRouter.new(@context).setup
|
||||
|
||||
Kemal.config.logging = false
|
||||
add_handler LogHandler.new @context.logger
|
||||
add_handler AuthHandler.new @context.storage
|
||||
{% if flag?(:release) %}
|
||||
# when building for relase, embed the static files in binary
|
||||
@context.debug "We are in release mode. Using embeded static files."
|
||||
@context.debug "We are in release mode. Using embedded static files."
|
||||
serve_static false
|
||||
add_handler StaticHandler.new
|
||||
{% end %}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
require "baked_file_system"
|
||||
require "kemal"
|
||||
require "gzip"
|
||||
require "./util"
|
||||
|
||||
class FS
|
||||
extend BakedFileSystem
|
||||
{% if read_file? "./dist" %}
|
||||
bake_folder "../dist"
|
||||
{% else %}
|
||||
bake_folder "../public"
|
||||
{% if flag?(:release) %}
|
||||
{% if read_file? "#{__DIR__}/../dist/favicon.ico" %}
|
||||
{% puts "baking ../dist" %}
|
||||
bake_folder "../dist"
|
||||
{% else %}
|
||||
{% puts "baking ../public" %}
|
||||
bake_folder "../public"
|
||||
{% end %}
|
||||
{% end %}
|
||||
end
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ def verify_password(hash, pw)
|
||||
end
|
||||
|
||||
def random_str
|
||||
Base64.strict_encode UUID.random().to_s
|
||||
UUID.random.to_s.gsub "-", ""
|
||||
end
|
||||
|
||||
class Storage
|
||||
@@ -25,10 +25,18 @@ class Storage
|
||||
end
|
||||
DB.open "sqlite3://#{path}" do |db|
|
||||
begin
|
||||
# We create the `ids` table first. even if the uses has an
|
||||
# early version installed and has the `user` table only,
|
||||
# we will still be able to create `ids`
|
||||
db.exec "create table ids" \
|
||||
"(path text, id text, is_title integer)"
|
||||
db.exec "create unique index path_idx on ids (path)"
|
||||
db.exec "create unique index id_idx on ids (id)"
|
||||
|
||||
db.exec "create table users" \
|
||||
"(username text, password text, token text, admin integer)"
|
||||
rescue e
|
||||
unless e.message == "table users already exists"
|
||||
unless e.message.not_nil!.ends_with? "already exists"
|
||||
@logger.fatal "Error when checking tables in DB: #{e}"
|
||||
raise e
|
||||
end
|
||||
@@ -147,4 +155,23 @@ class Storage
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_id(path, is_title)
|
||||
DB.open "sqlite3://#{@path}" do |db|
|
||||
begin
|
||||
id = db.query_one "select id from ids where path = (?)",
|
||||
path, as: {String}
|
||||
return id
|
||||
rescue
|
||||
id = random_str
|
||||
db.exec "insert into ids values (?, ?, ?)", path, id,
|
||||
is_title ? 1 : 0
|
||||
return id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_json(json : JSON::Builder)
|
||||
json.string self
|
||||
end
|
||||
end
|
||||
|
||||
39
src/util.cr
39
src/util.cr
@@ -9,7 +9,7 @@ macro send_img(env, img)
|
||||
end
|
||||
|
||||
macro get_username(env)
|
||||
# if the request gets here, its has gone through the auth handler, and
|
||||
# if the request gets here, it has gone through the auth handler, and
|
||||
# we can be sure that a valid token exists, so we can use not_nil! here
|
||||
cookie = {{env}}.request.cookies.find { |c| c.name == "token" }.not_nil!
|
||||
(@context.storage.verify_token cookie.value).not_nil!
|
||||
@@ -32,3 +32,40 @@ def request_path_startswith(env, ary)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def is_numeric(str)
|
||||
/^\d+/.match(str) != nil
|
||||
end
|
||||
|
||||
def split_by_alphanumeric(str)
|
||||
arr = [] of String
|
||||
str.scan(/([^\d\n\r]*)(\d*)([^\d\n\r]*)/) do |match|
|
||||
arr += match.captures.select{|s| s != ""}
|
||||
end
|
||||
arr
|
||||
end
|
||||
|
||||
def compare_alphanumerically(c, d)
|
||||
is_c_bigger = c.size <=> d.size
|
||||
if c.size > d.size
|
||||
d += [nil] * (c.size - d.size)
|
||||
elsif c.size < d.size
|
||||
c += [nil] * (d.size - c.size)
|
||||
end
|
||||
c.zip(d) do |a, b|
|
||||
return -1 if a.nil?
|
||||
return 1 if b.nil?
|
||||
if is_numeric(a) && is_numeric(b)
|
||||
compare = a.to_i <=> b.to_i
|
||||
return compare if compare != 0
|
||||
else
|
||||
compare = a <=> b
|
||||
return compare if compare != 0
|
||||
end
|
||||
end
|
||||
is_c_bigger
|
||||
end
|
||||
|
||||
def compare_alphanumerically(a : String, b : String)
|
||||
compare_alphanumerically split_by_alphanumeric(a), split_by_alphanumeric(b)
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<span hidden></span>
|
||||
</span>
|
||||
</li>
|
||||
<li data-url="/admin/downloads">Download Manager</li>
|
||||
</ul>
|
||||
|
||||
<hr class="uk-divider-icon">
|
||||
|
||||
32
src/views/download-manager.ecr
Normal file
32
src/views/download-manager.ecr
Normal file
@@ -0,0 +1,32 @@
|
||||
<div class="uk-margin">
|
||||
<div id="actions" class="uk-margin">
|
||||
<button class="uk-button uk-button-default" onclick="remove()">Delete Completed Tasks</button>
|
||||
<button class="uk-button uk-button-default" onclick="refresh()">Retry Failed Tasks</button>
|
||||
<button class="uk-button uk-button-default" onclick="load()">Refresh Queue</button>
|
||||
<button class="uk-button uk-button-default" onclick="toggle()" id="pause-resume-btn" hidden></button>
|
||||
</div>
|
||||
<div id="config" class="uk-margin">
|
||||
<label><input id="auto-refresh" class="uk-checkbox" type="checkbox" checked> Auto Refresh</label>
|
||||
</div>
|
||||
</div>
|
||||
<table class="uk-table uk-table-striped uk-overflow-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Chapter</th>
|
||||
<th>Manga</th>
|
||||
<th>Progress</th>
|
||||
<th>Time</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<% content_for "script" do %>
|
||||
<script>
|
||||
var baseURL = "<%= base_url %>".replace(/\/$/, "");
|
||||
</script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
|
||||
<script src="/js/alert.js"></script>
|
||||
<script src="/js/download-manager.js"></script>
|
||||
<% end %>
|
||||
83
src/views/download.ecr
Normal file
83
src/views/download.ecr
Normal file
@@ -0,0 +1,83 @@
|
||||
<h2 class=uk-title>Download from MangaDex</h2>
|
||||
<div class="uk-grid-small" uk-grid>
|
||||
<div class="uk-width-3-4">
|
||||
<input id="search-input" class="uk-input" type="text" placeholder="MangaDex manga ID or URL">
|
||||
</div>
|
||||
<div class="uk-width-1-4">
|
||||
<div id="spinner" uk-spinner class="uk-align-center" hidden></div>
|
||||
<button id="search-btn" class="uk-button uk-button-default" onclick="search()">Search</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class"uk-grid-small" uk-grid hidden id="manga-details">
|
||||
<div class="uk-width-1-4@s">
|
||||
<img id="cover">
|
||||
</div>
|
||||
<div class="uk-width-1-4@s">
|
||||
<p id="title"></p>
|
||||
<p id="artist"></p>
|
||||
<p id="author"></p>
|
||||
</div>
|
||||
<div id="filter-form" class="uk-form-stacked uk-width-1-2@s" hidden>
|
||||
<p class="uk-text-lead uk-margin-remove-bottom">Filter Chapters</p>
|
||||
<p class="uk-text-meta uk-margin-remove-top" id="count-text"></p>
|
||||
<div class="uk-margin">
|
||||
<label class="uk-form-label" for="lang-select">Language</label>
|
||||
<div class="uk-form-controls">
|
||||
<select class="uk-select filter-field" id="lang-select">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-margin">
|
||||
<label class="uk-form-label" for="group-select">Group</label>
|
||||
<div class="uk-form-controls">
|
||||
<select class="uk-select filter-field" id="group-select">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-margin">
|
||||
<label class="uk-form-label" for="volume-range">Volume</label>
|
||||
<div class="uk-form-controls">
|
||||
<input class="uk-input filter-field" type="text" id="volume-range" placeholder="e.g., 127, 10-14, >30, <=212, or leave it empty.">
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-margin">
|
||||
<label class="uk-form-label" for="chapter-range">Chapter</label>
|
||||
<div class="uk-form-controls">
|
||||
<input class="uk-input filter-field" type="text" id="chapter-range" placeholder="e.g., 127, 10-14, >30, <=212, or leave it empty.">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="selection-controls" class="uk-margin" hidden>
|
||||
<div class="uk-margin">
|
||||
<button class="uk-button uk-button-default" onclick="selectAll()">Select All</button>
|
||||
<button class="uk-button uk-button-default" onclick="unselect()">Clear Selections</button>
|
||||
<button class="uk-button uk-button-primary" id="download-btn" onclick="download()">Download Selected</button>
|
||||
<div id="download-spinner" uk-spinner class="uk-margin-left" hidden></div>
|
||||
</div>
|
||||
<p class="uk-text-meta">Click on a table row to select the chapter. Drag your mouse over multiple rows to select them all. Hold Ctrl to make multiple non-adjacent selections.</p>
|
||||
</div>
|
||||
<p id="filter-notification" hidden></p>
|
||||
<table class="uk-table uk-table-striped uk-overflow-auto" hidden>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Title</th>
|
||||
<th>Language</th>
|
||||
<th>Group</th>
|
||||
<th>Volume</th>
|
||||
<th>Chapter</th>
|
||||
<th>Timestamp</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<% content_for "script" do %>
|
||||
<script>
|
||||
var baseURL = "<%= base_url %>".replace(/\/$/, "");
|
||||
</script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
|
||||
<script src="/js/alert.js"></script>
|
||||
<script src="/js/download.js"></script>
|
||||
<% end %>
|
||||
@@ -1,23 +1,43 @@
|
||||
<h2 class=uk-title>Library</h2>
|
||||
<p class="uk-text-meta"><%= titles.size %> titles found</p>
|
||||
<div class="uk-margin">
|
||||
<form class="uk-search uk-search-default">
|
||||
<span uk-search-icon></span>
|
||||
<input class="uk-search-input" type="search" placeholder="Search">
|
||||
</form>
|
||||
<div class="uk-grid-small" uk-grid>
|
||||
<div class="uk-margin-bottom uk-width-3-4@s">
|
||||
<form class="uk-search uk-search-default">
|
||||
<span uk-search-icon></span>
|
||||
<input class="uk-search-input" type="search" placeholder="Search">
|
||||
</form>
|
||||
</div>
|
||||
<div class="uk-margin-bottom uk-width-1-4@s">
|
||||
<div class="uk-form-horizontal">
|
||||
<select class="uk-select" id="sort-select">
|
||||
<option id="name-up">â–˛ Name</option>
|
||||
<option id="name-down">â–Ľ Name</option>
|
||||
<option id="date-up">â–˛ Date Modified</option>
|
||||
<option id="date-down">â–Ľ Date Modified</option>
|
||||
<option id="progress-up">â–˛ Progress</option>
|
||||
<option id="progress-down">â–Ľ Progress</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-child-width-1-4@m uk-child-width-1-2" uk-grid>
|
||||
<div id="item-container" class="uk-child-width-1-4@m uk-child-width-1-2" uk-grid>
|
||||
<%- titles.each_with_index do |t, i| -%>
|
||||
<div class="item">
|
||||
<a class="acard" href="/book/<%= t.title %>">
|
||||
<div class="item" data-mtime="<%= t.mtime.to_unix %>" data-progress="<%= percentage[i] %>">
|
||||
<a class="acard" href="/book/<%= t.id %>">
|
||||
<div class="uk-card uk-card-default">
|
||||
<div class="uk-card-media-top">
|
||||
<%- if t.entries.size > 0 -%>
|
||||
<img src="<%= t.entries[0].cover_url %>" alt="">
|
||||
<%- else -%>
|
||||
<img src="/img/icon.png" alt="">
|
||||
<%- end -%>
|
||||
</div>
|
||||
<div class="uk-card-body">
|
||||
<%- if t.entries.size > 0 -%>
|
||||
<div class="uk-card-badge uk-label"><%= (percentage[i] * 100).round(1) %>%</div>
|
||||
<h3 class="uk-card-title"><%= t.title %></h3>
|
||||
<p><%= t.entries.size %> entries</p>
|
||||
<%- end -%>
|
||||
<h3 class="uk-card-title break-word"><%= t.title %></h3>
|
||||
<p><%= t.size %> entries</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
@@ -27,4 +47,5 @@
|
||||
|
||||
<% content_for "script" do %>
|
||||
<script src="/js/search.js"></script>
|
||||
<script src="/js/sort-items.js"></script>
|
||||
<% end %>
|
||||
|
||||
@@ -8,9 +8,12 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.3.1/dist/css/uikit.min.css" />
|
||||
<link rel="stylesheet" href="/css/mango.css" />
|
||||
<script defer src="/js/fontawesome.min.js"></script>
|
||||
<script defer src="/js/solid.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="/js/theme.js"></script>
|
||||
<div class="uk-offcanvas-content">
|
||||
<div class="uk-navbar-container uk-navbar-transparent" uk-navbar="uk-navbar">
|
||||
<div id="mobile-nav" uk-offcanvas="overlay: true">
|
||||
@@ -18,7 +21,9 @@
|
||||
<ul class="uk-nav uk-nav-primary uk-nav-center uk-margin-auto-vertical">
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="/admin">Admin</a></li>
|
||||
<li><a href="/download">Download</a></li>
|
||||
<hr uk-divider>
|
||||
<li><a onclick="toggleTheme()"><i class="fas fa-adjust"></i></a></li>
|
||||
<li><a href="/logout">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -35,19 +40,22 @@
|
||||
<ul class="uk-navbar-nav">
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="/admin">Admin</a></li>
|
||||
<li><a href="/download">Download</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="uk-navbar-right uk-visible@s">
|
||||
<ul class="uk-navbar-nav">
|
||||
<li><a onclick="toggleTheme()"><i class="fas fa-adjust"></i></a></li>
|
||||
<li><a href="/logout">Logout</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-section uk-section-default uk-section-small">
|
||||
<div class="uk-section uk-section-small">
|
||||
</div>
|
||||
<div class="uk-section uk-section-default uk-section-small">
|
||||
<div class="uk-section uk-section-small">
|
||||
<div class="uk-container uk-container-small">
|
||||
<div id="alert"></div>
|
||||
<%= content %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.3.1/dist/css/uikit.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="uk-section uk-section-muted uk-flex uk-flex-middle uk-animation-fade" uk-height-viewport="">
|
||||
<script src="/js/theme.js"></script>
|
||||
<div class="uk-section uk-flex uk-flex-middle uk-animation-fade" uk-height-viewport="">
|
||||
<div class="uk-width-1-1">
|
||||
<div class="uk-container">
|
||||
<div class="uk-grid-margin uk-grid uk-grid-stack" uk-grid="">
|
||||
|
||||
@@ -1 +1 @@
|
||||
<p class="uk-text-lead"><%= message %></p>
|
||||
<p class="uk-text-lead uk-text-center"><%= message %></p>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<script src="/js/theme.js"></script>
|
||||
<div class="uk-section uk-section-default uk-section-small reader-bg">
|
||||
<div class="uk-container uk-container-small">
|
||||
<%- urls.each_with_index do |url, i| -%>
|
||||
@@ -36,6 +37,9 @@
|
||||
<h3 class="uk-modal-title">Options</h3>
|
||||
</div>
|
||||
<div class="uk-modal-body">
|
||||
<div class="uk-margin">
|
||||
<p id="progress-label"></p>
|
||||
</div>
|
||||
<div class="uk-margin">
|
||||
<label class="uk-form-label" for="form-stacked-select">Jump to page</label>
|
||||
<div class="uk-form-controls">
|
||||
|
||||
@@ -1,17 +1,61 @@
|
||||
<div id="alert"></div>
|
||||
<h2 class=uk-title><%= title.title %></h2>
|
||||
<p class="uk-text-meta"><%= title.entries.size %> entries found</p>
|
||||
<div class="uk-margin">
|
||||
<form class="uk-search uk-search-default">
|
||||
<span uk-search-icon></span>
|
||||
<input class="uk-search-input" type="search" placeholder="Search">
|
||||
</form>
|
||||
<ul class="uk-breadcrumb">
|
||||
<li><a href="/">Library</a></li>
|
||||
<%- title.parents.each do |t| -%>
|
||||
<li><a href="/book/<%= t.id %>"><%= t.title %></a></li>
|
||||
<%- end -%>
|
||||
<li class="uk-disabled"><a><%= title.title %></a></li>
|
||||
</ul>
|
||||
<p class="uk-text-meta"><%= title.size %> entries found</p>
|
||||
<div class="uk-grid-small" uk-grid>
|
||||
<div class="uk-margin-bottom uk-width-3-4@s">
|
||||
<form class="uk-search uk-search-default">
|
||||
<span uk-search-icon></span>
|
||||
<input class="uk-search-input" type="search" placeholder="Search">
|
||||
</form>
|
||||
</div>
|
||||
<div class="uk-margin-bottom uk-width-1-4@s">
|
||||
<div class="uk-form-horizontal">
|
||||
<select class="uk-select" id="sort-select">
|
||||
<option id="auto-up">â–˛ Auto</option>
|
||||
<option id="auto-down">â–Ľ Auto</option>
|
||||
<option id="name-up">â–˛ Name</option>
|
||||
<option id="name-down">â–Ľ Name</option>
|
||||
<option id="date-up">â–˛ Date Modified</option>
|
||||
<option id="date-down">â–Ľ Date Modified</option>
|
||||
<option id="progress-up">â–˛ Progress</option>
|
||||
<option id="progress-down">â–Ľ Progress</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="uk-child-width-1-4@m uk-child-width-1-2" uk-grid>
|
||||
<div id="item-container" class="uk-child-width-1-4@m uk-child-width-1-2" uk-grid>
|
||||
<%- title.titles.each_with_index do |t, i| -%>
|
||||
<div class="item" data-mtime="<%= t.mtime.to_unix %>" data-progress="<%= titles_percentage[i] %>">
|
||||
<a class="acard" href="/book/<%= t.id %>">
|
||||
<div class="uk-card uk-card-default">
|
||||
<div class="uk-card-media-top">
|
||||
<%- if t.entries.size > 0 -%>
|
||||
<img src="<%= t.entries[0].cover_url %>" alt="">
|
||||
<%- else -%>
|
||||
<img src="/img/icon.png" alt="">
|
||||
<%- end -%>
|
||||
</div>
|
||||
<div class="uk-card-body">
|
||||
<%- if t.entries.size > 0 -%>
|
||||
<div class="uk-card-badge uk-label"><%= (titles_percentage[i] * 100).round(1) %>%</div>
|
||||
<%- end -%>
|
||||
<h3 class="uk-card-title break-word"><%= t.title %></h3>
|
||||
<p><%= t.size %> entries</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<%- end -%>
|
||||
<%- title.entries.each_with_index do |e, i| -%>
|
||||
<div class="item">
|
||||
<div class="item" data-mtime="<%= e.mtime.to_unix %>" data-progress="<%= percentage[i] %>">
|
||||
<a class="acard">
|
||||
<div class="uk-card uk-card-default" onclick="showModal('<%= e.title %>', '<%= e.zip_path %>', '<%= e.pages %>', <%= (percentage[i] * 100).round(1) %>, '<%= title.title %>', '<%= e.title %>')">
|
||||
<div class="uk-card uk-card-default" onclick="showModal("<%= e.encoded_path %>", '<%= e.pages %>', <%= (percentage[i] * 100).round(1) %>, "<%= title.encoded_title %>", "<%= e.encoded_title %>", '<%= e.title_id %>', '<%= e.id %>')">
|
||||
<div class="uk-card-media-top">
|
||||
<img src="<%= e.cover_url %>" alt="">
|
||||
</div>
|
||||
@@ -29,8 +73,8 @@
|
||||
<div class="uk-modal-dialog uk-margin-auto-vertical">
|
||||
<button class="uk-modal-close-default" type="button" uk-close></button>
|
||||
<div class="uk-modal-header">
|
||||
<h3 class="uk-modal-title" id="modal-title"></h3>
|
||||
<p class="uk-text-meta uk-margin-remove-bottom" id="path-text"></p>
|
||||
<h3 class="uk-modal-title break-word" id="modal-title"></h3>
|
||||
<p class="uk-text-meta uk-margin-remove-bottom break-word" id="path-text"></p>
|
||||
<p class="uk-text-meta uk-margin-remove-top" id="pages-text"></p>
|
||||
</div>
|
||||
<div class="uk-modal-body">
|
||||
@@ -49,6 +93,8 @@
|
||||
</div>
|
||||
|
||||
<% content_for "script" do %>
|
||||
<script src="/js/alert.js"></script>
|
||||
<script src="/js/title.js"></script>
|
||||
<script src="/js/search.js"></script>
|
||||
<script src="/js/sort-items.js"></script>
|
||||
<% end %>
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
<div id="alert"></div>
|
||||
|
||||
<form action="/admin/user/edit" method="post" accept-charset="utf-8">
|
||||
|
||||
<div class="uk-margin">
|
||||
@@ -51,5 +49,6 @@
|
||||
error = '<%= error %>';
|
||||
<%- end -%>
|
||||
</script>
|
||||
<script src="/js/alert.js"></script>
|
||||
<script src="/js/user-edit.js"></script>
|
||||
<% end %>
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
<div id="alert"></div>
|
||||
<table class="uk-table uk-table-divider">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -27,5 +26,6 @@
|
||||
|
||||
|
||||
<% content_for "script" do %>
|
||||
<script src="/js/alert.js"></script>
|
||||
<script src="/js/user.js"></script>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user