-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Théo mathieu
committed
Mar 20, 2016
1 parent
44aa8b3
commit a5bae25
Showing
5 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Collection from './Collection'; | ||
import Data from './Data'; | ||
|
||
export default function(name) { | ||
|
||
const Meteor = this; | ||
|
||
const collectionName = 'cfs.'+name+'.filerecord'; | ||
const setProperties = file => { | ||
const getStoreName = (params = {store: name}) => { | ||
return params.store; | ||
}; | ||
const getImageInfos = params => { | ||
if(!params || !params.store) return file.original || {}; | ||
return file.copies[params.store] || {}; | ||
}; | ||
const getType = params => { | ||
return getImageInfos(params).type; | ||
}; | ||
return { | ||
...file, | ||
url: params => { | ||
return Data.getUrl()+'/cfs/files/'+name+'/'+file._id+'?store='+getStoreName(params)+(Meteor._tokenIdSaved ? '&token='+btoa(JSON.stringify({authToken: Meteor._tokenIdSaved})) : ""); | ||
}, | ||
isImage: params => { | ||
const type = getType(params); | ||
return type && type.indexOf('image/')===0; | ||
}, | ||
isAudio: params => { | ||
const type = getType(params); | ||
return type && type.indexOf('audio/')===0; | ||
}, | ||
isVideo: params => { | ||
const type = getType(params); | ||
return type && type.indexOf('video/')===0; | ||
}, | ||
isUploaded: params => { | ||
return !!(getImageInfos(params).updatedAt); | ||
}, | ||
name: params => { | ||
return getImageInfos(params).name; | ||
}, | ||
extension: params => { | ||
const imageName = getImageInfos(params).name; | ||
if(!imageName) return; | ||
return imageName.substring(imageName.lastIndexOf('.')+1); | ||
}, | ||
size: params => { | ||
return getImageInfos(params).size; | ||
}, | ||
type: getType, | ||
updatedAt: params=>{ | ||
return getImageInfos(params).updatedAt; | ||
} | ||
} | ||
} | ||
|
||
return { | ||
find(selector, options) { | ||
const elems = Collection(collectionName).find(selector, options); | ||
return elems.map(elem=>{ | ||
return setProperties(elem); | ||
}); | ||
}, | ||
findOne(selector, options) { | ||
const elem = Collection(collectionName).findOne(selector, options); | ||
return elem && setProperties(elem); | ||
}, | ||
insert: Collection(collectionName).insert, | ||
update: Collection(collectionName).update, | ||
upsert: Collection(collectionName).upsert, | ||
remove: Collection(collectionName).remove | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters