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