Parse /f/ files.

This commit is contained in:
ccd0 2015-03-14 17:50:37 -07:00
parent 80b1aecd21
commit d6f2d9492e
10 changed files with 38 additions and 32 deletions

View File

@ -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

View File

@ -59,8 +59,8 @@
<fieldset>
<legend>File Info Formatting <span class=warning data-feature='File Info Formatting'>is disabled.</span></legend>
<div><input name=fileInfo class=field spellcheck=false>: <span class='file-info file-info-preview'></span></div>
<div>Link: <code>%l</code> (truncated), <code>%L</code> (untruncated), <code>%T</code> (Unix timestamp)</div>
<div>Original file name: <code>%n</code> (truncated), <code>%N</code> (untruncated), <code>%t</code> (Unix timestamp)</div>
<div>Link: <code>%l</code> (truncated), <code>%L</code> (untruncated), <code>%T</code> (4chan filename)</div>
<div>Filename: <code>%n</code> (truncated), <code>%N</code> (untruncated), <code>%t</code> (4chan filename)</div>
<div>Spoiler indicator: <code>%p</code></div>
<div>Size: <code>%B</code> (Bytes), <code>%K</code> (KB), <code>%M</code> (MB), <code>%s</code> (4chan default)</div>
<div>Resolution: <code>%r</code> (Displays 'PDF' for PDF files)</div>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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 ','

View File

@ -7,8 +7,11 @@ FileInfo =
cb: @node
node: ->
return if !@file or @isClone
$.extend @file.text, <%= html('<span class="file-info"></span>') %>
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('<a href="${this.file.URL}" target="_blank">&{FileInfo.formatters.t.call(this)}</a>') %>
l: -> <%= html('<a href="${this.file.URL}" target="_blank">&{FileInfo.formatters.n.call(this)}</a>') %>
L: -> <%= html('<a href="${this.file.URL}" target="_blank">&{FileInfo.formatters.N.call(this)}</a>') %>

View File

@ -38,7 +38,6 @@ ThreadStats =
node: ->
postCount = 0
fileCount = 0
fileCount++ if @board.ID is 'f'
@posts.forEach (post) ->
postCount++
fileCount++ if post.file

View File

@ -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