Skip to content

Instantly share code, notes, and snippets.

@maohais
Created March 2, 2025 12:49
Show Gist options
  • Save maohais/1a41f00f33ab3a08b1e971420ea7998a to your computer and use it in GitHub Desktop.
Save maohais/1a41f00f33ab3a08b1e971420ea7998a to your computer and use it in GitHub Desktop.
const { FilenSDK } = require("@filen/sdk")
const path = require("path")
const os = require("os")
const { S3Server } = require("@filen/s3")
const { S3 } = require("@aws-sdk/client-s3")
const filen = new FilenSDK({
metadataCache: true,
connectToSocket: true,
tmpPath: path.join(os.tmpdir(), "filen-sdk")
})
async function main() {
await filen.login({
email: "your@email.com",
password: "supersecret123",
twoFactorCode: "123456"
})
const hostname = "127.0.0.1"
const port = PORT # 此处改为实际开放端口
const https = false
const endpoint = `${https ? "https" : "http"}://${hostname === "127.0.0.1" ? "local.s3.filen.io" : hostname}:${port}`
const server = new S3Server({
hostname,
port,
https,
user: {
accessKeyId: "admin",
secretKeyId: "admin",
sdk: filen
}
})
const s3 = new S3({
credentials: {
accessKeyId: "admin",
secretAccessKey: "admin"
},
endpoint,
forcePathStyle: true,
region: "filen"
})
await server.start()
console.log(`S3 server started on ${endpoint}`)
await s3.listObjectsV2({
Bucket: "filen",
Prefix: ""
})
}
main().catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment