remove rimraf + fix graphql

This commit is contained in:
Pierre Noël 2022-02-16 12:23:11 +01:00
parent 8067dae25b
commit 83a5aeb8b6
2 changed files with 12 additions and 17 deletions

View File

@ -40,7 +40,6 @@
"react-redux": "7.2.3", "react-redux": "7.2.3",
"react-router": "^5.2.0", "react-router": "^5.2.0",
"react-router-dom": "5.2.0", "react-router-dom": "5.2.0",
"rimraf": "3.0.2",
"sharp": "0.30.1" "sharp": "0.30.1"
}, },
"engines": { "engines": {

View File

@ -42,7 +42,7 @@ module.exports = ({ strapi }) => {
* @param {object} metas * @param {object} metas
* @return {Promise<object>} * @return {Promise<object>}
*/ */
const formatFile = async (upload, extraInfo, metas, { tmpFolderPath }) => { const formatFile = async (upload, extraInfo, metas) => {
const uploadService = getUploadService('upload'); const uploadService = getUploadService('upload');
const { filename, mimetype, createReadStream } = await upload; const { filename, mimetype, createReadStream } = await upload;
@ -57,7 +57,7 @@ module.exports = ({ strapi }) => {
); );
currentFile.getStream = createReadStream; currentFile.getStream = createReadStream;
const newFile = await optimize(currentFile, { tmpFolderPath }); const newFile = await optimize(currentFile);
return newFile; return newFile;
}; };
@ -98,25 +98,21 @@ module.exports = ({ strapi }) => {
async resolve(parent, args) { async resolve(parent, args) {
// create temporary folder to store files for stream manipulation // create temporary folder to store files for stream manipulation
const tmpFolderPath = await fse.mkdtemp(path.join(os.tmpdir(), 'strapi-upload-')); const tmpWorkingDirectory = await fse.mkdtemp(path.join(os.tmpdir(), 'strapi-upload-'));
let sanitizedEntity; let sanitizedEntity;
try { try {
const { file: upload, info, ...fields } = args; const { file: upload, info, ...metas } = args;
const file = await formatFile(upload, info, fields, { tmpFolderPath }); const file = await formatFile(upload, info, { ...metas, tmpWorkingDirectory });
const uploadedFile = await getUploadService('upload').uploadFileAndPersist( const uploadedFile = await getUploadService('upload').uploadFileAndPersist(file, {});
file,
{},
{ tmpFolderPath }
);
sanitizedEntity = await toEntityResponse(uploadedFile, { sanitizedEntity = await toEntityResponse(uploadedFile, {
args, args,
resourceUID: fileTypeName, resourceUID: fileTypeName,
}); });
} finally { } finally {
// delete temporary folder // delete temporary folder
await fse.remove(tmpFolderPath); await fse.remove(tmpWorkingDirectory);
} }
return sanitizedEntity; return sanitizedEntity;
@ -138,20 +134,20 @@ module.exports = ({ strapi }) => {
async resolve(parent, args) { async resolve(parent, args) {
// create temporary folder to store files for stream manipulation // create temporary folder to store files for stream manipulation
const tmpFolderPath = await fse.mkdtemp(path.join(os.tmpdir(), 'strapi-upload-')); const tmpWorkingDirectory = await fse.mkdtemp(path.join(os.tmpdir(), 'strapi-upload-'));
let sanitizedEntities = []; let sanitizedEntities = [];
try { try {
const { files: uploads, ...fields } = args; const { files: uploads, ...metas } = args;
const files = await Promise.all( const files = await Promise.all(
uploads.map(upload => formatFile(upload, {}, fields, { tmpFolderPath })) uploads.map(upload => formatFile(upload, {}, { ...metas, tmpWorkingDirectory }))
); );
const uploadService = getUploadService('upload'); const uploadService = getUploadService('upload');
const uploadedFiles = await Promise.all( const uploadedFiles = await Promise.all(
files.map(file => uploadService.uploadFileAndPersist(file, {}, { tmpFolderPath })) files.map(file => uploadService.uploadFileAndPersist(file, {}))
); );
sanitizedEntities = uploadedFiles.map(file => sanitizedEntities = uploadedFiles.map(file =>
@ -159,7 +155,7 @@ module.exports = ({ strapi }) => {
); );
} finally { } finally {
// delete temporary folder // delete temporary folder
await fse.remove(tmpFolderPath); await fse.remove(tmpWorkingDirectory);
} }
return sanitizedEntities; return sanitizedEntities;