This commit is contained in:
56
app/ayanova/src/api/locale.js
Normal file
56
app/ayanova/src/api/locale.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import config from "../utils/config";
|
||||
import api from "./apiutil";
|
||||
import has from "../utils/lodash/map";
|
||||
|
||||
/*
|
||||
Locale:
|
||||
Methods
|
||||
- This module is responsible for handling all localized text operations
|
||||
- It stores a local in memory cache of the keys and returns them from cache whenever possible
|
||||
- Method: Get keys one at a time or in an array
|
||||
- a method that accepts lt keys and returns their text
|
||||
- If a key is not in the cache here then it fetches it from the server
|
||||
- Method: pre-fetch / Cache keys
|
||||
- Used to pre-fetch a bunch of keys at once if necessary
|
||||
- A caller will call this with the list of keys it will need in advance, the ones that are not present in the cache will be fetched from the server and the cache populated
|
||||
- No text is actually returned at this point, it's just a pre-setup kind of thing to ensure better perf later
|
||||
- Method: Clear cache
|
||||
- Clear the local cache entirely
|
||||
|
||||
|
||||
*/
|
||||
|
||||
const lt = {};
|
||||
|
||||
export default {
|
||||
async Get(keys) {},
|
||||
async PreFetch(keys) {},
|
||||
ClearCache() {},
|
||||
async authenticate(login, password) {
|
||||
return fetch(config.apiUrl + "auth", {
|
||||
method: "post",
|
||||
mode: "cors",
|
||||
headers: {
|
||||
Accept: "application/json, text/plain, */*",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
login: login,
|
||||
password: password
|
||||
})
|
||||
})
|
||||
.then(api.status)
|
||||
.then(api.json)
|
||||
.then(processLogin)
|
||||
.then(() => {
|
||||
return Promise.resolve(true);
|
||||
}) //succeeded, nothing to return
|
||||
.catch(function(error) {
|
||||
processLogout();
|
||||
return Promise.reject(error);
|
||||
});
|
||||
},
|
||||
logout() {
|
||||
processLogout();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user