opencomic-ai-bin 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,6 +31,9 @@ import OpenComicAI from 'opencomic-ai-bin';
31
31
 
32
32
  (async () => {
33
33
 
34
+ // Set the base directory for binary paths, for example change to app.asar.unpacked path in Electron apps
35
+ OpenComicAI.setDirname(OpenComicAI.__dirname.replace(/app(-(?:arm64|x64))?\.asar/, 'app$1.asar.unpacked'));
36
+
34
37
  // Models path, if the model is not found in this folder, it will be downloaded
35
38
  OpenComicAI.setModelsPath('./models');
36
39
 
@@ -68,6 +71,14 @@ import OpenComicAI from 'opencomic-ai-bin';
68
71
  })();
69
72
  ```
70
73
 
74
+ ### OpenComicAI.setDirname
75
+
76
+ Set the base directory for binary paths.
77
+
78
+ ```ts
79
+ OpenComicAI.setDirname(dirname: string): void
80
+ ```
81
+
71
82
  ### OpenComicAI.setModelsPath
72
83
 
73
84
  Set the directory where models will be downloaded and stored.
@@ -76,6 +87,14 @@ Set the directory where models will be downloaded and stored.
76
87
  OpenComicAI.setModelsPath(path: string): void
77
88
  ```
78
89
 
90
+ ### OpenComicAI.\_\_dirname
91
+
92
+ Get the base directory for binary paths.
93
+
94
+ ```ts
95
+ OpenComicAI.__dirname: string
96
+ ```
97
+
79
98
  ### OpenComicAI.models
80
99
 
81
100
  Object containing all available models organized by type (upscale, descreen, artifact-removal).
@@ -486,6 +486,7 @@ class OpenComicAI {
486
486
  static modelsList = modelsList;
487
487
  static modelsTypeList = modelsTypeList;
488
488
  static modelsPath = undefined;
489
+ static __dirname = ___dirname;
489
490
  static resolve = (path) => {
490
491
  if (!p.isAbsolute(path)) {
491
492
  if (typeof module !== 'undefined')
@@ -501,6 +502,9 @@ class OpenComicAI {
501
502
  throw new Error(`Models path does not exist: ${path}`);
502
503
  OpenComicAI.modelsPath = path;
503
504
  };
505
+ static setDirname = (dirname) => {
506
+ OpenComicAI.__dirname = OpenComicAI.resolve(dirname);
507
+ };
504
508
  static model = (model = DEFAULT_MODEL) => {
505
509
  if (!modelsList.includes(model))
506
510
  throw new Error(`Model not found: ${model}`);
@@ -515,7 +519,7 @@ class OpenComicAI {
515
519
  static binary = (model) => {
516
520
  if (!modelsList.includes(model))
517
521
  throw new Error(`Model not found: ${model}`);
518
- const base = p.join(___dirname, '..');
522
+ const base = p.join(OpenComicAI.__dirname, '..');
519
523
  const upscaler = OpenComicAI.model(model).upscaler;
520
524
  const result = upscalers[upscaler].platforms[process.platform]?.[process.arch] ?? upscalers[upscaler].platforms[process.platform]?.x64 ?? upscalers[upscaler].platforms.linux?.x64 ?? '';
521
525
  return p.join(base, result);
package/dist/index.cjs CHANGED
@@ -488,6 +488,7 @@ class OpenComicAI {
488
488
  static modelsList = modelsList;
489
489
  static modelsTypeList = modelsTypeList;
490
490
  static modelsPath = undefined;
491
+ static __dirname = ___dirname;
491
492
  static resolve = (path) => {
492
493
  if (!p.isAbsolute(path)) {
493
494
  if (typeof module !== 'undefined')
@@ -503,6 +504,9 @@ class OpenComicAI {
503
504
  throw new Error(`Models path does not exist: ${path}`);
504
505
  OpenComicAI.modelsPath = path;
505
506
  };
507
+ static setDirname = (dirname) => {
508
+ OpenComicAI.__dirname = OpenComicAI.resolve(dirname);
509
+ };
506
510
  static model = (model = DEFAULT_MODEL) => {
507
511
  if (!modelsList.includes(model))
508
512
  throw new Error(`Model not found: ${model}`);
@@ -517,7 +521,7 @@ class OpenComicAI {
517
521
  static binary = (model) => {
518
522
  if (!modelsList.includes(model))
519
523
  throw new Error(`Model not found: ${model}`);
520
- const base = p.join(___dirname, '..');
524
+ const base = p.join(OpenComicAI.__dirname, '..');
521
525
  const upscaler = OpenComicAI.model(model).upscaler;
522
526
  const result = upscalers[upscaler].platforms[process.platform]?.[process.arch] ?? upscalers[upscaler].platforms[process.platform]?.x64 ?? upscalers[upscaler].platforms.linux?.x64 ?? '';
523
527
  return p.join(base, result);
package/dist/index.d.ts CHANGED
@@ -42,8 +42,10 @@ declare class OpenComicAI {
42
42
  static modelsList: string[];
43
43
  static modelsTypeList: Record<ModelType, string[]>;
44
44
  static modelsPath: string | undefined;
45
+ static __dirname: any;
45
46
  private static resolve;
46
47
  static setModelsPath: (path: string) => void;
48
+ static setDirname: (dirname: string) => void;
47
49
  static model: (model?: Model) => ModelObject;
48
50
  static binary: (model: Model) => string;
49
51
  private static download;
package/dist/index.mjs CHANGED
@@ -486,6 +486,7 @@ class OpenComicAI {
486
486
  static modelsList = modelsList;
487
487
  static modelsTypeList = modelsTypeList;
488
488
  static modelsPath = undefined;
489
+ static __dirname = ___dirname;
489
490
  static resolve = (path) => {
490
491
  if (!p.isAbsolute(path)) {
491
492
  if (typeof module !== 'undefined')
@@ -501,6 +502,9 @@ class OpenComicAI {
501
502
  throw new Error(`Models path does not exist: ${path}`);
502
503
  OpenComicAI.modelsPath = path;
503
504
  };
505
+ static setDirname = (dirname) => {
506
+ OpenComicAI.__dirname = OpenComicAI.resolve(dirname);
507
+ };
504
508
  static model = (model = DEFAULT_MODEL) => {
505
509
  if (!modelsList.includes(model))
506
510
  throw new Error(`Model not found: ${model}`);
@@ -515,7 +519,7 @@ class OpenComicAI {
515
519
  static binary = (model) => {
516
520
  if (!modelsList.includes(model))
517
521
  throw new Error(`Model not found: ${model}`);
518
- const base = p.join(___dirname, '..');
522
+ const base = p.join(OpenComicAI.__dirname, '..');
519
523
  const upscaler = OpenComicAI.model(model).upscaler;
520
524
  const result = upscalers[upscaler].platforms[process.platform]?.[process.arch] ?? upscalers[upscaler].platforms[process.platform]?.x64 ?? upscalers[upscaler].platforms.linux?.x64 ?? '';
521
525
  return p.join(base, result);
package/index.mts CHANGED
@@ -566,6 +566,7 @@ export default class OpenComicAI {
566
566
  public static modelsList = modelsList;
567
567
  public static modelsTypeList = modelsTypeList;
568
568
  public static modelsPath: string | undefined = undefined;
569
+ public static __dirname = ___dirname;
569
570
 
570
571
  private static resolve = (path: string): string => {
571
572
 
@@ -592,6 +593,12 @@ export default class OpenComicAI {
592
593
 
593
594
  }
594
595
 
596
+ public static setDirname = (dirname: string): void => {
597
+
598
+ OpenComicAI.__dirname = OpenComicAI.resolve(dirname);
599
+
600
+ }
601
+
595
602
  public static model = (model: Model = DEFAULT_MODEL): ModelObject => {
596
603
 
597
604
  if(!modelsList.includes(model as Model))
@@ -612,7 +619,7 @@ export default class OpenComicAI {
612
619
  if(!modelsList.includes(model as Model))
613
620
  throw new Error(`Model not found: ${model}`);
614
621
 
615
- const base = p.join(___dirname, '..');
622
+ const base = p.join(OpenComicAI.__dirname, '..');
616
623
 
617
624
  const upscaler = OpenComicAI.model(model as Model).upscaler;
618
625
  const result = upscalers[upscaler].platforms[process.platform]?.[process.arch] ?? upscalers[upscaler].platforms[process.platform]?.x64 ?? upscalers[upscaler].platforms.linux?.x64 ?? '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencomic-ai-bin",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Upscale and dehalftone images using AI models like Real-CUGAN, Real-ESRGAN, Waifu2x and Upscayl.",
5
5
  "main": "index.mts",
6
6
  "type": "module",