@vocollege/app 0.0.58 → 0.0.59
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/dist/{types.d.ts → global.d.ts} +4 -0
- package/dist/{types.js → global.js} +0 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +9 -3
- package/dist/interceptor.js +14 -9
- package/dist/modules/Services/I18n/I18n.js +1 -1
- package/dist/modules/Services/I18n/strings.json +506 -25
- package/dist/modules/Services/Vapor/Vapor.js +3 -1
- package/dist/modules/VoApi/GraphClient.d.ts +3 -2
- package/dist/modules/VoApi/GraphClient.js +51 -13
- package/dist/modules/VoApi/VoApi.d.ts +4 -1
- package/dist/modules/VoApi/VoApi.js +18 -2
- package/dist/modules/VoApi/graphql.d.ts +5 -0
- package/dist/modules/VoApi/graphql.js +12 -3
- package/dist/modules/VoApi/index.js +5 -1
- package/dist/modules/VoApi/mutations/acl.js +5 -5
- package/dist/modules/VoApi/mutations/applications.d.ts +3 -0
- package/dist/modules/VoApi/mutations/applications.js +12 -0
- package/dist/modules/VoApi/mutations/articles.js +3 -3
- package/dist/modules/VoApi/mutations/books.d.ts +3 -0
- package/dist/modules/VoApi/mutations/books.js +12 -0
- package/dist/modules/VoApi/mutations/cards.js +3 -3
- package/dist/modules/VoApi/mutations/events.js +3 -3
- package/dist/modules/VoApi/mutations/navigation.js +3 -3
- package/dist/modules/VoApi/mutations/pages.js +3 -3
- package/dist/modules/VoApi/mutations/queues.js +3 -3
- package/dist/modules/VoApi/mutations/sections.js +3 -3
- package/dist/modules/VoApi/mutations/settings.js +1 -1
- package/dist/modules/VoApi/mutations/users.js +3 -3
- package/dist/modules/VoApi/mutations/vodocs.js +9 -9
- package/dist/modules/VoApi/mutations/vogroups.d.ts +1 -0
- package/dist/modules/VoApi/mutations/vogroups.js +10 -9
- package/dist/modules/VoApi/queries/acl.js +4 -4
- package/dist/modules/VoApi/queries/applications.d.ts +2 -0
- package/dist/modules/VoApi/queries/applications.js +11 -0
- package/dist/modules/VoApi/queries/articles.js +2 -2
- package/dist/modules/VoApi/queries/books.d.ts +4 -0
- package/dist/modules/VoApi/queries/books.js +13 -0
- package/dist/modules/VoApi/queries/cards.js +2 -2
- package/dist/modules/VoApi/queries/events.js +2 -2
- package/dist/modules/VoApi/queries/help.d.ts +1 -0
- package/dist/modules/VoApi/queries/help.js +11 -0
- package/dist/modules/VoApi/queries/navigation.js +4 -4
- package/dist/modules/VoApi/queries/pages.js +2 -2
- package/dist/modules/VoApi/queries/queues.js +2 -2
- package/dist/modules/VoApi/queries/search.d.ts +2 -0
- package/dist/modules/VoApi/queries/search.js +5 -3
- package/dist/modules/VoApi/queries/sections.js +2 -2
- package/dist/modules/VoApi/queries/settings.js +1 -1
- package/dist/modules/VoApi/queries/users.d.ts +1 -0
- package/dist/modules/VoApi/queries/users.js +5 -4
- package/dist/modules/VoApi/queries/vodocs.js +3 -3
- package/dist/modules/VoApi/queries/vogroups.js +7 -7
- package/dist/modules/VoApp.d.ts +1 -0
- package/dist/modules/VoApp.js +17 -0
- package/dist/modules/VoAuth.d.ts +2 -1
- package/dist/modules/VoAuth.js +119 -38
- package/dist/modules/VoBase.js +2 -2
- package/dist/modules/VoConfig.js +9 -0
- package/dist/modules/VoDocs/VoDocs.js +7 -2
- package/dist/modules/VoGroups.d.ts +7 -0
- package/dist/modules/VoGroups.js +39 -0
- package/dist/modules/VoHelpers.d.ts +36 -1
- package/dist/modules/VoHelpers.js +320 -48
- package/dist/modules/VoRouter.js +10 -2
- package/dist/modules/VoUtils_REMOVE.js +9 -5
- package/package.json +17 -9
- package/src/global.ts +44 -0
- package/src/index.ts +3 -2
- package/src/interceptor.ts +15 -8
- package/src/modules/Services/I18n/strings.json +505 -24
- package/src/modules/Services/Vapor/Vapor.ts +2 -1
- package/src/modules/VoApi/GraphClient.ts +66 -8
- package/src/modules/VoApi/VoApi.ts +23 -3
- package/src/modules/VoApi/graphql.ts +5 -0
- package/src/modules/VoApi/mutations/applications.ts +27 -0
- package/src/modules/VoApi/mutations/books.ts +27 -0
- package/src/modules/VoApi/mutations/users.ts +5 -0
- package/src/modules/VoApi/mutations/vodocs.ts +2 -0
- package/src/modules/VoApi/mutations/vogroups.ts +21 -7
- package/src/modules/VoApi/queries/applications.ts +71 -0
- package/src/modules/VoApi/queries/articles.ts +1 -1
- package/src/modules/VoApi/queries/books.ts +101 -0
- package/src/modules/VoApi/queries/cards.ts +14 -1
- package/src/modules/VoApi/queries/events.ts +1 -1
- package/src/modules/VoApi/queries/help.ts +12 -0
- package/src/modules/VoApi/queries/navigation.ts +3 -4
- package/src/modules/VoApi/queries/pages.ts +1 -1
- package/src/modules/VoApi/queries/queues.ts +18 -1
- package/src/modules/VoApi/queries/search.ts +98 -1
- package/src/modules/VoApi/queries/sections.ts +1 -1
- package/src/modules/VoApi/queries/users.ts +74 -8
- package/src/modules/VoApi/queries/vodocs.ts +8 -4
- package/src/modules/VoApi/queries/vogroups.ts +40 -11
- package/src/modules/VoApp.ts +25 -8
- package/src/modules/VoAuth.ts +134 -37
- package/src/modules/VoConfig.ts +11 -0
- package/src/modules/VoDocs/VoDocs.ts +5 -0
- package/src/modules/VoGroups.ts +33 -0
- package/src/modules/VoHelpers.ts +254 -42
- package/src/modules/VoRouter.ts +10 -3
- package/src/types.ts +0 -38
package/src/modules/VoConfig.ts
CHANGED
|
@@ -15,9 +15,13 @@ class VoConfig {
|
|
|
15
15
|
// }
|
|
16
16
|
|
|
17
17
|
config: VoConfigType = {
|
|
18
|
+
APP_VERSION: "",
|
|
19
|
+
|
|
18
20
|
API_BASE_URL: "",
|
|
19
21
|
API_ENDPOINT: "",
|
|
20
22
|
API_GRAPHQL: "",
|
|
23
|
+
API_SUBSCRIPTIONS_BASE_URL: "",
|
|
24
|
+
API_GRAPHQL_SUBSCRIPTIONS: "",
|
|
21
25
|
|
|
22
26
|
AUTH_CLIENT_ID: "",
|
|
23
27
|
AUTH_BASE_URL: "",
|
|
@@ -28,6 +32,10 @@ class VoConfig {
|
|
|
28
32
|
DOCS_BASE_URL: "",
|
|
29
33
|
DOCS_ENDPOINT: "",
|
|
30
34
|
DOCS_GRAPHQL: "",
|
|
35
|
+
DOCS_PUBLIC_DISKS: "",
|
|
36
|
+
DOCS_PRIVATE_DISKS: "",
|
|
37
|
+
AWS_BUCKET_VOFRONT_FILES: "",
|
|
38
|
+
AWS_BUCKET_VODOCS_FILES: "",
|
|
31
39
|
|
|
32
40
|
BASE_URL: "",
|
|
33
41
|
AUTH: "",
|
|
@@ -41,6 +49,9 @@ class VoConfig {
|
|
|
41
49
|
AUTH_STORAGE_ACCESS_TOKEN: "voapp_accesstoken",
|
|
42
50
|
AUTH_STORAGE_TOKEN_TYPE: "voapp_tokentype",
|
|
43
51
|
AUTH_STORAGE_EXPIRES_IN: "voapp_expiresin",
|
|
52
|
+
AUTH_DOMAIN: ".vo-college.se",
|
|
53
|
+
|
|
54
|
+
CURRENT_GROUP: "vo_group",
|
|
44
55
|
};
|
|
45
56
|
|
|
46
57
|
setConfig(config: VoConfigType) {
|
|
@@ -6,6 +6,7 @@ import GraphClient from "../VoApi/GraphClient";
|
|
|
6
6
|
import VoBase from "../VoBase";
|
|
7
7
|
// import VoAuth from '../VoAuth';
|
|
8
8
|
import VoConfig from "../VoConfig";
|
|
9
|
+
import VoGroups from "../VoGroups";
|
|
9
10
|
|
|
10
11
|
class VoDocs extends VoBase {
|
|
11
12
|
graphqlClient: any;
|
|
@@ -23,6 +24,10 @@ class VoDocs extends VoBase {
|
|
|
23
24
|
|
|
24
25
|
async getTemporaryFileUrl(id: string) {
|
|
25
26
|
try {
|
|
27
|
+
let currentGroup = VoGroups.getCurrent(true);
|
|
28
|
+
axios.defaults.headers.common["VoGroup"] = currentGroup
|
|
29
|
+
? currentGroup.id
|
|
30
|
+
: "";
|
|
26
31
|
const url = `${this.getUrl}/docs/download/${id}`;
|
|
27
32
|
return axios.get(url);
|
|
28
33
|
} catch (error) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { localStorage } from "./VoHelpers";
|
|
2
|
+
import VoConfig from "./VoConfig";
|
|
3
|
+
import { GeneralObject } from "../global";
|
|
4
|
+
|
|
5
|
+
class VoGroups {
|
|
6
|
+
getCurrent(getFromDomain = false): null | GeneralObject {
|
|
7
|
+
const group: any = localStorage.get(VoConfig.get.CURRENT_GROUP);
|
|
8
|
+
if (group) {
|
|
9
|
+
return JSON.parse(group);
|
|
10
|
+
}
|
|
11
|
+
if (getFromDomain) {
|
|
12
|
+
let groupName = this.getGroupNameFromDomain(window.location.host);
|
|
13
|
+
if (groupName && groupName !== "") {
|
|
14
|
+
return { id: groupName };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
getGroupNameFromDomain(host: string) {
|
|
20
|
+
let subdomain = host?.split(".")[0];
|
|
21
|
+
let localIndex = subdomain?.indexOf("local");
|
|
22
|
+
if (localIndex !== undefined && localIndex > -1) {
|
|
23
|
+
let hyphenIndex = subdomain?.indexOf("-") || 0;
|
|
24
|
+
subdomain = subdomain?.substring(hyphenIndex + 1);
|
|
25
|
+
}
|
|
26
|
+
if (subdomain === "admin") {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return subdomain;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default new VoGroups();
|
package/src/modules/VoHelpers.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import crypto from "crypto-js";
|
|
2
|
+
import he from "he";
|
|
3
|
+
|
|
4
|
+
// Custom.
|
|
5
|
+
import { GeneralObject } from "../global";
|
|
2
6
|
|
|
3
7
|
export const base64Url = (string: crypto.lib.WordArray | String) => {
|
|
4
8
|
return string
|
|
@@ -14,6 +18,7 @@ export const createRandomString = (num: number) => {
|
|
|
14
18
|
|
|
15
19
|
export const localStorage = {
|
|
16
20
|
set: (key: string, value: string) => {
|
|
21
|
+
if (typeof window === "undefined") return false;
|
|
17
22
|
try {
|
|
18
23
|
window.localStorage.setItem(key, value);
|
|
19
24
|
return true;
|
|
@@ -23,6 +28,7 @@ export const localStorage = {
|
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
30
|
get: (key: string) => {
|
|
31
|
+
if (typeof window === "undefined") return false;
|
|
26
32
|
try {
|
|
27
33
|
const item = window.localStorage.getItem(key);
|
|
28
34
|
return item;
|
|
@@ -58,14 +64,15 @@ export const regexPatterns = {
|
|
|
58
64
|
email: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
|
59
65
|
stringNonDigit: /^[^0-9]+$/,
|
|
60
66
|
password: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/, // At least 8 characters, 1 uppercase, 1 lowercase and 1 digit.
|
|
61
|
-
cleanName: /(^[A-Za-z]{1,})(\w
|
|
67
|
+
cleanName: /(^[A-Za-z]{1,})(\w|-?)+$/,
|
|
62
68
|
personalNumber: /^(\d{8})[-]\d{4}$/,
|
|
69
|
+
orgnr: /^(\d{6})[-]\d{4}$/,
|
|
63
70
|
};
|
|
64
71
|
|
|
65
72
|
type errorObjectType = {
|
|
66
73
|
message: string;
|
|
67
74
|
fields?: {
|
|
68
|
-
[key: string]:
|
|
75
|
+
[key: string]: any;
|
|
69
76
|
};
|
|
70
77
|
};
|
|
71
78
|
|
|
@@ -177,46 +184,251 @@ export const downloadFile = (url: string) => {
|
|
|
177
184
|
}
|
|
178
185
|
};
|
|
179
186
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
187
|
+
export const orderByPosition = (a: any, b: any) => {
|
|
188
|
+
if (a.position < b.position) {
|
|
189
|
+
return -1;
|
|
190
|
+
}
|
|
191
|
+
if (a.position > b.position) {
|
|
192
|
+
return 1;
|
|
193
|
+
}
|
|
194
|
+
return 0;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export const orderByField = (a: any, b: any, field: string) => {
|
|
198
|
+
if (a[field] < b[field]) {
|
|
199
|
+
return -1;
|
|
200
|
+
}
|
|
201
|
+
if (a[field] > b[field]) {
|
|
202
|
+
return 1;
|
|
203
|
+
}
|
|
204
|
+
return 0;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export const shortenText = (
|
|
208
|
+
str: string,
|
|
209
|
+
limit = 30,
|
|
210
|
+
stripHtml = true,
|
|
211
|
+
addEllipsis = false
|
|
212
|
+
) => {
|
|
213
|
+
let output = "";
|
|
214
|
+
if (stripHtml) {
|
|
215
|
+
output = str.replace(/(<([^>]+)>)/gi, "");
|
|
216
|
+
output = he.decode(output);
|
|
217
|
+
}
|
|
218
|
+
if (addEllipsis) {
|
|
219
|
+
output += "...";
|
|
220
|
+
}
|
|
221
|
+
return output.substring(0, limit).trim();
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export const getImageContact = (item: any, width = 400, height = 400) => {
|
|
225
|
+
let entity = item.entity || item;
|
|
226
|
+
return entity.images && entity.images[0] && entity.images[0]?.url
|
|
227
|
+
? `${entity.images[0]?.url}?d=${width}x${height}`
|
|
228
|
+
: "/images/avatar-user.png";
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export const getImage = (
|
|
232
|
+
item: any,
|
|
233
|
+
width: number,
|
|
234
|
+
height: number,
|
|
235
|
+
field = "images"
|
|
236
|
+
) => {
|
|
237
|
+
let entity =
|
|
238
|
+
(item.images && item.images.length > 0) || !item.entity
|
|
239
|
+
? item
|
|
240
|
+
: item.entity;
|
|
241
|
+
return entity[field] && entity[field][0]
|
|
242
|
+
? `${entity[field][0]?.url}?d=${width}x${height}`
|
|
243
|
+
: "/images/avatar-content.png";
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
export const getImageDescription = (item: any, field = "images") => {
|
|
247
|
+
let entity =
|
|
248
|
+
(item.images && item.images.length > 0) || !item.entity
|
|
249
|
+
? item
|
|
250
|
+
: item.entity;
|
|
251
|
+
return entity[field] && entity[field][0]?.description;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
export const getContactName = (item?: GeneralObject) => {
|
|
255
|
+
if (!item) {
|
|
256
|
+
return "";
|
|
257
|
+
}
|
|
258
|
+
let name = [];
|
|
259
|
+
if (item.firstname) {
|
|
260
|
+
name.push(item.firstname);
|
|
261
|
+
}
|
|
262
|
+
if (item.lastname) {
|
|
263
|
+
name.push(item.lastname);
|
|
264
|
+
}
|
|
265
|
+
if (name.length === 0) {
|
|
266
|
+
name.push(item.name);
|
|
267
|
+
}
|
|
268
|
+
return name.join(" ");
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export const getUserString = (item?: GeneralObject) => {
|
|
272
|
+
if (!item) {
|
|
273
|
+
return "";
|
|
274
|
+
}
|
|
275
|
+
return `${getContactName(item)} | ${item.email}`;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export const parseState = (state: any, initialState: any) => {
|
|
279
|
+
let newState: GeneralObject = {};
|
|
280
|
+
for (const field in initialState) {
|
|
281
|
+
newState[field] = state[field];
|
|
282
|
+
}
|
|
283
|
+
return newState;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// This method is copied from
|
|
287
|
+
// https://stackoverflow.com/questions/6393943/convert-javascript-string-in-dot-notation-into-an-object-reference
|
|
288
|
+
//
|
|
289
|
+
// @TODO Maybe this entire logic can be replaced by Array.reduce(),
|
|
290
|
+
// something like this:
|
|
291
|
+
// let data = is.split(".").reduce((o: any, i) => o && o[i], pbj);
|
|
292
|
+
// data = value;
|
|
293
|
+
//
|
|
294
|
+
export const changeObj = (obj: any, is: any, value: any): {} => {
|
|
295
|
+
if (typeof is == "string") return changeObj(obj, is.split("."), value);
|
|
296
|
+
else if (is.length == 1 && value !== undefined) return (obj[is[0]] = value);
|
|
297
|
+
else if (is.length == 0) return obj;
|
|
298
|
+
else return changeObj(obj[is[0]], is.slice(1), value);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export const reducer = (state: any, action: any) => {
|
|
302
|
+
const { key, values } = action;
|
|
303
|
+
if (!key) {
|
|
304
|
+
return { ...state, ...values };
|
|
305
|
+
}
|
|
306
|
+
if (key === "loading") {
|
|
307
|
+
let i = state.loading.indexOf(values);
|
|
308
|
+
let newValues = [...state.loading];
|
|
309
|
+
if (i > -1) {
|
|
310
|
+
newValues.splice(i, 1);
|
|
311
|
+
} else {
|
|
312
|
+
newValues.push(values);
|
|
313
|
+
}
|
|
314
|
+
return { ...state, loading: newValues };
|
|
315
|
+
}
|
|
316
|
+
if (key.indexOf(".") > -1) {
|
|
317
|
+
changeObj(state, key, values);
|
|
318
|
+
return { ...state };
|
|
319
|
+
}
|
|
320
|
+
return { ...state, [key]: values };
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export const getGroupLogotype = (
|
|
324
|
+
group: GeneralObject,
|
|
325
|
+
logo = "logo2",
|
|
326
|
+
output: GeneralObject[] = []
|
|
327
|
+
) => {
|
|
328
|
+
if (group && Array.isArray(group[logo]) && group[logo].length > 0) {
|
|
329
|
+
output.push.apply(output, group[logo]);
|
|
330
|
+
} else if (group && group.parentGroups) {
|
|
331
|
+
return group.parentGroups.forEach((v: any) => {
|
|
332
|
+
return getGroupLogotype(v, logo, output);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
return null;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// export const makeId = (length = 10) => {
|
|
339
|
+
// let result = "";
|
|
340
|
+
// let characters =
|
|
341
|
+
// "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
342
|
+
// let charactersLength = characters.length;
|
|
343
|
+
// for (var i = 0; i < length; i++) {
|
|
344
|
+
// result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
205
345
|
// }
|
|
206
|
-
// return
|
|
207
|
-
// <ul>
|
|
208
|
-
// {error.map((v) => (
|
|
209
|
-
// <li>{typeof error[0] === "object" ? error[0].message : error[0]}</li>
|
|
210
|
-
// ))}
|
|
211
|
-
// </ul>
|
|
212
|
-
// );
|
|
346
|
+
// return result;
|
|
213
347
|
// };
|
|
214
348
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
349
|
+
export const getObjValue = (obj: any, ...props: string[]): any => {
|
|
350
|
+
return (
|
|
351
|
+
obj &&
|
|
352
|
+
props.reduce(
|
|
353
|
+
(result, prop) => (result == null ? undefined : result[prop]),
|
|
354
|
+
obj
|
|
355
|
+
)
|
|
356
|
+
);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Convert an SVG into an image.
|
|
361
|
+
* @param url
|
|
362
|
+
* @param width
|
|
363
|
+
* @param height
|
|
364
|
+
* @param format
|
|
365
|
+
* @param quality
|
|
366
|
+
* @returns Promise
|
|
367
|
+
*
|
|
368
|
+
* @note Convert logic inpired by
|
|
369
|
+
* https://levelup.gitconnected.com/draw-an-svg-to-canvas-and-download-it-as-image-in-javascript-f7f7713cf81f
|
|
370
|
+
* https://medium.com/@benjamin.black/using-blob-from-svg-text-as-image-source-2a8947af7a8e
|
|
371
|
+
*
|
|
372
|
+
* In this method we could actually assign "url" directly to "image.src" and then
|
|
373
|
+
* extract an image with canvas, but Firefox doesn't support drawing an SVG into
|
|
374
|
+
* canvas if it misses width/height attributes. Read more here:
|
|
375
|
+
* https://stackoverflow.com/questions/28690643/firefox-error-rendering-an-svg-image-to-html5-canvas-with-drawimage
|
|
376
|
+
* https://bugzilla.mozilla.org/show_bug.cgi?id=700533
|
|
377
|
+
*/
|
|
378
|
+
export const convertSvgToImage = (
|
|
379
|
+
url: string,
|
|
380
|
+
width: null | number = null,
|
|
381
|
+
height: null | number = null,
|
|
382
|
+
format = "image/png",
|
|
383
|
+
quality = 0.92
|
|
384
|
+
) => {
|
|
385
|
+
return new Promise(async (resolve, reject) => {
|
|
386
|
+
try {
|
|
387
|
+
let response = await fetch(url);
|
|
388
|
+
let svg = await response.text();
|
|
389
|
+
|
|
390
|
+
let parser = new DOMParser();
|
|
391
|
+
let doc = parser.parseFromString(svg, "image/svg+xml");
|
|
392
|
+
|
|
393
|
+
let viewBox = doc.documentElement.getAttribute("viewBox")?.split(" ");
|
|
394
|
+
|
|
395
|
+
let canvas = document.createElement("canvas");
|
|
396
|
+
if (!width) {
|
|
397
|
+
canvas.width = viewBox && viewBox[2] ? parseInt(viewBox[2]) : 100;
|
|
398
|
+
} else {
|
|
399
|
+
canvas.width = width;
|
|
400
|
+
}
|
|
401
|
+
if (!height && !width) {
|
|
402
|
+
canvas.height = viewBox && viewBox[3] ? parseInt(viewBox[3]) : 100;
|
|
403
|
+
} else if (!height) {
|
|
404
|
+
canvas.height =
|
|
405
|
+
viewBox && viewBox[3]
|
|
406
|
+
? (parseInt(viewBox[3]) / parseInt(viewBox[2])) * canvas.width
|
|
407
|
+
: 100;
|
|
408
|
+
} else {
|
|
409
|
+
canvas.height = height;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// These steps, to ensure that the SVG has width/height attributes
|
|
413
|
+
// are only required because of Firefox.
|
|
414
|
+
// Otherwise we could assign "url" directly to "image.src".
|
|
415
|
+
let inlineSVG = doc.getElementsByTagName("svg")[0];
|
|
416
|
+
inlineSVG.setAttribute("width", `${canvas.width}px`);
|
|
417
|
+
inlineSVG.setAttribute("height", `${canvas.height}px`);
|
|
418
|
+
let svg64 = btoa(new XMLSerializer().serializeToString(inlineSVG));
|
|
419
|
+
let image64 = "data:image/svg+xml;base64," + svg64;
|
|
420
|
+
|
|
421
|
+
let context = canvas.getContext("2d");
|
|
422
|
+
let image = new Image();
|
|
423
|
+
|
|
424
|
+
image.onload = () => {
|
|
425
|
+
context?.drawImage(image, 0, 0);
|
|
426
|
+
let result = canvas.toDataURL(format, quality);
|
|
427
|
+
resolve(result);
|
|
428
|
+
};
|
|
429
|
+
image.src = image64;
|
|
430
|
+
} catch (error) {
|
|
431
|
+
reject(error);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
};
|
package/src/modules/VoRouter.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import Cookies from "js-cookie";
|
|
2
|
+
|
|
3
|
+
// Custom.
|
|
1
4
|
import VoConfig from "./VoConfig";
|
|
2
|
-
import VoAuth from "./VoAuth";
|
|
3
5
|
|
|
4
6
|
type RoutesType = {
|
|
5
7
|
[key: string]: any;
|
|
@@ -24,6 +26,7 @@ class VoRouter {
|
|
|
24
26
|
return params[arg];
|
|
25
27
|
}
|
|
26
28
|
isCurrentRouterProtected() {
|
|
29
|
+
if (typeof window === "undefined") return false;
|
|
27
30
|
const currentPath = this.getPath(window.location.pathname, 0);
|
|
28
31
|
// const routes = VoConfig.getConfigByKey('routes');
|
|
29
32
|
const routes = this.getRoutes();
|
|
@@ -47,9 +50,13 @@ class VoRouter {
|
|
|
47
50
|
const webUrl = [];
|
|
48
51
|
if (VoConfig.get.AUTH_BASE_URL) {
|
|
49
52
|
webUrl.push(VoConfig.get.AUTH_BASE_URL + "/logout");
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
let redirectTo = Cookies.get("voapp_redirectTo") || VoConfig.get.BASE_URL;
|
|
54
|
+
if (redirectTo) {
|
|
55
|
+
webUrl.push(`?redirect=${redirectTo}`);
|
|
52
56
|
}
|
|
57
|
+
// if (VoConfig.get.BASE_URL) {
|
|
58
|
+
// webUrl.push(`?redirect=${VoConfig.get.BASE_URL}`);
|
|
59
|
+
// }
|
|
53
60
|
}
|
|
54
61
|
if (webUrl.length > 0) {
|
|
55
62
|
window.location.href = webUrl.join("");
|
package/src/types.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type AuthStorageConfigType = {
|
|
2
|
-
STATE: string,
|
|
3
|
-
VERIFIER: string,
|
|
4
|
-
REFRESH_TOKEN: string,
|
|
5
|
-
ACCESS_TOKEN: string,
|
|
6
|
-
TOKEN_TYPE: string
|
|
7
|
-
EXPIRES_IN: string
|
|
8
|
-
}
|
|
9
|
-
export type AuthConfigType = {
|
|
10
|
-
BASE_URL: string,
|
|
11
|
-
CLIENT_ID?: string,
|
|
12
|
-
LOGIN?: string,
|
|
13
|
-
ENDPOINT?: string,
|
|
14
|
-
STORAGE?: AuthStorageConfigType
|
|
15
|
-
}
|
|
16
|
-
export type ApiConfigType = {
|
|
17
|
-
BASE_URL: string,
|
|
18
|
-
ENDPOINT?: string,
|
|
19
|
-
GRAPHQL?: string
|
|
20
|
-
}
|
|
21
|
-
export type AppConfigType = {
|
|
22
|
-
BASE_URL: string,
|
|
23
|
-
AUTH?: string,
|
|
24
|
-
HOME?: string,
|
|
25
|
-
LOGIN?: string
|
|
26
|
-
}
|
|
27
|
-
export type VoAppType = {
|
|
28
|
-
configure: Function,
|
|
29
|
-
config?: Function,
|
|
30
|
-
auth: any,
|
|
31
|
-
api: any
|
|
32
|
-
}
|
|
33
|
-
export type VoTokenType = {
|
|
34
|
-
token_type: string,
|
|
35
|
-
access_token: string,
|
|
36
|
-
refresh_token: string,
|
|
37
|
-
expires_in: string
|
|
38
|
-
}
|