Skip to content
This repository was archived by the owner on Jan 7, 2020. It is now read-only.

Commit afef34b

Browse files
Shankarhitman401
authored andcommitted
MAID-2373 Refactored web hosting manager (#317)
* feat/common_code: refactor web hosting manager Refactored web hosting manager to have common code as other example apps * feat/common_code: update common code Improved common code. * fix/minor_tweak: resolve minor issues Resolve minor typo and import issue.
1 parent 40044b1 commit afef34b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+738
-482
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import initialiser from './initialiser';
2+
import publicNames from './public_names';
3+
4+
export default {
5+
...initialiser,
6+
...publicNames,
7+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Action types common to application initialisation
3+
* - includes App Authorisation, Connecting to Network
4+
*/
5+
6+
export default {
7+
AUTHORISE_APP: 'AUTHORISE_APP',
8+
CONNECT_APP: 'CONNECT_APP',
9+
RECONNECT_APP: 'RECONNECT_APP',
10+
AUTHORISE_SHARE_MD: 'AUTHORISE_SHARE_MD',
11+
CONNECT_SHARE_MD: 'CONNECT_SHARE_MD',
12+
NET_STATUS_CHANGED: 'NET_STATUS_CHANGED',
13+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
CREATE_PUBLIC_NAME: 'CREATE_PUBLIC_NAME',
3+
FETCH_PUBLIC_NAMES: 'FETCH_PUBLIC_NAMES',
4+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import ACTION_TYPES from './action_types';
2+
import { requestAuth, requestSharedMDAuth, connect, connectWithSharedMd } from '../safe_comm/network';
3+
import CONSTANTS from '../constants';
4+
5+
const newNetStatusCallback = (dispatch) => {
6+
return function (state) {
7+
dispatch({
8+
type: ACTION_TYPES.NET_STATUS_CHANGED,
9+
payload: state
10+
});
11+
}
12+
};
13+
14+
const connectApp = (uri, dispatch) => ({
15+
type: ACTION_TYPES.CONNECT_APP,
16+
payload: connect(uri, newNetStatusCallback(dispatch)),
17+
});
18+
19+
const connectSharedMD = (app, uri, serviceToRegister) => ({
20+
type: ACTION_TYPES.CONNECT_SHARE_MD,
21+
payload: connectWithSharedMd(app, uri),
22+
});
23+
24+
/**
25+
* Send authorisation request to Authenticator
26+
*/
27+
export const authoriseApplication = () => ({
28+
type: ACTION_TYPES.AUTHORISE_APP,
29+
payload: requestAuth(),
30+
});
31+
32+
export const authoriseSharedMD = publicName => {
33+
return (dispatch, getState) => {
34+
const app = getState().initialiser.app;
35+
return dispatch({
36+
type: ACTION_TYPES.AUTHORISE_APP,
37+
payload: requestSharedMDAuth(app, publicName),
38+
})
39+
};
40+
};
41+
42+
export const receiveResponse = (uri) => {
43+
return function (dispatch, getState) {
44+
const initialiserState = getState().initialiser;
45+
const appStatus = initialiserState.appStatus;
46+
// handle app authorisation
47+
if (appStatus === CONSTANTS.APP_STATUS.AUTHORISED) {
48+
return dispatch(connectApp(uri, dispatch));
49+
}
50+
51+
// handle shared MD authorisation
52+
const sharedMDAuthStatus = initialiserState.sharedMDAuthStatus;
53+
if (sharedMDAuthStatus === CONSTANTS.APP_STATUS.AUTHORISED) {
54+
let app = initialiserState.app;
55+
return dispatch(connectSharedMD(app, uri));
56+
}
57+
};
58+
};
59+
60+
export const reconnectApplication = () => {
61+
return function (dispatch, getState) {
62+
const app = getState().initialiser.app;
63+
return dispatch({
64+
type: ACTION_TYPES.RECONNECT_APP,
65+
payload: reconnect(app)
66+
});
67+
};
68+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import ACTION_TYPES from './action_types';
2+
import { fetchPublicNames } from '../safe_comm/app';
3+
4+
export const newPublicName = name => {
5+
return (dispatch, getState) => {
6+
const app = getState().initialiser.app;
7+
return dispatch({
8+
type: ACTION_TYPES.CREATE_PUBLIC_NAME,
9+
payload: createPublicName(app, name),
10+
})
11+
};
12+
};
13+
14+
export const getPublicNamesList = () => {
15+
return (dispatch, getState) => {
16+
const app = getState().initialiser.app;
17+
return dispatch({
18+
type: ACTION_TYPES.FETCH_PUBLIC_NAMES,
19+
payload: fetchPublicNames(app),
20+
})
21+
};
22+
};
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import pkg from './package.json';
2+
3+
export default {
4+
TYPE_TAG: {
5+
DNS: 15001,
6+
WWW: 15002,
7+
},
8+
APP_INFO: {
9+
info: {
10+
id: pkg.identifier,
11+
scope: null,
12+
name: pkg.productName,
13+
vendor: pkg.author.name,
14+
},
15+
opt: {
16+
own_container: false,
17+
},
18+
permissions: {
19+
_public: [
20+
'Read',
21+
'Insert',
22+
'Update',
23+
'Delete',
24+
],
25+
_publicNames: [
26+
'Read',
27+
'Insert',
28+
'Update',
29+
'Delete',
30+
],
31+
},
32+
},
33+
APP_STATUS: {
34+
AUTHORISED: 'AUTHORISED',
35+
AUTHORISING: 'AUTHORISING',
36+
AUTHORISATION_FAILED: 'AUTHORISATION_FAILED',
37+
AUTHORISATION_DENIED: 'AUTHORISATION_DENIED',
38+
},
39+
ACCESS_CONTAINERS: {
40+
PUBLIC: '_public',
41+
PUBLIC_NAMES: '_publicNames',
42+
},
43+
NETWORK_STATE: {
44+
INIT: 'Init',
45+
CONNECTED: 'Connected',
46+
UNKNOWN: 'Unknown',
47+
DISCONNECTED: 'Disconnected',
48+
},
49+
SAFE_APP_ERROR_CODES: {
50+
ERR_AUTH_DENIED: -200,
51+
}
52+
};

example_common_js_app_utils/initialiser_action_types.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

example_common_js_app_utils/initialiser_actions.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

example_common_js_app_utils/network_interface_functions.js

Lines changed: 0 additions & 118 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "example_common_js_app_utils",
3+
"productName": "Example common js app utils",
4+
"version": "1.0.0",
5+
"description": "Application code common to all example apps",
6+
"identifier": "net.maidsafe.examples.examplecommonjs",
7+
"main": "main.js",
8+
"scripts": {
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"author": {
12+
"name": "MaidSafe",
13+
"email": "[email protected]",
14+
"url": "https://maidsafe.net"
15+
},
16+
"license": "ISC"
17+
}

0 commit comments

Comments
 (0)