mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
clean
This commit is contained in:
parent
8d504c1400
commit
bd14963fa9
@ -1,27 +1,7 @@
|
|||||||
import path from "path"
|
async function serveRemoteStatic(req, res) {
|
||||||
import fs from "fs"
|
|
||||||
import LiveDirectory from "live-directory"
|
|
||||||
|
|
||||||
function serveStaticFiles(req, res, live_dir) {
|
|
||||||
const path = req.path.replace("/static", "")
|
const path = req.path.replace("/static", "")
|
||||||
|
|
||||||
const asset = live_dir.get(path)
|
global.storage.getObject(process.env.S3_BUCKET, path, (err, dataStream) => {
|
||||||
|
|
||||||
if (!asset) {
|
|
||||||
return res.status(404).send("Not Found")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (asset.cached) {
|
|
||||||
return res.send(asset.content)
|
|
||||||
} else {
|
|
||||||
const readable = asset.stream()
|
|
||||||
|
|
||||||
return readable.pipe(res)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function serveRemoteStatic(req, res) {
|
|
||||||
global.storage.getObject(process.env.S3_BUCKET, req.path, (err, dataStream) => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
return res.status(404).send("Not Found")
|
return res.status(404).send("Not Found")
|
||||||
@ -37,33 +17,8 @@ async function serveRemoteStatic(req, res) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function syncFolder(dir) {
|
|
||||||
const files = await fs.promises.readdir(dir)
|
|
||||||
|
|
||||||
for await (const file of files) {
|
|
||||||
const filePath = path.resolve(dir, file)
|
|
||||||
|
|
||||||
const stat = fs.statSync(filePath)
|
|
||||||
|
|
||||||
if (stat.isDirectory()) {
|
|
||||||
await syncFolder(filePath)
|
|
||||||
} else {
|
|
||||||
const fileContent = await fs.promises.readFile(filePath)
|
|
||||||
|
|
||||||
await global.storage.putObject(process.env.S3_BUCKET, filePath.replace(process.cwd(), ""), fileContent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default (router) => {
|
export default (router) => {
|
||||||
const StaticDirectory = new LiveDirectory(path.resolve(process.cwd(), "static"), {
|
router.get("*", (req, res) => serveRemoteStatic(req, res))
|
||||||
static: true
|
|
||||||
})
|
|
||||||
|
|
||||||
//const static_dir = path.resolve(process.cwd(), "static")
|
|
||||||
//syncFolder(static_dir)
|
|
||||||
|
|
||||||
router.get("*", (req, res) => serveRemoteStatic(req, res, StaticDirectory))
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: "/static/",
|
path: "/static/",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user