storage-upload/api/media/routes.mjs

23 lines
524 B
JavaScript
Raw Normal View History

import * as security from './security.mjs'
2021-10-11 00:56:22 +00:00
import * as formidable from './formidable.mjs'
2017-12-10 09:45:38 +00:00
export default class MediaRoutes {
constructor(opts = {}) {
Object.assign(this, {
security: opts.security || security,
2021-10-11 00:56:22 +00:00
formidable: opts.formidable || formidable,
})
}
async upload(ctx) {
let site = await this.security.verifyToken(ctx)
2017-12-10 09:45:38 +00:00
2021-10-11 00:56:22 +00:00
let result = await this.formidable.uploadFile(ctx, site)
2017-12-10 09:45:38 +00:00
ctx.body = {
filename: result.filename,
path: `/${site}/${result.filename}`
}
2017-12-10 09:45:38 +00:00
}
}