From e24f83d4c648698edea245aa56828a7648d2de5a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 26 Sep 2013 21:58:06 +0000 Subject: [PATCH] dont reupload files if already on server --- pandora/archive/models.py | 2 + static/js/uploadVideoDialog.js | 90 ++++++++++++++++++++-------------- 2 files changed, 56 insertions(+), 36 deletions(-) diff --git a/pandora/archive/models.py b/pandora/archive/models.py index f37c748f..f8d3fed3 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 e23f760c..7e344afa 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(); + } }); }); }