Allow frontend to use mime_type property
This commit is contained in:
parent
346b0fab8e
commit
5ffc39feff
@ -104,6 +104,11 @@ describe('PreviewPopupComponent', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should get text content from http if appropriate', () => {
|
it('should get text content from http if appropriate', () => {
|
||||||
|
component.document = {
|
||||||
|
...doc,
|
||||||
|
original_file_name: 'sample.txt',
|
||||||
|
mime_type: 'text/plain',
|
||||||
|
}
|
||||||
const httpSpy = jest.spyOn(http, 'get')
|
const httpSpy = jest.spyOn(http, 'get')
|
||||||
httpSpy.mockReturnValueOnce(
|
httpSpy.mockReturnValueOnce(
|
||||||
throwError(() => new Error('Error getting preview'))
|
throwError(() => new Error('Error getting preview'))
|
||||||
|
@ -46,8 +46,8 @@ export class PreviewPopupComponent implements OnDestroy {
|
|||||||
get isPdf(): boolean {
|
get isPdf(): boolean {
|
||||||
// We dont have time to retrieve metadata, make a best guess by file name
|
// We dont have time to retrieve metadata, make a best guess by file name
|
||||||
return (
|
return (
|
||||||
this.document?.original_file_name?.endsWith('.pdf') ||
|
this.document?.archived_file_name?.length > 0 ||
|
||||||
this.document?.archived_file_name?.endsWith('.pdf')
|
this.document?.mime_type?.includes('pdf')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,6 +62,7 @@ export class PreviewPopupComponent implements OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
if (this.document.mime_type?.includes('text')) {
|
||||||
this.http
|
this.http
|
||||||
.get(this.previewURL, { responseType: 'text' })
|
.get(this.previewURL, { responseType: 'text' })
|
||||||
.pipe(first(), takeUntil(this.unsubscribeNotifier))
|
.pipe(first(), takeUntil(this.unsubscribeNotifier))
|
||||||
@ -74,6 +75,7 @@ export class PreviewPopupComponent implements OnDestroy {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onError(event: any) {
|
onError(event: any) {
|
||||||
if (event.name == 'PasswordException') {
|
if (event.name == 'PasswordException') {
|
||||||
|
@ -350,7 +350,7 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
|
|
||||||
<ng-template #previewContent>
|
<ng-template #previewContent>
|
||||||
@if (!metadata) {
|
@if (!document) {
|
||||||
<div class="w-100 h-100 d-flex align-items-center justify-content-center">
|
<div class="w-100 h-100 d-flex align-items-center justify-content-center">
|
||||||
<div>
|
<div>
|
||||||
<div class="spinner-border spinner-border-sm me-2" role="status"></div>
|
<div class="spinner-border spinner-border-sm me-2" role="status"></div>
|
||||||
|
@ -921,7 +921,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
|
|
||||||
it('should display built-in pdf viewer if not disabled', () => {
|
it('should display built-in pdf viewer if not disabled', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
component.metadata = { has_archive_version: true }
|
component.document.archived_file_name = 'file.pdf'
|
||||||
jest.spyOn(settingsService, 'get').mockReturnValue(false)
|
jest.spyOn(settingsService, 'get').mockReturnValue(false)
|
||||||
expect(component.useNativePdfViewer).toBeFalsy()
|
expect(component.useNativePdfViewer).toBeFalsy()
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
@ -930,7 +930,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
|
|
||||||
it('should display native pdf viewer if enabled', () => {
|
it('should display native pdf viewer if enabled', () => {
|
||||||
initNormally()
|
initNormally()
|
||||||
component.metadata = { has_archive_version: true }
|
component.document.archived_file_name = 'file.pdf'
|
||||||
jest.spyOn(settingsService, 'get').mockReturnValue(true)
|
jest.spyOn(settingsService, 'get').mockReturnValue(true)
|
||||||
expect(component.useNativePdfViewer).toBeTruthy()
|
expect(component.useNativePdfViewer).toBeTruthy()
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
@ -1072,8 +1072,8 @@ describe('DocumentDetailComponent', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should change preview element by render type', () => {
|
it('should change preview element by render type', () => {
|
||||||
component.metadata = { has_archive_version: true }
|
|
||||||
initNormally()
|
initNormally()
|
||||||
|
component.document.archived_file_name = 'file.pdf'
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(component.archiveContentRenderType).toEqual(
|
expect(component.archiveContentRenderType).toEqual(
|
||||||
component.ContentRenderType.PDF
|
component.ContentRenderType.PDF
|
||||||
@ -1082,10 +1082,8 @@ describe('DocumentDetailComponent', () => {
|
|||||||
fixture.debugElement.query(By.css('pdf-viewer-container'))
|
fixture.debugElement.query(By.css('pdf-viewer-container'))
|
||||||
).not.toBeUndefined()
|
).not.toBeUndefined()
|
||||||
|
|
||||||
component.metadata = {
|
component.document.archived_file_name = undefined
|
||||||
has_archive_version: false,
|
component.document.mime_type = 'text/plain'
|
||||||
original_mime_type: 'text/plain',
|
|
||||||
}
|
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(component.archiveContentRenderType).toEqual(
|
expect(component.archiveContentRenderType).toEqual(
|
||||||
component.ContentRenderType.Text
|
component.ContentRenderType.Text
|
||||||
@ -1094,10 +1092,7 @@ describe('DocumentDetailComponent', () => {
|
|||||||
fixture.debugElement.query(By.css('div.preview-sticky'))
|
fixture.debugElement.query(By.css('div.preview-sticky'))
|
||||||
).not.toBeUndefined()
|
).not.toBeUndefined()
|
||||||
|
|
||||||
component.metadata = {
|
component.document.mime_type = 'image/jpeg'
|
||||||
has_archive_version: false,
|
|
||||||
original_mime_type: 'image/jpg',
|
|
||||||
}
|
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(component.archiveContentRenderType).toEqual(
|
expect(component.archiveContentRenderType).toEqual(
|
||||||
component.ContentRenderType.Image
|
component.ContentRenderType.Image
|
||||||
@ -1105,12 +1100,8 @@ describe('DocumentDetailComponent', () => {
|
|||||||
expect(
|
expect(
|
||||||
fixture.debugElement.query(By.css('.preview-sticky img'))
|
fixture.debugElement.query(By.css('.preview-sticky img'))
|
||||||
).not.toBeUndefined()
|
).not.toBeUndefined()
|
||||||
|
;(component.document.mime_type =
|
||||||
component.metadata = {
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'),
|
||||||
has_archive_version: false,
|
|
||||||
original_mime_type:
|
|
||||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
||||||
}
|
|
||||||
fixture.detectChanges()
|
fixture.detectChanges()
|
||||||
expect(component.archiveContentRenderType).toEqual(
|
expect(component.archiveContentRenderType).toEqual(
|
||||||
component.ContentRenderType.Other
|
component.ContentRenderType.Other
|
||||||
|
@ -72,6 +72,7 @@ import { DeletePagesConfirmDialogComponent } from '../common/confirm-dialog/dele
|
|||||||
import { HotKeyService } from 'src/app/services/hot-key.service'
|
import { HotKeyService } from 'src/app/services/hot-key.service'
|
||||||
import { PDFDocumentProxy } from 'ng2-pdf-viewer'
|
import { PDFDocumentProxy } from 'ng2-pdf-viewer'
|
||||||
import { DataType } from 'src/app/data/datatype'
|
import { DataType } from 'src/app/data/datatype'
|
||||||
|
import { log } from '@angular-devkit/build-angular/src/builders/ssr-dev-server'
|
||||||
|
|
||||||
enum DocumentDetailNavIDs {
|
enum DocumentDetailNavIDs {
|
||||||
Details = 1,
|
Details = 1,
|
||||||
@ -221,15 +222,13 @@ export class DocumentDetailComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
get archiveContentRenderType(): ContentRenderType {
|
get archiveContentRenderType(): ContentRenderType {
|
||||||
return this.getRenderType(
|
return this.document?.archived_file_name
|
||||||
this.metadata?.has_archive_version
|
? this.getRenderType('application/pdf')
|
||||||
? 'application/pdf'
|
: this.getRenderType(this.document?.mime_type)
|
||||||
: this.metadata?.original_mime_type
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get originalContentRenderType(): ContentRenderType {
|
get originalContentRenderType(): ContentRenderType {
|
||||||
return this.getRenderType(this.metadata?.original_mime_type)
|
return this.getRenderType(this.document?.mime_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRenderType(mimeType: string): ContentRenderType {
|
private getRenderType(mimeType: string): ContentRenderType {
|
||||||
|
@ -150,6 +150,8 @@ export interface Document extends ObjectWithPermissions {
|
|||||||
|
|
||||||
added?: Date
|
added?: Date
|
||||||
|
|
||||||
|
mime_type?: string
|
||||||
|
|
||||||
deleted_at?: Date
|
deleted_at?: Date
|
||||||
|
|
||||||
original_file_name?: string
|
original_file_name?: string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user