@@ -6,6 +6,7 @@ import { PDFWorker } from '../common/pdf-worker.js';
66import { REQUEST_EXPORT_PDF , RECEIVE_EXPORT_PDF , ERROR_EXPORT_PDF } from '../constants/actions' ;
77import { saveAs } from 'file-saver' ;
88import { READER_CONTENT_TYPES } from '../constants/reader' ;
9+ import { getProxyPdfUrl } from '../common/proxy' ;
910
1011const tryGetFirstLink = itemKey => {
1112 return async ( dispatch , getState ) => {
@@ -32,16 +33,16 @@ const tryGetAttachmentURL = attachmentItemKey => {
3233 return async ( dispatch , getState ) => {
3334 const state = getState ( ) ;
3435 const item = get ( state , [ 'libraries' , state . current . libraryKey , 'items' , attachmentItemKey ] , null ) ;
35- const proxyBase = state . config ?. pdfProxyBaseUrl ;
36+ const proxyUrl = getProxyPdfUrl ( state , attachmentItemKey ) ;
3637
37- // If a proxy base URL is configured , bypass Storage/enclosure links and use the proxy.
38- if ( proxyBase ) {
38+ // If a proxy URL is available , bypass Storage/enclosure links and use the proxy.
39+ if ( proxyUrl ) {
3940 // Debug: trace when proxy URL is requested.
4041 console . log ( '[proxy-debug] tryGetAttachmentURL using proxy' , {
4142 attachmentItemKey,
4243 linkMode : item ?. linkMode ,
4344 contentType : item ?. contentType ,
44- proxyBase ,
45+ proxyUrl ,
4546 } ) ;
4647 return dispatch ( getAttachmentUrl ( attachmentItemKey ) ) ;
4748 }
@@ -119,29 +120,29 @@ const pickBestItemAction = itemKey => {
119120const pickBestAttachmentItemAction = attachmentItemKey => {
120121 return async ( dispatch , getState ) => {
121122 const state = getState ( ) ;
122- const current = state . current ;
123- const item = get ( state , [ 'libraries' , state . current . libraryKey , 'items' , attachmentItemKey ] , null ) ;
124- const proxyBase = state . config ?. pdfProxyBaseUrl ;
125-
126- const isFile = item && item . linkMode && item . linkMode . startsWith ( 'imported' ) && item [ Symbol . for ( 'links' ) ] . enclosure ;
127- const isLink = item && item . linkMode && item . linkMode === 'linked_url' ;
128-
129- if ( isFile ) {
130- if ( Object . keys ( READER_CONTENT_TYPES ) . includes ( item . contentType ) ) {
131- // If proxy is available, prefer proxy URL to force PDF fetch even when reader path is used.
132- if ( proxyBase ) {
133- console . log ( '[proxy-debug] pickBestAttachmentItemAction -> proxy open' , {
134- attachmentItemKey,
135- linkMode : item . linkMode ,
136- contentType : item . contentType ,
137- proxyBase,
138- } ) ;
139- return openDelayedURL ( dispatch ( getAttachmentUrl ( attachmentItemKey ) ) ) ;
140- }
123+ const current = state . current ;
124+ const item = get ( state , [ 'libraries' , state . current . libraryKey , 'items' , attachmentItemKey ] , null ) ;
125+ const proxyUrl = getProxyPdfUrl ( state , attachmentItemKey ) ;
141126
142- const readerPath = makePath ( state . config , {
143- attachmentKey : null ,
144- collection : current . collectionKey ,
127+ const isFile = item && item . linkMode && item . linkMode . startsWith ( 'imported' ) && item [ Symbol . for ( 'links' ) ] . enclosure ;
128+ const isLink = item && item . linkMode && item . linkMode === 'linked_url' ;
129+
130+ if ( isFile ) {
131+ if ( Object . keys ( READER_CONTENT_TYPES ) . includes ( item . contentType ) ) {
132+ // If proxy URL is available, prefer it to force PDF fetch even when reader path is used.
133+ if ( proxyUrl ) {
134+ console . log ( '[proxy-debug] pickBestAttachmentItemAction -> proxy open' , {
135+ attachmentItemKey,
136+ linkMode : item . linkMode ,
137+ contentType : item . contentType ,
138+ proxyUrl,
139+ } ) ;
140+ return openDelayedURL ( dispatch ( getAttachmentUrl ( attachmentItemKey ) ) ) ;
141+ }
142+
143+ const readerPath = makePath ( state . config , {
144+ attachmentKey : null ,
145+ collection : current . collectionKey ,
145146 items : [ attachmentItemKey ] ,
146147 library : current . libraryKey ,
147148 noteKey : null ,
0 commit comments