mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 08:19:07 +00:00
Remove fileInfo.name when unchanged
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
500c12f7c7
commit
c69b6e8d4e
@ -1,7 +1,7 @@
|
||||
import React, { useReducer, useEffect, useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { request, generateSearchFromFilters, useGlobalContext } from 'strapi-helper-plugin';
|
||||
import { get, isEmpty } from 'lodash';
|
||||
import { clone, get, isEmpty, set } from 'lodash';
|
||||
import axios from 'axios';
|
||||
import pluginId from '../../pluginId';
|
||||
import {
|
||||
@ -72,9 +72,9 @@ const InputModalStepperProvider = ({
|
||||
|
||||
return axios
|
||||
.get(file.fileURL, {
|
||||
headers: new Headers({ Origin: window.location.origin, mode: 'cors' }),
|
||||
responseType: 'blob',
|
||||
cancelToken: source.token,
|
||||
timeout: 30000,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
const createdFile = new File([data], file.fileURL, {
|
||||
@ -352,11 +352,19 @@ const InputModalStepperProvider = ({
|
||||
});
|
||||
|
||||
const requests = filesToUpload.map(
|
||||
async ({ file, fileInfo, originalIndex, abortController }) => {
|
||||
async ({ file, fileInfo, originalIndex, originalName, abortController }) => {
|
||||
const formData = new FormData();
|
||||
const headers = {};
|
||||
const infos = clone(fileInfo);
|
||||
|
||||
if (originalName === infos.name) {
|
||||
set(infos, 'name', null);
|
||||
}
|
||||
|
||||
console.log(infos);
|
||||
|
||||
formData.append('files', file);
|
||||
formData.append('fileInfo', JSON.stringify(fileInfo));
|
||||
formData.append('fileInfo', JSON.stringify(infos));
|
||||
|
||||
try {
|
||||
const uploadedFile = await request(
|
||||
|
@ -220,7 +220,7 @@ const reducer = (state, action) =>
|
||||
...draftState.filesToUpload[index],
|
||||
isDownloading: false,
|
||||
hasError: true,
|
||||
errorMessage: draftState.filesToUpload[index].fileURL,
|
||||
errorMessage: draftState.filesToUpload[index].fileOriginalURL,
|
||||
};
|
||||
|
||||
break;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { useEffect, useState, useReducer, useRef } from 'react';
|
||||
import axios from 'axios';
|
||||
import PropTypes from 'prop-types';
|
||||
import { isEqual, isEmpty, get } from 'lodash';
|
||||
import { isEqual, isEmpty, get, set } from 'lodash';
|
||||
import { Modal, ModalFooter, PopUpWarning, useGlobalContext, request } from 'strapi-helper-plugin';
|
||||
import { Button } from '@buffetjs/core';
|
||||
import pluginId from '../../pluginId';
|
||||
@ -85,10 +85,9 @@ const ModalStepper = ({
|
||||
|
||||
return axios
|
||||
.get(file.fileURL, {
|
||||
headers: new Headers({ Origin: window.location.origin, mode: 'cors' }),
|
||||
responseType: 'blob',
|
||||
cancelToken: source.token,
|
||||
// Should we add a timeout?
|
||||
timeout: 30000,
|
||||
})
|
||||
.then(({ data }) => {
|
||||
const fileName = file.fileInfo.name;
|
||||
@ -356,9 +355,14 @@ const ModalStepper = ({
|
||||
});
|
||||
|
||||
const requests = filesToUpload.map(
|
||||
async ({ file, fileInfo, originalIndex, abortController }) => {
|
||||
async ({ file, fileInfo, originalName, originalIndex, abortController }) => {
|
||||
const formData = new FormData();
|
||||
const headers = {};
|
||||
|
||||
if (originalName === fileInfo.name) {
|
||||
set(fileInfo, 'name', null);
|
||||
}
|
||||
|
||||
formData.append('files', file);
|
||||
formData.append('fileInfo', JSON.stringify(fileInfo));
|
||||
|
||||
|
@ -100,7 +100,7 @@ const reducer = (state, action) => {
|
||||
return file
|
||||
.update('isDownloading', () => false)
|
||||
.update('hasError', () => true)
|
||||
.update('errorMessage', () => file.get('fileURL'));
|
||||
.update('errorMessage', () => file.get('fileOriginalURL'));
|
||||
}
|
||||
|
||||
return file;
|
||||
|
@ -18,26 +18,34 @@ const createNewFilesToDownloadArray = (filesURLArray, alreadyUploadedFiles) => {
|
||||
return acc;
|
||||
}
|
||||
|
||||
const CancelToken = axios.CancelToken;
|
||||
const abortController = new AbortController();
|
||||
const source = CancelToken.source();
|
||||
try {
|
||||
const url = new URL(current);
|
||||
const name = decodeURIComponent(url.pathname.substring(url.pathname.lastIndexOf('/') + 1));
|
||||
const CancelToken = axios.CancelToken;
|
||||
const abortController = new AbortController();
|
||||
const source = CancelToken.source();
|
||||
|
||||
acc.push({
|
||||
abortController,
|
||||
source,
|
||||
file: null,
|
||||
fileInfo: {
|
||||
alternativeText: '',
|
||||
caption: '',
|
||||
name: current.substring(current.lastIndexOf('/') + 1),
|
||||
},
|
||||
fileURL: current,
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
isUploading: false,
|
||||
isDownloading: true,
|
||||
tempId: max + index,
|
||||
});
|
||||
acc.push({
|
||||
abortController,
|
||||
source,
|
||||
file: null,
|
||||
fileInfo: {
|
||||
alternativeText: '',
|
||||
caption: '',
|
||||
name,
|
||||
},
|
||||
fileURL: url,
|
||||
fileOriginalURL: current,
|
||||
originalName: name,
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
isUploading: false,
|
||||
isDownloading: true,
|
||||
tempId: max + index,
|
||||
});
|
||||
} catch (err) {
|
||||
// invalid url
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
@ -13,6 +13,7 @@ const createNewFilesToUploadArray = filesObject => {
|
||||
},
|
||||
hasError: false,
|
||||
errorMessage: null,
|
||||
originalName: currentFile.name,
|
||||
isUploading: false,
|
||||
tempId: null,
|
||||
});
|
||||
|
@ -13,7 +13,16 @@ const urlSchema = yup.object().shape({
|
||||
message: '${path}',
|
||||
test(values) {
|
||||
const filtered = values.filter(val => {
|
||||
return !val.startsWith('http');
|
||||
// return !val.startsWith('http');
|
||||
try {
|
||||
// eslint-disable-next-line no-new
|
||||
new URL(val);
|
||||
|
||||
return false;
|
||||
} catch (err) {
|
||||
// invalid url
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
const filteredLength = filtered.length;
|
||||
|
Loading…
x
Reference in New Issue
Block a user