File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,20 @@ export class Book extends EventTarget {
183183 /** @returns {BookContainer } */
184184 getContainer ( ) { return this . #bookContainer; }
185185
186+ /**
187+ * Returns a filename based on the source of the book (request, file, url).
188+ * @returns {string }
189+ */
190+ getFilename ( ) {
191+ if ( this . #uri || this . #request) {
192+ let url = this . #uri ?? this . #request. url ;
193+ return url . substring ( url . lastIndexOf ( '/' ) + 1 ) ;
194+ } else if ( this . #file || this . #fileHandle) {
195+ return ( this . #file || this . #fileHandle) . name ;
196+ }
197+ throw 'Unknown type of book source' ;
198+ }
199+
186200 /** @returns {FileSystemFileHandle } */
187201 getFileSystemHandle ( ) { return this . #fileHandle; }
188202
Original file line number Diff line number Diff line change @@ -1088,7 +1088,7 @@ export class KthoomApp {
10881088 const blob = new Blob ( [ ab ] , { type : this . currentBook_ . getMIMEType ( ) } ) ;
10891089 const link = document . createElement ( 'a' ) ;
10901090 link . href = window . URL . createObjectURL ( blob ) ;
1091- const fileName = this . currentBook_ . getName ( ) ;
1091+ const fileName = this . currentBook_ . getFilename ( ) ;
10921092 link . download = fileName ;
10931093 link . click ( ) ;
10941094 }
You can’t perform that action at this time.
0 commit comments