|
|
|
|
@ -1,7 +1,13 @@
|
|
|
|
|
import "./App.css"; |
|
|
|
|
import React, { useState } from "react"; |
|
|
|
|
import ReactDOM from "react-dom/client"; |
|
|
|
|
import { BrowserRouter as Router, Routes, Route, Link } from "react-router-dom"; |
|
|
|
|
import { |
|
|
|
|
BrowserRouter as Router, |
|
|
|
|
Routes, |
|
|
|
|
Route, |
|
|
|
|
Link, |
|
|
|
|
useParams, |
|
|
|
|
} from "react-router-dom"; |
|
|
|
|
import firebase from "firebase/compat/app"; |
|
|
|
|
import "firebase/compat/database"; |
|
|
|
|
import "firebase/compat/analytics"; |
|
|
|
|
@ -11,6 +17,7 @@ import { Admin } from "./Admin";
|
|
|
|
|
import { Galleria } from "./Galleria"; |
|
|
|
|
import { ListaEventi } from "./ListaEventi"; |
|
|
|
|
import { Button } from "@mui/material"; |
|
|
|
|
import EXIF from "exif-js"; |
|
|
|
|
|
|
|
|
|
const firebaseConfig = { |
|
|
|
|
apiKey: "AIzaSyBWE1l8WV_7eyKT-PMu0Kq2w_WiV0SUhJw", |
|
|
|
|
@ -27,7 +34,13 @@ const firebaseConfig = {
|
|
|
|
|
firebase.initializeApp(firebaseConfig); |
|
|
|
|
firebase.analytics(); |
|
|
|
|
|
|
|
|
|
function parseDate(s) { |
|
|
|
|
var b = s.split(/\D/); |
|
|
|
|
return new Date(b[0], b[1] - 1, b[2], b[3], b[4], b[5]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const Upload = () => { |
|
|
|
|
const { evento } = useParams(); |
|
|
|
|
const [uploadedFiles, setUploadedFiles] = useState([]); |
|
|
|
|
|
|
|
|
|
const handleUploadFiles = (files) => { |
|
|
|
|
@ -35,31 +48,50 @@ const Upload = () => {
|
|
|
|
|
|
|
|
|
|
function upload() { |
|
|
|
|
const image = files[index]; |
|
|
|
|
const uploadTask = firebase |
|
|
|
|
.storage() |
|
|
|
|
.ref(`images/${image.name}`) |
|
|
|
|
.put(image, { |
|
|
|
|
cacheControl: "public,max-age=3000000", |
|
|
|
|
contentType: "image/jpeg", |
|
|
|
|
}); |
|
|
|
|
EXIF.getData(image, function () { |
|
|
|
|
var time = EXIF.getTag(this, "DateTime"); |
|
|
|
|
if (time) { |
|
|
|
|
const timestamp = new Date(parseDate(time)).getTime(); |
|
|
|
|
const uploadTask = firebase |
|
|
|
|
.storage() |
|
|
|
|
.ref(`images/${evento}/${image.name}`) |
|
|
|
|
.put(image, { |
|
|
|
|
cacheControl: "public,max-age=3000000", |
|
|
|
|
contentType: "image/jpeg", |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
uploadTask.on( |
|
|
|
|
"state_changed", |
|
|
|
|
(snapshot) => { |
|
|
|
|
const progress = Math.round( |
|
|
|
|
(snapshot.bytesTransferred / snapshot.totalBytes) * 100 |
|
|
|
|
); |
|
|
|
|
console.log(progress); |
|
|
|
|
}, |
|
|
|
|
(error) => { |
|
|
|
|
console.log(error); |
|
|
|
|
}, |
|
|
|
|
(d) => { |
|
|
|
|
// all done
|
|
|
|
|
console.log(d); |
|
|
|
|
// var postListRef = firebase.database().ref(`messaggi/${evento}`);
|
|
|
|
|
// var newPostRef = postListRef.push();
|
|
|
|
|
// const update = {
|
|
|
|
|
// id: newPostRef.key,
|
|
|
|
|
// timestamp,
|
|
|
|
|
// approvato: true,
|
|
|
|
|
// immagineURL: "",
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// newPostRef.set(update);
|
|
|
|
|
|
|
|
|
|
uploadTask.on( |
|
|
|
|
"state_changed", |
|
|
|
|
(snapshot) => { |
|
|
|
|
const progress = Math.round( |
|
|
|
|
(snapshot.bytesTransferred / snapshot.totalBytes) * 100 |
|
|
|
|
// if (++index < files.length) {
|
|
|
|
|
// upload();
|
|
|
|
|
// }
|
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
console.log(progress); |
|
|
|
|
}, |
|
|
|
|
(error) => { |
|
|
|
|
console.log(error); |
|
|
|
|
}, |
|
|
|
|
() => { |
|
|
|
|
if (++index < files.length) { |
|
|
|
|
upload(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
upload(); |
|
|
|
|
|