Misc Bugfixes (#1015)

* Fixed some security issues in dev env

* When deleting folders in bookmark cleanup, delete empty folders correctly.

* When a new library is created and cards are added, cards can have a blank library name. Card library name code is reworked to be much lighter on memory.

* Added a config for github issues to disable blank issues.

* Skip any sort of directory iteration code if we haven't deleted any bookmarks.

* Fixed a bug where some style overrides were duplicating. Now logic is much more targetted, only applying to the correct tags.

* Applied sorting to the filtering apis.

* Reverted one of my changes for a better version Robbie did.
This commit is contained in:
Joseph Milazzo 2022-01-31 08:50:13 -08:00 committed by GitHub
parent c631395aae
commit c6d1311560
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 186 additions and 47 deletions

View file

@ -34,6 +34,21 @@ export class LibraryService {
}));
}
getLibraryName(libraryId: number) {
if (this.libraryNames != undefined && this.libraryNames.hasOwnProperty(libraryId)) {
return of(this.libraryNames[libraryId]);
}
return this.httpClient.get<Library[]>(this.baseUrl + 'library').pipe(map(l => {
this.libraryNames = {};
l.forEach(lib => {
if (this.libraryNames !== undefined) {
this.libraryNames[lib.id] = lib.name;
}
});
return this.libraryNames[libraryId];
}));
}
listDirectories(rootPath: string) {
let query = '';
if (rootPath !== undefined && rootPath.length > 0) {

View file

@ -43,6 +43,15 @@ const TOP_OFFSET = -50 * 1.5; // px the sticky header takes up
const CHAPTER_ID_NOT_FETCHED = -2;
const CHAPTER_ID_DOESNT_EXIST = -1;
/**
* Styles that should be applied on the top level book-content tag
*/
const pageLevelStyles = ['margin-left', 'margin-right', 'font-size'];
/**
* Styles that should be applied on every element within book-content tag
*/
const elementLevelStyles = ['line-height', 'font-family'];
@Component({
selector: 'app-book-reader',
templateUrl: './book-reader.component.html',
@ -680,17 +689,10 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {
page = 0;
}
// BUG: Last page is not counting as read
if (!(page === 0 || page === this.maxPages - 1)) {
page -= 1;
}
// // Due to the fact that we start at image 0, but page 1, we need the last page to have progress as page + 1 to be completed
// let tempPageNum = this.pageNum;
// if (this.pageNum == this.maxPages - 1) {
// tempPageNum = this.pageNum + 1;
// }
this.pageNum = page;
this.loadPage();
@ -903,31 +905,41 @@ export class BookReaderComponent implements OnInit, AfterViewInit, OnDestroy {
this.updateReaderStyles();
}
/**
* Applies styles onto the html of the book page
*/
updateReaderStyles() {
if (this.readingHtml != undefined && this.readingHtml.nativeElement) {
Object.entries(this.pageStyles).forEach(item => {
if (item[1] == '100%' || item[1] == '0px' || item[1] == 'inherit') {
// Remove the style or skip
this.renderer.removeStyle(this.readingHtml.nativeElement, item[0]);
return;
}
this.renderer.setStyle(this.readingHtml.nativeElement, item[0], item[1], RendererStyleFlags2.Important);
});
if (this.readingHtml === undefined || !this.readingHtml.nativeElement) return;
for(let i = 0; i < this.readingHtml.nativeElement.children.length; i++) {
const elem = this.readingHtml.nativeElement.children.item(i);
if (elem?.tagName === 'STYLE') continue;
Object.entries(this.pageStyles).forEach(item => {
if (item[1] == '100%' || item[1] == '0px' || item[1] == 'inherit') {
// Remove the style or skip
this.renderer.removeStyle(elem, item[0]);
return;
}
this.renderer.setStyle(elem, item[0], item[1], RendererStyleFlags2.Important);
});
// Line Height must be placed on each element in the page
// Apply page level overrides
Object.entries(this.pageStyles).forEach(item => {
if (item[1] == '100%' || item[1] == '0px' || item[1] == 'inherit') {
// Remove the style or skip
this.renderer.removeStyle(this.readingHtml.nativeElement, item[0]);
return;
}
if (pageLevelStyles.includes(item[0])) {
this.renderer.setStyle(this.readingHtml.nativeElement, item[0], item[1], RendererStyleFlags2.Important);
}
});
const individualElementStyles = Object.entries(this.pageStyles).filter(item => elementLevelStyles.includes(item[0]));
for(let i = 0; i < this.readingHtml.nativeElement.children.length; i++) {
const elem = this.readingHtml.nativeElement.children.item(i);
if (elem?.tagName === 'STYLE') continue;
individualElementStyles.forEach(item => {
if (item[1] == '100%' || item[1] == '0px' || item[1] == 'inherit') {
// Remove the style or skip
this.renderer.removeStyle(elem, item[0]);
return;
}
this.renderer.setStyle(elem, item[0], item[1], RendererStyleFlags2.Important);
});
}
}

View file

@ -115,12 +115,15 @@ export class CardItemComponent implements OnInit, OnDestroy {
}
if (this.supressLibraryLink === false) {
this.libraryService.getLibraryNames().pipe(takeUntil(this.onDestroy)).subscribe(names => {
if (this.entity !== undefined && this.entity.hasOwnProperty('libraryId')) {
this.libraryId = (this.entity as Series).libraryId;
this.libraryName = names[this.libraryId];
}
});
if (this.entity !== undefined && this.entity.hasOwnProperty('libraryId')) {
this.libraryId = (this.entity as Series).libraryId;
}
if (this.libraryId !== undefined && this.libraryId > 0) {
this.libraryService.getLibraryName(this.libraryId).pipe(takeUntil(this.onDestroy)).subscribe(name => {
this.libraryName = name;
});
}
}
this.format = (this.entity as Series).format;