diff --git a/pandora/archive/models.py b/pandora/archive/models.py index f37c748f1..f8d3fed37 100644 --- a/pandora/archive/models.py +++ b/pandora/archive/models.py @@ -371,6 +371,8 @@ class File(models.Model): for key in self.PATH_INFO: data[key] = self.info.get(key) data['users'] = list(set([i['user'] for i in data['instances']])) + if 'item' in keys: + data['item'] = self.item.itemId if keys: for k in data.keys(): if k not in keys: diff --git a/static/js/uploadVideoDialog.js b/static/js/uploadVideoDialog.js index e23f760ca..7e344afaf 100644 --- a/static/js/uploadVideoDialog.js +++ b/static/js/uploadVideoDialog.js @@ -206,44 +206,62 @@ pandora.ui.uploadVideoDialog = function(data) { resetProgress(); $info.html(Ox._('Uploading {0}', [file.name])); Ox.oshash(file, function(oshash) { - pandora.api.addMedia({ - filename: file.name, - id: oshash, - item: pandora.site.itemRequiresVideo ? undefined : pandora.user.ui.item + pandora.api.findMedia({ + query: { + conditions: [{key: 'oshash', value: oshash}] + }, + keys: ['id', 'item', 'available'] }, function(result) { - var item = result.data.item; - pandora.$ui.upload = pandora.chunkupload({ - file: file, - url: '/api/upload/direct/', - data: { - id: oshash - } - }).bindEvent({ - done: function(data) { - if (data.progress == 1) { - Ox.Request.clearCache(); - if (pandora.user.ui.item == item && pandora.user.ui.itemView == 'media') { - pandora.$ui.item.reload(); - } else { - pandora.UI.set({ - item: item, - itemView: 'media' - }); + if ( + result.data.items.length === 0 + || !result.data.items[0].available + ) { + pandora.api.addMedia({ + filename: file.name, + id: oshash, + item: pandora.site.itemRequiresVideo ? undefined : pandora.user.ui.item + }, function(result) { + var item = result.data.item; + pandora.$ui.upload = pandora.chunkupload({ + file: file, + url: '/api/upload/direct/', + data: { + id: oshash } - that.close(); - } else { - $status.html(cancelled ? Ox._('Upload cancelled.') : Ox._('Upload failed.')); - !cancelled && pandora.api.log({ - text: data.responseText, - url: '/' + item, - line: 1 - }); - } - }, - progress: function(data) { - $progress.options({progress: data.progress || 0}); - } - }); + }).bindEvent({ + done: function(data) { + if (data.progress == 1) { + Ox.Request.clearCache(); + if (pandora.user.ui.item == item && pandora.user.ui.itemView == 'media') { + pandora.$ui.item.reload(); + } else { + pandora.UI.set({ + item: item, + itemView: 'media' + }); + } + that.close(); + } else { + $status.html(cancelled ? Ox._('Upload cancelled.') : Ox._('Upload failed.')); + !cancelled && pandora.api.log({ + text: data.responseText, + url: '/' + item, + line: 1 + }); + } + }, + progress: function(data) { + $progress.options({progress: data.progress || 0}); + } + }); + }); + } else { + pandora.UI.set({ + item: result.data.items[0].item, + itemView: 'media' + }); + that.close(); + } }); }); }