]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/core-utils.ts
Import torrents with webtorrent
[github/Chocobozzz/PeerTube.git] / server / helpers / core-utils.ts
index 884206aad0c4043830bf4e168346519e9bb97994..25eb6454ae52f1dbef6694decc8daa9cf1f75368 100644 (file)
@@ -13,6 +13,7 @@ import * as pem from 'pem'
 import * as rimraf from 'rimraf'
 import { URL } from 'url'
 import { truncate } from 'lodash'
+import * as crypto from 'crypto'
 
 function sanitizeUrl (url: string) {
   const urlObject = new URL(url)
@@ -95,6 +96,10 @@ function peertubeTruncate (str: string, maxLength: number) {
   return truncate(str, options)
 }
 
+function sha256 (str: string) {
+  return crypto.createHash('sha256').update(str).digest('hex')
+}
+
 function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> {
   return function promisified (): Promise<A> {
     return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => {
@@ -165,6 +170,7 @@ export {
   sanitizeHost,
   buildPath,
   peertubeTruncate,
+  sha256,
 
   promisify0,
   promisify1,