Skip to content

Commit

Permalink
Fix code issues
Browse files Browse the repository at this point in the history
  • Loading branch information
apiweb committed Aug 5, 2023
1 parent 6b04750 commit 0ecd47b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
6 changes: 6 additions & 0 deletions src/web/mjs/HakuNeko.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import BookmarkManager from './engine/BookmarkManager.mjs';
import ChaptermarkManager from './engine/ChaptermarkManager.mjs';
import Connectors from './engine/Connectors.mjs';
import DownloadManager from './engine/DownloadManager.mjs';
import ComicInfoGenerator from './engine/ComicInfoGenerator.mjs';
//import HistoryWorker from './engine/HistoryWorker.mjs'
import Request from './engine/Request.mjs';
import Settings from './engine/Settings.mjs';
Expand All @@ -32,6 +33,7 @@ export default class HakuNeko {
this._connectors = new Connectors(ipc);
this._storage = new Storage();
this._bookmarkManager = new BookmarkManager(this._settings, new BookmarkImporter());
this._comicInfoGenerator = new ComicInfoGenerator();
this._chaptermarkManager = new ChaptermarkManager(this._settings);
this._discordPresence = new DiscordPresence(this._settings);
}
Expand Down Expand Up @@ -63,6 +65,10 @@ export default class HakuNeko {
return this._bookmarkManager;
}

get ComicInfoGenerator() {
return this._comicInfoGenerator;
}

get ChaptermarkManager() {
return this._chaptermarkManager;
}
Expand Down
25 changes: 11 additions & 14 deletions src/web/mjs/engine/ComicInfoGenerator.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default class ComicInfoGenerator {
static createComicInfoXML(series, title, pagesCount) {
createComicInfoXML(series, title, pagesCount) {
series = this.escapeXML(series);
title = this.escapeXML(title);
return `<?xml version="1.0" encoding="utf-8"?>
Expand All @@ -10,20 +10,17 @@ export default class ComicInfoGenerator {
</ComicInfo>`;
}

static escapeXML(str) {
escapeXML(str) {
const symbols = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
'\'': '&apos;',
'"': '&quot;'
};

return str.replace(/[<>&'"]/g, function (c) {
switch (c) {
case '<':
return '&lt;';
case '>':
return '&gt;';
case '&':
return '&amp;';
case '\'':
return '&apos;';
case '"':
return '&quot;';
}
return symbols[c];
});
}
}
7 changes: 0 additions & 7 deletions src/web/mjs/engine/Settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@ export default class Settings extends EventTarget {
value: extensions.img
};

this.includesComicFile = {
label: 'Include Comic File in CBZ',
description: 'Include a comic file (comicinfo.xml) in the chapter archive',
input: types.checkbox,
value: false
};

this.recompressionFormat = {
label: 'De-Scrambling Format',
description: [
Expand Down
27 changes: 18 additions & 9 deletions src/web/mjs/engine/Storage.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import EbookGenerator from './EbookGenerator.mjs';
import ComicInfoGenerator from './ComicInfoGenerator.mjs';
import Chapter from './Chapter.mjs';

const extensions = {
Expand Down Expand Up @@ -449,9 +448,7 @@ export default class Storage {
}
if (Engine.Settings.chapterFormat.value === extensions.cbz) {
this._createDirectoryChain(this.path.dirname(output));
let mangaName = chapter.manga.title;
let chapterName = chapter.title;
promise = this._saveChapterPagesCBZ(output, pageData, mangaName, chapterName)
promise = this._saveChapterPagesCBZ(output, pageData, chapter.manga.title, chapter.title)
.then(() => this._runPostChapterDownloadCommand(chapter, output));
}
if (Engine.Settings.chapterFormat.value === extensions.pdf) {
Expand Down Expand Up @@ -554,10 +551,8 @@ export default class Storage {
_saveChapterPagesCBZ(archive, pageData, mangaName = '', chapterName = '') {
let zip = new JSZip();

if (Engine.Settings.includesComicFile.value) {
let comicFile = ComicInfoGenerator.createComicInfoXML(mangaName, chapterName, pageData.length);
zip.file('ComicInfo.xml', comicFile);
}
let comicFile = Engine.ComicInfoGenerator.createComicInfoXML(mangaName, chapterName, pageData.length);
zip.file('ComicInfo.xml', comicFile);

pageData.forEach(page => {
zip.file(page.name, page.data);
Expand Down Expand Up @@ -902,4 +897,18 @@ export default class Storage {
});
});
}
}

/**
* Convenience function wrapping key value saving for pinned connectors
*/
savePinnedConnectors(pinnedConnectors) {
return this.saveConfig('pinnedConnectors', pinnedConnectors);
}

/**
* Convenience function wrapping key value loading for pinned connectors
*/
loadPinnedConnectors() {
return this.loadConfig('pinnedConnectors');
}
}

0 comments on commit 0ecd47b

Please sign in to comment.