dont reupload files if already on server

This commit is contained in:
j 2013-09-26 21:58:06 +00:00
parent 054d07fcf3
commit e24f83d4c6
2 changed files with 56 additions and 36 deletions

View file

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

View file

@ -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();
}
});
});
}