]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/root-helpers/utils.ts
Add support for saving video files to object storage (#4290)
[github/Chocobozzz/PeerTube.git] / client / src / root-helpers / utils.ts
index 6df151ad9bc4dfa0b029247397ac549d0dc98da8..00bd92411247aedfb890ea38fac7e3bd4acca28d 100644 (file)
@@ -1,5 +1,3 @@
-import { environment } from '../environments/environment'
-
 function objectToUrlEncoded (obj: any) {
   const str: string[] = []
   for (const key of Object.keys(obj)) {
@@ -9,42 +7,26 @@ function objectToUrlEncoded (obj: any) {
   return str.join('&')
 }
 
-// Thanks: https://github.com/uupaa/dynamic-import-polyfill
-function importModule (path: string) {
-  return new Promise((resolve, reject) => {
-    const vector = '$importModule$' + Math.random().toString(32).slice(2)
-    const script = document.createElement('script')
-
-    const destructor = () => {
-      delete window[ vector ]
-      script.onerror = null
-      script.onload = null
-      script.remove()
-      URL.revokeObjectURL(script.src)
-      script.src = ''
-    }
-
-    script.defer = true
-    script.type = 'module'
-
-    script.onerror = () => {
-      reject(new Error(`Failed to import: ${path}`))
-      destructor()
-    }
-    script.onload = () => {
-      resolve(window[ vector ])
-      destructor()
-    }
-    const absURL = (environment.apiUrl || window.location.origin) + path
-    const loader = `import * as m from "${absURL}"; window.${vector} = m;` // export Module
-    const blob = new Blob([ loader ], { type: 'text/javascript' })
-    script.src = URL.createObjectURL(blob)
+function copyToClipboard (text: string) {
+  const el = document.createElement('textarea')
+  el.value = text
+  el.setAttribute('readonly', '')
+  el.style.position = 'absolute'
+  el.style.left = '-9999px'
+  document.body.appendChild(el)
+  el.select()
+  document.execCommand('copy')
+  document.body.removeChild(el)
+}
 
-    document.head.appendChild(script)
+function wait (ms: number) {
+  return new Promise<void>(res => {
+    setTimeout(() => res(), ms)
   })
 }
 
 export {
-  importModule,
-  objectToUrlEncoded
+  copyToClipboard,
+  objectToUrlEncoded,
+  wait
 }