mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 19:14:16 +00:00
added /objects
This commit is contained in:
parent
0d1ecc5f03
commit
15a6126feb
@ -4,8 +4,48 @@ import uploadBodyFiles from "./services/uploadBodyFiles"
|
||||
|
||||
export default class FilesController extends Controller {
|
||||
static refName = "FilesController"
|
||||
static useRoute = "/files"
|
||||
|
||||
httpEndpoints = {
|
||||
get: {
|
||||
"/objects": {
|
||||
middlewares: ["withAuthentication"],
|
||||
fn: async (req, res) => {
|
||||
const user_id = req.user.id
|
||||
|
||||
let totalSize = 0
|
||||
|
||||
const objectsPath = `${user_id}/`
|
||||
|
||||
const objects = await new Promise((resolve, reject) => {
|
||||
const objects = []
|
||||
|
||||
const objectsStream = global.storage.listObjects(global.storage.defaultBucket, objectsPath, true)
|
||||
|
||||
objectsStream.on("data", (obj) => {
|
||||
objects.push(obj)
|
||||
})
|
||||
|
||||
objectsStream.on("error", (err) => {
|
||||
return reject(err)
|
||||
})
|
||||
|
||||
objectsStream.on("end", () => {
|
||||
return resolve(objects)
|
||||
})
|
||||
})
|
||||
|
||||
for await (const object of objects) {
|
||||
totalSize += object.size
|
||||
}
|
||||
|
||||
return res.json({
|
||||
totalSize,
|
||||
objects,
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
post: {
|
||||
"/upload": {
|
||||
middlewares: ["withAuthentication"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user