@gudhub/core 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GUDHUB/AppProcessor/AppProcessor.js +4 -13
- package/GUDHUB/Auth/Auth.js +0 -18
- package/GUDHUB/Auth/Auth.test.js +1 -11
- package/GUDHUB/ChunksManager/ChunksManager.js +1 -1
- package/GUDHUB/DataService/AppDataService.js +5 -0
- package/GUDHUB/DataService/CacheAPI/index.js +1 -0
- package/GUDHUB/DataService/ChunkDataService.js +5 -0
- package/GUDHUB/DataService/DataService.js +1 -0
- package/GUDHUB/DataService/IndexedDB/IndexedDBAppService.js +98 -0
- package/GUDHUB/{ChunksManager/DataService/IndexedDBCacheService.js → DataService/IndexedDB/IndexedDBChunkService.js} +30 -21
- package/GUDHUB/DataService/IndexedDB/IndexedDBService.js +7 -0
- package/GUDHUB/DataService/IndexedDB/appDataConf.js +7 -0
- package/GUDHUB/DataService/IndexedDB/chunkDataConf.js +7 -0
- package/GUDHUB/DataService/IndexedDB/consts.js +2 -0
- package/GUDHUB/DataService/IndexedDB/init.js +21 -0
- package/GUDHUB/DataService/export.js +48 -0
- package/GUDHUB/DataService/httpService/AppHttpService.js +31 -0
- package/GUDHUB/DataService/httpService/ChunkHttpService.js +32 -0
- package/GUDHUB/DataService/httpService/HttpService.js +1 -0
- package/GUDHUB/DataService/utils.js +34 -0
- package/GUDHUB/api/AppApi.js +14 -0
- package/GUDHUB/config.js +3 -0
- package/GUDHUB/gudhub.js +6 -19
- package/package.json +1 -1
- package/umd/library.min.js +42 -15
- package/umd/library.min.js.map +1 -1
- package/GUDHUB/ChunksManager/DataService/export.js +0 -13
- package/GUDHUB/ChunksManager/DataService/httpDataService.js +0 -21
- /package/GUDHUB/{ChunksManager → api}/ChunkApi.js +0 -0
|
@@ -8,7 +8,8 @@ export class AppProcessor {
|
|
|
8
8
|
websocket,
|
|
9
9
|
chunksManager,
|
|
10
10
|
util,
|
|
11
|
-
activateSW
|
|
11
|
+
activateSW,
|
|
12
|
+
dataService,
|
|
12
13
|
) {
|
|
13
14
|
this.storage = storage;
|
|
14
15
|
this.pipeService = pipeService;
|
|
@@ -19,6 +20,7 @@ export class AppProcessor {
|
|
|
19
20
|
this.chunksManager = chunksManager;
|
|
20
21
|
this.util = util;
|
|
21
22
|
this.appListeners();
|
|
23
|
+
this.dataService = dataService;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
async createNewAppApi(app) {
|
|
@@ -77,18 +79,7 @@ export class AppProcessor {
|
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
async getAppApi(app_id) {
|
|
80
|
-
|
|
81
|
-
const response = await this.req.get({
|
|
82
|
-
url: "/api/app/get",
|
|
83
|
-
params: {
|
|
84
|
-
app_id: app_id,
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
return response;
|
|
88
|
-
} catch (err) {
|
|
89
|
-
console.log(err);
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
82
|
+
return this.dataService.getApp(app_id);
|
|
92
83
|
}
|
|
93
84
|
|
|
94
85
|
getAppListFromStorage() {
|
package/GUDHUB/Auth/Auth.js
CHANGED
|
@@ -10,12 +10,6 @@ export class Auth {
|
|
|
10
10
|
return user;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
async loginWithToken(token) {
|
|
14
|
-
const user = await this.loginWithTokenApi(token);
|
|
15
|
-
this.storage.updateUser(user);
|
|
16
|
-
return user;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
13
|
async logout(token) {
|
|
20
14
|
const response = await this.logoutApi(token);
|
|
21
15
|
return response;
|
|
@@ -64,18 +58,6 @@ export class Auth {
|
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
60
|
|
|
67
|
-
async loginWithTokenApi(token) {
|
|
68
|
-
try {
|
|
69
|
-
const user = await this.req.axiosRequest({
|
|
70
|
-
method: 'POST',
|
|
71
|
-
url: `${this.req.root}/auth/login?accesstoken=${token}`
|
|
72
|
-
});
|
|
73
|
-
return user;
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.log(error);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
61
|
async updateTokenApi(auth_key) {
|
|
80
62
|
try {
|
|
81
63
|
const user = await this.req.axiosRequest({
|
package/GUDHUB/Auth/Auth.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import should from "should";
|
|
2
2
|
import {GudHub} from './../gudhub.js';
|
|
3
3
|
|
|
4
4
|
describe("AUTHORIZATION", async function() {
|
|
@@ -22,16 +22,6 @@ describe("AUTHORIZATION", async function() {
|
|
|
22
22
|
user.fullname.should.equal('Vasya Pupkin');
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
it("Authentication with access token", async function () {
|
|
26
|
-
const gudhub = new GudHub();
|
|
27
|
-
|
|
28
|
-
const token = 'accesstoken';
|
|
29
|
-
|
|
30
|
-
const user = await gudhub.loginWithToken(token);
|
|
31
|
-
|
|
32
|
-
user.hasOwnProperty('fullname').should.equal(true);
|
|
33
|
-
})
|
|
34
|
-
|
|
35
25
|
it("Signing up user", async function () {
|
|
36
26
|
const gudhub = new GudHub();
|
|
37
27
|
let credentials = {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//TODO later if Cache API will be used
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class DataService {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { AppDataService } from "../AppDataService.js";
|
|
2
|
+
import { ChunkCacheDataService, ChunkDataService } from "../ChunkDataService.js";
|
|
3
|
+
import { AppHttpService } from "../httpService/AppHttpService.js";
|
|
4
|
+
import { objectAssignWithOverride } from "../utils.js";
|
|
5
|
+
import { IndexedDBService } from "./IndexedDBService.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
//this should be global in project
|
|
9
|
+
// class IndexedDBFacade extends CacheService {
|
|
10
|
+
|
|
11
|
+
// }
|
|
12
|
+
|
|
13
|
+
export class IndexedDBAppService extends AppDataService {
|
|
14
|
+
constructor(req, conf) {
|
|
15
|
+
super(req, conf);
|
|
16
|
+
|
|
17
|
+
this.dataService = new AppHttpService(req);
|
|
18
|
+
|
|
19
|
+
let indexDBService = new IndexedDBService(conf);
|
|
20
|
+
|
|
21
|
+
objectAssignWithOverride(this, indexDBService);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
static [Symbol.hasInstance](instance) {
|
|
26
|
+
if (instance instanceof IndexedDBService) return true;
|
|
27
|
+
if (instance.chunkDataService instanceof IndexedDBAppService) return true;
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//TODO use IndexedDBFacade here
|
|
32
|
+
// indexDBAccess = new IndexedDBFacade;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
async getApp(id) {
|
|
36
|
+
let dataServiceRequest = this.dataService.getApp(id);
|
|
37
|
+
|
|
38
|
+
dataServiceRequest.then(data => this.putApp(id, data));
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const db = await this.openDatabase();
|
|
42
|
+
const transaction = db.transaction(this.store, "readonly");
|
|
43
|
+
const store = transaction.objectStore(this.store);
|
|
44
|
+
|
|
45
|
+
const storeRequest = store.get(id);
|
|
46
|
+
|
|
47
|
+
return await new Promise((resolve, reject) => {
|
|
48
|
+
storeRequest.onsuccess = (e) => {
|
|
49
|
+
|
|
50
|
+
let cachedData = e.target.result;
|
|
51
|
+
|
|
52
|
+
if (
|
|
53
|
+
!cachedData
|
|
54
|
+
) {
|
|
55
|
+
reject();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (
|
|
59
|
+
cachedData
|
|
60
|
+
) {
|
|
61
|
+
|
|
62
|
+
resolve(cachedData);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
storeRequest.onerror = reject
|
|
67
|
+
});
|
|
68
|
+
} catch(e) {
|
|
69
|
+
return dataServiceRequest;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async putApp(id, data) {
|
|
74
|
+
try {
|
|
75
|
+
const db = await this.openDatabase();
|
|
76
|
+
|
|
77
|
+
const transaction = db.transaction(this.store, "readwrite");
|
|
78
|
+
const store = transaction.objectStore(this.store);
|
|
79
|
+
|
|
80
|
+
store.put(data, id);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async openDatabase() {
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
const request = indexedDB.open(this.dbName, this.dbVersion);
|
|
89
|
+
|
|
90
|
+
request.onsuccess = event => {
|
|
91
|
+
resolve(event.target.result);
|
|
92
|
+
};
|
|
93
|
+
request.onerror = event => {
|
|
94
|
+
reject(event.target.error);
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChunkCacheDataService, ChunkDataService } from "../ChunkDataService.js";
|
|
2
|
+
import { ChunkHttpService } from "../httpService/ChunkHttpService.js";
|
|
3
|
+
import { objectAssignWithOverride } from "../utils.js";
|
|
4
|
+
import { IndexedDBService } from "./IndexedDBService.js";
|
|
2
5
|
|
|
3
6
|
|
|
4
7
|
//this should be global in project
|
|
@@ -8,34 +11,43 @@ import { ChunkDataService, HttpDataService } from "./httpDataService.js";
|
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
|
|
11
|
-
class ChunkCachedDataService extends ChunkDataService {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
+
// class ChunkCachedDataService extends ChunkDataService {
|
|
15
|
+
// dataService;
|
|
16
|
+
// }
|
|
14
17
|
|
|
15
18
|
|
|
16
|
-
export class
|
|
17
|
-
constructor(req) {
|
|
18
|
-
super();
|
|
19
|
+
export class IndexedDBChunkService extends ChunkDataService {
|
|
20
|
+
constructor(req, conf) {
|
|
21
|
+
super(req, conf);
|
|
19
22
|
|
|
20
|
-
this.dataService = new
|
|
21
|
-
}
|
|
23
|
+
this.dataService = new ChunkHttpService(req);
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
DatabaseName = "my-cache-db";
|
|
26
|
-
DatabaseVersion = 1;
|
|
26
|
+
let indexDBService = new IndexedDBService(conf);
|
|
27
27
|
|
|
28
|
+
objectAssignWithOverride(this, indexDBService);
|
|
29
|
+
}
|
|
28
30
|
|
|
29
31
|
//TODO use IndexedDBFacade here
|
|
30
32
|
// indexDBAccess = new IndexedDBFacade;
|
|
31
33
|
|
|
32
34
|
|
|
35
|
+
|
|
36
|
+
static [Symbol.hasInstance](instance) {
|
|
37
|
+
if (instance instanceof IndexedDBService) return true;
|
|
38
|
+
if (instance.chunkDataService instanceof IndexedDBChunkService) return true;
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
33
45
|
async putChunk(id, data) {
|
|
34
46
|
try {
|
|
35
47
|
const db = await this.openDatabase();
|
|
36
48
|
|
|
37
|
-
const transaction = db.transaction(this.
|
|
38
|
-
const store = transaction.objectStore(this.
|
|
49
|
+
const transaction = db.transaction(this.store, "readwrite");
|
|
50
|
+
const store = transaction.objectStore(this.store);
|
|
39
51
|
|
|
40
52
|
store.put(data, id);
|
|
41
53
|
} catch (error) {
|
|
@@ -47,8 +59,8 @@ export class IndexedDBChunkCacheService extends ChunkCachedDataService {
|
|
|
47
59
|
async getChunk(app_id, id) {
|
|
48
60
|
try {
|
|
49
61
|
const db = await this.openDatabase();
|
|
50
|
-
const transaction = db.transaction(this.
|
|
51
|
-
const store = transaction.objectStore(this.
|
|
62
|
+
const transaction = db.transaction(this.store, "readonly");
|
|
63
|
+
const store = transaction.objectStore(this.store);
|
|
52
64
|
|
|
53
65
|
const storeRequest = store.get(id);
|
|
54
66
|
|
|
@@ -85,11 +97,8 @@ export class IndexedDBChunkCacheService extends ChunkCachedDataService {
|
|
|
85
97
|
|
|
86
98
|
async openDatabase() {
|
|
87
99
|
return new Promise((resolve, reject) => {
|
|
88
|
-
const request = indexedDB.open(this.
|
|
89
|
-
|
|
90
|
-
const db = event.target.result;
|
|
91
|
-
db.createObjectStore(this.OBJECT_STORE);
|
|
92
|
-
};
|
|
100
|
+
const request = indexedDB.open(this.dbName, this.dbVersion);
|
|
101
|
+
|
|
93
102
|
request.onsuccess = event => {
|
|
94
103
|
resolve(event.target.result);
|
|
95
104
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IS_WEB } from "../../consts.js";
|
|
2
|
+
import { appsConf } from "./appDataConf.js";
|
|
3
|
+
import { chunksConf } from "./chunkDataConf.js";
|
|
4
|
+
import { dbName, dbVersion } from "./consts.js";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
if (
|
|
8
|
+
IS_WEB
|
|
9
|
+
) {
|
|
10
|
+
const request = indexedDB.open(dbName, dbVersion);
|
|
11
|
+
|
|
12
|
+
request.onupgradeneeded = event => {
|
|
13
|
+
const db = event.target.result;
|
|
14
|
+
|
|
15
|
+
for (let store of [appsConf.store, chunksConf.store]) {
|
|
16
|
+
if (!db.objectStoreNames.contains(store)) {
|
|
17
|
+
db.createObjectStore(store);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { cache_app_requests, cache_chunk_requests } from "../config.js";
|
|
2
|
+
import { IS_WEB } from "../consts.js";
|
|
3
|
+
import { IndexedDBAppService } from "./IndexedDB/IndexedDBAppService.js";
|
|
4
|
+
import { IndexedDBChunkService } from "./IndexedDB/IndexedDBChunkService.js";
|
|
5
|
+
import { appsConf } from "./IndexedDB/appDataConf.js";
|
|
6
|
+
import { chunksConf } from "./IndexedDB/chunkDataConf.js";
|
|
7
|
+
import { AppHttpService } from "./httpService/AppHttpService.js";
|
|
8
|
+
import { ChunkHttpService } from "./httpService/ChunkHttpService.js";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
import "./IndexedDB/init.js";
|
|
12
|
+
|
|
13
|
+
let AppDataService;
|
|
14
|
+
let ChunkDataService;
|
|
15
|
+
|
|
16
|
+
let appDataServiceConf;
|
|
17
|
+
let chunkDataServiceConf;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
IS_WEB &&
|
|
22
|
+
cache_chunk_requests
|
|
23
|
+
) {
|
|
24
|
+
ChunkDataService = IndexedDBChunkService;
|
|
25
|
+
chunkDataServiceConf = chunksConf;
|
|
26
|
+
|
|
27
|
+
} else {
|
|
28
|
+
ChunkDataService = ChunkHttpService;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
IS_WEB &&
|
|
34
|
+
cache_app_requests
|
|
35
|
+
) {
|
|
36
|
+
AppDataService = IndexedDBAppService;
|
|
37
|
+
appDataServiceConf = appsConf;
|
|
38
|
+
} else {
|
|
39
|
+
AppDataService = AppHttpService;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export {
|
|
44
|
+
AppDataService,
|
|
45
|
+
ChunkDataService,
|
|
46
|
+
appDataServiceConf,
|
|
47
|
+
chunkDataServiceConf,
|
|
48
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AppAPI } from "../../api/AppApi.js";
|
|
2
|
+
import { AppDataService } from "../AppDataService.js";
|
|
3
|
+
import { objectAssignWithOverride } from "../utils.js";
|
|
4
|
+
import { HttpService } from "./HttpService.js";
|
|
5
|
+
|
|
6
|
+
export class AppHttpService extends AppDataService {
|
|
7
|
+
constructor(req, conf) {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.appApi = new AppAPI(req);
|
|
11
|
+
|
|
12
|
+
let indexDBService = new HttpService(conf);
|
|
13
|
+
|
|
14
|
+
objectAssignWithOverride(this, indexDBService);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async getApp(id) {
|
|
19
|
+
return this.appApi.getApp(id);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async putApp(id, app) {
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static [Symbol.hasInstance](instance) {
|
|
27
|
+
if (instance instanceof AppHttpService) return true;
|
|
28
|
+
if (instance.chunkDataService instanceof HttpService) return true;
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ChunkAPI } from "../../api/ChunkApi.js";
|
|
2
|
+
import { ChunkDataService } from "../ChunkDataService.js";
|
|
3
|
+
import { objectAssignWithOverride } from "../utils.js";
|
|
4
|
+
import { HttpService } from "./HttpService.js";
|
|
5
|
+
|
|
6
|
+
export class ChunkHttpService extends ChunkDataService {
|
|
7
|
+
constructor(req, conf) {
|
|
8
|
+
super();
|
|
9
|
+
|
|
10
|
+
this.chunkApi = new ChunkAPI(req);
|
|
11
|
+
|
|
12
|
+
let indexDBService = new HttpService(conf);
|
|
13
|
+
|
|
14
|
+
objectAssignWithOverride(this, indexDBService);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getChunk(app_id, id) {
|
|
18
|
+
return this.chunkApi.getChunk(app_id, id);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
putChunk() {
|
|
23
|
+
//do nothing
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
static [Symbol.hasInstance](instance) {
|
|
28
|
+
if (instance instanceof ChunkHttpService) return true;
|
|
29
|
+
if (instance.chunkDataService instanceof HttpService) return true;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class HttpService {}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
export let objectAssignWithoutOverride = (target, ...sourceList) => {
|
|
3
|
+
for (let source of sourceList) {
|
|
4
|
+
if (!source) continue;
|
|
5
|
+
for(let key of Object.keys(source)) {//this doesnt iterate over class like source properties
|
|
6
|
+
if (!(key in target)) {//checks own and inherited keys, works fine also for class prototypes and instances
|
|
7
|
+
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
8
|
+
if (desc.enumerable) Object.defineProperty(target, key, desc);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export let objectAssignWithOverride = (target, ...sourceList) => {
|
|
15
|
+
for (let source of sourceList) {
|
|
16
|
+
if (!source) continue;
|
|
17
|
+
for(let key of Object.keys(source)) {//this doesnt iterate over class like source properties
|
|
18
|
+
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
19
|
+
if (desc.enumerable) Object.defineProperty(target, key, desc);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export let checkInstanceModifier = (target, ...sourceList) => {
|
|
27
|
+
for (let source of sourceList) {
|
|
28
|
+
if (!source) continue;
|
|
29
|
+
for(let key of Object.keys(source)) {//this doesnt iterate over class like source properties
|
|
30
|
+
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
31
|
+
if (desc.enumerable) Object.defineProperty(target, key, desc);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
package/GUDHUB/config.js
CHANGED
|
@@ -8,5 +8,8 @@ export const async_modules_path = 'build/latest/async_modules_node/';
|
|
|
8
8
|
export const automation_modules_path = 'build/latest/automation_modules/'
|
|
9
9
|
export const file_server_url = 'https://gudhub.com'
|
|
10
10
|
|
|
11
|
+
export const cache_chunk_requests = true;
|
|
12
|
+
export const cache_app_requests = true;
|
|
13
|
+
|
|
11
14
|
// FOR TESTS
|
|
12
15
|
export const port = 9000;
|
package/GUDHUB/gudhub.js
CHANGED
|
@@ -18,7 +18,7 @@ import { WebsocketHandler } from './WebSocket/WebsocketHandler.js';
|
|
|
18
18
|
import { GroupSharing } from './Utils/sharing/GroupSharing.js';
|
|
19
19
|
import { Sharing } from './Utils/sharing/Sharing.js';
|
|
20
20
|
import { WebSocketEmitter } from './WebSocket/WebSocketEmitter.js';
|
|
21
|
-
import {
|
|
21
|
+
import { AppDataService, ChunkDataService, appDataServiceConf, chunkDataServiceConf } from "./DataService/export.js";
|
|
22
22
|
|
|
23
23
|
export class GudHub {
|
|
24
24
|
constructor(
|
|
@@ -32,9 +32,7 @@ export class GudHub {
|
|
|
32
32
|
swLink: "",
|
|
33
33
|
async_modules_path,
|
|
34
34
|
file_server_url,
|
|
35
|
-
automation_modules_path
|
|
36
|
-
accesstoken: this.accesstoken,
|
|
37
|
-
expirydate: this.expirydate
|
|
35
|
+
automation_modules_path
|
|
38
36
|
}
|
|
39
37
|
) {
|
|
40
38
|
this.config = options;
|
|
@@ -47,15 +45,7 @@ export class GudHub {
|
|
|
47
45
|
this.auth = new Auth(this.req, this.storage);
|
|
48
46
|
this.sharing = new Sharing(this, this.req);
|
|
49
47
|
this.groupSharing = new GroupSharing(this, this.req, this.pipeService);
|
|
50
|
-
|
|
51
|
-
// Login with access token - pass to setUser access token and after it user can make requests with access token
|
|
52
|
-
// This method created for optimize GudHub initialization without auth key
|
|
53
|
-
if (authKey) {
|
|
54
|
-
this.storage.setUser({ auth_key: authKey })
|
|
55
|
-
} else if(options.accesstoken && options.expirydate) {
|
|
56
|
-
this.storage.setUser({accesstoken: options.accesstoken, expirydate: options.expirydate})
|
|
57
|
-
}
|
|
58
|
-
|
|
48
|
+
if (authKey) this.storage.setUser({ auth_key: authKey });
|
|
59
49
|
this.req.init(this.auth.getToken.bind(this.auth));
|
|
60
50
|
|
|
61
51
|
this.ws = new WebSocketApi(options.wss_url, this.auth);
|
|
@@ -64,7 +54,7 @@ export class GudHub {
|
|
|
64
54
|
this.pipeService,
|
|
65
55
|
this.req,
|
|
66
56
|
this.util,
|
|
67
|
-
new
|
|
57
|
+
new ChunkDataService(this.req, chunkDataServiceConf),
|
|
68
58
|
);
|
|
69
59
|
this.appProcessor = new AppProcessor(
|
|
70
60
|
this.storage,
|
|
@@ -73,7 +63,8 @@ export class GudHub {
|
|
|
73
63
|
this.ws,
|
|
74
64
|
this.chunksManager,
|
|
75
65
|
this.util,
|
|
76
|
-
options.activateSW
|
|
66
|
+
options.activateSW,
|
|
67
|
+
new AppDataService(this.req, appDataServiceConf),
|
|
77
68
|
);
|
|
78
69
|
this.itemProcessor = new ItemProcessor(
|
|
79
70
|
this.storage,
|
|
@@ -454,10 +445,6 @@ export class GudHub {
|
|
|
454
445
|
return this.auth.login(data);
|
|
455
446
|
}
|
|
456
447
|
|
|
457
|
-
loginWithToken(token) {
|
|
458
|
-
return this.auth.loginWithToken(token);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
448
|
logout(token) {
|
|
462
449
|
this.appProcessor.clearAppProcessor();
|
|
463
450
|
return this.auth.logout(token);
|