Divec has uploaded a new change for review.
https://gerrit.wikimedia.org/r/146738
Change subject: Put MT request html into post body
......................................................................
Put MT request html into post body
Change-Id: I3d67455094c7d5943a05029fb031f103b3f9c021
---
M ContentTranslationService.js
M public/js/mt.js
2 files changed, 31 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/cxserver
refs/changes/38/146738/1
diff --git a/ContentTranslationService.js b/ContentTranslationService.js
index f77a0b0..721460b 100644
--- a/ContentTranslationService.js
+++ b/ContentTranslationService.js
@@ -90,11 +90,10 @@
);
} );
-app.post( '/mt/:sourceLang/:targetLang/:sourceHtml', function ( req, res ) {
- var mtProviders, mtClient,
+app.post( '/mt/:sourceLang/:targetLang', function ( req, res ) {
+ var mtProviders, mtClient, sourceHtmlChunks, sourceHtml, reqLength,
sourceLang = req.params.sourceLang,
targetLang = req.params.targetLang,
- sourceHtml = req.params.sourceHtml,
registry = require( __dirname + '/registry' ),
toolset;
@@ -105,17 +104,34 @@
}
mtProviders = require( __dirname + '/mt' );
mtClient = mtProviders[ toolset.mt.provider ];
- sourceHtml = '<div>' + sourceHtml + '</div>';
- mtClient.translateHtmlWithNativeMarkup( sourceLang, targetLang,
sourceHtml ).then(
- function ( data ) {
- res.send( data );
- },
- function ( error ) {
- res.send( 500, {
- error: error
- } );
+
+ sourceHtmlChunks = [ '<div>' ];
+ reqLength = 0;
+ console.log( req );
+ console.dir( req );
+ req.on( 'data', function ( data ) {
+ reqLength += data.length;
+ if ( reqLength > 50000 ) {
+ // Too long
+ res.send( 500 );
+ return;
}
- );
+ sourceHtmlChunks.push( data );
+ } );
+ req.on( 'end', function () {
+ sourceHtmlChunks.push( '</div>' );
+ sourceHtml = sourceHtmlChunks.join( '' );
+ mtClient.translateHtmlWithNativeMarkup( sourceLang, targetLang,
sourceHtml ).then(
+ function ( data ) {
+ res.send( data );
+ },
+ function ( error ) {
+ res.send( 500, {
+ error: error
+ } );
+ }
+ );
+ } );
} );
app.get( '/dictionary/:word/:from/:to', function ( req, res ) {
diff --git a/public/js/mt.js b/public/js/mt.js
index 20c9a40..9eca076 100644
--- a/public/js/mt.js
+++ b/public/js/mt.js
@@ -12,8 +12,8 @@
var sourceHtml = $( 'textarea[name=sourceHtml]' ).val(),
sourceLanguage = $(
'input[name=sourceLanguage]' ).val(),
targetLanguage = $(
'input[name=targetLanguage]' ).val(),
- url = '/mt/' + sourceLanguage + '/' + targetLanguage + '/' +
encodeURIComponent( sourceHtml );
- $.post( url, function ( response ) {
+ url = '/mt/' + sourceLanguage + '/' + targetLanguage;
+ $.post( url, sourceHtml, function ( response ) {
$( '.targetHtmlRaw' ).text( response );
$( '.targetHtmlRendered' ).html( response );
} ).fail( function () {
--
To view, visit https://gerrit.wikimedia.org/r/146738
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3d67455094c7d5943a05029fb031f103b3f9c021
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/cxserver
Gerrit-Branch: master
Gerrit-Owner: Divec <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits