mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-23 23:09:28 +00:00
refactor(utils): add tmpdir function
This commit is contained in:
@@ -131,6 +131,33 @@ function deepCompare(obj1, obj2) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the os tmpdir.
|
||||
* @returns {string}
|
||||
*/
|
||||
function getTmpdir() {
|
||||
const env = BROWSER ? {} : process.env;
|
||||
|
||||
const is_windows = process.platform === 'win32';
|
||||
const trailing_slash_re = is_windows ? /[^:]\\$/ : /.\/$/;
|
||||
|
||||
let path;
|
||||
|
||||
if (is_windows) {
|
||||
path = env.TEMP || env.TMP ||
|
||||
(env.SystemRoot || env.windir) + '\\temp';
|
||||
} else {
|
||||
path = env.TMPDIR || env.TMP ||
|
||||
env.TEMP || '/tmp';
|
||||
}
|
||||
|
||||
if (trailing_slash_re.test(path)) {
|
||||
path = path.slice(0, -1);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a string between two delimiters.
|
||||
*
|
||||
@@ -284,7 +311,7 @@ function refineNTokenData(data) {
|
||||
const errors = { InnertubeError, UnavailableContentError, ParsingError, DownloadError, MissingParamError, NoStreamingDataError, OAuthError };
|
||||
|
||||
const functions = {
|
||||
findNode, observe, getRandomUserAgent, generateSidAuth, generateRandomString, getStringBetweenStrings,
|
||||
findNode, observe, getTmpdir, getRandomUserAgent, generateSidAuth, generateRandomString, getStringBetweenStrings,
|
||||
camelToSnake, isValidClient, throwIfMissing, timeToSeconds, refineNTokenData
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user