-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ba4808
commit 704e94b
Showing
19 changed files
with
328 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/app/components/attachment-dialog/attachment-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<h2 mat-dialog-title> | ||
{{ data.name }} | ||
</h2> | ||
|
||
<mat-dialog-content> | ||
<p>Description: {{ data.description }}</p> | ||
<p>MimeType: {{ data.mimeType }}</p> | ||
</mat-dialog-content> | ||
|
||
<mat-dialog-content> | ||
<pre>{{ fileContent }}</pre> | ||
</mat-dialog-content> | ||
|
||
<mat-dialog-actions align="end"> | ||
<button mat-flat-button color="accent" mat-dialog-close> | ||
{{ 'close' | transloco }} | ||
</button> | ||
</mat-dialog-actions> |
Empty file.
36 changes: 36 additions & 0 deletions
36
src/app/components/attachment-dialog/attachment-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; | ||
import { DatePipe } from '@angular/common'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog'; | ||
import { MatFormFieldModule } from '@angular/material/form-field'; | ||
import { MatInputModule } from '@angular/material/input'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { TranslocoPipe } from '@jsverse/transloco'; | ||
|
||
import { DocumentAttachment } from '@app/types/attachment'; | ||
|
||
@Component({ | ||
selector: 'app-attachment-dialog', | ||
templateUrl: './attachment-dialog.component.html', | ||
styleUrls: ['./attachment-dialog.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
imports: [ | ||
DatePipe, | ||
MatButtonModule, | ||
MatDialogModule, | ||
MatFormFieldModule, | ||
MatInputModule, | ||
MatIconModule, | ||
TranslocoPipe, | ||
], | ||
}) | ||
export class AttachmentDialogComponent { | ||
readonly data = inject<DocumentAttachment>(MAT_DIALOG_DATA); | ||
|
||
fileContent: string | undefined; | ||
|
||
constructor() { | ||
this.fileContent = new TextDecoder().decode(this.data.data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<mat-expansion-panel> | ||
<mat-expansion-panel-header> | ||
Attachments: {{ attachments().length }} | ||
</mat-expansion-panel-header> | ||
|
||
<ng-template matExpansionPanelContent> | ||
@for (attachment of attachments(); track attachment.name) { | ||
<div class="item"> | ||
<button class="tool" mat-mini-fab (click)="inspectAttachment(attachment)"> | ||
<mat-icon>search</mat-icon> | ||
</button> | ||
|
||
@if (attachment.mimeType.includes('image/')) { | ||
<mat-icon class="icon large" svgIcon="image" /> | ||
} @else if (attachment.mimeType.includes('xml')) { | ||
<mat-icon class="icon large" svgIcon="xml" /> | ||
} @else { | ||
<mat-icon class="icon large" svgIcon="unknown" /> | ||
} | ||
|
||
<div class="truncate"> | ||
{{ attachment.name }} | ||
</div> | ||
</div> | ||
} @empty {} | ||
</ng-template> | ||
</mat-expansion-panel> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
:host { | ||
display: block; | ||
width: 100%; | ||
padding-left: 1rem; | ||
padding-bottom: 1.25rem; | ||
padding-right: 6rem; | ||
} | ||
|
||
.item { | ||
position: relative; | ||
border-radius: 0.25rem; | ||
border: grey solid 2px; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
box-sizing: border-box; | ||
|
||
margin: 0.5rem; | ||
max-width: 200px; | ||
|
||
&:hover { | ||
border-color: #3f51b5; | ||
} | ||
|
||
.tool { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
} | ||
} | ||
|
||
.icon.large { | ||
font-size: 3rem; | ||
width: 3rem; | ||
height: 3rem; | ||
} | ||
|
||
.truncate { | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
max-width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
Component, | ||
ChangeDetectionStrategy, | ||
inject, | ||
input, | ||
} from '@angular/core'; | ||
import { | ||
MatExpansionPanel, | ||
MatExpansionPanelContent, | ||
MatExpansionPanelHeader, | ||
} from '@angular/material/expansion'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { TranslocoPipe } from '@jsverse/transloco'; | ||
|
||
import { DocumentAttachment } from '@app/types/attachment'; | ||
import { LazyDialogService } from '@app/services/lazy-dialog.service'; | ||
|
||
@Component({ | ||
selector: 'app-attachments', | ||
templateUrl: './attachments.component.html', | ||
styleUrls: ['./attachments.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
standalone: true, | ||
imports: [ | ||
MatExpansionPanel, | ||
MatExpansionPanelHeader, | ||
MatExpansionPanelContent, | ||
MatIconModule, | ||
MatButtonModule, | ||
TranslocoPipe, | ||
], | ||
}) | ||
export class AttachmentsComponent { | ||
private readonly lazyDialogService = inject(LazyDialogService); | ||
|
||
readonly attachments = input.required<DocumentAttachment[]>(); | ||
|
||
inspectAttachment(attachment: DocumentAttachment) { | ||
this.lazyDialogService.openAttachmentDialog(attachment); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
:host { | ||
display: block; | ||
height: 100%; | ||
position: relative; | ||
text-align: center; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
decodePDFRawStream, | ||
PDFArray, | ||
PDFDict, | ||
PDFDocument, | ||
PDFHexString, | ||
PDFName, | ||
PDFRawStream, | ||
PDFStream, | ||
PDFString, | ||
} from 'pdf-lib'; | ||
|
||
export const extractRawAttachments = (pdfDoc: PDFDocument) => { | ||
if (!pdfDoc.catalog.has(PDFName.of('Names'))) return []; | ||
const Names = pdfDoc.catalog.lookup(PDFName.of('Names'), PDFDict); | ||
|
||
if (!Names.has(PDFName.of('EmbeddedFiles'))) return []; | ||
let EmbeddedFiles = Names.lookup(PDFName.of('EmbeddedFiles'), PDFDict); | ||
|
||
if ( | ||
!EmbeddedFiles.has(PDFName.of('Names')) && | ||
EmbeddedFiles.has(PDFName.of('Kids')) | ||
) | ||
EmbeddedFiles = EmbeddedFiles.lookup(PDFName.of('Kids'), PDFArray).lookup( | ||
0 | ||
) as PDFDict; | ||
|
||
if (!EmbeddedFiles.has(PDFName.of('Names'))) return []; | ||
const EFNames = EmbeddedFiles.lookup(PDFName.of('Names'), PDFArray); | ||
|
||
const rawAttachments = []; | ||
for (let idx = 0, len = EFNames.size(); idx < len; idx += 2) { | ||
const fileName = EFNames.lookup(idx) as PDFHexString | PDFString; | ||
const fileSpec = EFNames.lookup(idx + 1, PDFDict); | ||
rawAttachments.push({ fileName, fileSpec }); | ||
} | ||
|
||
return rawAttachments; | ||
}; | ||
|
||
export const extractAttachments = (pdfDoc: PDFDocument) => { | ||
const rawAttachments = extractRawAttachments(pdfDoc); | ||
return rawAttachments.map(({ fileName, fileSpec }) => { | ||
const stream = fileSpec | ||
.lookup(PDFName.of('EF'), PDFDict) | ||
.lookup(PDFName.of('F'), PDFStream) as PDFRawStream; | ||
|
||
const description = fileSpec.lookup(PDFName.of('Desc'), PDFString); | ||
const subtype = stream.dict.lookup(PDFName.of('Subtype'), PDFName); | ||
|
||
return { | ||
name: fileName.decodeText(), | ||
description: description.decodeText(), | ||
mimeType: subtype.decodeText(), | ||
data: decodePDFRawStream(stream).decode(), | ||
}; | ||
}); | ||
}; |
Oops, something went wrong.