DrKain / subclean

A cross-platform CLI tool and node module to remove advertising from subtitles. Supports Bazarr and bulk cleaning!
MIT License
54 stars 5 forks source link

[Feature Request] Prevent writing to file in serverless environment #35

Closed elyeandre closed 7 months ago

elyeandre commented 7 months ago

Problem: When using the library on serverless environments like Vercel with a read-only file system, the current implementation creates a log directory during the ensureDir function, causing issues.

Solution: I propose two potential solutions:

  1. Disable Log Feature: Introduce a configuration option to disable logging entirely. This would be useful for environments where writing to the file system is not feasible.
const options = {
  disableLog: true,
};
  1. Custom Log Path: Allow users to specify a custom log path, giving them the flexibility to choose a writable directory, such as the /tmp directory on Vercel.
const options = {
  logPath: '/tmp/logs',
};

Alternatives Considered: The temporary solution I've implemented uses the /tmp directory, but having these options in the library directly would provide a more elegant and configurable solution.

private ensureDirs() {
    let $app = this.getPath();
    let $filters = join($app, 'filters');

    // Specify the log directory path, redirected to '/tmp' to avoid issues in serverless environments like Vercel
    let $logs = join('/tmp', 'logs');

    if (!existsSync($app)) mkdirSync($app);
    if (!existsSync($filters)) mkdirSync($filters);
    if (!existsSync($logs)) mkdirSync($logs);
}
DrKain commented 7 months ago

Hi. Thanks for the feedback. In the next release I've already planned a noFileOutput value that will be false by default in a node environment, it exists in code but has no action yet. I'm a bit unwell at the moment but I'll prioritize this as soon as I can. If you want to speed things up you're more than welcome to create a PR, otherwise I'll handle this as soon as I can.

DrKain commented 7 months ago

@elyeandre I've just pushed a new version that should prevent file operations when used as a node module. Please let me know if you encounter any other problems and I'll see what I can do.

DrKain commented 7 months ago

As an extra note I plan on re-working the logging when I get the chance. I'll likely set up a simple event emitter that gives people the option to receive logging information if they want it, instead of blocking it completely with silent = true.
The majority of the code needs to be redone but I'm still very sick so the amount of time I can dedicate to these things is limited. Sorry for the inconvenience

elyeandre commented 7 months ago

@DrKain It's okay, thank you for taking the time to address the issue, and I appreciate your very useful library. I'm saddened to hear that you are unwell, I hope you get well soon. Take care