speedly 2.0.30 → 2.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@ declare global {
7
7
  }
8
8
  }
9
9
  }
10
- declare const _default: (destination?: string | ((req: Request, file: Express.Multer.File) => string), config?: {
10
+ declare const _default: (destination: string | ((req: Request, file: Express.Multer.File) => string) | undefined, filename: string | ((req: Request, file: Express.Multer.File) => string), config?: {
11
11
  [key: string]: any;
12
12
  saveInDb: boolean;
13
13
  prefix: string;
@@ -16,7 +16,7 @@ let configs = {
16
16
  path: "../../../public",
17
17
  ...(0, getConfig_1.default)("uploader"),
18
18
  };
19
- exports.default = (destination = "/image", config = configs) => {
19
+ exports.default = (destination = "/image", filename, config = configs) => {
20
20
  let dest;
21
21
  try {
22
22
  Object.entries(config).forEach(([key, val]) => {
@@ -51,7 +51,9 @@ exports.default = (destination = "/image", config = configs) => {
51
51
  }
52
52
  const originalName = Buffer.from(file.originalname, "latin1").toString("utf8");
53
53
  const fileName = (configs.prefix ? configs.prefix + "-" : "") +
54
- (req.body.name || originalName.replace(/\.\w+$/, "")) +
54
+ ((typeof filename === "function"
55
+ ? filename(req, file)
56
+ : filename) || originalName.replace(/\.\w+$/, "")) +
55
57
  ext;
56
58
  const filePath = path_1.default.join(configs.path, dest, fileName);
57
59
  try {
@@ -7,7 +7,7 @@ declare global {
7
7
  }
8
8
  }
9
9
  }
10
- declare const _default: (destination?: string | ((req: Request, file: Express.Multer.File) => string), config?: {
10
+ declare const _default: (destination: string | ((req: Request, file: Express.Multer.File) => string) | undefined, filename: string | ((req: Request, file: Express.Multer.File) => string), config?: {
11
11
  [key: string]: any;
12
12
  saveInDb: boolean;
13
13
  prefix: string;
@@ -16,7 +16,7 @@ let configs = {
16
16
  path: "../../../public",
17
17
  ...(0, getConfig_1.default)("uploader"),
18
18
  };
19
- exports.default = (destination = "/image", config = configs) => {
19
+ exports.default = (destination = "/image", filename, config = configs) => {
20
20
  let dest;
21
21
  try {
22
22
  Object.entries(config).forEach(([key, val]) => {
@@ -51,7 +51,9 @@ exports.default = (destination = "/image", config = configs) => {
51
51
  }
52
52
  const originalName = Buffer.from(file.originalname, "latin1").toString("utf8");
53
53
  const fileName = (configs.prefix ? configs.prefix + "-" : "") +
54
- (req.body.name || originalName.replace(/\.\w+$/, "")) +
54
+ ((typeof filename === "function"
55
+ ? filename(req, file)
56
+ : filename) || originalName.replace(/\.\w+$/, "")) +
55
57
  ext;
56
58
  const filePath = path_1.default.join(configs.path, dest, fileName);
57
59
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "2.0.30",
3
+ "version": "2.0.32",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",