jan/core/src/fs.ts
Louis 5250061c11
feat: Jan Server, API and decoupled clients (#948)
* chore: expose fs apis

* chore: correct electron import path

* update download api

Signed-off-by: James <james@jan.ai>

* update chat_completion

Signed-off-by: James <james@jan.ai>

* fix electron import

Signed-off-by: James <james@jan.ai>

* feat: adding API support at 1337 (#991)

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>

* feat: Add /chat/completion api and handler

* chore: add todo for modelList

* chore: read engine.json for openai chat_completion (#1030)

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>

* refactor: move routes to shared node module

* refactor: exported modules from core with types (#1172)

* refactor: exported modules from core with types

* fix: fix file reading args

* refactor: fileManager handles

* fix: app issues with server refactoring

* refactor: shared server module (#1210)

* chore: resolve main

* chore: update makefile

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
Co-authored-by: NamH <NamNh0122@gmail.com>
Co-authored-by: hiro <vuonghoainam.work@gmail.com>
2023-12-28 17:57:39 +07:00

75 lines
2.5 KiB
TypeScript

/**
* Writes data to a file at the specified path.
* @returns {Promise<any>} A Promise that resolves when the file is written successfully.
*/
const writeFileSync = (...args: any[]) => global.core.api?.writeFileSync(...args)
/**
* Reads the contents of a file at the specified path.
* @returns {Promise<any>} A Promise that resolves with the contents of the file.
*/
const readFileSync = (...args: any[]) => global.core.api?.readFileSync(...args)
/**
* Check whether the file exists
* @param {string} path
* @returns {boolean} A boolean indicating whether the path is a file.
*/
const existsSync = (...args: any[]) => global.core.api?.existsSync(...args)
/**
* List the directory files
* @returns {Promise<any>} A Promise that resolves with the contents of the directory.
*/
const readdirSync = (...args: any[]) => global.core.api?.readdirSync(...args)
/**
* Creates a directory at the specified path.
* @returns {Promise<any>} A Promise that resolves when the directory is created successfully.
*/
const mkdirSync = (...args: any[]) => global.core.api?.mkdirSync(...args)
/**
* Removes a directory at the specified path.
* @returns {Promise<any>} A Promise that resolves when the directory is removed successfully.
*/
const rmdirSync = (...args: any[]) =>
global.core.api?.rmdirSync(...args, { recursive: true, force: true })
/**
* 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.
*/
const unlinkSync = (...args: any[]) => global.core.api?.unlinkSync(...args)
/**
* Appends data to a file at the specified path.
*/
const appendFileSync = (...args: any[]) => global.core.api?.appendFileSync(...args)
/**
* Synchronizes a file from a source path to a destination path.
* @param {string} src - The source path of the file to be synchronized.
* @param {string} dest - The destination path where the file will be synchronized to.
* @returns {Promise<any>} - A promise that resolves when the file has been successfully synchronized.
*/
const syncFile: (src: string, dest: string) => Promise<any> = (src, dest) =>
global.core.api?.syncFile(src, dest)
/**
* Copy file sync.
*/
const copyFileSync = (...args: any[]) => global.core.api?.copyFileSync(...args)
// TODO: Export `dummy` fs functions automatically
// Currently adding these manually
export const fs = {
writeFileSync,
readFileSync,
existsSync,
readdirSync,
mkdirSync,
rmdirSync,
unlinkSync,
appendFileSync,
copyFileSync,
syncFile,
}