aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/utils.ts')
-rw-r--r--server/helpers/utils.ts37
1 files changed, 26 insertions, 11 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index 6228fec04..cb0e823c5 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -19,10 +19,7 @@ async function generateRandomString (size: number) {
19 return raw.toString('hex') 19 return raw.toString('hex')
20} 20}
21 21
22interface FormattableToJSON { 22interface FormattableToJSON { toFormattedJSON (args?: any) }
23 toFormattedJSON (args?: any)
24}
25
26function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number, formattedArg?: any) { 23function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], objectsTotal: number, formattedArg?: any) {
27 const formattedObjects: U[] = [] 24 const formattedObjects: U[] = []
28 25
@@ -40,21 +37,24 @@ const getServerActor = memoizee(async function () {
40 const application = await ApplicationModel.load() 37 const application = await ApplicationModel.load()
41 if (!application) throw Error('Could not load Application from database.') 38 if (!application) throw Error('Could not load Application from database.')
42 39
43 return application.Account.Actor 40 const actor = application.Account.Actor
41 actor.Account = application.Account
42
43 return actor
44}) 44})
45 45
46function generateVideoTmpPath (target: string | ParseTorrent) { 46function generateVideoImportTmpPath (target: string | ParseTorrent) {
47 const id = typeof target === 'string' ? target : target.infoHash 47 const id = typeof target === 'string' ? target : target.infoHash
48 48
49 const hash = sha256(id) 49 const hash = sha256(id)
50 return join(CONFIG.STORAGE.VIDEOS_DIR, hash + '-import.mp4') 50 return join(CONFIG.STORAGE.TMP_DIR, hash + '-import.mp4')
51} 51}
52 52
53function getSecureTorrentName (originalName: string) { 53function getSecureTorrentName (originalName: string) {
54 return sha256(originalName) + '.torrent' 54 return sha256(originalName) + '.torrent'
55} 55}
56 56
57async function getVersion () { 57async function getServerCommit () {
58 try { 58 try {
59 const tag = await execPromise2( 59 const tag = await execPromise2(
60 '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true', 60 '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true',
@@ -74,7 +74,21 @@ async function getVersion () {
74 logger.debug('Cannot get version from git HEAD.', { err }) 74 logger.debug('Cannot get version from git HEAD.', { err })
75 } 75 }
76 76
77 return require('../../../package.json').version 77 return ''
78}
79
80/**
81 * From a filename like "ede4cba5-742b-46fa-a388-9a6eb3a3aeb3.mp4", returns
82 * only the "ede4cba5-742b-46fa-a388-9a6eb3a3aeb3" part. If the filename does
83 * not contain a UUID, returns null.
84 */
85function getUUIDFromFilename (filename: string) {
86 const regex = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
87 const result = filename.match(regex)
88
89 if (!result || Array.isArray(result) === false) return null
90
91 return result[0]
78} 92}
79 93
80// --------------------------------------------------------------------------- 94// ---------------------------------------------------------------------------
@@ -85,6 +99,7 @@ export {
85 getFormattedObjects, 99 getFormattedObjects,
86 getSecureTorrentName, 100 getSecureTorrentName,
87 getServerActor, 101 getServerActor,
88 getVersion, 102 getServerCommit,
89 generateVideoTmpPath 103 generateVideoImportTmpPath,
104 getUUIDFromFilename
90} 105}