aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/helpers')
-rw-r--r--client/src/app/helpers/index.ts1
-rw-r--r--client/src/app/helpers/peertube-web-storage.ts81
-rw-r--r--client/src/app/helpers/utils.ts10
3 files changed, 0 insertions, 92 deletions
diff --git a/client/src/app/helpers/index.ts b/client/src/app/helpers/index.ts
index 06806402e..cc61255ba 100644
--- a/client/src/app/helpers/index.ts
+++ b/client/src/app/helpers/index.ts
@@ -1,6 +1,5 @@
1export * from './locales' 1export * from './locales'
2export * from './constants' 2export * from './constants'
3export * from './i18n-utils' 3export * from './i18n-utils'
4export * from './peertube-web-storage'
5export * from './utils' 4export * from './utils'
6export * from './zone' 5export * from './zone'
diff --git a/client/src/app/helpers/peertube-web-storage.ts b/client/src/app/helpers/peertube-web-storage.ts
deleted file mode 100644
index 0db1301bd..000000000
--- a/client/src/app/helpers/peertube-web-storage.ts
+++ /dev/null
@@ -1,81 +0,0 @@
1// Thanks: https://github.com/capaj/localstorage-polyfill
2
3const valuesMap = new Map()
4
5function proxify (instance: MemoryStorage) {
6 return new Proxy(instance, {
7 set: function (obj, prop: string | number, value) {
8 if (MemoryStorage.prototype.hasOwnProperty(prop)) {
9 instance[prop] = value
10 } else {
11 instance.setItem(prop, value)
12 }
13 return true
14 },
15 get: function (target, name: string | number) {
16 if (MemoryStorage.prototype.hasOwnProperty(name)) {
17 return instance[name]
18 }
19 if (valuesMap.has(name)) {
20 return instance.getItem(name)
21 }
22 }
23 })
24}
25
26class MemoryStorage {
27 [key: string]: any
28 [index: number]: string
29
30 getItem (key: any) {
31 const stringKey = String(key)
32 if (valuesMap.has(key)) {
33 return String(valuesMap.get(stringKey))
34 }
35
36 return null
37 }
38
39 setItem (key: any, val: any) {
40 valuesMap.set(String(key), String(val))
41 }
42
43 removeItem (key: any) {
44 valuesMap.delete(key)
45 }
46
47 clear () {
48 valuesMap.clear()
49 }
50
51 key (i: any) {
52 if (arguments.length === 0) {
53 throw new TypeError('Failed to execute "key" on "Storage": 1 argument required, but only 0 present.')
54 }
55
56 const arr = Array.from(valuesMap.keys())
57 return arr[i]
58 }
59
60 get length () {
61 return valuesMap.size
62 }
63}
64
65let peertubeLocalStorage: Storage
66let peertubeSessionStorage: Storage
67try {
68 peertubeLocalStorage = localStorage
69 peertubeSessionStorage = sessionStorage
70} catch (err) {
71 const instanceLocalStorage = new MemoryStorage()
72 const instanceSessionStorage = new MemoryStorage()
73
74 peertubeLocalStorage = proxify(instanceLocalStorage)
75 peertubeSessionStorage = proxify(instanceSessionStorage)
76}
77
78export {
79 peertubeLocalStorage,
80 peertubeSessionStorage
81}
diff --git a/client/src/app/helpers/utils.ts b/client/src/app/helpers/utils.ts
index 8e9f72adb..825b6ca96 100644
--- a/client/src/app/helpers/utils.ts
+++ b/client/src/app/helpers/utils.ts
@@ -81,15 +81,6 @@ function immutableAssign <A, B> (target: A, source: B) {
81 return Object.assign({}, target, source) 81 return Object.assign({}, target, source)
82} 82}
83 83
84function objectToUrlEncoded (obj: any) {
85 const str: string[] = []
86 for (const key of Object.keys(obj)) {
87 str.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]))
88 }
89
90 return str.join('&')
91}
92
93// Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34 84// Thanks: https://gist.github.com/ghinda/8442a57f22099bdb2e34
94function objectToFormData (obj: any, form?: FormData, namespace?: string) { 85function objectToFormData (obj: any, form?: FormData, namespace?: string) {
95 const fd = form || new FormData() 86 const fd = form || new FormData()
@@ -207,7 +198,6 @@ export {
207 sortBy, 198 sortBy,
208 durationToString, 199 durationToString,
209 lineFeedToHtml, 200 lineFeedToHtml,
210 objectToUrlEncoded,
211 getParameterByName, 201 getParameterByName,
212 populateAsyncUserVideoChannels, 202 populateAsyncUserVideoChannels,
213 getAbsoluteAPIUrl, 203 getAbsoluteAPIUrl,