Skip to content

Commit

Permalink
admin: send serverId with migrate msg
Browse files Browse the repository at this point in the history
Signed-off-by: Rash419 <[email protected]>
Change-Id: I484620df234a1dcbedeba5b5102dacee7451015a
  • Loading branch information
Rash419 committed Sep 7, 2023
1 parent e0ce56d commit 855429d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
3 changes: 2 additions & 1 deletion browser/src/core/Socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ app.definitions.Socket = L.Class.extend({
}
else if (textMsg.startsWith('migrate:') && window.indirectSocket) {
var migrate = JSON.parse(textMsg.substring(textMsg.indexOf('{')));
console.log(migrate);
var afterSave = migrate.afterSave;
if (!afterSave) {
window.migrating = true;
Expand All @@ -748,6 +747,7 @@ app.definitions.Socket = L.Class.extend({
}
if (migrate.saved) {
window.routeToken = migrate.routeToken;
window.expectedServerId = migrate.serverId;
this.connect();
this._map.uiManager.closeAll();
}
Expand All @@ -756,6 +756,7 @@ app.definitions.Socket = L.Class.extend({
// even after save attempt, if document is unsaved reset the file permission
if (migrate.saved) {
window.routeToken = migrate.routeToken;
window.expectedServerId = migrate.serverId;
this.connect();
this._map.uiManager.closeAll();
} else {
Expand Down
9 changes: 5 additions & 4 deletions wsd/Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ void AdminSocketHandler::handleMessage(const std::vector<char> &payload)
const std::string& docStatus = tokens[1];
const std::string& dockey = tokens[2];
const std::string& routeToken = tokens[3];
if (!dockey.empty() && !routeToken.empty())
const std::string& serverId = tokens[4];
if (!dockey.empty() && !routeToken.empty() && !serverId.empty())
{
model.setMigratingInfo(dockey, routeToken, serverId);
std::ostringstream oss;
oss << "migrate: {";
model.setCurrentMigDoc(dockey);
model.setCurrentMigToken(routeToken);
oss << "\"afterSave\"" << ":false,";
if (docStatus == "unsaved" && !model.isDocSaved(dockey))
{
Expand All @@ -344,7 +344,8 @@ void AdminSocketHandler::handleMessage(const std::vector<char> &payload)
{
oss << "\"saved\"" << ":true,";
}
oss << "\"routeToken\"" << ':' << "\"" << routeToken << "\"" << '}';
oss << "\"routeToken\"" << ':' << '"' << routeToken << '"' << ',';
oss << "\"serverId\"" << ':' << '"' << serverId << '"' << '}';
COOLWSD::alertUserInternal(dockey, oss.str());
}
else
Expand Down
38 changes: 27 additions & 11 deletions wsd/AdminModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,7 @@ void AdminModel::doRemove(std::map<std::string, std::unique_ptr<Document>>::iter
}
else
{
setCurrentMigDoc(std::string());
setCurrentMigToken(std::string());
resetMigratingInfo();
}

std::unique_ptr<Document> doc;
Expand Down Expand Up @@ -1272,18 +1271,21 @@ void AdminModel::sendMigrateMsgAfterSave(bool lastSaveSuccessful, const std::str
{
return;
}
if (!lastSaveSuccessful)
{
setCurrentMigToken(std::string());
setCurrentMigDoc(std::string());
}
std::string saveSuccessful = lastSaveSuccessful ? "true" : "false";
std::ostringstream oss;
std::string saveSuccessful = lastSaveSuccessful ? "true" : "false";
oss << "migrate: {";
oss << "\"afterSave\"" << ":true,";
oss << "\"afterSave\""
<< ":true,";
oss << "\"saved\":" << saveSuccessful << ',';
oss << "\"routeToken\"" << ':' << "\"" << getCurrentMigToken()
<< "\"" << '}';
if (lastSaveSuccessful)
{
oss << "\"routeToken\"" << ':' << '"' << getCurrentMigToken() << '"' << ',';
oss << "\"serverId\"" << ':' << '"' << getTargetMigServerId() << '"' << '}';
}
else
{
resetMigratingInfo();
}
COOLWSD::alertUserInternal(docKey, oss.str());
}

Expand All @@ -1310,4 +1312,18 @@ std::string AdminModel::getWopiSrcMap()
return oss.str();
}

void AdminModel::setMigratingInfo(const std::string& docKey, const std::string& routeToken, const std::string& serverId)
{
_currentMigDoc = docKey;
_currentMigToken = routeToken;
_targetMigServerId = serverId;
}

void AdminModel::resetMigratingInfo()
{
_currentMigDoc = std::string();
_currentMigToken = std::string();
_targetMigServerId = std::string();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
7 changes: 5 additions & 2 deletions wsd/AdminModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,11 @@ class AdminModel
static int getKitPidsFromSystem(std::vector<int> *pids);
bool isDocSaved(const std::string&);
bool isDocReadOnly(const std::string&);
void setCurrentMigDoc(const std::string& docKey) { _currentMigDoc = docKey; }
void setMigratingInfo(const std::string& docKey, const std::string& routeToken, const std::string& serverId);
void resetMigratingInfo();
std::string getCurrentMigDoc() { return _currentMigDoc; }
void setCurrentMigToken(const std::string& routeToken) { _currentMigToken = routeToken; }
std::string getCurrentMigToken() { return _currentMigToken; }
std::string getTargetMigServerId() { return _targetMigServerId; }
void sendMigrateMsgAfterSave(bool lastSaveSuccessful, const std::string& docKey);
std::string getWopiSrcMap();

Expand Down Expand Up @@ -485,6 +486,8 @@ class AdminModel
std::string _currentMigDoc = std::string();

std::string _currentMigToken = std::string();

std::string _targetMigServerId = std::string();
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

0 comments on commit 855429d

Please sign in to comment.