diff --git a/src/Filtering/Filter.coffee b/src/Filtering/Filter.coffee index 0088446e9..fc8493b95 100755 --- a/src/Filtering/Filter.coffee +++ b/src/Filtering/Filter.coffee @@ -155,7 +155,7 @@ Filter = false dimensions: (post) -> {file} = post - if file and (file.isImage or file.isVideo) + if file?.dimensions return file.dimensions false filesize: (post) -> @@ -163,7 +163,7 @@ Filter = return post.file.size false MD5: (post) -> - if post.file + if post.file?.MD5 return post.file.MD5 false diff --git a/src/General/html/Settings/Advanced.html b/src/General/html/Settings/Advanced.html index 520da1d4f..f1f2e3347 100755 --- a/src/General/html/Settings/Advanced.html +++ b/src/General/html/Settings/Advanced.html @@ -59,8 +59,8 @@
File Info Formatting is disabled.
:
-
Link: %l (truncated), %L (untruncated), %T (Unix timestamp)
-
Original file name: %n (truncated), %N (untruncated), %t (Unix timestamp)
+
Link: %l (truncated), %L (untruncated), %T (4chan filename)
+
Filename: %n (truncated), %N (untruncated), %t (4chan filename)
Spoiler indicator: %p
Size: %B (Bytes), %K (KB), %M (MB), %s (4chan default)
Resolution: %r (Displays 'PDF' for PDF files)
diff --git a/src/General/lib/clone.class b/src/General/lib/clone.class index 4ae25630b..f0c42ecbf 100755 --- a/src/General/lib/clone.class +++ b/src/General/lib/clone.class @@ -65,7 +65,7 @@ class Clone extends Post @file.thumb.muted = true if @file.videoThumb # Contract thumbnails in quote preview - ImageExpand.contract @ if contractThumb + ImageExpand.contract @ if @file.thumb and contractThumb @isDead = true if @origin.isDead @isClone = true diff --git a/src/General/lib/post.class b/src/General/lib/post.class index de206d2d7..604eab51a 100755 --- a/src/General/lib/post.class +++ b/src/General/lib/post.class @@ -163,29 +163,29 @@ class Post @quotes.push fullID unless fullID in @quotes parseFile: -> - return unless (fileEl = $ '.file', @nodes.post) and thumb = $ 'img[data-md5]', fileEl - # Supports JPG/PNG/GIF/PDF. - # Flash files are not supported. - anchor = thumb.parentNode + return unless (fileEl = $ '.file', @nodes.post) and not $('.fileDeletedRes', fileEl) fileText = fileEl.firstElementChild - @file = - text: fileText - thumb: thumb - URL: anchor.href - size: thumb.alt.match(/[\d.]+\s\w+/)[0] - MD5: thumb.dataset.md5 - isSpoiler: $.hasClass anchor, 'imgspoiler' + link = $ 'a', fileText + info = link.nextSibling.textContent + @file = + text: fileText + link: link + URL: link.href + name: fileText.title or link.title or link.textContent + size: info.match(/[\d.]+\s\w+/)[0] + isImage: /(jpg|png|gif)$/i.test link.href + isVideo: /webm$/i.test link.href + dimensions: info.match(/\d+x\d+/)?[0] size = +@file.size.match(/[\d.]+/)[0] unit = ['B', 'KB', 'MB', 'GB'].indexOf @file.size.match(/\w+$/)[0] size *= 1024 while unit-- > 0 @file.sizeInBytes = size - @file.thumbURL = "#{location.protocol}//i.4cdn.org/#{@board}/#{@file.URL.match(/(\d+)\./)[1]}s.jpg" - @file.isImage = /(jpg|png|gif)$/i.test @file.URL - @file.isVideo = /webm$/i.test @file.URL - nameNode = $ 'a', fileText - if @file.isImage or @file.isVideo - @file.dimensions = nameNode.nextSibling.textContent.match(/\d+x\d+/)[0] - @file.name = fileText.title or nameNode.title or nameNode.textContent + if (thumb = $ 'img[data-md5]', fileEl) + $.extend @file, + thumb: thumb + thumbURL: "#{location.protocol}//i.4cdn.org/#{@board}/#{link.href.match(/(\d+)\./)[1]}s.jpg" + MD5: thumb.dataset.md5 + isSpoiler: $.hasClass thumb.parentNode, 'imgspoiler' kill: (file) -> if file diff --git a/src/Images/Gallery.coffee b/src/Images/Gallery.coffee index 64808fdc1..49a591e0b 100644 --- a/src/Images/Gallery.coffee +++ b/src/Images/Gallery.coffee @@ -20,7 +20,7 @@ Gallery = cb: @node node: -> - return unless @file + return unless @file?.thumb if Gallery.nodes Gallery.generateThumb @ Gallery.nodes.total.textContent = Gallery.images.length @@ -82,7 +82,7 @@ Gallery = for file in $$ '.post .file' post = Get.postFromNode file - continue unless post.file + continue unless post.file?.thumb Gallery.generateThumb post # If no image to open is given, pick image we have scrolled to. if !image and Gallery.fullIDs[post.fullID] @@ -105,7 +105,7 @@ Gallery = generateThumb: (post) -> return if post.isClone or post.isHidden - return unless post.file and (post.file.isImage or post.file.isVideo or Conf['PDF in Gallery']) + return unless post.file and post.file.thumb and (post.file.isImage or post.file.isVideo or Conf['PDF in Gallery']) return if Gallery.fullIDs[post.fullID] Gallery.fullIDs[post.fullID] = true diff --git a/src/Images/RevealSpoilers.coffee b/src/Images/RevealSpoilers.coffee index bfe88de21..4c3e65709 100755 --- a/src/Images/RevealSpoilers.coffee +++ b/src/Images/RevealSpoilers.coffee @@ -7,7 +7,7 @@ RevealSpoilers = cb: @node node: -> - return if @isClone or !@file?.isSpoiler + return unless not @isClone and @file and @file.thumb and @file.isSpoiler {thumb} = @file # Remove old width and height. thumb.removeAttribute 'style' diff --git a/src/Images/Sauce.coffee b/src/Images/Sauce.coffee index ab46e2aa5..067372f21 100755 --- a/src/Images/Sauce.coffee +++ b/src/Images/Sauce.coffee @@ -23,6 +23,7 @@ Sauce = m = part.match /^(\w*):(.*)$/ parts[m[1]] = m[2] parts['text'] or= parts['url'].match(/(\w+)\.\w+\//)?[1] or '?' + skip = false for key of parts parts[key] = parts[key].replace /%(T?URL|MD5|board|name|%|semi)/g, (parameter) -> type = { @@ -34,10 +35,14 @@ Sauce = '%%': '%' '%semi': ';' }[parameter] + if not type? + skip = true + return '' if key is 'url' and parameter isnt '%%' and parameter isnt '%semi' type = JSON.stringify type if /^javascript:/i.test parts['url'] type = encodeURIComponent type type + return null if skip ext = post.file.URL.match(/\.([^\.]*)$/)?[1] or '' return null unless !parts['boards'] or post.board.ID in parts['boards'].split ',' return null unless !parts['types'] or ext in parts['types'].split ',' diff --git a/src/Miscellaneous/FileInfo.coffee b/src/Miscellaneous/FileInfo.coffee index 1aa868c03..a14a1125a 100755 --- a/src/Miscellaneous/FileInfo.coffee +++ b/src/Miscellaneous/FileInfo.coffee @@ -7,8 +7,11 @@ FileInfo = cb: @node node: -> return if !@file or @isClone - $.extend @file.text, <%= html('') %> - FileInfo.format Conf['fileInfo'], @, @file.text.firstElementChild + @file.link.hidden = true + @file.link.previousSibling.nodeValue = @file.link.nextSibling.nodeValue = '' + info = $.el 'span', className: 'file-info' + $.after @file.link.nextSibling, info + FileInfo.format Conf['fileInfo'], @, info format: (formatString, post, outputNode) -> output = [] formatString.replace /%(.)|[^%]+/g, (s, c) -> @@ -19,7 +22,7 @@ FileInfo = '' $.extend outputNode, <%= html('@{output}') %> formatters: - t: -> <%= html('${this.file.URL.match(/\\d+\\..+$/)[0]}') %> + t: -> <%= html('${this.file.URL.match(/[^\/]*$/)[0]}') %> T: -> <%= html('&{FileInfo.formatters.t.call(this)}') %> l: -> <%= html('&{FileInfo.formatters.n.call(this)}') %> L: -> <%= html('&{FileInfo.formatters.N.call(this)}') %> diff --git a/src/Monitoring/ThreadStats.coffee b/src/Monitoring/ThreadStats.coffee index ed895ba2c..3b56bd949 100755 --- a/src/Monitoring/ThreadStats.coffee +++ b/src/Monitoring/ThreadStats.coffee @@ -38,7 +38,6 @@ ThreadStats = node: -> postCount = 0 fileCount = 0 - fileCount++ if @board.ID is 'f' @posts.forEach (post) -> postCount++ fileCount++ if post.file diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index 0ff209342..3e31bdbfc 100755 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -70,7 +70,6 @@ ThreadUpdater = # as posts may be `kill`ed elsewhere. ThreadUpdater.postIDs = [] ThreadUpdater.fileIDs = [] - ThreadUpdater.fileIDs.push @ID if @board.ID is 'f' @posts.forEach (post) -> ThreadUpdater.postIDs.push post.ID ThreadUpdater.fileIDs.push post.ID if post.file