Skip to content

Commit

Permalink
chore: update koa-body
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin committed Apr 3, 2024
1 parent d09716f commit e31e7e0
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/core/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"@types/react-window": "1.8.8",
"@types/sanitize-html": "2.11.0",
"@vitejs/plugin-react-swc": "3.6.0",
"koa-body": "4.2.0",
"koa-body": "6.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "6.22.3",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/admin/server/src/services/project-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ const parseFilesData = async (files: UpdateProjectSettings.Request['files']) =>
return;
}

const getStream = () => fs.createReadStream(file.path);
const getStream = () => fs.createReadStream(file.filepath);

// Add formated data for the upload provider
formatedFilesData[inputName] = await strapi
.plugin('upload')
.service('upload')
.formatFileInfo({
filename: file.name,
type: file.type,
filename: file.newFilename,
type: file.mimetype,
size: file.size,
});

Expand All @@ -56,7 +56,7 @@ const parseFilesData = async (files: UpdateProjectSettings.Request['files']) =>
// Add file path, and stream
Object.assign(formatedFilesData[inputName]!, {
stream: getStream(),
tmpPath: file.path,
tmpPath: file.filepath,
// TODO
// @ts-expect-error define the correct return type
provider: strapi.config.get('plugin::upload').provider,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/content-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"@testing-library/react": "14.0.0",
"@types/jest": "29.5.2",
"@types/lodash": "^4.14.191",
"koa-body": "4.2.0",
"koa-body": "6.0.1",
"msw": "1.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/content-type-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@testing-library/user-event": "14.4.3",
"@types/pluralize": "0.0.30",
"koa": "2.15.2",
"koa-body": "4.2.0",
"koa-body": "6.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-query": "3.39.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"inquirer": "8.2.5",
"is-docker": "2.2.1",
"koa": "2.15.2",
"koa-body": "4.2.0",
"koa-body": "6.0.1",
"koa-compose": "4.1.0",
"koa-compress": "5.1.1",
"koa-favicon": "2.1.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/core/core/src/middlewares/body.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import fse from 'fs-extra';
import { defaultsDeep } from 'lodash/fp';
import body from 'koa-body';
import body, { KoaBodyMiddlewareOptions } from 'koa-body';
import mime from 'mime-types';
import type Koa from 'koa';
import type { Core } from '@strapi/types';

export type Config = body.IKoaBodyOptions;
export type Config = KoaBodyMiddlewareOptions;

const defaults = {
multipart: true,
Expand Down Expand Up @@ -37,7 +37,7 @@ const bodyMiddleware: Core.MiddlewareFactory<Config> = (config, { strapi }) => {
await next();
} else {
try {
await body({ patchKoa: true, ...bodyConfig })(ctx, async () => {});
await body(bodyConfig)(ctx, async () => {});

const files = getFiles(ctx);

Expand Down Expand Up @@ -73,10 +73,10 @@ const bodyMiddleware: Core.MiddlewareFactory<Config> = (config, { strapi }) => {
if (files) {
if (Array.isArray(files)) {
// not awaiting to not slow the request
Promise.all(files.map((file) => fse.remove(file.path)));
} else if (files && files.path) {
Promise.all(files.map((file) => fse.remove(file.filepath)));
} else if (files && files.filepath) {
// not awaiting to not slow the request
fse.remove(files.path);
fse.remove(files.filepath);
}
delete ctx.request.files;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/email/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@types/koa": "2.13.4",
"@types/lodash": "^4.14.191",
"koa": "2.15.2",
"koa-body": "4.2.0",
"koa-body": "6.0.1",
"msw": "1.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/upload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"@types/koa-static": "4.0.2",
"formidable": "3.5.1",
"koa": "2.15.2",
"koa-body": "4.2.0",
"koa-body": "6.0.1",
"msw": "1.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/upload/server/src/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const baseProvider = {
checkFileSize(file: InputFile, { sizeLimit }: { sizeLimit: number }) {
if (sizeLimit && kbytesToBytes(file.size) > sizeLimit) {
throw new PayloadTooLargeError(
`${file.name} exceeds size limit of ${bytesToHumanReadable(sizeLimit)}.`
`${file.originalFilename} exceeds size limit of ${bytesToHumanReadable(sizeLimit)}.`
);
}
},
Expand Down
6 changes: 3 additions & 3 deletions packages/core/upload/server/src/services/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ export default ({ strapi }: { strapi: Core.Strapi }) => {
): Promise<UploadableFile> {
const currentFile = (await formatFileInfo(
{
filename: file.name ?? 'unamed',
type: file.type ?? 'application/octet-stream',
filename: file.originalFilename ?? 'unamed',
type: file.mimetype ?? 'application/octet-stream',
size: file.size,
},
fileInfo,
Expand All @@ -204,7 +204,7 @@ export default ({ strapi }: { strapi: Core.Strapi }) => {
}
)) as UploadableFile;

currentFile.getStream = () => fs.createReadStream(file.path);
currentFile.getStream = () => fs.createReadStream(file.filepath);

const { optimize, isImage, isFaultyImage, isOptimizableImage } = strapi
.plugin('upload')
Expand Down
2 changes: 1 addition & 1 deletion packages/core/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@types/node": "18.19.24",
"eslint-config-custom": "5.0.0-beta.2",
"koa": "2.15.2",
"koa-body": "4.2.0",
"koa-body": "6.0.1",
"tsconfig": "5.0.0-beta.2"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/documentation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"@types/koa-session": "6.4.1",
"@types/swagger-ui-dist": "3.30.4",
"koa": "2.15.2",
"koa-body": "4.2.0",
"koa-body": "6.0.1",
"koa-session": "6.4.0",
"msw": "1.3.0",
"openapi-types": "12.1.3",
Expand Down
55 changes: 44 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7084,7 +7084,7 @@ __metadata:
js-cookie: "npm:2.2.1"
jsonwebtoken: "npm:9.0.0"
koa: "npm:2.15.2"
koa-body: "npm:4.2.0"
koa-body: "npm:6.0.1"
koa-compose: "npm:4.1.0"
koa-passport: "npm:6.0.0"
koa-static: "npm:5.0.0"
Expand Down Expand Up @@ -7312,7 +7312,7 @@ __metadata:
inquirer: "npm:8.2.5"
is-docker: "npm:2.2.1"
koa: "npm:2.15.2"
koa-body: "npm:4.2.0"
koa-body: "npm:6.0.1"
koa-compose: "npm:4.1.0"
koa-compress: "npm:5.1.1"
koa-favicon: "npm:2.1.0"
Expand Down Expand Up @@ -7892,7 +7892,7 @@ __metadata:
highlight.js: "npm:^10.4.1"
immer: "npm:9.0.21"
koa: "npm:2.15.2"
koa-body: "npm:4.2.0"
koa-body: "npm:6.0.1"
lodash: "npm:4.17.21"
markdown-it: "npm:^12.3.2"
markdown-it-abbr: "npm:^1.0.4"
Expand Down Expand Up @@ -7982,7 +7982,7 @@ __metadata:
fs-extra: "npm:10.1.0"
immer: "npm:9.0.21"
koa: "npm:2.15.2"
koa-body: "npm:4.2.0"
koa-body: "npm:6.0.1"
lodash: "npm:4.17.21"
pluralize: "npm:8.0.0"
qs: "npm:6.11.1"
Expand Down Expand Up @@ -8062,7 +8062,7 @@ __metadata:
fs-extra: "npm:10.1.0"
immer: "npm:9.0.21"
koa: "npm:2.15.2"
koa-body: "npm:4.2.0"
koa-body: "npm:6.0.1"
koa-session: "npm:6.4.0"
koa-static: "npm:^5.0.0"
lodash: "npm:4.17.21"
Expand Down Expand Up @@ -8125,7 +8125,7 @@ __metadata:
"@types/koa": "npm:2.13.4"
"@types/lodash": "npm:^4.14.191"
koa: "npm:2.15.2"
koa-body: "npm:4.2.0"
koa-body: "npm:6.0.1"
lodash: "npm:4.17.21"
msw: "npm:1.3.0"
react: "npm:^18.2.0"
Expand Down Expand Up @@ -8385,7 +8385,7 @@ __metadata:
fs-extra: "npm:10.1.0"
immer: "npm:9.0.21"
koa: "npm:2.15.2"
koa-body: "npm:4.2.0"
koa-body: "npm:6.0.1"
koa-range: "npm:0.3.0"
koa-static: "npm:5.0.0"
lodash: "npm:4.17.21"
Expand Down Expand Up @@ -9110,7 +9110,7 @@ __metadata:
execa: "npm:5.1.1"
http-errors: "npm:1.8.1"
koa: "npm:2.15.2"
koa-body: "npm:4.2.0"
koa-body: "npm:6.0.1"
lodash: "npm:4.17.21"
node-machine-id: "npm:1.1.12"
p-map: "npm:4.0.0"
Expand Down Expand Up @@ -9538,6 +9538,16 @@ __metadata:
languageName: node
linkType: hard

"@types/co-body@npm:^6.1.0":
version: 6.1.3
resolution: "@types/co-body@npm:6.1.3"
dependencies:
"@types/node": "npm:*"
"@types/qs": "npm:*"
checksum: e93fdc177f69ee0535cf401783258e4255f5eb8235c58b5a2a5a8958cf341fadf3d0bf2c75907ed6b7d188ce2c2f2cf9593a71d4eef12900beba54ebbbdd5cc1
languageName: node
linkType: hard

"@types/codemirror5@npm:@types/codemirror@^5.60.15":
version: 5.60.15
resolution: "@types/codemirror@npm:5.60.15"
Expand Down Expand Up @@ -9719,6 +9729,15 @@ __metadata:
languageName: node
linkType: hard

"@types/formidable@npm:^2.0.5":
version: 2.0.6
resolution: "@types/formidable@npm:2.0.6"
dependencies:
"@types/node": "npm:*"
checksum: 808a9bc11276e3bd44a8b9d20f4d567ef0e452dcff7fa6ce2575b769bab049ccc4225d02ddd80f0f4de34aa2d2e7242e036bc547811667868860e8dc632d8b16
languageName: node
linkType: hard

"@types/fs-extra@npm:9.0.13":
version: 9.0.13
resolution: "@types/fs-extra@npm:9.0.13"
Expand Down Expand Up @@ -13459,7 +13478,7 @@ __metadata:
languageName: node
linkType: hard

"co-body@npm:^6.0.0":
"co-body@npm:^6.0.0, co-body@npm:^6.1.0":
version: 6.1.0
resolution: "co-body@npm:6.1.0"
dependencies:
Expand Down Expand Up @@ -17343,7 +17362,7 @@ __metadata:
languageName: node
linkType: hard

"formidable@npm:^2.1.2":
"formidable@npm:^2.0.1, formidable@npm:^2.1.2":
version: 2.1.2
resolution: "formidable@npm:2.1.2"
dependencies:
Expand Down Expand Up @@ -21228,6 +21247,20 @@ __metadata:
languageName: node
linkType: hard

"koa-body@npm:6.0.1":
version: 6.0.1
resolution: "koa-body@npm:6.0.1"
dependencies:
"@types/co-body": "npm:^6.1.0"
"@types/formidable": "npm:^2.0.5"
"@types/koa": "npm:^2.13.5"
co-body: "npm:^6.1.0"
formidable: "npm:^2.0.1"
zod: "npm:^3.19.1"
checksum: d241d4d228117da43ccd485babe9f8e221188360faef93f936f85ced03d8df900b1bd3af0f2e26b8e514f66361373078ef8501b50089b20e19c578566d25a239
languageName: node
linkType: hard

"koa-bodyparser@npm:4.4.1":
version: 4.4.1
resolution: "koa-bodyparser@npm:4.4.1"
Expand Down Expand Up @@ -31037,7 +31070,7 @@ __metadata:
languageName: node
linkType: hard

"zod@npm:^3.22.4":
"zod@npm:^3.19.1, zod@npm:^3.22.4":
version: 3.22.4
resolution: "zod@npm:3.22.4"
checksum: 73622ca36a916f785cf528fe612a884b3e0f183dbe6b33365a7d0fc92abdbedf7804c5e2bd8df0a278e1472106d46674281397a3dd800fa9031dc3429758c6ac
Expand Down

0 comments on commit e31e7e0

Please sign in to comment.