mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-30 23:01:34 +00:00
feat: slowly transition to fs-jetpack
controllers/handlers/ServeStatic.js controllers/middlewares/ServeStaticQuick.js
This commit is contained in:
parent
6d103c1e28
commit
65d9a76071
@ -19,10 +19,10 @@
|
||||
|
||||
const contentDisposition = require('content-disposition')
|
||||
const etag = require('etag')
|
||||
const fs = require('fs')
|
||||
const fsPromises = require('fs/promises')
|
||||
const jetpack = require('fs-jetpack')
|
||||
const SimpleDataStore = require('./../utils/SimpleDataStore')
|
||||
const errors = require('./../errorsController')
|
||||
const paths = require('./../pathsController')
|
||||
const utils = require('./../utilsController')
|
||||
const serveUtils = require('./../utils/serveUtils')
|
||||
const logger = require('./../../logger')
|
||||
@ -106,7 +106,7 @@ class ServeStatic {
|
||||
}
|
||||
|
||||
async #get (fullPath) {
|
||||
const stat = await paths.stat(fullPath)
|
||||
const stat = await fsPromises.stat(fullPath)
|
||||
|
||||
if (stat.isDirectory()) return
|
||||
|
||||
@ -237,7 +237,7 @@ class ServeStatic {
|
||||
}
|
||||
|
||||
async #stream (req, res, fullPath, result) {
|
||||
const readStream = fs.createReadStream(fullPath, result.options)
|
||||
const readStream = jetpack.createReadStream(fullPath, result.options)
|
||||
|
||||
readStream.on('error', error => {
|
||||
readStream.destroy()
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
const chokidar = require('chokidar')
|
||||
const etag = require('etag')
|
||||
const fs = require('fs')
|
||||
const jetpack = require('fs-jetpack')
|
||||
const serveUtils = require('./../utils/serveUtils')
|
||||
const logger = require('./../../logger')
|
||||
|
||||
@ -70,7 +70,8 @@ class ServeStaticQuick {
|
||||
this.files = new Map()
|
||||
|
||||
this.watcher = chokidar.watch(this.directory, {
|
||||
alwaysStat: true,
|
||||
// fs.Stats object is already always available with add/addDir/change events
|
||||
alwaysStat: false,
|
||||
awaitWriteFinish: {
|
||||
pollInterval: 100,
|
||||
stabilityThreshold: 500
|
||||
@ -220,7 +221,7 @@ class ServeStaticQuick {
|
||||
|
||||
#stream (req, res, path, stat, result) {
|
||||
const fullPath = this.directory + path
|
||||
const readStream = fs.createReadStream(fullPath, result.options)
|
||||
const readStream = jetpack.createReadStream(fullPath, result.options)
|
||||
|
||||
readStream.on('error', error => {
|
||||
readStream.destroy()
|
||||
|
Loading…
Reference in New Issue
Block a user