Skip to content

Commit

Permalink
[feature] Remove unused handler 'uploadold' (needed for compatibility…
Browse files Browse the repository at this point in the history
… with ie9)
  • Loading branch information
konovalovsergey committed Dec 22, 2024
1 parent 95eaea9 commit 01c353a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 92 deletions.
90 changes: 0 additions & 90 deletions DocService/sources/fileuploaderservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,96 +75,6 @@ function checkJwtUploadTransformRes(ctx, errorName, checkJwtRes){
}
return res;
}
exports.uploadImageFileOld = function(req, res) {
return co(function* () {
let ctx = new operationContext.Context();
ctx.initFromRequest(req);
yield ctx.initTenantCache();
var docId = req.params.docid;
ctx.setDocId(docId);
ctx.logger.debug('Start uploadImageFileOld');
const tenImageSize = ctx.getCfg('services.CoAuthoring.server.limits_image_size', cfgImageSize);
const tenTokenEnableBrowser = ctx.getCfg('services.CoAuthoring.token.enable.browser', cfgTokenEnableBrowser);

if (tenTokenEnableBrowser) {
var checkJwtRes = yield* checkJwtUpload(ctx, 'uploadImageFileOld', req.query['token']);
if(!checkJwtRes.err){
docId = checkJwtRes.docId || docId;
ctx.setDocId(docId);
ctx.setUserId(checkJwtRes.userid);
} else {
res.sendStatus(403);
return;
}
}
var listImages = [];
if (docId) {
var isError = false;
var form = new multiparty.Form();
form.on('error', function(err) {
ctx.logger.error('Error parsing form:%s', err.toString());
res.sendStatus(400);
});
form.on('part', function(part) {
if (!part.filename) {
// ignore field's content
part.resume();
}
if (part.filename) {
if (part.byteCount > tenImageSize) {
isError = true;
}
if (isError) {
part.resume();
} else {
//a hash is written at the beginning to avoid errors during parallel upload in co-editing
var strImageName = crypto.randomBytes(16).toString("hex");
var strPath = docId + '/media/' + strImageName + '.jpg';
listImages.push(strPath);
utils.stream2Buffer(part).then(function(buffer) {
return storageBase.putObject(ctx, strPath, buffer, buffer.length);
}).then(function() {
part.resume();
}).catch(function(err) {
ctx.logger.error('Upload putObject:%s', err.stack);
isError = true;
part.resume();
});
}
}
part.on('error', function(err) {
ctx.logger.error('Error parsing form part:%s', err.toString());
});
});
form.once('close', function() {
if (isError) {
res.sendStatus(400);
} else {
storageBase.getSignedUrlsByArray(ctx, utils.getBaseUrlByRequest(ctx, req), listImages, docId,
commonDefines.c_oAscUrlTypes.Session).then(function(urls) {
var outputData = {'type': 0, 'error': constants.NO_ERROR, 'urls': urls, 'input': req.query};
var output = '<html><head><script type="text/javascript">function load(){ parent.postMessage("';
output += JSON.stringify(outputData).replace(/"/g, '\\"');
output += '", "*"); }</script></head><body onload="load()"></body></html>';

//res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Content-Type', 'text/html');
res.send(output);
ctx.logger.debug('End uploadImageFileOld:%s', output);
}
).catch(function(err) {
ctx.logger.error('error getSignedUrlsByArray:%s', err.stack);
res.sendStatus(400);
});
}
});
form.parse(req);
} else {
ctx.logger.debug('Error params uploadImageFileOld');
res.sendStatus(400);
}
});
};
exports.uploadImageFile = function(req, res) {
return co(function* () {
let httpStatus = 200;
Expand Down
2 changes: 0 additions & 2 deletions DocService/sources/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ docsCoServer.install(server, () => {
res.sendStatus(403);
}
});
//'*' for backward compatible
app.post('/uploadold/:docid*', fileUploaderService.uploadImageFileOld);
app.post('/upload/:docid*', rawFileParser, fileUploaderService.uploadImageFile);

app.post('/downloadas/:docid', rawFileParser, canvasService.downloadAs);
Expand Down

0 comments on commit 01c353a

Please sign in to comment.