-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
56 lines (51 loc) · 1.47 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// client side api for communicating with a familyfound server
var angular = require('angularjs')
, request = require('superagent')
, cookie = require('cookie')
, settings = require('settings')('ffapi')
, SessionCache = require('./lib/session')
, FFApi = require('./lib')
settings.config({
ffhome: {
value: '/',
title: 'FamilyFound URL',
description: 'the FamilyFound URL to use',
type: 'text'
},
cache: {
value: 'page',
title: 'Caching policy',
description: 'How should data be cached?',
type: 'select',
options: [['Page - until refresh', 'page'],
['Session - until browser restart', 'session'],
['No caching', 'none']]
}
})
angular.module('ffapi', [])
.factory('ffauthorize', function () {
return function (req) {
var sid = cookie('fssessionid')
if (sid) req.set('Authorization', 'Bearer ' + sid)
return req
}
})
.factory('ffapi', function (ffauthorize) {
return new FFApi(settings, new SessionCache(sessionStorage), ffauthorize)
})
.factory('ffperson', function (ffapi) {
var cache = {}
return function (personId, nocache, next) {
if (!next && typeof (nocache) == 'function') {
next = nocache
nocache = false
}
if (!nocache && cache[personId]) {
return next(cache[personId])
}
ffapi.get('person/' + personId, null, function (data) {
cache[personId] = data
return next(data)
})
}
})