diff --git a/src/backend/src/main/kotlin/org/icpclive/admin/Routing.kt b/src/backend/src/main/kotlin/org/icpclive/admin/Routing.kt index 3dbc46b68..f77faad1e 100644 --- a/src/backend/src/main/kotlin/org/icpclive/admin/Routing.kt +++ b/src/backend/src/main/kotlin/org/icpclive/admin/Routing.kt @@ -19,7 +19,6 @@ import org.icpclive.cds.tunning.toAdvancedProperties import org.icpclive.data.Controllers import org.icpclive.data.DataBus import org.icpclive.util.sendFlow -import org.icpclive.util.sendJsonFlow import java.nio.file.Files fun Route.configureAdminApiRouting() { @@ -130,7 +129,7 @@ fun Route.configureAdminApiRouting() { post("/upload") { call.adminApiAction { - var uploadedFileUrl: String? = null + val uploadedFileUrls = mutableListOf() val multipart = call.receiveMultipart() multipart.forEachPart { partData -> if (partData is PartData.FileItem) { @@ -138,10 +137,10 @@ fun Route.configureAdminApiRouting() { Config.mediaDirectory.resolve(partData.storeName), partData.streamProvider().readBytes() ) - uploadedFileUrl = partData.storeName + uploadedFileUrls += partData.storeName } } - uploadedFileUrl + uploadedFileUrls } } } diff --git a/src/frontend/admin/src/components/MediaFiles.js b/src/frontend/admin/src/components/MediaFiles.js index ecf2fd85f..e4359a423 100644 --- a/src/frontend/admin/src/components/MediaFiles.js +++ b/src/frontend/admin/src/components/MediaFiles.js @@ -43,7 +43,7 @@ function MediaFiles() { const apiGet = createApiGet(BASE_URL_BACKEND + "/media"); const [mediaFiles, setMediaFiles] = useState([]); - const [uploadedFileUrl, setUploadedFileUrl] = useState(null); + const [uploadedFileUrls, setUploadedFileUrls] = useState(null); const loadFiles = () => { apiGet("").then(f => setMediaFiles(f)); @@ -51,39 +51,40 @@ function MediaFiles() { useEffect(() => { loadFiles(); - }, []); + }, [uploadedFileUrls]); - const uploadNewFile = (file) => { - // const files = e.target.files; - // if (files.length < 1) { - // errorHandler("No media file selected"); - // return; - // } + const uploadNewFile = (files) => { + files = [...files]; const formData = new FormData(); - formData.append("file", file); + files.forEach(file => formData.append("file", file)); fetch(BASE_URL_BACKEND + "/media/upload", { method: "POST", body: formData, }).then(r => r.json()).then(r => { if (r.status === "error") { - errorHandler("Failed to uplaod file: " + file); + errorHandler("Failed to upload files " + files.map(f => f.name).join(",")); } else if (r.status !== "ok" && !r.response) { - errorHandler("Failed to uplaod file"); + errorHandler("Failed to upload files"); } - setUploadedFileUrl(r.status === "ok" && r.response ? r.response : null); + setUploadedFileUrls(r.status === "ok" && r.response ? r.response : null); loadFiles(); }); }; return ( - + - {uploadedFileUrl && ( - - + {uploadedFileUrls && uploadedFileUrls.map(file => ( + + - )} + ))}