6627b1c33bdef1886f84fce4df14d0dd5c786657 chmalee Fri Mar 8 17:10:21 2024 -0800 Make the DataTable update dynamically. Correctly use a hidden file input to keep track of submitted and unsubmitted files diff --git src/hg/hgHubConnect/hooks/pre-create.c src/hg/hgHubConnect/hooks/pre-create.c index 947df6e..9f66112 100644 --- src/hg/hgHubConnect/hooks/pre-create.c +++ src/hg/hgHubConnect/hooks/pre-create.c @@ -19,40 +19,30 @@ void usage() /* Explain usage and exit. */ { errAbort( "pre-create - tus daemon pre-create hook program\n" "usage:\n" " pre-create < input\n" ); } /* Command line validation table. */ static struct optionSpec options[] = { {NULL, 0}, }; -struct jsonElement *makeDefaultResponse() -/* Create the default response json with some fields pre-filled */ -{ -struct hash *defHash = hashNew(8); -struct jsonElement *response = newJsonObject(defHash); -// only the HTTP Response object is important to have by default, the other -// fields will be created as needed -jsonObjectAdd(response, HTTP_NAME, newJsonObject(hashNew(8))); -return response; -} int preCreate() /* pre-create hook for tus daemon. Read JSON encoded hook request from * stdin and write a JSON encoded hook to stdout. Writing to stderr * will be redirected to the tusd log and not seen by the user, so for * errors that the user needs to see, they need to be in the JSON response */ { // TODO: create response object and do all error catching through that char *reqId = getenv("TUS_ID"); char *reqOffsetEnv = getenv("TUS_OFFSET"); char *reqSizeEnv = getenv("TUS_SIZE"); // always return an exit status to the daemon and print to stdout, as // stdout gets sent by the daemon back to the client int exitStatus = 0; struct jsonElement *response = makeDefaultResponse(); @@ -69,54 +59,55 @@ struct lineFile *lf = lineFileStdin(FALSE); char *request = lineFileReadAll(lf); struct jsonElement *req = jsonParse(request); fprintf(stderr, "Hook request:\n"); jsonPrintToFile(req, NULL, stderr, 0); char *reqCookie= jsonQueryString(req, "", "Event.HTTPRequest.Header.Cookie[0]", NULL); if (reqCookie) { setenv("HTTP_COOKIE", reqCookie, 0); } fprintf(stderr, "reqCookie='%s'\n", reqCookie); char *userName = (loginSystemEnabled() || wikiLinkEnabled()) ? wikiLinkUserName() : NULL; fprintf(stderr, "userName='%s'\n'", userName); if (!userName) { - rejectUpload(response, "not logged in"); + rejectUpload(response, "You are not logged in. Please navigate to My Data -> My Sessions and log in or create an account."); exitStatus = 1; } else { long reqFileSize = jsonQueryInt(req, "", "Event.Upload.Size", 0, NULL); + char *reqFileName = jsonQueryString(req, "", "Event.Upload.MetaData.filename", NULL); long currQuota = checkUserQuota(userName); long newQuota = currQuota + reqFileSize; if (newQuota > MAX_QUOTA) { - rejectUpload(response, "file too large, current stored files is %0.2fgb", currQuota / 1000000000.0); + rejectUpload(response, "File '%s' is too large, need %s free space but current used space is %s out of %s", reqFileName, prettyFileSize(reqFileSize), prettyFileSize(currQuota), prettyFileSize(MAX_QUOTA)); exitStatus = 1; } } // we've passed all the checks so we can return that we are safe if (exitStatus == 0) fillOutHttpResponseSuccess(response); } if (errCatch->gotError) { rejectUpload(response, errCatch->message->string); exitStatus = 1; } errCatchEnd(errCatch); } // always print a response no matter what jsonPrintToFile(response, NULL, stdout, 0); -return exitStatus; +return 0; } int main(int argc, char *argv[]) /* Process command line. */ { optionInit(&argc, argv, options); if (argc != 1) usage(); return preCreate(); }