chore: fs module should not cover app logic

This commit is contained in:
Louis 2023-11-24 21:57:44 +07:00
parent ec7703ec8d
commit 8a14edaeea
4 changed files with 14 additions and 14 deletions

View File

@ -41,9 +41,8 @@ const downloadFile: (url: string, fileName: string) => Promise<any> = (
window.electronAPI?.downloadFile(url, fileName); window.electronAPI?.downloadFile(url, fileName);
/** /**
* Deletes a file from the local file system. * @deprecated This object is deprecated and should not be used.
* @param {string} path - The path of the file to delete. * Use fs module instead.
* @returns {Promise<any>} A promise that resolves when the file is deleted.
*/ */
const deleteFile: (path: string) => Promise<any> = (path) => const deleteFile: (path: string) => Promise<any> = (path) =>
window.coreAPI?.deleteFile(path) ?? window.electronAPI?.deleteFile(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(); 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 /** Register extension point function type definition
* *
*/ */
@ -75,6 +81,7 @@ export const core = {
downloadFile, downloadFile,
deleteFile, deleteFile,
appDataPath, appDataPath,
getUserSpace,
}; };
/** /**
@ -86,4 +93,5 @@ export {
downloadFile, downloadFile,
deleteFile, deleteFile,
appDataPath, appDataPath,
getUserSpace,
}; };

View File

@ -8,13 +8,6 @@ const writeFile: (path: string, data: string) => Promise<any> = (path, data) =>
window.coreAPI?.writeFile(path, data) ?? window.coreAPI?.writeFile(path, data) ??
window.electronAPI?.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. * Checks whether the path is a directory.
* @param path - The path to check. * @param path - The path to check.
@ -64,7 +57,6 @@ const deleteFile: (path: string) => Promise<any> = (path) =>
export const fs = { export const fs = {
isDirectory, isDirectory,
getUserSpace,
writeFile, writeFile,
readFile, readFile,
listFiles, listFiles,

View File

@ -8,7 +8,7 @@ export { core, deleteFile, invokePluginFunc } from "./core";
* Core module exports. * Core module exports.
* @module * @module
*/ */
export { downloadFile, executeOnMain, appDataPath } from "./core"; export { downloadFile, executeOnMain, appDataPath, getUserSpace } from "./core";
/** /**
* Events module exports. * Events module exports.

View File

@ -20,7 +20,7 @@ import { InferencePlugin } from "@janhq/core/lib/plugins";
import { requestInference } from "./helpers/sse"; import { requestInference } from "./helpers/sse";
import { ulid } from "ulid"; import { ulid } from "ulid";
import { join } from "path"; 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. * 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. * @returns {Promise<void>} A promise that resolves when the model is initialized.
*/ */
async initModel(modelFileName: string): Promise<void> { async initModel(modelFileName: string): Promise<void> {
const userSpacePath = await fs.getUserSpace(); const userSpacePath = await getUserSpace();
const modelFullPath = join(userSpacePath, modelFileName); const modelFullPath = join(userSpacePath, modelFileName);
return executeOnMain(MODULE, "initModel", modelFullPath); return executeOnMain(MODULE, "initModel", modelFullPath);