chore: fs module should not cover app logic
This commit is contained in:
parent
ec7703ec8d
commit
8a14edaeea
@ -41,9 +41,8 @@ const downloadFile: (url: string, fileName: string) => Promise<any> = (
|
||||
window.electronAPI?.downloadFile(url, fileName);
|
||||
|
||||
/**
|
||||
* Deletes a file from the local file system.
|
||||
* @param {string} path - The path of the file to delete.
|
||||
* @returns {Promise<any>} A promise that resolves when the file is deleted.
|
||||
* @deprecated This object is deprecated and should not be used.
|
||||
* Use fs module instead.
|
||||
*/
|
||||
const deleteFile: (path: string) => Promise<any> = (path) =>
|
||||
window.coreAPI?.deleteFile(path) ?? window.electronAPI?.deleteFile(path);
|
||||
@ -55,6 +54,13 @@ const deleteFile: (path: string) => Promise<any> = (path) =>
|
||||
*/
|
||||
const appDataPath: () => Promise<any> = () => window.coreAPI?.appDataPath();
|
||||
|
||||
/**
|
||||
* Gets the user space path.
|
||||
* @returns {Promise<any>} A Promise that resolves with the user space path.
|
||||
*/
|
||||
const getUserSpace = (): Promise<string> =>
|
||||
window.coreAPI?.getUserSpace() ?? window.electronAPI?.getUserSpace();
|
||||
|
||||
/** Register extension point function type definition
|
||||
*
|
||||
*/
|
||||
@ -75,6 +81,7 @@ export const core = {
|
||||
downloadFile,
|
||||
deleteFile,
|
||||
appDataPath,
|
||||
getUserSpace,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -86,4 +93,5 @@ export {
|
||||
downloadFile,
|
||||
deleteFile,
|
||||
appDataPath,
|
||||
getUserSpace,
|
||||
};
|
||||
|
||||
@ -8,13 +8,6 @@ const writeFile: (path: string, data: string) => Promise<any> = (path, data) =>
|
||||
window.coreAPI?.writeFile(path, data) ??
|
||||
window.electronAPI?.writeFile(path, data);
|
||||
|
||||
/**
|
||||
* Gets the user space path.
|
||||
* @returns {Promise<any>} A Promise that resolves with the user space path.
|
||||
*/
|
||||
const getUserSpace = (): Promise<string> =>
|
||||
window.coreAPI?.getUserSpace() ?? window.electronAPI?.getUserSpace();
|
||||
|
||||
/**
|
||||
* Checks whether the path is a directory.
|
||||
* @param path - The path to check.
|
||||
@ -64,7 +57,6 @@ const deleteFile: (path: string) => Promise<any> = (path) =>
|
||||
|
||||
export const fs = {
|
||||
isDirectory,
|
||||
getUserSpace,
|
||||
writeFile,
|
||||
readFile,
|
||||
listFiles,
|
||||
|
||||
@ -8,7 +8,7 @@ export { core, deleteFile, invokePluginFunc } from "./core";
|
||||
* Core module exports.
|
||||
* @module
|
||||
*/
|
||||
export { downloadFile, executeOnMain, appDataPath } from "./core";
|
||||
export { downloadFile, executeOnMain, appDataPath, getUserSpace } from "./core";
|
||||
|
||||
/**
|
||||
* Events module exports.
|
||||
|
||||
@ -20,7 +20,7 @@ import { InferencePlugin } from "@janhq/core/lib/plugins";
|
||||
import { requestInference } from "./helpers/sse";
|
||||
import { ulid } from "ulid";
|
||||
import { join } from "path";
|
||||
import { fs } from "@janhq/core";
|
||||
import { getUserSpace } from "@janhq/core";
|
||||
|
||||
/**
|
||||
* A class that implements the InferencePlugin interface from the @janhq/core package.
|
||||
@ -60,7 +60,7 @@ export default class JanInferencePlugin implements InferencePlugin {
|
||||
* @returns {Promise<void>} A promise that resolves when the model is initialized.
|
||||
*/
|
||||
async initModel(modelFileName: string): Promise<void> {
|
||||
const userSpacePath = await fs.getUserSpace();
|
||||
const userSpacePath = await getUserSpace();
|
||||
const modelFullPath = join(userSpacePath, modelFileName);
|
||||
|
||||
return executeOnMain(MODULE, "initModel", modelFullPath);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user