mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	frontend support for downloading originals
This commit is contained in:
		@@ -5,12 +5,26 @@
 | 
			
		||||
        </svg>
 | 
			
		||||
        <span class="d-none d-lg-inline"> Delete</span>
 | 
			
		||||
    </button>
 | 
			
		||||
    <a [href]="downloadUrl" class="btn btn-sm btn-outline-primary mr-2">
 | 
			
		||||
        <svg class="buttonicon" fill="currentColor">
 | 
			
		||||
            <use xlink:href="assets/bootstrap-icons.svg#download" />
 | 
			
		||||
        </svg>
 | 
			
		||||
        <span class="d-none d-lg-inline"> Download</span>
 | 
			
		||||
    </a>
 | 
			
		||||
 | 
			
		||||
    <div class="btn-group mr-2">
 | 
			
		||||
 | 
			
		||||
        <a [href]="downloadUrl" class="btn btn-sm btn-outline-primary">
 | 
			
		||||
            <svg class="buttonicon" fill="currentColor">
 | 
			
		||||
                <use xlink:href="assets/bootstrap-icons.svg#download" />
 | 
			
		||||
            </svg>
 | 
			
		||||
            <span class="d-none d-lg-inline"> Download</span>
 | 
			
		||||
        </a>
 | 
			
		||||
    
 | 
			
		||||
        <div class="btn-group" ngbDropdown role="group" *ngIf="metadata?.paperless__has_archive_version">
 | 
			
		||||
          <button class="btn btn-sm btn-outline-primary dropdown-toggle-split" ngbDropdownToggle></button>
 | 
			
		||||
          <div class="dropdown-menu" ngbDropdownMenu>
 | 
			
		||||
            <a ngbDropdownItem [href]="downloadOriginalUrl">Download original</a>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    <button type="button" class="btn btn-sm btn-outline-primary" (click)="close()">
 | 
			
		||||
        <svg class="buttonicon" fill="currentColor">
 | 
			
		||||
            <use xlink:href="assets/bootstrap-icons.svg#x" />
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ import { ActivatedRoute, Router } from '@angular/router';
 | 
			
		||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
 | 
			
		||||
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent';
 | 
			
		||||
import { PaperlessDocument } from 'src/app/data/paperless-document';
 | 
			
		||||
import { PaperlessDocumentMetadata } from 'src/app/data/paperless-document-metadata';
 | 
			
		||||
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type';
 | 
			
		||||
import { TAG_COLOURS, PaperlessTag } from 'src/app/data/paperless-tag';
 | 
			
		||||
import { DocumentListViewService } from 'src/app/services/document-list-view.service';
 | 
			
		||||
@@ -27,9 +28,11 @@ export class DocumentDetailComponent implements OnInit {
 | 
			
		||||
 | 
			
		||||
  documentId: number
 | 
			
		||||
  document: PaperlessDocument
 | 
			
		||||
  metadata: PaperlessDocumentMetadata
 | 
			
		||||
  title: string
 | 
			
		||||
  previewUrl: string
 | 
			
		||||
  downloadUrl: string
 | 
			
		||||
  downloadOriginalUrl: string
 | 
			
		||||
 | 
			
		||||
  correspondents: PaperlessCorrespondent[]
 | 
			
		||||
  documentTypes: PaperlessDocumentType[]
 | 
			
		||||
@@ -66,6 +69,7 @@ export class DocumentDetailComponent implements OnInit {
 | 
			
		||||
      this.documentId = +paramMap.get('id')
 | 
			
		||||
      this.previewUrl = this.documentsService.getPreviewUrl(this.documentId)
 | 
			
		||||
      this.downloadUrl = this.documentsService.getDownloadUrl(this.documentId)
 | 
			
		||||
      this.downloadOriginalUrl = this.documentsService.getDownloadUrl(this.documentId, true)
 | 
			
		||||
      if (this.openDocumentService.getOpenDocument(this.documentId)) {
 | 
			
		||||
        this.updateComponent(this.openDocumentService.getOpenDocument(this.documentId))
 | 
			
		||||
      } else {
 | 
			
		||||
@@ -80,6 +84,9 @@ export class DocumentDetailComponent implements OnInit {
 | 
			
		||||
 | 
			
		||||
  updateComponent(doc: PaperlessDocument) {
 | 
			
		||||
    this.document = doc
 | 
			
		||||
    this.documentsService.getMetadata(doc.id).subscribe(result => {
 | 
			
		||||
      this.metadata = result
 | 
			
		||||
    })
 | 
			
		||||
    this.title = doc.title
 | 
			
		||||
    this.documentForm.patchValue(doc)
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								src-ui/src/app/data/paperless-document-metadata.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								src-ui/src/app/data/paperless-document-metadata.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
export interface PaperlessDocumentMetadata {
 | 
			
		||||
    
 | 
			
		||||
  paperless__checksum?: string
 | 
			
		||||
 | 
			
		||||
  paperless__mime_type?: string
 | 
			
		||||
 | 
			
		||||
  paperless__filename?: string
 | 
			
		||||
 | 
			
		||||
  paperless__has_archive_version?: boolean
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
import { Injectable } from '@angular/core';
 | 
			
		||||
import { PaperlessDocument } from 'src/app/data/paperless-document';
 | 
			
		||||
import { PaperlessDocumentMetadata } from 'src/app/data/paperless-document-metadata';
 | 
			
		||||
import { AbstractPaperlessService } from './abstract-paperless-service';
 | 
			
		||||
import { HttpClient } from '@angular/common/http';
 | 
			
		||||
import { Observable } from 'rxjs';
 | 
			
		||||
@@ -50,20 +51,32 @@ export class DocumentService extends AbstractPaperlessService<PaperlessDocument>
 | 
			
		||||
    return super.list(page, pageSize, sortField, sortDirection, this.filterRulesToQueryParams(filterRules))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getPreviewUrl(id: number): string {
 | 
			
		||||
    return this.getResourceUrl(id, 'preview')
 | 
			
		||||
  getPreviewUrl(id: number, original: boolean = false): string {
 | 
			
		||||
    let url = this.getResourceUrl(id, 'preview')
 | 
			
		||||
    if (original) {
 | 
			
		||||
      url += "?original=true"
 | 
			
		||||
    }
 | 
			
		||||
    return url
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getThumbUrl(id: number): string {
 | 
			
		||||
    return this.getResourceUrl(id, 'thumb')
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getDownloadUrl(id: number): string {
 | 
			
		||||
    return this.getResourceUrl(id, 'download')
 | 
			
		||||
  getDownloadUrl(id: number, original: boolean = false): string {
 | 
			
		||||
    let url = this.getResourceUrl(id, 'download')
 | 
			
		||||
    if (original) {
 | 
			
		||||
      url += "?original=true"
 | 
			
		||||
    }
 | 
			
		||||
    return url
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  uploadDocument(formData) {
 | 
			
		||||
    return this.http.post(this.getResourceUrl(null, 'post_document'), formData)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getMetadata(id: number): Observable<PaperlessDocumentMetadata> {
 | 
			
		||||
    return this.http.get<PaperlessDocumentMetadata>(this.getResourceUrl(id, 'metadata'))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user