Upload files one at a time & fix encoding problems
This commit is contained in:
@@ -28,6 +28,8 @@ w = require 'when'
|
|||||||
|
|
||||||
module.exports = class ItemPageController extends PageController
|
module.exports = class ItemPageController extends PageController
|
||||||
|
|
||||||
|
FILE_UPLOAD_DELAY = 250
|
||||||
|
|
||||||
constructor: (options={})->
|
constructor: (options={})->
|
||||||
if not options.client? then throw new Error 'options.client is required'
|
if not options.client? then throw new Error 'options.client is required'
|
||||||
if not options.itemSlug? then throw new Error 'options.itemSlug is required'
|
if not options.itemSlug? then throw new Error 'options.itemSlug is required'
|
||||||
@@ -164,7 +166,7 @@ module.exports = class ItemPageController extends PageController
|
|||||||
@_descriptionFile = new EditableFile attributes, client:@client
|
@_descriptionFile = new EditableFile attributes, client:@client
|
||||||
@_descriptionFile.fetch()
|
@_descriptionFile.fetch()
|
||||||
.then =>
|
.then =>
|
||||||
if @_descriptionFile.encodedData.length > 0
|
if @_descriptionFile.encodedData?.length > 0
|
||||||
@model.item.parse @_descriptionFile.getDecodedData 'utf8'
|
@model.item.parse @_descriptionFile.getDecodedData 'utf8'
|
||||||
else
|
else
|
||||||
@model.item.description = ''
|
@model.item.description = ''
|
||||||
@@ -175,16 +177,27 @@ module.exports = class ItemPageController extends PageController
|
|||||||
oldDescription = @model.item.description
|
oldDescription = @model.item.description
|
||||||
promises = []
|
promises = []
|
||||||
|
|
||||||
commitMessage = "User-submitted image for #{@model.item.name} from #{global.hostName}"
|
saveList = []
|
||||||
for imageFile in @_descriptionController.imageFiles
|
for imageFile in @_descriptionController.imageFiles
|
||||||
promises.push imageFile.save commitMessage
|
saveList.push
|
||||||
|
file: imageFile
|
||||||
|
message: "User-submitted image for #{@model.item.name} from #{global.hostName}"
|
||||||
|
|
||||||
commitMessage = "User-submitted text for #{@model.item.name} from #{global.hostName}"
|
|
||||||
@model.item.description = @_descriptionController.model
|
@model.item.description = @_descriptionController.model
|
||||||
@_descriptionFile.setDecodedData @model.item.unparse()
|
@_descriptionFile.setDecodedData @model.item.unparse()
|
||||||
promises.push @_descriptionFile.save commitMessage
|
saveList.push
|
||||||
|
file: @_descriptionFile
|
||||||
|
message: "User-submitted text for #{@model.item.name} from #{global.hostName}"
|
||||||
|
|
||||||
w.all promises
|
saveNextFile = (fileList)->
|
||||||
|
return w(true) if fileList.length is 0
|
||||||
|
{file, message} = fileList.shift()
|
||||||
|
file.save message
|
||||||
|
.delay FILE_UPLOAD_DELAY
|
||||||
|
.then ->
|
||||||
|
saveNextFile fileList
|
||||||
|
|
||||||
|
saveNextFile saveList
|
||||||
.catch (e)=>
|
.catch (e)=>
|
||||||
@model.item.description = oldDescription
|
@model.item.description = oldDescription
|
||||||
throw e
|
throw e
|
||||||
|
|||||||
@@ -16,7 +16,8 @@
|
|||||||
.instructions
|
.instructions
|
||||||
p.
|
p.
|
||||||
Edit using <a href="https://help.github.com/articles/github-flavored-markdown/" target="new">GitHub
|
Edit using <a href="https://help.github.com/articles/github-flavored-markdown/" target="new">GitHub
|
||||||
Flavored Markdown</a>. Use <tt>[[Item Name]]</tt> to link to another item.
|
Flavored Markdown</a>. Use <tt>[[Item Name]]</tt> to link to another item and
|
||||||
|
<tt></tt> to add an image.
|
||||||
textarea
|
textarea
|
||||||
.sizer
|
.sizer
|
||||||
.image_list
|
.image_list
|
||||||
|
|||||||
Reference in New Issue
Block a user