费伦 SDK
SDK用于与 Filen 为 Node.JS 进行交互,浏览器和React Industrial.
探索文件“
安装
- 使用国家预防机制安装
npm install @filen/sdk@latest
- 初始化 SDK.
import { FilenSDK } from "@filen/sdk"
import path from "path"
import os from "os"
type FilenSDKConfig = {
email?: string
password?: string
twoFactorCode?: string
masterKeys?: string[]
apiKey?: string
publicKey?: string
privateKey?: string
authVersion?: AuthVersion
baseFolderUUID?: string
userId?: number
metadataCache?: boolean // Cache decrypted metadata in memory. Recommended.
tmpPath?: string // Temporary local path used to store metadata and chunks. Only available in Node.JS.,
connectToSocket?: boolean // Recommended if you are using the virtual FS class. Keeps the internal item tree up to date with remote changes.
}
// You can either directly supply all needed config parameters to the constructor or call the .login() function to fetch them using your login information.
const filen = new FilenSDK({
metadataCache: true,
connectToSocket: true,
tmpPath: path.join(os.tmpdir(), "filen-sdk")
})
await filen.login({
email: "[email protected]",
password: "supersecret123",
twoFactorCode: "123456"
})
- 与云互动
// Create a directory
await filen.fs().mkdir({
path: "/Pictures"
})
// Upload a file
await filen.fs().upload({
path: "/Pictures",
source: "/Local/path/to/a/file.jpg"
})
// Read contents of the directory
const content: string[] = await filen.fs().readdir({
path: "/Pictures"
})
// Stat a file
const stats: FSStats = await filen.fs().stat({
path: "/Pictures/file.jpg"
})
// Download a file
await filen.fs().download({
path: "/Pictures/file.jpg",
destination: "/Local/path/to/a/file.jpg"
})
// Read a file
const content: Buffer = await filen.fs().readFile({
path: "/Pictures/file.jpg"
})
// Write to a path
await filen.fs().writeFile({
path: "/text.txt",
content: Buffer.from("foobar", "utf-8")
})
许可证
根据AGPL-3.0许可证分发。 见 自由主义 更多信息.