aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-03 15:08:36 +0200
committerChocobozzz <me@florianbigard.com>2022-08-03 15:08:36 +0200
commitc795e19663a93c24908a7318975f820bac63164f (patch)
tree149a303be38eedf5aa5a0ec02938f67c75a267fe /server/helpers
parentfd59208e8ccd796f9ad7e35db82d0c33acfcb92c (diff)
downloadPeerTube-c795e19663a93c24908a7318975f820bac63164f.tar.gz
PeerTube-c795e19663a93c24908a7318975f820bac63164f.tar.zst
PeerTube-c795e19663a93c24908a7318975f820bac63164f.zip
Automatically rebuild native modules on ABI change
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/utils.ts26
-rw-r--r--server/helpers/version.ts36
2 files changed, 37 insertions, 25 deletions
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index 6b9333b53..5a4fe4fdd 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -4,7 +4,7 @@ import { join } from 'path'
4import { sha256 } from '@shared/extra-utils' 4import { sha256 } from '@shared/extra-utils'
5import { ResultList } from '@shared/models' 5import { ResultList } from '@shared/models'
6import { CONFIG } from '../initializers/config' 6import { CONFIG } from '../initializers/config'
7import { execPromise, execPromise2, randomBytesPromise } from './core-utils' 7import { randomBytesPromise } from './core-utils'
8import { logger } from './logger' 8import { logger } from './logger'
9 9
10function deleteFileAndCatch (path: string) { 10function deleteFileAndCatch (path: string) {
@@ -44,29 +44,6 @@ function getSecureTorrentName (originalName: string) {
44 return sha256(originalName) + '.torrent' 44 return sha256(originalName) + '.torrent'
45} 45}
46 46
47async function getServerCommit () {
48 try {
49 const tag = await execPromise2(
50 '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true',
51 { stdio: [ 0, 1, 2 ] }
52 )
53
54 if (tag) return tag.replace(/^v/, '')
55 } catch (err) {
56 logger.debug('Cannot get version from git tags.', { err })
57 }
58
59 try {
60 const version = await execPromise('[ ! -d .git ] || git rev-parse --short HEAD')
61
62 if (version) return version.toString().trim()
63 } catch (err) {
64 logger.debug('Cannot get version from git HEAD.', { err })
65 }
66
67 return ''
68}
69
70/** 47/**
71 * From a filename like "ede4cba5-742b-46fa-a388-9a6eb3a3aeb3.mp4", returns 48 * From a filename like "ede4cba5-742b-46fa-a388-9a6eb3a3aeb3.mp4", returns
72 * only the "ede4cba5-742b-46fa-a388-9a6eb3a3aeb3" part. If the filename does 49 * only the "ede4cba5-742b-46fa-a388-9a6eb3a3aeb3" part. If the filename does
@@ -88,7 +65,6 @@ export {
88 generateRandomString, 65 generateRandomString,
89 getFormattedObjects, 66 getFormattedObjects,
90 getSecureTorrentName, 67 getSecureTorrentName,
91 getServerCommit,
92 generateVideoImportTmpPath, 68 generateVideoImportTmpPath,
93 getUUIDFromFilename 69 getUUIDFromFilename
94} 70}
diff --git a/server/helpers/version.ts b/server/helpers/version.ts
new file mode 100644
index 000000000..5b3bf59dd
--- /dev/null
+++ b/server/helpers/version.ts
@@ -0,0 +1,36 @@
1import { execPromise, execPromise2 } from './core-utils'
2import { logger } from './logger'
3
4async function getServerCommit () {
5 try {
6 const tag = await execPromise2(
7 '[ ! -d .git ] || git name-rev --name-only --tags --no-undefined HEAD 2>/dev/null || true',
8 { stdio: [ 0, 1, 2 ] }
9 )
10
11 if (tag) return tag.replace(/^v/, '')
12 } catch (err) {
13 logger.debug('Cannot get version from git tags.', { err })
14 }
15
16 try {
17 const version = await execPromise('[ ! -d .git ] || git rev-parse --short HEAD')
18
19 if (version) return version.toString().trim()
20 } catch (err) {
21 logger.debug('Cannot get version from git HEAD.', { err })
22 }
23
24 return ''
25}
26
27function getNodeABIVersion () {
28 const version = process.versions.modules
29
30 return parseInt(version)
31}
32
33export {
34 getServerCommit,
35 getNodeABIVersion
36}