Fix upload error when no files are set (#1156)

This commit is contained in:
Nikhil Rao 2023-06-06 21:24:23 -07:00 committed by GitHub
parent 2a92aba3a2
commit 78aac243cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 12 deletions

View File

@ -4,9 +4,11 @@ import io from "socket.io-client";
import JSON5 from "json5"; import JSON5 from "json5";
import env from "env.json"; import env from "env.json";
// Endpoint URLs.
const PINGURL = env.pingUrl const PINGURL = env.pingUrl
const EVENTURL = env.eventUrl const EVENTURL = env.eventUrl
const UPLOADURL = env.uploadUrl const UPLOADURL = env.uploadUrl
// Global variable to hold the token. // Global variable to hold the token.
let token; let token;
@ -124,13 +126,18 @@ export const applyEvent = async (event, router, socket) => {
/** /**
* Process an event off the event queue. * Process an event off the event queue.
* @param queue_event The current event * @param event The current event
* @param state The state with the event queue. * @param state The state with the event queue.
* @param setResult The function to set the result. * @param setResult The function to set the result.
*/ */
export const applyRestEvent = async (queue_event, state, setResult) => { export const applyRestEvent = async (event, state, setResult) => {
if (queue_event.handler == "uploadFiles") { let eventSent = false;
await uploadFiles(state, setResult, queue_event.name); if (event.handler == "uploadFiles") {
eventSent = await uploadFiles(state, setResult, event.name);
}
if (!eventSent) {
// If no event was sent, set processing to false and return.
setResult({ ...state, processing: false });
} }
}; };
@ -160,15 +167,15 @@ export const updateState = async (
setResult({ ...result, processing: true }); setResult({ ...result, processing: true });
// Pop the next event off the queue and apply it. // Pop the next event off the queue and apply it.
const queue_event = state.events.shift(); const event = state.events.shift();
// Set new events to avoid reprocessing the same event. // Set new events to avoid reprocessing the same event.
setState({ ...state, events: state.events }); setState({ ...state, events: state.events });
// Process events with handlers via REST and all others via websockets. // Process events with handlers via REST and all others via websockets.
if (queue_event.handler) { if (event.handler) {
await applyRestEvent(queue_event, state, setResult); await applyRestEvent(event, state, setResult);
} else { } else {
const eventSent = await applyEvent(queue_event, router, socket); const eventSent = await applyEvent(event, router, socket);
if (!eventSent) { if (!eventSent) {
// If no event was sent, set processing to false and return. // If no event was sent, set processing to false and return.
setResult({ ...state, processing: false }); setResult({ ...state, processing: false });
@ -197,10 +204,10 @@ export const connect = async (
setNotConnected setNotConnected
) => { ) => {
// Get backend URL object from the endpoint // Get backend URL object from the endpoint
const endpoint_url = new URL(EVENTURL); const endpoint = new URL(EVENTURL);
// Create the socket. // Create the socket.
socket.current = io(EVENTURL, { socket.current = io(EVENTURL, {
path: endpoint_url["pathname"], path: endpoint["pathname"],
transports: transports, transports: transports,
autoUnref: false, autoUnref: false,
}); });
@ -240,7 +247,7 @@ export const uploadFiles = async (state, setResult, handler) => {
// return if there's no file to upload // return if there's no file to upload
if (files.length == 0) { if (files.length == 0) {
return; return false;
} }
const headers = { const headers = {
@ -270,6 +277,8 @@ export const uploadFiles = async (state, setResult, handler) => {
events: update.events, events: update.events,
}); });
}); });
return true;
}; };
/** /**

View File

@ -208,7 +208,6 @@ def setup_frontend(root: Path, disable_telemetry: bool = True):
prerequisites.install_frontend_packages(web_dir) prerequisites.install_frontend_packages(web_dir)
# Copy asset files to public folder. # Copy asset files to public folder.
path_ops.mkdir(str(root / constants.WEB_ASSETS_DIR))
path_ops.cp( path_ops.cp(
src=str(root / constants.APP_ASSETS_DIR), src=str(root / constants.APP_ASSETS_DIR),
dest=str(root / constants.WEB_ASSETS_DIR), dest=str(root / constants.WEB_ASSETS_DIR),