Skip to content

Commit

Permalink
Unified file data representation
Browse files Browse the repository at this point in the history
Fixed thumbnail generation
  • Loading branch information
Colin Kuebler committed Nov 16, 2012
1 parent a7db482 commit df80666
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions app/FileBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ function FileBrowser(fs,defaultApps){
/* create the dom elements */
var container = document.createElement('li'),
icon = document.createElement('div'),
title = document.createElement('input'),
thumbnail = document.createElement('pre');
title = document.createElement('input');
/* set the icon image */
function updateThumb(){
var file = fs.read(id);
icon.innerHTML = '';
var thumbnail, file = fs.read(id);
if( filetype === 'text' && file.data !== '' ){
icon.className = '';
thumbnail = document.createElement('pre');
// get a 5x10 text preview
var data = file.data;
var previewLines = data.split('\n',5);
Expand All @@ -85,19 +85,21 @@ function FileBrowser(fs,defaultApps){
preview += previewLines[i].substr(0,10) + '\n';
thumbnail.innerText =
thumbnail.textContent = preview;
icon.className = '';
icon.appendChild( thumbnail );
} else if( filetype === 'image' ){
scaleImage( file.data, 48, 48, function(img){
scaleImage( 'data:' + file.type + ';base64,' + btoa(file.data), 48, 48, function(img){
thumbnail = new Image;
thumbnail.src = img;
thumbnail.draggable = false;
icon.className = 'blank';
icon.appendChild( thumbnail );
});
} else {
icon.className = filetype;
}
}
updateThumb();
icon.appendChild(thumbnail);

/* set the icon title */
title.type = 'text';
Expand Down Expand Up @@ -213,6 +215,7 @@ function FileBrowser(fs,defaultApps){
// filter out huge files (size in bytes)
if( file.size > 100*1024 )
return alert("FILE TOO BIG");
// TODO mimetype resolution and whitelist
// try to create a new file with the name and type
var id = fs.touch( dest, file.name, file.type );
// abort on failure
Expand All @@ -231,12 +234,7 @@ function FileBrowser(fs,defaultApps){
fs.remove(id);
};
// begin the upload, upload text documents as text
if( file.type.split('/',1)[0] === 'text' ||
file.type === 'application/javascript' ){
reader.readAsText(file);
} else {
reader.readAsDataURL(file);
}
reader.readAsBinaryString(file);
};

/* drop handler for uploads */
Expand Down

0 comments on commit df80666

Please sign in to comment.