remove old upload implementation

add viewer of file submissions
This commit is contained in:
Tina_Azure
2023-08-09 16:25:52 +02:00
parent 552b1d62fe
commit 89421d7ac5
5 changed files with 55 additions and 84 deletions

View File

@@ -1160,82 +1160,6 @@ int main(int argc, char *argv[]) {
}
});
/*
CROW_ROUTE(app, "/freelancer/submissionManagement/add/fulfillment").methods(crow::HTTPMethod::Post)
([&, configuration](const crow::request& postRequest) {
auto& cookieCtx = app.get_context<crow::CookieParser>(postRequest);
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
pqxx::connection databaseConnection(configuration.databaseConnectionString);
Database::prepareStatements(databaseConnection, {
ID_SELECT_FREELANCER_ID,
ID_SELECT_FREELANCER_NAME
});
string freelancerName, freelancerID;
pqxx::result freelancerNameResult = Database::executePreparedStatement_SELECT_FREELANCER_NAME(databaseConnection, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
freelancerName = freelancerNameResult.at(0).at(0).c_str();
pqxx::result freelancerIDResult = Database::executePreparedStatement_SELECT_FREELANCER_ID(databaseConnection, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
freelancerID = freelancerIDResult.at(0).at(0).c_str();
crow::multipart::message multipartMessage(postRequest);
return crow::response(400);
for (const auto& part : multipartMessage.part_map)
{
const auto& mustacheSubmissionNameValue = part.first;
const auto& fileSubmission = part.second;
if (MUSTACHE_FREELANCER_SUBMISSION_NAME == mustacheSubmissionNameValue)
{
auto contentDispositionIt = fileSubmission.headers.find("Content-Disposition");
if (contentDispositionIt == fileSubmission.headers.end())
return crow::response(400, "Content-Disposition could not be found");
auto filenameIt = contentDispositionIt->second.params.find("filename");
if (filenameIt == contentDispositionIt->second.params.end())
return crow::response(400, "File Submission does not have a filename");
if (!Utilities::checkFiletypeValidity(configuration, filenameIt->second))
return crow::response(400, "Submitted File does not have a valid filetype");
if (!Utilities::validateFileSize(configuration, fileSubmission.body))
return crow::response(400, "File Size is not valid");
const std::string outputFolderPath = Utilities::generateSubmissionFolderPath(configuration, freelancerName, freelancerID);
if(!Utilities::validateFolderPath(outputFolderPath))
return crow::response(400, "Unable to write to Freelancer folder");
const std::string outputFilename = filenameIt->second;
const std::string outputFilePath = Utilities::generateSubmissionFilePath(outputFolderPath, outputFilename);
cout << outputFolderPath << endl;
cout << outputFilePath << endl;
if(!Utilities::validateFilePath(outputFilePath))
return crow::response(400, "file already exists - hash collision");
std::ofstream outputFileStream(outputFilePath);
if (!outputFileStream)
return crow::response(500, "File could not be written to disk");
outputFileStream << fileSubmission.body;
outputFileStream.close();
}
else
{
return crow::response(400, "Mustache Submission name could not be found in the request");
}
}
return crow::response(200);
}
else
{
//ERROR not logged in
return crow::response(403, "Not logged in");
}
});*/
/*
* Page for freelancer to view existing submissions
*/
@@ -1244,6 +1168,7 @@ int main(int argc, char *argv[]) {
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
crow::mustache::context ctx;
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
ctx = Utilities::getFreelancerSubmissions(configuration, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;