fix sharing for newly uploaded or created files

This commit is contained in:
Robin Appelman 2012-09-26 13:24:41 +02:00
parent 2c00f8c850
commit cfbca40fbe
3 changed files with 17 additions and 9 deletions

View File

@ -66,8 +66,10 @@ if($source) {
$target=$dir.'/'.$filename;
$result=OC_Filesystem::file_put_contents($target, $sourceStream);
if($result) {
$mime=OC_Filesystem::getMimetype($target);
$eventSource->send('success', array('mime'=>$mime, 'size'=>OC_Filesystem::filesize($target)));
$meta = OC_FileCache::get($target);
$mime=$meta['mimetype'];
$id = OC_FileCache::getId($target);
$eventSource->send('success', array('mime'=>$mime, 'size'=>OC_Filesystem::filesize($target), 'id' => $id));
} else {
$eventSource->send('error', "Error while downloading ".$source. ' to '.$target);
}
@ -76,11 +78,15 @@ if($source) {
} else {
if($content) {
if(OC_Filesystem::file_put_contents($dir.'/'.$filename, $content)) {
OCP\JSON::success(array("data" => array('content'=>$content)));
$meta = OC_FileCache::get($dir.'/'.$filename);
$id = OC_FileCache::getId($dir.'/'.$filename);
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id)));
exit();
}
}elseif(OC_Files::newFile($dir, $filename, 'file')) {
OCP\JSON::success(array("data" => array('content'=>$content)));
$meta = OC_FileCache::get($dir.'/'.$filename);
$id = OC_FileCache::getId($dir.'/'.$filename);
OCP\JSON::success(array("data" => array('content'=>$content, 'id' => $id)));
exit();
}
}

View File

@ -50,7 +50,8 @@ if(strpos($dir, '..') === false) {
$target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]);
if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
$meta = OC_FileCache::get($target);
$result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'],'name'=>basename($target));
$id = OC_FileCache::getId($target);
$result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'], 'id'=>$id, 'name'=>basename($target));
}
}
OCP\JSON::encodedPrint($result);

View File

@ -336,7 +336,7 @@ $(document).ready(function() {
if(response[0] != undefined && response[0].status == 'success') {
var file=response[0];
delete uploadingFiles[file.name];
$('tr').filterAttr('data-file',file.name).data('mime',file.mime);
$('tr').filterAttr('data-file',file.name).data('mime',file.mime).data('id',file.id);
var size = $('tr').filterAttr('data-file',file.name).find('td.filesize').text();
if(size==t('files','Pending')){
$('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size);
@ -366,7 +366,7 @@ $(document).ready(function() {
if(response[0] != undefined && response[0].status == 'success') {
var file=response[0];
delete uploadingFiles[file.name];
$('tr').filterAttr('data-file',file.name).data('mime',file.mime);
$('tr').filterAttr('data-file',file.name).data('mime',file.mime).data('id',file.id);
var size = $('tr').filterAttr('data-file',file.name).find('td.filesize').text();
if(size==t('files','Pending')){
$('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size);
@ -512,7 +512,7 @@ $(document).ready(function() {
var date=new Date();
FileList.addFile(name,0,date,false,hidden);
var tr=$('tr').filterAttr('data-file',name);
tr.data('mime','text/plain');
tr.data('mime','text/plain').data('id',result.data.id);
getMimeIcon('text/plain',function(path){
tr.find('td.filename').attr('style','background-image:url('+path+')');
});
@ -560,11 +560,12 @@ $(document).ready(function() {
eventSource.listen('success',function(data){
var mime=data.mime;
var size=data.size;
var id=data.id;
$('#uploadprogressbar').fadeOut();
var date=new Date();
FileList.addFile(localName,size,date,false,hidden);
var tr=$('tr').filterAttr('data-file',localName);
tr.data('mime',mime);
tr.data('mime',mime).data('id',id);
getMimeIcon(mime,function(path){
tr.find('td.filename').attr('style','background-image:url('+path+')');
});