feat: add needed methods to the file module and providers (#12325)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import type { Readable } from "stream"
|
||||
import {
|
||||
Context,
|
||||
CreateFileDTO,
|
||||
@@ -28,6 +29,10 @@ export default class FileModuleService implements FileTypes.IFileModuleService {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
getProvider() {
|
||||
return this.fileProviderService_
|
||||
}
|
||||
|
||||
createFiles(
|
||||
data: CreateFileDTO[],
|
||||
sharedContext?: Context
|
||||
@@ -154,4 +159,26 @@ export default class FileModuleService implements FileTypes.IFileModuleService {
|
||||
1,
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file contents as a readable stream.
|
||||
*
|
||||
* @example
|
||||
* const stream = await fileModuleService.getAsStream("file_123")
|
||||
* writeable.pipe(stream)
|
||||
*/
|
||||
getAsStream(id: string): Promise<Readable> {
|
||||
return this.fileProviderService_.getAsStream({ fileKey: id })
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file contents as a Node.js Buffer
|
||||
*
|
||||
* @example
|
||||
* const contents = await fileModuleService.getAsBuffer("file_123")
|
||||
* contents.toString('utf-8')
|
||||
*/
|
||||
getAsBuffer(id: string): Promise<Buffer> {
|
||||
return this.fileProviderService_.getAsBuffer({ fileKey: id })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Readable } from "stream"
|
||||
import { Constructor, FileTypes } from "@medusajs/framework/types"
|
||||
import { MedusaError } from "@medusajs/framework/utils"
|
||||
import { FileProviderRegistrationPrefix } from "@types"
|
||||
@@ -68,4 +69,12 @@ export default class FileProviderService {
|
||||
|
||||
return this.fileProvider_.getPresignedUploadUrl(fileData)
|
||||
}
|
||||
|
||||
getAsStream(fileData: FileTypes.ProviderGetFileDTO): Promise<Readable> {
|
||||
return this.fileProvider_.getAsStream(fileData)
|
||||
}
|
||||
|
||||
getAsBuffer(fileData: FileTypes.ProviderGetFileDTO): Promise<Buffer> {
|
||||
return this.fileProvider_.getAsBuffer(fileData)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user