@@ -20,8 +20,9 @@ import type {
2020 Workflow ,
2121} from "@/types/crawler" ;
2222import type { QARun } from "@/types/qa" ;
23- import type { NonEmptyArray } from "@/types/utils" ;
2423import { isApiError } from "@/utils/api" ;
24+ import { downloadLink } from "@/utils/crawl-workflows/downloadLink" ;
25+ import { hasFiles } from "@/utils/crawl-workflows/hasFiles" ;
2526import {
2627 isActive ,
2728 isNotFailed ,
@@ -126,29 +127,6 @@ export class ArchivedItemDetail extends BtrixElement {
126127 config : msg ( "Crawl Settings" ) ,
127128 } ;
128129
129- private get authQuery ( ) {
130- return `auth_bearer=${ this . authState ?. headers . Authorization . split ( " " ) [ 1 ] } ` ;
131- }
132-
133- private get itemDownload ( ) {
134- let path = "" ;
135- let name = "" ;
136-
137- if ( this . hasFiles ( this . item ) ) {
138- if ( this . item . resources . length > 1 ) {
139- path = `/api/orgs/${ this . orgId } /all-crawls/${ this . itemId } /download?${ this . authQuery } ` ;
140- name = `${ this . itemId } .wacz` ;
141- } else {
142- const file = this . item . resources [ 0 ] ;
143-
144- path = file . path ;
145- name = file . name ;
146- }
147- }
148-
149- return { path, name } ;
150- }
151-
152130 private get listUrl ( ) : string {
153131 let path = "items" ;
154132 if ( this . workflowId ) {
@@ -169,15 +147,6 @@ export class ArchivedItemDetail extends BtrixElement {
169147
170148 private timerId ?: number ;
171149
172- private hasFiles ( item ?: ArchivedItem ) : item is ArchivedItem & {
173- resources : NonEmptyArray < NonNullable < ArchivedItem [ "resources" ] > [ number ] > ;
174- } {
175- if ( ! item ) return false ;
176- if ( ! item . resources ) return false ;
177-
178- return Boolean ( item . resources [ 0 ] ) ;
179- }
180-
181150 private get formattedFinishedDate ( ) {
182151 if ( ! this . item ) return ;
183152
@@ -351,7 +320,7 @@ export class ArchivedItemDetail extends BtrixElement {
351320 case "files" :
352321 sectionContent = this . renderPanel (
353322 html ` ${ this . renderTitle ( this . tabLabels . files ) }
354- ${ this . renderDownloadFiles ( ) } ` ,
323+ ${ this . renderDownloadFilesButton ( ) } ` ,
355324 this . renderFiles ( ) ,
356325 ) ;
357326 break ;
@@ -360,7 +329,7 @@ export class ArchivedItemDetail extends BtrixElement {
360329 html ` ${ this . renderTitle ( this . tabLabels . logs ) }
361330 <sl-tooltip content=${ msg ( "Download Entire Log File" ) } >
362331 <sl-button
363- href=${ `/api/orgs/${ this . orgId } /crawls/${ this . itemId } /logs?${ this . authQuery } ` }
332+ href=${ `/api/orgs/${ this . orgId } /crawls/${ this . itemId } /logs?auth_bearer= ${ this . authState ?. headers . Authorization . split ( " " ) [ 1 ] } ` }
364333 download=${ `browsertrix-${ this . itemId } -logs.log` }
365334 size="small"
366335 variant="primary"
@@ -637,7 +606,7 @@ export class ArchivedItemDetail extends BtrixElement {
637606 private renderMenu ( ) {
638607 if ( ! this . item ) return ;
639608
640- const { path , name } = this . itemDownload ;
609+ const download = downloadLink ( this . item , this . authState ) ;
641610
642611 return html `
643612 <sl-dropdown placement="bottom-end" distance="4" hoist>
@@ -671,7 +640,10 @@ export class ArchivedItemDetail extends BtrixElement {
671640 </btrix-menu-item-link>
672641 ` ,
673642 ) }
674- <btrix-menu-item-link href=${ path } download=${ name } >
643+ <btrix-menu-item-link
644+ href=${ download . path }
645+ download=${ download . name }
646+ >
675647 <sl-icon name="cloud-download" slot="prefix"></sl-icon>
676648 ${ msg ( "Download Item" ) }
677649 ${ this . item ?. fileSize
@@ -775,7 +747,7 @@ export class ArchivedItemDetail extends BtrixElement {
775747
776748 const config = JSON . stringify ( { headers } ) ;
777749
778- const canReplay = this . hasFiles ( this . item ) ;
750+ const canReplay = hasFiles ( this . item ) ;
779751
780752 return html `
781753 <!-- https://github.com/webrecorder/browsertrix-crawler/blob/9f541ab011e8e4bccf8de5bd7dc59b632c694bab/screencast/index.html -->
@@ -989,7 +961,7 @@ export class ArchivedItemDetail extends BtrixElement {
989961
990962 private renderFiles ( ) {
991963 return html `
992- ${ this . hasFiles ( this . item )
964+ ${ hasFiles ( this . item )
993965 ? html `
994966 <ul class="rounded-lg border text-sm">
995967 ${ this . item . resources . map (
@@ -1038,17 +1010,22 @@ export class ArchivedItemDetail extends BtrixElement {
10381010 ` ;
10391011 }
10401012
1041- private renderDownloadFiles ( ) {
1042- if ( ! this . hasFiles ( this . item ) ) return ;
1013+ private renderDownloadFilesButton ( ) {
1014+ if ( ! hasFiles ( this . item ) ) return ;
10431015
10441016 const singleFile = this . item . resources . length === 1 ;
1045- const { path , name } = this . itemDownload ;
1017+ const download = downloadLink ( this . item , this . authState ) ;
10461018
10471019 return html `<sl-tooltip
10481020 content=${ msg ( "Download Files as Multi-WACZ" ) }
10491021 ?disabled=${ singleFile }
10501022 >
1051- <sl-button href=${ path } download=${ name } size="small" variant="primary">
1023+ <sl-button
1024+ href=${ download . path }
1025+ download=${ download . name }
1026+ size="small"
1027+ variant="primary"
1028+ >
10521029 <sl-icon slot="prefix" name="cloud-download"></sl-icon>
10531030 ${ singleFile ? msg ( "Download File" ) : msg ( "Download Files" ) }
10541031 </sl-button>
0 commit comments