Skip to content

Commit

Permalink
fix: file upload status
Browse files Browse the repository at this point in the history
https://telecominfraproject.atlassian.net/browse/WIFI-14134

Summary of changes:
- Return 202 in case of file pening upload.

Signed-off-by: Ivan Chvets <[email protected]>
  • Loading branch information
i-chvets committed Sep 26, 2024
1 parent 83eb603 commit 4a150a9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
9 changes: 8 additions & 1 deletion src/RESTAPI/RESTAPI_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ namespace OpenWifi {

std::string FileType;
std::string FileContent;
if (!StorageService()->GetAttachedFileContent(UUID, SerialNumber, FileContent, FileType) || FileContent.empty()) {
int WaitingForFile = 0;
if (!StorageService()->GetAttachedFileContent(UUID, SerialNumber, FileContent, FileType, WaitingForFile) && !WaitingForFile) {
return NotFound();
}
else if (WaitingForFile)
{
// waiting for file to be uploaded, return Accepted
return Accepted();
}

if (FileType == "pcap") {
SendFileContent(FileContent, "application/vnd.tcpdump.pcap", UUID + ".pcap");
}
Expand Down
2 changes: 1 addition & 1 deletion src/StorageService.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ namespace OpenWifi {
const std::string &Type);
bool CancelWaitFile(std::string &UUID, std::string &ErrorText);
bool GetAttachedFileContent(std::string &UUID, const std::string &SerialNumber,
std::string &FileContent, std::string &Type);
std::string &FileContent, std::string &Type, int& WaitingForFile);
bool RemoveAttachedFile(std::string &UUID);
bool SetCommandResult(std::string &UUID, std::string &Result);
bool GetNewestCommands(std::string &SerialNumber, uint64_t HowMany,
Expand Down
5 changes: 5 additions & 0 deletions src/framework/RESTAPI_Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ namespace OpenWifi {
}
}

inline void Accepted() {
PrepareResponse(Poco::Net::HTTPResponse::HTTP_ACCEPTED);
Response->send();
}

inline void SendCompressedTarFile(const std::string &FileName, const std::string &Content) {
Response->setStatus(Poco::Net::HTTPResponse::HTTPStatus::HTTP_OK);
SetCommonHeaders();
Expand Down
30 changes: 15 additions & 15 deletions src/storage/storage_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,18 +647,6 @@ namespace OpenWifi {
Sess.begin();
Poco::Data::Statement Statement(Sess);

std::string StatementStr;

// Get the existing command

StatementStr =
"UPDATE CommandList SET WaitingForFile=?, AttachDate=?, AttachSize=? WHERE UUID=?";

Statement << ConvertParams(StatementStr), Poco::Data::Keywords::use(WaitForFile),
Poco::Data::Keywords::use(Now), Poco::Data::Keywords::use(Size),
Poco::Data::Keywords::use(UUID);
Statement.execute();
Sess.commit();
if (Size < FileUploader()->MaxSize()) {

Poco::Data::BLOB TheBlob;
Expand All @@ -681,6 +669,18 @@ namespace OpenWifi {
poco_warning(Logger(), fmt::format("File {} is too large.", UUID));
}
Sess.commit();

// update CommandList here to ensure that file us uploaded
std::string StatementStr;
StatementStr =
"UPDATE CommandList SET WaitingForFile=?, AttachDate=?, AttachSize=? WHERE UUID=?";

Statement << ConvertParams(StatementStr), Poco::Data::Keywords::use(WaitForFile),
Poco::Data::Keywords::use(Now), Poco::Data::Keywords::use(Size),
Poco::Data::Keywords::use(UUID);
Statement.execute();
Sess.commit();

return true;
} catch (const Poco::Exception &E) {
Logger().log(E);
Expand All @@ -689,7 +689,7 @@ namespace OpenWifi {
}

bool Storage::GetAttachedFileContent(std::string &UUID, const std::string &SerialNumber,
std::string &FileContent, std::string &Type) {
std::string &FileContent, std::string &Type, int &WaitingForFile) {
try {
Poco::Data::BLOB L;
/*
Expand All @@ -702,10 +702,10 @@ namespace OpenWifi {
Poco::Data::Statement Select1(Sess);

std::string TmpSerialNumber;
std::string st1{"SELECT SerialNumber, Command FROM CommandList WHERE UUID=?"};
std::string st1{"SELECT SerialNumber, Command , WaitingForFile FROM CommandList WHERE UUID=?"};
std::string Command;
Select1 << ConvertParams(st1), Poco::Data::Keywords::into(TmpSerialNumber),
Poco::Data::Keywords::into(Command), Poco::Data::Keywords::use(UUID);
Poco::Data::Keywords::into(Command), Poco::Data::Keywords::into(WaitingForFile), Poco::Data::Keywords::use(UUID);
Select1.execute();

if (TmpSerialNumber != SerialNumber) {
Expand Down

0 comments on commit 4a150a9

Please sign in to comment.