Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

abstract the plugin to provide support of virtual file system #432

Open
2 tasks done
climba03003 opened this issue Feb 2, 2024 · 1 comment
Open
2 tasks done
Labels
feature request New feature to be added

Comments

@climba03003
Copy link
Member

climba03003 commented Feb 2, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

馃殌 Feature Proposal

I believe it is a good idea to provide an interface for file serving through different storage engine.
For example,

  1. File System (which is currently)
  2. MongoDB GridFS
  3. S3 compatible interface

Motivation

Manage of Range header is hard and maybe problematic.
Instead, we can provide a generic interface for the user to choose storage engine.
Then, we provide all the others function.

It enables the user to highly customize how to serve file based on their application logic and provide a proper storage engine.
Even file system serving can be customize in this case.

Example

import Fastify from 'fastify'
import FastifyStatic from '@fastify/static'
import FastifyMongoDB from '@fastify/mongodb'
import { MongoDBGridFS } from '@fastify/static/engine'

const fastify = Fastify()

fastify.register(FastifyMongoDB, {
  // proper configuration here
  // not to demo how to use mongodb
})
fastify.register(FastifyStatic, {
  engine: MongoDBGridFS,
  db: fastify.mongo.db,
  bucketName: 'vfs'
})

// you can serve the file like currently
// but it is backed by other engine
@climba03003 climba03003 added the feature request New feature to be added label Feb 2, 2024
@mcollina
Copy link
Member

mcollina commented Feb 2, 2024

I would love this to happen, but first we should refactor this module and get a better send utility (fix fastify/send#15 among other things).

Then, it would mean that we should just swap the internal "send" with "send-mongodb".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature to be added
Projects
None yet
Development

No branches or pull requests

2 participants