-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Several bugfixes and improvements - Verify disc space on start as well. Recording is not going to start if space not enough. - space_full event occures correctly now - unsuscribe progress, file_created & space_full events when ffmpeg process stopped only. Not before as it was. - Event start occurs before progress
- Loading branch information
Showing
22 changed files
with
384 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import fs from 'fs'; | ||
|
||
export default function directoryExists(path: string) { | ||
try { | ||
const stats = fs.lstatSync(path); | ||
if (!stats.isDirectory()) { | ||
throw new TypeError(`${path} exists but it is not a directory.`); | ||
} | ||
return true; | ||
} catch (err) { | ||
if (err instanceof TypeError) { | ||
throw err; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { DurationFactor, SegmentTimeOption } from '../types'; | ||
|
||
const SEGMENT_TIME_PATTERN = /^(\d+)(s|m|h)?$/; | ||
|
||
export default function transformSegmentTime(value: SegmentTimeOption) { | ||
if (typeof value === 'number') return value; | ||
const [operand, factor] = matchSegmentTime(value); | ||
return getDuration(operand, factor); | ||
} | ||
|
||
function matchSegmentTime(value: string): [number, DurationFactor] { | ||
const match = value.match(SEGMENT_TIME_PATTERN); | ||
if (!match) { | ||
throw new Error(`segmentTime value has to match to pattern ${SEGMENT_TIME_PATTERN.toString()}.`); | ||
} | ||
const operand = Number(match[1]); | ||
if (!operand) { | ||
throw new Error('segmentTime value has to be more than zero.'); | ||
} | ||
|
||
const factor = match[2] as DurationFactor; | ||
return [operand, factor]; | ||
} | ||
|
||
/** | ||
* @returns seconds | ||
*/ | ||
function getDuration(operand: number, factor: DurationFactor): number { | ||
switch (factor) { | ||
case DurationFactor.Minutes: | ||
return operand * 60; | ||
case DurationFactor.Hours: | ||
return operand * Math.pow(60, 2); | ||
case DurationFactor.Seconds: | ||
default: | ||
return operand; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { BytesFactor, DirSizeThresholdOption } from '../types'; | ||
|
||
const DIR_SIZE_THRESHOLD_PATTERN = /^(\d+)(M|G|T)?$/; | ||
|
||
export default function transformDirSizeThreshold(value: DirSizeThresholdOption) { | ||
if (typeof value === 'number') return value; | ||
const [operand, factor] = matchDirSizeThreshold(value); | ||
return getBytesSize(operand, factor); | ||
} | ||
|
||
function matchDirSizeThreshold(value: string): [number, BytesFactor] { | ||
const match = value.match(DIR_SIZE_THRESHOLD_PATTERN); | ||
if (!match) { | ||
throw new Error(`dirSizeThreshold value has to match to pattern ${DIR_SIZE_THRESHOLD_PATTERN.toString()}.`); | ||
} | ||
const operand = Number(match[1]); | ||
if (!operand) { | ||
throw new Error('dirSizeThreshold value has to be more than zero.'); | ||
} | ||
|
||
const factor = match[2] as BytesFactor; | ||
return [operand, factor]; | ||
} | ||
|
||
/** | ||
* @returns bytes | ||
*/ | ||
function getBytesSize(operand: number, factor: BytesFactor): number { | ||
switch (factor) { | ||
case BytesFactor.Gigabytes: | ||
return operand * Math.pow(1024, 3); | ||
case BytesFactor.Terabytes: | ||
return operand * Math.pow(1024, 4); | ||
case BytesFactor.Megabytes: | ||
default: | ||
return operand * Math.pow(1024, 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import fs from 'fs'; | ||
import pathApi from 'path'; | ||
|
||
/** | ||
* @returns bytes | ||
*/ | ||
export default function dirSize(path: string) { | ||
return getDirListing(path) | ||
.map((item) => fs.statSync(item).size) | ||
.reduce((acc, size) => acc + size, 0); | ||
} | ||
|
||
function getDirListing(dir: string): string[] { | ||
return fs.readdirSync(dir) | ||
.map((item) => { | ||
const path = pathApi.join(dir, item); | ||
if (fs.statSync(path).isDirectory()) { | ||
return getDirListing(path); | ||
} | ||
return path; | ||
}) | ||
.reduce<string[]>((acc, i) => { | ||
if (Array.isArray(i)) { | ||
return [...acc, ...i]; | ||
} | ||
return [...acc, i]; | ||
}, []); | ||
} |
Oops, something went wrong.