feature(Frontend multiple file upload fix):

Fixed multi file upload for frontend
Allowed missing ttl in backend
This commit is contained in:
Devoalda 2023-10-23 15:44:50 +08:00
parent 56b128d5d4
commit a6faf8720d
5 changed files with 43 additions and 9 deletions

View File

@ -11,6 +11,7 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.5.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-drag-drop-files": "^2.3.10",
@ -5336,6 +5337,29 @@
"node": ">=4"
}
},
"node_modules/axios": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.5.1.tgz",
"integrity": "sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==",
"dependencies": {
"follow-redirects": "^1.15.0",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/axios/node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/axobject-query": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.2.1.tgz",
@ -14508,6 +14532,11 @@
"node": ">= 0.10"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/psl": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",

View File

@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.5.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-drag-drop-files": "^2.3.10",

View File

@ -13,14 +13,19 @@ function ShareFile() {
console.log(file);
if (file) {
const formData = new FormData();
formData.append('files', file);
formData.append('file', file);
formData.append('ttl', "2");
// Send POST request to the backend API using Axios
axios.post('http://127.0.0.1:8000/api/files/', formData)
.then(response => {
// Handle a successful response from the server
setPasscode(response.data.passcode);
// Handle a successful response from the server, set passcode to "key" in the response body
const data = response.data;
// If data is an array, take the first item
if (Array.isArray(data)) {
setPasscode(data[0].key);
}
})
.catch(error => {
// Handle errors here

View File

@ -94,6 +94,7 @@ SIMPLE_JWT = {
CORS_ALLOWED_ORIGINS = [
'http://localhost:3000',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',

View File

@ -1,11 +1,9 @@
import uuid
import threading
import uuid
import redis
from django.conf import settings
from django.core.cache import cache
from rest_framework.decorators import api_view
from rest_framework.response import Response
from django.core.cache import cache
@api_view(['POST'])
@ -16,9 +14,9 @@ def manage_items(request, *args, **kwargs):
# Get the list of files and the TTL value from the request data
files = request.FILES.getlist('file')
ttl = request.data.get('ttl')
if not ttl:
return Response({'msg': 'TTL not provided'}, status=400)
# Set ttl to 3 days
ttl = 259200 # 3 * 24 * 60 * 60
try:
# Convert the TTL to an integer