Ver Fonte

ripped file fingerprinting out

Henry Oswald há 8 anos atrás
pai
commit
bf276b0814

+ 25 - 45
services/web/app/coffee/infrastructure/ExpressLocals.coffee

@@ -12,7 +12,6 @@ Modules = require "./Modules"
 Url = require "url"
 PackageVersions = require "./PackageVersions"
 htmlEncoder = new require("node-html-encoder").Encoder("numerical")
-fingerprints = {}
 hashedFiles = {}
 Path = require 'path'
 Features = require "./Features"
@@ -31,49 +30,39 @@ getFileContent = (filePath)->
 	filePath = Path.join __dirname, "../../../", "public#{filePath}"
 	exists = fs.existsSync filePath
 	if exists
-		content = fs.readFileSync filePath
+		content = fs.readFileSync filePath, "UTF-8"
 		return content
 	else
-		logger.log filePath:filePath, "file does not exist for fingerprints"
+		logger.log filePath:filePath, "file does not exist for hashing"
 		return ""
 
-logger.log "Generating file fingerprints..."
+logger.log "Generating file hashes..."
 pathList = [
-	["#{jsPath}libs/require.js"]
-	["#{jsPath}ide.js"]
-	["#{jsPath}main.js"]
-	["#{jsPath}libraries.js"]
-	["/stylesheets/style.css"]
-	["/stylesheets/ol-style.css"]
+	"#{jsPath}libs/require.js"
+	"#{jsPath}ide.js"
+	"#{jsPath}main.js"
+	"#{jsPath}libraries.js"
+	"/stylesheets/style.css"
+	"/stylesheets/ol-style.css"
 ]
 
-for paths in pathList
-	contentList = _.map(paths, getFileContent)
-	content = contentList.join("")
+for path in pathList
+	content = getFileContent(path)
 	hash = crypto.createHash("md5").update(content).digest("hex")
-	_.each paths, (filePath)-> 
-		logger.log "#{filePath}: #{hash}"
-		fingerprints[filePath] = hash
-
-	for path in paths
-		splitPath = path.split("/")
-		filenameSplit = splitPath.pop().split(".")
-		filenameSplit.splice(filenameSplit.length-1, 0, hash)
-		splitPath.push(filenameSplit.join("."))
-		hashPath = splitPath.join("/")
-		fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}"
-		fs.writeFileSync(fsHashPath, content)
-		hashedFiles[paths] = hashPath
-
-
-getFingerprint = (path) ->
-	if fingerprints[path]?
-		return fingerprints[path]
-	else
-		logger.err "No fingerprint for file: #{path}"
-		return ""
+	
+	splitPath = path.split("/")
+	filenameSplit = splitPath.pop().split(".")
+	filenameSplit.splice(filenameSplit.length-1, 0, hash)
+	splitPath.push(filenameSplit.join("."))
+
+	hashPath = splitPath.join("/")
+	hashedFiles[path] = hashPath
 
-logger.log "Finished generating file fingerprints"
+	fsHashPath = Path.join __dirname, "../../../", "public#{hashPath}"
+	fs.writeFileSync(fsHashPath, content)
+
+
+logger.log "Finished hashing static content"
 
 cdnAvailable = Settings.cdn?.web?.host?
 darkCdnAvailable = Settings.cdn?.web?.darkHost?
@@ -135,14 +124,9 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
 			if opts.hashedPath
 				path = hashedFiles[path]
 
-			doFingerPrint = opts.fingerprint != false
-
 			if !opts.qs?
 				opts.qs = {}
 
-			if !opts.qs?.fingerprint? and doFingerPrint
-				opts.qs.fingerprint = getFingerprint(path)
-
 			if opts.cdn != false
 				path = Url.resolve(staticFilesBase, path)
 
@@ -160,7 +144,7 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
 			if opts?.hashedPath
 				hashedPath = hashedFiles[path]
 				return Url.resolve(staticFilesBase, hashedPath)
-			return Url.resolve(staticFilesBase, path) + "?fingerprint=" + getFingerprint(path)
+			return Url.resolve(staticFilesBase, path)
 
 		res.locals.buildImgPath = (imgFile)->
 			path = Path.join("/img/", imgFile)
@@ -245,10 +229,6 @@ module.exports = (app, webRouter, privateApiRouter, publicApiRouter)->
 			return req.query?[field]
 		next()
 
-	webRouter.use (req, res, next)->
-		res.locals.fingerprint = getFingerprint
-		next()
-
 	webRouter.use (req, res, next)->
 		res.locals.formatPrice = SubscriptionFormatters.formatPrice
 		next()

+ 6 - 6
services/web/app/views/layout.pug

@@ -57,7 +57,7 @@ html(itemscope, itemtype='http://schema.org/Product')
 		script(type="text/javascript").
 			window.csrfToken = "#{csrfToken}";
 			
-		script(src=buildJsPath("libs/jquery-1.11.1.min.js", {fingerprint:false}))
+		script(src=buildJsPath("libs/jquery-1.11.1.min.js"))
 		script(type="text/javascript").
 			var noCdnKey = "nocdn=true"
 			var cdnBlocked = typeof jQuery === 'undefined'
@@ -68,7 +68,7 @@ html(itemscope, itemtype='http://schema.org/Product')
 
 		block scripts
 
-		script(src=buildJsPath("libs/angular-1.6.4.min.js", {fingerprint:false}))
+		script(src=buildJsPath("libs/angular-1.6.4.min.js"))
 
 		script.
 			window.sharelatex = {
@@ -143,8 +143,8 @@ html(itemscope, itemtype='http://schema.org/Product')
 					"paths" : {
 						"moment": "libs/#{lib('moment')}",
 						"fineuploader": "libs/#{lib('fineuploader')}",
-						"main": "#{buildJsPath('main.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}",
-						"libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}",
+						"main": "#{buildJsPath('main.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}",
+						"libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}",
 					},
 					"config":{
 						"moment":{
@@ -153,9 +153,9 @@ html(itemscope, itemtype='http://schema.org/Product')
 					}
 				};
 			script(
-				data-main=buildJsPath('main.js', {hashedPath:false, fingerprint:false}),
+				data-main=buildJsPath('main.js', {hashedPath:false}),
 				baseurl=fullJsPath,
-				src=buildJsPath('libs/require.js')
+				src=buildJsPath('libs/require.js', {hashedPath:true})
 			)
 
 		include contact-us-modal

+ 9 - 9
services/web/app/views/project/editor.pug

@@ -98,9 +98,9 @@ block requirejs
 	script(type="text/javascript" src='/socket.io/socket.io.js')
 
 	//- don't use cdn for workers
-	- var aceWorkerPath = buildJsPath(lib('ace'), {cdn:false,fingerprint:false})
-	- var pdfWorkerPath = buildJsPath('/libs/' + lib('pdfjs') + '/pdf.worker', {cdn:false,fingerprint:false})
-	- var pdfCMapsPath = buildJsPath('/libs/' + lib('pdfjs') + '/bcmaps/', {cdn:false,fingerprint:false})
+	- var aceWorkerPath = buildJsPath(lib('ace'), {cdn:false})
+	- var pdfWorkerPath = buildJsPath('/libs/' + lib('pdfjs') + '/pdf.worker', {cdn:false})
+	- var pdfCMapsPath = buildJsPath('/libs/' + lib('pdfjs') + '/bcmaps/', {cdn:false})
 
 	//- We need to do .replace(/\//g, '\\/') do that '</script>' -> '<\/script>'
 	//- and doesn't prematurely end the script tag.
@@ -126,14 +126,14 @@ block requirejs
 		window.wikiEnabled = #{!!(settings.apis.wiki && settings.apis.wiki.url)};
 		window.requirejs = {
 			"paths" : {
-				"mathjax": "#{buildJsPath('/libs/mathjax/MathJax.js', {cdn:false, fingerprint:false, qs:{config:'TeX-AMS_HTML'}})}",
+				"mathjax": "#{buildJsPath('/libs/mathjax/MathJax.js', {cdn:false, qs:{config:'TeX-AMS_HTML'}})}",
 				"moment": "libs/#{lib('moment')}",
 				"pdfjs-dist/build/pdf": "libs/#{lib('pdfjs')}/pdf",
 				"pdfjs-dist/build/pdf.worker": "#{pdfWorkerPath}",
 				"ace": "#{lib('ace')}",
 				"fineuploader": "libs/#{lib('fineuploader')}",
-				"ide": "#{buildJsPath('ide.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}",
-				"libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, fingerprint:false, removeExtension:true})}",
+				"ide": "#{buildJsPath('ide.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}",
+				"libraries": "#{buildJsPath('libraries.js', {hashedPath:settings.useMinifiedJs, removeExtension:true})}",
 			},
 			"waitSeconds": 0,
 			"shim": {
@@ -161,8 +161,8 @@ block requirejs
 		window.uiConfig = JSON.parse('!{JSON.stringify(uiConfig).replace(/\//g, "\\/")}');
 
 	script(
-		data-main=buildJsPath("ide.js", {hashedPath:false, fingerprint:false}),
+		data-main=buildJsPath("ide.js", {hashedPath:false}),
 		baseurl=fullJsPath,
-		data-ace-base=buildJsPath(lib('ace'), {fingerprint:false}),
-		src=buildJsPath('libs/require.js', {hashedPath:false})
+		data-ace-base=buildJsPath(lib('ace')),
+		src=buildJsPath('libs/require.js', {hashedPath:true})
 	)