mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
[bug] Fix form sending with c_oAscForceSaveTypes.Form type
This commit is contained in:
@ -94,6 +94,7 @@ function InputCommand(data, copyExplicit) {
|
||||
this['forcesave'] = undefined;
|
||||
}
|
||||
this['userdata'] = data['userdata'];
|
||||
this['formdata'] = data['formdata'];
|
||||
this['inline'] = data['inline'];
|
||||
this['password'] = data['password'];
|
||||
this['savepassword'] = data['savepassword'];
|
||||
@ -154,6 +155,7 @@ function InputCommand(data, copyExplicit) {
|
||||
this['useractionindex'] = undefined;
|
||||
this['forcesave'] = undefined;
|
||||
this['userdata'] = undefined;
|
||||
this['formdata'] = undefined;
|
||||
this['inline'] = undefined;//content disposition
|
||||
this['password'] = undefined;
|
||||
this['savepassword'] = undefined;
|
||||
@ -374,9 +376,15 @@ InputCommand.prototype = {
|
||||
setUserActionIndex: function(data) {
|
||||
this['useractionindex'] = data;
|
||||
},
|
||||
/**
|
||||
* @return {CForceSaveData | null}
|
||||
*/
|
||||
getForceSave: function() {
|
||||
return this['forcesave'];
|
||||
},
|
||||
/**
|
||||
* @param {CForceSaveData} data
|
||||
*/
|
||||
setForceSave: function(data) {
|
||||
this['forcesave'] = data;
|
||||
},
|
||||
@ -386,6 +394,12 @@ InputCommand.prototype = {
|
||||
setUserData: function(data) {
|
||||
this['userdata'] = data;
|
||||
},
|
||||
getFormData: function() {
|
||||
return this['formdata'];
|
||||
},
|
||||
setFormData: function(data) {
|
||||
this['formdata'] = data;
|
||||
},
|
||||
getInline: function() {
|
||||
return this['inline'];
|
||||
},
|
||||
@ -806,6 +820,7 @@ function OutputSfcData(key) {
|
||||
this['actions'] = undefined;
|
||||
this['mailMerge'] = undefined;
|
||||
this['userdata'] = undefined;
|
||||
this['formdata'] = undefined;
|
||||
this['lastsave'] = undefined;
|
||||
this['notmodified'] = undefined;
|
||||
this['forcesavetype'] = undefined;
|
||||
@ -873,6 +888,12 @@ OutputSfcData.prototype.getUserData= function() {
|
||||
OutputSfcData.prototype.setUserData = function(data) {
|
||||
return this['userdata'] = data;
|
||||
};
|
||||
OutputSfcData.prototype.getFormData= function() {
|
||||
return this['formdata'];
|
||||
};
|
||||
OutputSfcData.prototype.setFormData = function(data) {
|
||||
return this['formdata'] = data;
|
||||
};
|
||||
OutputSfcData.prototype.getLastSave = function() {
|
||||
return this['lastsave']
|
||||
};
|
||||
|
||||
@ -804,8 +804,21 @@ const hasChanges = co.wrap(function*(ctx, docId) {
|
||||
});
|
||||
function* setForceSave(ctx, docId, forceSave, cmd, success, url) {
|
||||
let forceSaveType = forceSave.getType();
|
||||
const end = success && commonDefines.c_oAscForceSaveTypes.Form !== forceSaveType && commonDefines.c_oAscForceSaveTypes.Internal !== forceSaveType;
|
||||
yield editorData.checkAndSetForceSave(ctx, docId, forceSave.getTime(), forceSave.getIndex(), end, end, cmd);
|
||||
let end = success;
|
||||
if (commonDefines.c_oAscForceSaveTypes.Form === forceSaveType || commonDefines.c_oAscForceSaveTypes.Internal === forceSaveType) {
|
||||
let forceSave = yield editorData.getForceSave(ctx, docId);
|
||||
end = forceSave.ended;
|
||||
}
|
||||
let convertInfo = new commonDefines.InputCommand(cmd, true);
|
||||
//remove request specific fields from cmd
|
||||
convertInfo.setUserConnectionDocId(undefined);
|
||||
convertInfo.setUserConnectionId(undefined);
|
||||
convertInfo.setResponseKey(undefined);
|
||||
convertInfo.setFormData(undefined);
|
||||
if (convertInfo.getForceSave()) {
|
||||
convertInfo.getForceSave().setType(undefined);
|
||||
}
|
||||
yield editorData.checkAndSetForceSave(ctx, docId, forceSave.getTime(), forceSave.getIndex(), end, end, convertInfo);
|
||||
|
||||
if (commonDefines.c_oAscForceSaveTypes.Command !== forceSaveType) {
|
||||
let data = {type: forceSaveType, time: forceSave.getTime(), success: success};
|
||||
@ -822,7 +835,7 @@ function* setForceSave(ctx, docId, forceSave, cmd, success, url) {
|
||||
}
|
||||
}
|
||||
}
|
||||
let checkForceSaveCache= co.wrap (function* (ctx, convertInfo) {
|
||||
async function checkForceSaveCache(ctx, convertInfo) {
|
||||
let res = {hasCache: false, hasValidCache: false, cmd: null};
|
||||
if (convertInfo) {
|
||||
res.hasCache = true;
|
||||
@ -831,42 +844,45 @@ let checkForceSaveCache= co.wrap (function* (ctx, convertInfo) {
|
||||
const outputPath = cmd.getOutputPath();
|
||||
if (saveKey && outputPath) {
|
||||
const savePathDoc = saveKey + '/' + outputPath;
|
||||
const metadata = yield storage.headObject(ctx, savePathDoc);
|
||||
const metadata = await storage.headObject(ctx, savePathDoc);
|
||||
res.hasValidCache = !!metadata;
|
||||
res.cmd = cmd;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
});
|
||||
let applyForceSaveCache = co.wrap (function* (ctx, docId, forceSave, type, opt_userConnectionId, opt_userConnectionDocId, opt_responseKey) {
|
||||
}
|
||||
async function applyForceSaveCache(ctx, docId, forceSave, type, opt_userConnectionId, opt_userConnectionDocId,
|
||||
opt_responseKey, opt_formdata) {
|
||||
let res = {ok: false, notModified: false, inProgress: false, startedForceSave: null};
|
||||
if (!forceSave) {
|
||||
res.notModified = true;
|
||||
return res;
|
||||
}
|
||||
let forceSaveCache = yield checkForceSaveCache(ctx, forceSave.convertInfo);
|
||||
let forceSaveCache = await checkForceSaveCache(ctx, forceSave.convertInfo);
|
||||
if (forceSaveCache.hasCache || forceSave.ended) {
|
||||
if (commonDefines.c_oAscForceSaveTypes.Form === type || commonDefines.c_oAscForceSaveTypes.Internal === type || !forceSave.ended) {
|
||||
if (forceSaveCache.hasValidCache) {
|
||||
let cmd = forceSaveCache.cmd;
|
||||
if (commonDefines.c_oAscForceSaveTypes.Internal === type) {
|
||||
cmd.setUserConnectionDocId(opt_userConnectionDocId);
|
||||
cmd.setUserConnectionId(opt_userConnectionId);
|
||||
cmd.setResponseKey(opt_responseKey);
|
||||
cmd.setUserConnectionDocId(opt_userConnectionDocId);
|
||||
cmd.setUserConnectionId(opt_userConnectionId);
|
||||
cmd.setResponseKey(opt_responseKey);
|
||||
cmd.setFormData(opt_formdata);
|
||||
if (cmd.getForceSave()) {
|
||||
cmd.getForceSave().setType(type);
|
||||
}
|
||||
//todo timeout because commandSfcCallback make request?
|
||||
yield canvasService.commandSfcCallback(ctx, cmd, true, false);
|
||||
await canvasService.commandSfcCallback(ctx, cmd, true, false);
|
||||
res.ok = true;
|
||||
} else {
|
||||
yield editorData.checkAndSetForceSave(ctx, docId, forceSave.getTime(), forceSave.getIndex(), false, false, null);
|
||||
res.startedForceSave = yield editorData.checkAndStartForceSave(ctx, docId);
|
||||
await editorData.checkAndSetForceSave(ctx, docId, forceSave.getTime(), forceSave.getIndex(), false, false, null);
|
||||
res.startedForceSave = await editorData.checkAndStartForceSave(ctx, docId);
|
||||
res.ok = !!res.startedForceSave;
|
||||
}
|
||||
} else {
|
||||
res.notModified = true;
|
||||
}
|
||||
} else if (!forceSave.started) {
|
||||
res.startedForceSave = yield editorData.checkAndStartForceSave(ctx, docId);
|
||||
res.startedForceSave = await editorData.checkAndStartForceSave(ctx, docId);
|
||||
res.ok = !!res.startedForceSave;
|
||||
return res;
|
||||
} else if (commonDefines.c_oAscForceSaveTypes.Form === type || commonDefines.c_oAscForceSaveTypes.Internal === type) {
|
||||
@ -876,25 +892,23 @@ let applyForceSaveCache = co.wrap (function* (ctx, docId, forceSave, type, opt_u
|
||||
res.notModified = true;
|
||||
}
|
||||
return res;
|
||||
});
|
||||
let startForceSave = co.wrap(function*(ctx, docId, type, opt_userdata, opt_userId, opt_userConnectionId, opt_userConnectionDocId, opt_userIndex, opt_responseKey, opt_baseUrl, opt_queue, opt_pubsub) {
|
||||
}
|
||||
async function startForceSave(ctx, docId, type, opt_userdata, opt_formdata, opt_userId, opt_userConnectionId, opt_userConnectionDocId, opt_userIndex, opt_responseKey, opt_baseUrl, opt_queue, opt_pubsub) {
|
||||
ctx.logger.debug('startForceSave start');
|
||||
let res = {code: commonDefines.c_oAscServerCommandErrors.NoError, time: null, inProgress: false};
|
||||
let startedForceSave;
|
||||
let hasEncrypted = false;
|
||||
if (!shutdownFlag) {
|
||||
let hvals = yield editorData.getPresence(ctx, docId, connections);
|
||||
let hvals = await editorData.getPresence(ctx, docId, connections);
|
||||
hasEncrypted = hvals.some((currentValue) => {
|
||||
return !!JSON.parse(currentValue).encrypted;
|
||||
});
|
||||
if (!hasEncrypted) {
|
||||
let forceSave = yield editorData.getForceSave(ctx, docId);
|
||||
// let forceSaveCache = yield checkForceSaveCache(ctx, forceSave);
|
||||
// let applyCacheRes = yield applyForceSaveCache(ctx, docId, forceSave, forceSaveCache, type);
|
||||
let applyCacheRes = yield applyForceSaveCache(ctx, docId, forceSave, type, opt_userConnectionId, opt_userConnectionDocId, opt_responseKey);
|
||||
let forceSave = await editorData.getForceSave(ctx, docId);
|
||||
let applyCacheRes = await applyForceSaveCache(ctx, docId, forceSave, type, opt_userConnectionId, opt_userConnectionDocId, opt_responseKey, opt_formdata);
|
||||
startedForceSave = applyCacheRes.startedForceSave;
|
||||
if (applyCacheRes.notModified) {
|
||||
let selectRes = yield taskResult.select(ctx, docId);
|
||||
let selectRes = await taskResult.select(ctx, docId);
|
||||
if (selectRes.length > 0) {
|
||||
res.code = commonDefines.c_oAscServerCommandErrors.NotModified;
|
||||
} else {
|
||||
@ -916,10 +930,10 @@ let startForceSave = co.wrap(function*(ctx, docId, type, opt_userdata, opt_userI
|
||||
forceSave.setAuthorUserIndex(opt_userIndex);
|
||||
|
||||
if (commonDefines.c_oAscForceSaveTypes.Timeout === type) {
|
||||
yield* publish(ctx, {
|
||||
await co(publish(ctx, {
|
||||
type: commonDefines.c_oPublishType.forceSave, ctx: ctx, docId: docId,
|
||||
data: {type: type, time: forceSave.getTime(), start: true}
|
||||
}, undefined, undefined, opt_pubsub);
|
||||
}, undefined, undefined, opt_pubsub));
|
||||
}
|
||||
|
||||
let priority;
|
||||
@ -931,8 +945,9 @@ let startForceSave = co.wrap(function*(ctx, docId, type, opt_userdata, opt_userI
|
||||
priority = constants.QUEUE_PRIORITY_LOW;
|
||||
}
|
||||
//start new convert
|
||||
let status = yield converterService.convertFromChanges(ctx, docId, baseUrl, forceSave, startedForceSave.changeInfo,
|
||||
opt_userdata, opt_userConnectionId, opt_userConnectionDocId, opt_responseKey, priority, expiration, opt_queue);
|
||||
let status = await converterService.convertFromChanges(ctx, docId, baseUrl, forceSave, startedForceSave.changeInfo,
|
||||
opt_userdata, opt_formdata, opt_userConnectionId, opt_userConnectionDocId, opt_responseKey, priority, expiration,
|
||||
opt_queue);
|
||||
if (constants.NO_ERROR === status.err) {
|
||||
res.time = forceSave.getTime();
|
||||
} else {
|
||||
@ -942,7 +957,7 @@ let startForceSave = co.wrap(function*(ctx, docId, type, opt_userdata, opt_userI
|
||||
}
|
||||
ctx.logger.debug('startForceSave end');
|
||||
return res;
|
||||
});
|
||||
}
|
||||
function getExternalChangeInfo(user, date) {
|
||||
return {user_id: user.id, user_id_original: user.idOriginal, user_name: user.username, change_date: date};
|
||||
}
|
||||
@ -975,7 +990,7 @@ let saveRelativeFromChanges = co.wrap(function*(ctx, conn, responseKey, data) {
|
||||
}
|
||||
}
|
||||
if (!forceSaveRes) {
|
||||
forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Internal, undefined, undefined, conn.user.id, conn.docId, undefined, responseKey);
|
||||
forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Internal, undefined, undefined, undefined, conn.user.id, conn.docId, undefined, responseKey);
|
||||
}
|
||||
if (commonDefines.c_oAscServerCommandErrors.NoError !== forceSaveRes.code || forceSaveRes.inProgress) {
|
||||
sendDataRpc(ctx, conn, responseKey, forceSaveRes);
|
||||
@ -988,7 +1003,7 @@ function* startRPC(ctx, conn, responseKey, data) {
|
||||
case 'sendForm': {
|
||||
let forceSaveRes;
|
||||
if (conn.user) {
|
||||
forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Form, undefined, conn.user.idOriginal, conn.user.id, undefined, conn.user.indexUser, responseKey);
|
||||
forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Form, undefined, data.formdata, conn.user.idOriginal, conn.user.id, undefined, conn.user.indexUser, responseKey);
|
||||
}
|
||||
if (!forceSaveRes || commonDefines.c_oAscServerCommandErrors.NoError !== forceSaveRes.code || forceSaveRes.inProgress) {
|
||||
sendDataRpc(ctx, conn, responseKey, forceSaveRes);
|
||||
@ -1641,7 +1656,7 @@ exports.install = function(server, callbackFunction) {
|
||||
case 'forceSaveStart' :
|
||||
var forceSaveRes;
|
||||
if (conn.user) {
|
||||
forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Button, undefined, conn.user.idOriginal, conn.user.id, undefined, conn.user.indexUser);
|
||||
forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Button, undefined, undefined, conn.user.idOriginal, conn.user.id, undefined, conn.user.indexUser);
|
||||
} else {
|
||||
forceSaveRes = {code: commonDefines.c_oAscServerCommandErrors.UnknownError, time: null};
|
||||
}
|
||||
@ -4226,7 +4241,7 @@ function* commandHandle(ctx, params, req, output) {
|
||||
break;
|
||||
}
|
||||
case 'forcesave': {
|
||||
let forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Command, params.userdata, undefined, undefined, undefined, undefined, undefined, utils.getBaseUrlByRequest(ctx, req));
|
||||
let forceSaveRes = yield startForceSave(ctx, docId, commonDefines.c_oAscForceSaveTypes.Command, params.userdata, undefined, undefined, undefined, undefined, undefined, undefined, utils.getBaseUrlByRequest(ctx, req));
|
||||
output.error = forceSaveRes.code;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -997,6 +997,7 @@ const commandSfcCallback = co.wrap(function*(ctx, cmd, isSfcm, isEncrypted) {
|
||||
outputSfc.setActions([new commonDefines.OutputAction(commonDefines.c_oAscUserAction.ForceSaveButton, forceSaveUserId)]);
|
||||
}
|
||||
outputSfc.setUserData(cmd.getUserData());
|
||||
outputSfc.setFormData(cmd.getFormData());
|
||||
if (!isError || isErrorCorrupted) {
|
||||
try {
|
||||
let forgotten = yield storage.listObjects(ctx, docId, tenForgottenFiles);
|
||||
@ -1051,7 +1052,8 @@ const commandSfcCallback = co.wrap(function*(ctx, cmd, isSfcm, isEncrypted) {
|
||||
} else {
|
||||
try {
|
||||
if (wopiParams) {
|
||||
replyStr = yield processWopiPutFile(ctx, docId, wopiParams, savePathDoc, userLastChangeId, true, forceSaveType !== commonDefines.c_oAscForceSaveTypes.Button, false);
|
||||
let isAutoSave = forceSaveType !== commonDefines.c_oAscForceSaveTypes.Button && forceSaveType !== commonDefines.c_oAscForceSaveTypes.Form;
|
||||
replyStr = yield processWopiPutFile(ctx, docId, wopiParams, savePathDoc, userLastChangeId, true, isAutoSave, false);
|
||||
} else {
|
||||
replyStr = yield* docsCoServer.sendServerRequest(ctx, uri, outputSfc, checkAndFixAuthorizationLength);
|
||||
}
|
||||
|
||||
@ -184,8 +184,8 @@ function* convertByCmd(ctx, cmd, async, opt_fileTo, opt_taskExist, opt_priority,
|
||||
return status;
|
||||
}
|
||||
|
||||
let convertFromChanges = co.wrap(function*(ctx, docId, baseUrl, forceSave, externalChangeInfo, opt_userdata, opt_userConnectionId,
|
||||
opt_userConnectionDocId, opt_responseKey, opt_priority, opt_expiration, opt_queue, opt_redisKey) {
|
||||
async function convertFromChanges(ctx, docId, baseUrl, forceSave, externalChangeInfo, opt_userdata, opt_formdata, opt_userConnectionId,
|
||||
opt_userConnectionDocId, opt_responseKey, opt_priority, opt_expiration, opt_queue, opt_redisKey) {
|
||||
var cmd = new commonDefines.InputCommand();
|
||||
cmd.setCommand('sfcm');
|
||||
cmd.setDocId(docId);
|
||||
@ -198,6 +198,10 @@ let convertFromChanges = co.wrap(function*(ctx, docId, baseUrl, forceSave, exter
|
||||
if (opt_userdata) {
|
||||
cmd.setUserData(opt_userdata);
|
||||
}
|
||||
if (opt_formdata) {
|
||||
//todo put file to storage
|
||||
cmd.setFormData(opt_formdata);
|
||||
}
|
||||
if (opt_userConnectionId) {
|
||||
cmd.setUserConnectionId(opt_userConnectionId);
|
||||
}
|
||||
@ -211,20 +215,20 @@ let convertFromChanges = co.wrap(function*(ctx, docId, baseUrl, forceSave, exter
|
||||
cmd.setRedisKey(opt_redisKey);
|
||||
}
|
||||
|
||||
yield canvasService.commandSfctByCmd(ctx, cmd, opt_priority, opt_expiration, opt_queue);
|
||||
await canvasService.commandSfctByCmd(ctx, cmd, opt_priority, opt_expiration, opt_queue);
|
||||
var fileTo = constants.OUTPUT_NAME;
|
||||
let outputExt = formatChecker.getStringFromFormat(cmd.getOutputFormat());
|
||||
if (outputExt) {
|
||||
fileTo += '.' + outputExt;
|
||||
}
|
||||
let status = yield* convertByCmd(ctx, cmd, true, fileTo, undefined, opt_priority, opt_expiration, opt_queue);
|
||||
let status = await co(convertByCmd(ctx, cmd, true, fileTo, undefined, opt_priority, opt_expiration, opt_queue));
|
||||
if (status.end) {
|
||||
let fileToPath = yield* getConvertPath(ctx, docId, fileTo, cmd.getOutputFormat());
|
||||
let fileToPath = await co(getConvertPath(ctx, docId, fileTo, cmd.getOutputFormat()));
|
||||
status.setExtName(path.extname(fileToPath));
|
||||
status.setUrl(yield* getConvertUrl(ctx, baseUrl, fileToPath, cmd.getTitle()));
|
||||
status.setUrl(await co(getConvertUrl(ctx, baseUrl, fileToPath, cmd.getTitle())));
|
||||
}
|
||||
return status;
|
||||
});
|
||||
}
|
||||
function parseIntParam(val){
|
||||
return (typeof val === 'string') ? parseInt(val) : val;
|
||||
}
|
||||
|
||||
@ -171,7 +171,8 @@ let forceSaveTimeout = function() {
|
||||
ctx.init(tenant, docId, ctx.userId);
|
||||
yield ctx.initTenantCache();
|
||||
actions.push(docsCoServer.startForceSave(ctx, docId, commondefines.c_oAscForceSaveTypes.Timeout,
|
||||
undefined, undefined, undefined, undefined, undefined, undefined, undefined, queue, pubsub));
|
||||
undefined, undefined, undefined, undefined,
|
||||
undefined, undefined, undefined, undefined, queue, pubsub));
|
||||
}
|
||||
}
|
||||
yield Promise.all(actions);
|
||||
|
||||
Reference in New Issue
Block a user