Adds an image connector; introduces file service
This commit is contained in:
1 parent
8c5fa44e5f
commit
716415263d
16 files changed
+314
-9
No files matched your search
@@ -11,6 +11,7 @@ import shippingProfileRoutes from "./shipping-profiles"
|
||||
import discountRoutes from "./discounts"
|
||||
import orderRoutes from "./orders"
|
||||
import storeRoutes from "./store"
|
||||
import uploadRoutes from "./uploads"
|
||||
|
||||
const route = Router()
|
||||
|
||||
@@ -46,6 +47,7 @@ export default (app, container, config) => {
|
||||
discountRoutes(route)
|
||||
orderRoutes(route)
|
||||
storeRoutes(route)
|
||||
uploadRoutes(route)
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import fs from "fs"
|
||||
|
||||
export default async (req, res) => {
|
||||
try {
|
||||
const fileService = req.scope.resolve("fileService")
|
||||
|
||||
console.log(fileService)
|
||||
|
||||
const result = await Promise.all(
|
||||
req.files.map(async f => {
|
||||
console.log(f)
|
||||
return fileService.upload(f).then(result => {
|
||||
fs.unlinkSync(f.path)
|
||||
return result
|
||||
})
|
||||
})
|
||||
)
|
||||
|
||||
res.status(200).json({ uploads: result })
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Router } from "express"
|
||||
import multer from "multer"
|
||||
|
||||
import middlewares from "../../../middlewares"
|
||||
|
||||
const route = Router()
|
||||
const upload = multer({ dest: "uploads/" })
|
||||
|
||||
export default app => {
|
||||
app.use("/uploads", route)
|
||||
|
||||
route.post(
|
||||
"/",
|
||||
upload.array("files"),
|
||||
middlewares.wrap(require("./create-upload").default)
|
||||
)
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
BaseService,
|
||||
PaymentService,
|
||||
FulfillmentService,
|
||||
FileService,
|
||||
} from "medusa-interfaces"
|
||||
import { getConfigFile, createRequireFromPath } from "medusa-core-utils"
|
||||
import _ from "lodash"
|
||||
@@ -147,6 +148,13 @@ function registerServices(pluginDetails, container) {
|
||||
[name]: asFunction(cradle => new loaded(cradle, pluginDetails.options)),
|
||||
[`fp_${loaded.identifier}`]: aliasTo(name),
|
||||
})
|
||||
} else if (loaded.prototype instanceof FileService) {
|
||||
// Add the service directly to the container in order to make simple
|
||||
// resolution if we already know which payment provider we need to use
|
||||
container.register({
|
||||
[name]: asFunction(cradle => new loaded(cradle, pluginDetails.options)),
|
||||
[`fileService`]: aliasTo(name),
|
||||
})
|
||||
} else {
|
||||
container.register({
|
||||
[name]: asFunction(cradle => new loaded(cradle, pluginDetails.options)),
|
||||
|
||||
Reference in new issue
Block a user