mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-18 01:41:14 -06:00
Compare commits
1 Commits
feature-2-
...
fix-rmpipe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55ddcd753e |
@@ -14,7 +14,7 @@
|
||||
@if (previewText) {
|
||||
<div class="bg-light p-3 overflow-auto whitespace-preserve" width="100%">{{previewText}}</div>
|
||||
} @else {
|
||||
<object [data]="previewURL | safeUrl" width="100%" class="bg-light" [class.p-2]="!isPdf"></object>
|
||||
<object [data]="previewURL" width="100%" class="bg-light" [class.p-2]="!isPdf"></object>
|
||||
}
|
||||
} @else {
|
||||
@if (requiresPassword) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import { first, Subject, takeUntil } from 'rxjs'
|
||||
import { Document } from 'src/app/data/document'
|
||||
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
|
||||
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
||||
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
||||
import { DocumentService } from 'src/app/services/rest/document.service'
|
||||
import { SettingsService } from 'src/app/services/settings.service'
|
||||
|
||||
@@ -19,7 +18,6 @@ import { SettingsService } from 'src/app/services/settings.service'
|
||||
NgbPopoverModule,
|
||||
DocumentTitlePipe,
|
||||
PdfViewerModule,
|
||||
SafeUrlPipe,
|
||||
NgxBootstrapIconsModule,
|
||||
],
|
||||
})
|
||||
|
||||
@@ -32,7 +32,6 @@ import { IfPermissionsDirective } from 'src/app/directives/if-permissions.direct
|
||||
import { PermissionsGuard } from 'src/app/guards/permissions.guard'
|
||||
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
|
||||
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
||||
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
||||
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
|
||||
import { PermissionsService } from 'src/app/services/permissions.service'
|
||||
import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service'
|
||||
@@ -128,7 +127,6 @@ describe('SavedViewWidgetComponent', () => {
|
||||
IfPermissionsDirective,
|
||||
CustomDatePipe,
|
||||
DocumentTitlePipe,
|
||||
SafeUrlPipe,
|
||||
PreviewPopupComponent,
|
||||
CustomFieldDisplayComponent,
|
||||
],
|
||||
|
||||
@@ -379,7 +379,7 @@
|
||||
<ng-template #previewContent>
|
||||
<div class="thumb-preview position-absolute pe-none text-center" [class.fade]="previewLoaded">
|
||||
@if (showThumbnailOverlay) {
|
||||
<img [src]="thumbUrl | safeUrl" class="mx-auto" [attr.width]="previewZoomScale === 'page-fit' ? 'auto' : '100%'" [attr.height]="previewZoomScale === 'page-fit' ? '100%' : 'auto'" alt="Document loading..." i18n-alt />
|
||||
<img [src]="thumbUrl" class="mx-auto" [attr.width]="previewZoomScale === 'page-fit' ? 'auto' : '100%'" [attr.height]="previewZoomScale === 'page-fit' ? '100%' : 'auto'" alt="Document loading..." i18n-alt />
|
||||
}
|
||||
<div class="position-absolute top-0 start-0 m-2 p-2 d-flex align-items-center justify-content-center">
|
||||
<div>
|
||||
@@ -406,7 +406,7 @@
|
||||
</pdf-viewer>
|
||||
</div>
|
||||
} @else {
|
||||
<object [data]="previewUrl | safeUrl" class="preview-sticky" width="100%"></object>
|
||||
<object [data]="previewUrl" class="preview-sticky" width="100%"></object>
|
||||
}
|
||||
}
|
||||
@case (ContentRenderType.Text) {
|
||||
@@ -414,7 +414,7 @@
|
||||
}
|
||||
@case (ContentRenderType.Image) {
|
||||
<div class="preview-sticky">
|
||||
<img [src]="previewUrl | safeUrl" width="100%" height="100%" alt="{{title}}" />
|
||||
<img [src]="previewUrl" width="100%" height="100%" alt="{{title}}" />
|
||||
</div>
|
||||
}
|
||||
@case (ContentRenderType.TIFF) {
|
||||
@@ -427,7 +427,7 @@
|
||||
}
|
||||
}
|
||||
@case (ContentRenderType.Other) {
|
||||
<object [data]="previewUrl | safeUrl" class="preview-sticky" width="100%"></object>
|
||||
<object [data]="previewUrl" class="preview-sticky" width="100%"></object>
|
||||
}
|
||||
}
|
||||
@if (requiresPassword) {
|
||||
|
||||
@@ -60,7 +60,6 @@ import { IfPermissionsDirective } from 'src/app/directives/if-permissions.direct
|
||||
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
|
||||
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
||||
import { FileSizePipe } from 'src/app/pipes/file-size.pipe'
|
||||
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
||||
import { ComponentRouterService } from 'src/app/services/component-router.service'
|
||||
import { DocumentListViewService } from 'src/app/services/document-list-view.service'
|
||||
import { HotKeyService } from 'src/app/services/hot-key.service'
|
||||
@@ -169,7 +168,6 @@ export enum ZoomSetting {
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
NgTemplateOutlet,
|
||||
SafeUrlPipe,
|
||||
NgbNavModule,
|
||||
NgbDropdownModule,
|
||||
NgxBootstrapIconsModule,
|
||||
|
||||
@@ -14,7 +14,6 @@ import { IfPermissionsDirective } from 'src/app/directives/if-permissions.direct
|
||||
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
|
||||
import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe'
|
||||
import { IsNumberPipe } from 'src/app/pipes/is-number.pipe'
|
||||
import { SafeUrlPipe } from 'src/app/pipes/safeurl.pipe'
|
||||
import { CustomFieldDisplayComponent } from '../../common/custom-field-display/custom-field-display.component'
|
||||
import { PreviewPopupComponent } from '../../common/preview-popup/preview-popup.component'
|
||||
import { DocumentCardLargeComponent } from './document-card-large.component'
|
||||
@@ -53,7 +52,6 @@ describe('DocumentCardLargeComponent', () => {
|
||||
DocumentTitlePipe,
|
||||
CustomDatePipe,
|
||||
IfPermissionsDirective,
|
||||
SafeUrlPipe,
|
||||
IsNumberPipe,
|
||||
PreviewPopupComponent,
|
||||
CustomFieldDisplayComponent,
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
import { BrowserModule, DomSanitizer } from '@angular/platform-browser'
|
||||
import { SafeUrlPipe } from './safeurl.pipe'
|
||||
|
||||
describe('SafeUrlPipe', () => {
|
||||
let pipe: SafeUrlPipe
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [SafeUrlPipe],
|
||||
imports: [BrowserModule],
|
||||
})
|
||||
pipe = TestBed.inject(SafeUrlPipe)
|
||||
})
|
||||
|
||||
it('should bypass security and trust the url', () => {
|
||||
const url = 'https://example.com'
|
||||
const domSanitizer = TestBed.inject(DomSanitizer)
|
||||
const sanitizerSpy = jest.spyOn(
|
||||
domSanitizer,
|
||||
'bypassSecurityTrustResourceUrl'
|
||||
)
|
||||
|
||||
let safeResourceUrl = pipe.transform(url)
|
||||
expect(safeResourceUrl).not.toBeNull()
|
||||
expect(sanitizerSpy).toHaveBeenCalled()
|
||||
|
||||
safeResourceUrl = pipe.transform(null)
|
||||
expect(safeResourceUrl).not.toBeNull()
|
||||
expect(sanitizerSpy).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -1,17 +0,0 @@
|
||||
import { Pipe, PipeTransform, inject } from '@angular/core'
|
||||
import { DomSanitizer } from '@angular/platform-browser'
|
||||
|
||||
@Pipe({
|
||||
name: 'safeUrl',
|
||||
})
|
||||
export class SafeUrlPipe implements PipeTransform {
|
||||
private sanitizer = inject(DomSanitizer)
|
||||
|
||||
transform(url) {
|
||||
if (url == null) {
|
||||
return this.sanitizer.bypassSecurityTrustResourceUrl('')
|
||||
} else {
|
||||
return this.sanitizer.bypassSecurityTrustResourceUrl(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,25 +106,15 @@ export class LocalizedDateParserFormatter extends NgbDateParserFormatter {
|
||||
value = this.preformatDateInput(value)
|
||||
let match = this.getDateParseRegex().exec(value)
|
||||
if (match) {
|
||||
const currentYear = new Date().getFullYear()
|
||||
const currentCentury = currentYear - (currentYear % 100)
|
||||
|
||||
let year = +match.groups.year
|
||||
if (year < 100) {
|
||||
let fourDigitYear = currentCentury + year
|
||||
// Mimic python-dateutil: keep result within -50/+49 years of current year
|
||||
if (fourDigitYear > currentYear + 49) {
|
||||
fourDigitYear -= 100
|
||||
} else if (fourDigitYear <= currentYear - 50) {
|
||||
fourDigitYear += 100
|
||||
}
|
||||
year = fourDigitYear
|
||||
}
|
||||
|
||||
let dateStruct = {
|
||||
day: +match.groups.day,
|
||||
month: +match.groups.month,
|
||||
year,
|
||||
year: +match.groups.year,
|
||||
}
|
||||
if (dateStruct.year <= new Date().getFullYear() - 2000) {
|
||||
dateStruct.year += 2000
|
||||
} else if (dateStruct.year < 100) {
|
||||
dateStruct.year += 1900
|
||||
}
|
||||
return dateStruct
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user