はじまりの大地

このコミットが含まれているのは:
2024-07-15 09:14:04 +09:00
コミット 6632905f32
3501個のファイルの変更1439465行の追加0行の削除
+20
ファイルの表示
@@ -0,0 +1,20 @@
import { BinaryToTextEncoding, createHash } from 'crypto'
function sha256 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') {
return createHash('sha256').update(str).digest(encoding)
}
function sha1 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') {
return createHash('sha1').update(str).digest(encoding)
}
// high excluded
function randomInt (low: number, high: number) {
return Math.floor(Math.random() * (high - low) + low)
}
export {
randomInt,
sha256,
sha1
}
+62
ファイルの表示
@@ -0,0 +1,62 @@
export function parallelTests () {
return process.env.MOCHA_PARALLEL === 'true'
}
export function isGithubCI () {
return !!process.env.GITHUB_WORKSPACE
}
export function areHttpImportTestsDisabled () {
const disabled = process.env.DISABLE_HTTP_IMPORT_TESTS === 'true'
if (disabled) console.log('DISABLE_HTTP_IMPORT_TESTS env set to "true" so import tests are disabled')
return disabled
}
export function areMockObjectStorageTestsDisabled () {
const disabled = process.env.ENABLE_OBJECT_STORAGE_TESTS !== 'true'
if (disabled) console.log('ENABLE_OBJECT_STORAGE_TESTS env is not set to "true" so object storage tests are disabled')
return disabled
}
export function areScalewayObjectStorageTestsDisabled () {
if (areMockObjectStorageTestsDisabled()) return true
const enabled = process.env.OBJECT_STORAGE_SCALEWAY_KEY_ID && process.env.OBJECT_STORAGE_SCALEWAY_ACCESS_KEY
if (!enabled) {
console.log(
'OBJECT_STORAGE_SCALEWAY_KEY_ID and/or OBJECT_STORAGE_SCALEWAY_ACCESS_KEY are not set, so scaleway object storage tests are disabled'
)
return true
}
return false
}
export function isTestInstance () {
return process.env.NODE_ENV === 'test'
}
export function isDevInstance () {
return process.env.NODE_ENV === 'dev'
}
export function isTestOrDevInstance () {
return isTestInstance() || isDevInstance()
}
export function isProdInstance () {
return process.env.NODE_ENV === 'production'
}
export function getAppNumber () {
return process.env.NODE_APP_INSTANCE || ''
}
export function isUsingViewersFederationV2 () {
return process.env.USE_VIEWERS_FEDERATION_V2 === 'true'
}
+11
ファイルの表示
@@ -0,0 +1,11 @@
import { stat } from 'fs/promises'
async function getFileSize (path: string) {
const stats = await stat(path)
return stats.size
}
export {
getFileSize
}
+5
ファイルの表示
@@ -0,0 +1,5 @@
export * from './crypto.js'
export * from './env.js'
export * from './file.js'
export * from './path.js'
export * from './uuid.js'
+62
ファイルの表示
@@ -0,0 +1,62 @@
import { basename, extname, isAbsolute, join, parse, resolve } from 'path'
import { fileURLToPath } from 'url'
let rootPath: string
export function currentDir (metaUrl: string) {
return resolve(fileURLToPath(metaUrl), '..')
}
export function root (metaUrl?: string) {
if (rootPath) return rootPath
if (!metaUrl) {
metaUrl = import.meta.url
const filename = basename(metaUrl) === 'path.js' || basename(metaUrl) === 'path.ts'
if (!filename) throw new Error('meta url must be specified as this file has been bundled in another one')
}
rootPath = currentDir(metaUrl)
if (basename(rootPath) === 'src' || basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..')
if ([ 'node-utils', 'peertube-cli', 'peertube-runner' ].includes(basename(rootPath))) rootPath = resolve(rootPath, '..')
if ([ 'packages', 'apps' ].includes(basename(rootPath))) rootPath = resolve(rootPath, '..')
if (basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..')
return rootPath
}
export function buildPath (path: string) {
if (isAbsolute(path)) return path
return join(root(), path)
}
export function getLowercaseExtension (filename: string) {
const ext = extname(filename) || ''
return ext.toLowerCase()
}
export function buildAbsoluteFixturePath (path: string, customCIPath = false) {
if (isAbsolute(path)) return path
if (customCIPath && process.env.GITHUB_WORKSPACE) {
return join(process.env.GITHUB_WORKSPACE, 'fixtures', path)
}
return join(root(), 'packages', 'tests', 'fixtures', path)
}
export function getFilenameFromUrl (url: string) {
return getFilename(new URL(url).pathname)
}
export function getFilename (path: string) {
return parse(path).base
}
export function getFilenameWithoutExt (path: string) {
return parse(path).name
}
+39
ファイルの表示
@@ -0,0 +1,39 @@
import short, { SUUID } from 'short-uuid'
const translator = short()
function buildUUID () {
return short.uuid()
}
function buildSUUID (): SUUID {
return short.generate()
}
function uuidToShort (uuid: string) {
if (!uuid) return uuid
return translator.fromUUID(uuid)
}
function shortToUUID (shortUUID: string) {
if (!shortUUID) return shortUUID
return translator.toUUID(shortUUID)
}
function isShortUUID (value: string) {
if (!value) return false
return value.length === translator.maxLength
}
export {
buildUUID,
buildSUUID,
uuidToShort,
shortToUUID,
isShortUUID
}
export type { SUUID }