Просмотр исходного кода

Error if update would make document too long

James Allen 11 лет назад
Родитель
Сommit
e73890bfc2

+ 1 - 1
services/document-updater/app/coffee/ShareJsUpdateManager.coffee

@@ -15,7 +15,7 @@ ShareJsModel:: = {}
 util.inherits ShareJsModel, EventEmitter
 
 module.exports = ShareJsUpdateManager =
-	getNewShareJsModel: () -> new ShareJsModel(ShareJsDB)
+	getNewShareJsModel: () -> new ShareJsModel(ShareJsDB, maxDocLength: Settings.max_doc_length)
 
 	applyUpdates: (project_id, doc_id, updates, callback = (error, updatedDocLines) ->) ->
 		logger.log project_id: project_id, doc_id: doc_id, updates: updates, "applying sharejs updates"

+ 3 - 0
services/document-updater/app/coffee/sharejs/server/model.coffee

@@ -136,6 +136,9 @@ module.exports = Model = (db, options) ->
       catch error
         console.error error.stack
         return callback error.message
+        
+      if options.maxDocLength? and doc.snapshot.length > options.maxDocLength
+        return callback "Update takes doc over max doc size"
 
       # The op data should be at the current version, and the new document data should be at
       # the next version.

+ 2 - 0
services/document-updater/config/settings.defaults.coffee

@@ -23,6 +23,8 @@ module.exports =
 		zip:
 			minSize: 10*1024
 			writesEnabled: false
+	
+	max_doc_length: 2 * 1024 * 1024 # 2mb
 
 	mongo:
 		url: 'mongodb://127.0.0.1/sharelatex'