react-native-meteor
Advanced tools
Comparing version 1.0.0-beta21 to 1.0.0-beta22
{ | ||
"name": "react-native-meteor", | ||
"version": "1.0.0-beta21", | ||
"version": "1.0.0-beta22", | ||
"description": "Full Meteor Client for React Native", | ||
@@ -5,0 +5,0 @@ "main": "src/Meteor.js", |
@@ -1,17 +0,5 @@ | ||
[](https://badge.fury.io/gh/inProgress-team%2Freact-native-meteor) | ||
[](http://badge.fury.io/js/react-native-meteor) | ||
[](https://david-dm.org/inProgress-team/react-native-meteor) | ||
[](https://david-dm.org/inProgress-team/react-native-meteor#info=devDependencies) | ||
[![MIT][license-badge]][license] | ||
[![bitHound Score][bithound-badge]][bithound] | ||
# react-native-meteor [](https://www.npmjs.org/package/react-native-meteor) [](http://badge.fury.io/js/react-native-meteor) [](https://david-dm.org/inProgress-team/react-native-meteor) | ||
[bithound-badge]: https://www.bithound.io/github/inProgress-Team/react-native-meteor/badges/score.svg | ||
[bithound]: https://www.bithound.io/github/inProgress-Team/react-native-meteor | ||
[license-badge]: https://img.shields.io/dub/l/vibe-d.svg | ||
[license]: https://github.com/inProgress-team/react-native-meteor/blob/master/LICENSE | ||
Meteor-like methods for React Native. ! For old docs, see [v0.6.2 documentation](https://github.com/inProgress-team/react-native-meteor/tree/0.6.2) (classic ddp interface). | ||
# react-native-meteor | ||
Meteor-like methods for React Native. **Currently in v1.0.0-beta20** ! For old docs, see [v0.6.2 documentation](https://github.com/inProgress-team/react-native-meteor/tree/0.6.2) (classic ddp interface). | ||
## What is it for ? | ||
@@ -18,0 +6,0 @@ |
@@ -0,58 +1,27 @@ | ||
import EJSON from "ejson"; | ||
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; | ||
} | ||
EJSON.addType('FS.File', function(value) { | ||
return { | ||
getFileRecord() { | ||
const collection = Data.db['cfs.'+value.collectionName+'.filerecord']; | ||
const item = collection && collection.get(value._id); | ||
if(!item) return value; | ||
return setProperties(value.collectionName, item); | ||
} | ||
} | ||
}; | ||
}); | ||
export default function(name) { | ||
const collectionName = 'cfs.'+name+'.filerecord'; | ||
return { | ||
@@ -62,3 +31,3 @@ find(selector, options) { | ||
return elems.map(elem=>{ | ||
return setProperties(elem); | ||
return setProperties(name, elem); | ||
}); | ||
@@ -68,3 +37,3 @@ }, | ||
const elem = Collection(collectionName).findOne(selector, options); | ||
return elem && setProperties(elem); | ||
return elem && setProperties(name, elem); | ||
}, | ||
@@ -75,2 +44,58 @@ insert: Collection(collectionName).insert, | ||
}; | ||
} | ||
const setProperties = (name, 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 => { | ||
const token = Data._tokenIdSaved; | ||
return Data.getUrl()+'/cfs/files/'+name+'/'+file._id+'?store='+getStoreName(params)+(token ? '&token='+btoa(JSON.stringify({authToken: token})) : ""); | ||
}, | ||
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; | ||
} | ||
} | ||
} |
@@ -23,5 +23,5 @@ import { AsyncStorage } from 'react-native'; | ||
AsyncStorage.removeItem(TOKEN_KEY); | ||
this._tokenIdSaved = null; | ||
Data._tokenIdSaved = null; | ||
this._userIdSaved = null; | ||
this.connect(); | ||
@@ -74,3 +74,3 @@ | ||
AsyncStorage.setItem(TOKEN_KEY, result.token); | ||
this._tokenIdSaved = result.token; | ||
Data._tokenIdSaved = result.token; | ||
this._userIdSaved = result.id; | ||
@@ -82,3 +82,3 @@ } | ||
var value = await AsyncStorage.getItem(TOKEN_KEY); | ||
this._tokenIdSaved = value; | ||
Data._tokenIdSaved = value; | ||
if (value !== null){ | ||
@@ -85,0 +85,0 @@ this._startLoggingIn(); |
1093
44711
185