separated the path to the database from the path to the download output#140
separated the path to the database from the path to the download output#140therrealdude wants to merge 2 commits into
Conversation
patrickkfkan
left a comment
There was a problem hiding this comment.
Thanks. I have made some comments. Also, how would this affect the browse (web server) functionality? I see no changes to the server code.
| export interface DownloaderFileLoggerInit { | ||
| targetURL: string; | ||
| outDir?: string; | ||
| dbDir?: string; |
There was a problem hiding this comment.
What is the purpose of having dbDir here?
There was a problem hiding this comment.
It seems like nothing. It is removed now.
| console.log('Proceeding...', EOL); | ||
| if (postConfirm) { | ||
| postConfirm(); | ||
| } | ||
| } | ||
| else { | ||
| __logBegin(); | ||
| commonLog(logger, 'debug', null, `Created ${downloaderName} instance with config: `, this.#getDisplayConfig(downloader.getConfig())); | ||
| if (index === 0) { | ||
| __checkProxy(); | ||
| __checkDeno(); | ||
| } | ||
| } | ||
|
|
||
| let hasDownloaderError = false; | ||
| let isAborted = false; | ||
| let endMessage = ''; | ||
| downloader.on('end', ({ aborted, error, message }) => { | ||
| if (aborted) { | ||
| commonLog(logger, 'info', null, `${downloaderName} aborted`); | ||
| isAborted = true; | ||
| } | ||
| else if (!error) { | ||
| commonLog(logger, 'info', null, `${downloaderName} end`); | ||
| } | ||
| else { | ||
| commonLog(logger, 'warn', null, `${downloaderName} end with error`); | ||
| hasDownloaderError = true; | ||
| } | ||
| endMessage = message; | ||
| }); | ||
|
|
||
| try { | ||
| const abortController = new AbortController(); | ||
| const abortHandler = () => { | ||
| abortController.abort(); | ||
| }; | ||
| process.on('SIGINT', abortHandler); | ||
| await downloader.start({ signal: abortController.signal }); | ||
| await logger.end(); | ||
| process.off('SIGINT', abortHandler); | ||
| return { hasError: hasDownloaderError, aborted: isAborted, endMessage }; | ||
| } | ||
| catch (error) { | ||
| commonLog(logger, 'error', null, `Uncaught ${downloaderName} error:`, error); | ||
| return { hasError: true, aborted: isAborted, endMessage: 'Uncaught error' }; | ||
| } | ||
| } | ||
|
|
||
| #confirmProceed(prompt?: PromptSync.Prompt): boolean { | ||
| if (!prompt) { | ||
| prompt = PromptSync({ sigint: true }); | ||
| } | ||
| const confirmProceed = prompt('Proceed (Y/n)? '); | ||
| if (!confirmProceed.trim() || confirmProceed.trim().toLowerCase() === 'y') { | ||
| return true; | ||
| try { | ||
| if (!prompt) { | ||
| prompt = PromptSync({ sigint: true }); | ||
| console.log(); | ||
| } | ||
| const confirmProceed = prompt('Proceed (Y/n)? '); | ||
| if (!confirmProceed.trim() || confirmProceed.trim().toLowerCase() === 'y') { | ||
| console.log('Proceeding...', EOL); | ||
| return true; | ||
| } | ||
| else if (confirmProceed.trim().toLowerCase() === 'n') { | ||
| return false; | ||
| } | ||
|
|
||
| return this.#confirmProceed(prompt); | ||
| } | ||
| else if (confirmProceed.trim().toLowerCase() === 'n') { | ||
| catch (error) { | ||
| console.error('Error obtaining user input: ', error instanceof Error ? error.message : error); | ||
| return false; | ||
| } | ||
|
|
||
| return this.#confirmProceed(prompt); |
There was a problem hiding this comment.
These changes do not appear to be related to the dbDir feature. If they are unrelated, please move them into a separate PR.
There was a problem hiding this comment.
This should be removed with my latest update
…base at the server level
I just added some code to give the server the same functionality so the user can define the path for the database. Thanks for the feedback. Let me know if you think any more changes would be helpful. |
Hello,
I had a use case where I needed the database to be in a separate folder from the downloaded content. In my use case, I was trying to backup the data to a Samba share which was not playing well with SQLite. To fix this, I created a new command line argument, db-dir, to specify where the database should be saved. I created a pull request because I believe that this could be a common use case for others who want to backup content to a Samba share, NAS, ZFS share or whatever else there is.