1
0
Fork 1
mirror of https://example.com synced 2024-11-22 16:36:39 +09:00
firefish/neko/index.js

383 lines
12 KiB
JavaScript
Raw Permalink Normal View History

2024-02-03 22:15:40 +09:00
// prettier-ignore
2023-07-22 20:25:52 +09:00
/* eslint-disable */
/* auto-generated by NAPI-RS */
const { existsSync, readFileSync } = require('fs')
const { join } = require('path')
2023-07-22 20:25:52 +09:00
const { platform, arch } = process
2023-07-22 20:25:52 +09:00
let nativeBinding = null
let localFileExisted = false
let loadError = null
2023-07-22 20:25:52 +09:00
2024-02-03 22:15:40 +09:00
const isMusl = () => {
let musl = false
if (process.platform === 'linux') {
musl = isMuslFromFilesystem()
if (musl === null) {
musl = isMuslFromReport()
}
if (musl === null) {
musl = isMuslFromChildProcess()
}
}
return musl
}
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
const isMuslFromFilesystem = () => {
try {
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
} catch {
return null
}
}
const isMuslFromReport = () => {
const report = typeof process.report.getReport === 'function' ? process.report.getReport() : null
if (!report) {
return null
}
if (report.header && report.header.glibcVersionRuntime) {
return false
}
if (Array.isArray(report.sharedObjects)) {
if (report.sharedObjects.some(isFileMusl)) {
return true
}
2024-02-03 22:15:40 +09:00
}
return false
}
const isMuslFromChildProcess = () => {
try {
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
} catch (e) {
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
return false
}
2023-07-22 20:25:52 +09:00
}
switch (platform) {
case 'android':
switch (arch) {
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'backend-rs.android-arm64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.android-arm64.node')
} else {
nativeBinding = require('backend-rs-android-arm64')
}
} catch (e) {
loadError = e
}
break
case 'arm':
localFileExisted = existsSync(join(__dirname, 'backend-rs.android-arm-eabi.node'))
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.android-arm-eabi.node')
} else {
nativeBinding = require('backend-rs-android-arm-eabi')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Android ${arch}`)
}
break
case 'win32':
switch (arch) {
case 'x64':
localFileExisted = existsSync(
join(__dirname, 'backend-rs.win32-x64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.win32-x64-msvc.node')
} else {
nativeBinding = require('backend-rs-win32-x64-msvc')
}
} catch (e) {
loadError = e
}
break
case 'ia32':
localFileExisted = existsSync(
join(__dirname, 'backend-rs.win32-ia32-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.win32-ia32-msvc.node')
} else {
nativeBinding = require('backend-rs-win32-ia32-msvc')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'backend-rs.win32-arm64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.win32-arm64-msvc.node')
} else {
nativeBinding = require('backend-rs-win32-arm64-msvc')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`)
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'backend-rs.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.darwin-universal.node')
} else {
nativeBinding = require('backend-rs-darwin-universal')
}
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'backend-rs.darwin-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.darwin-x64.node')
} else {
nativeBinding = require('backend-rs-darwin-x64')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'backend-rs.darwin-arm64.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.darwin-arm64.node')
} else {
nativeBinding = require('backend-rs-darwin-arm64')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`)
}
break
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
}
localFileExisted = existsSync(join(__dirname, 'backend-rs.freebsd-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.freebsd-x64.node')
} else {
nativeBinding = require('backend-rs-freebsd-x64')
}
} catch (e) {
loadError = e
}
break
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'backend-rs.linux-x64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.linux-x64-musl.node')
} else {
nativeBinding = require('backend-rs-linux-x64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'backend-rs.linux-x64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.linux-x64-gnu.node')
} else {
nativeBinding = require('backend-rs-linux-x64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'backend-rs.linux-arm64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.linux-arm64-musl.node')
} else {
nativeBinding = require('backend-rs-linux-arm64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'backend-rs.linux-arm64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.linux-arm64-gnu.node')
} else {
nativeBinding = require('backend-rs-linux-arm64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm':
localFileExisted = existsSync(
join(__dirname, 'backend-rs.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('backend-rs-linux-arm-gnueabihf')
}
} catch (e) {
loadError = e
}
break
case 'riscv64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'backend-rs.linux-riscv64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.linux-riscv64-musl.node')
} else {
nativeBinding = require('backend-rs-linux-riscv64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'backend-rs.linux-riscv64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.linux-riscv64-gnu.node')
} else {
nativeBinding = require('backend-rs-linux-riscv64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 's390x':
localFileExisted = existsSync(
join(__dirname, 'backend-rs.linux-s390x-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./backend-rs.linux-s390x-gnu.node')
} else {
nativeBinding = require('backend-rs-linux-s390x-gnu')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
break
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
2023-07-22 20:25:52 +09:00
}
2024-02-03 22:15:40 +09:00
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
try {
nativeBinding = require('./backend-rs.wasi.cjs')
} catch {
// ignore
}
if (!nativeBinding) {
try {
nativeBinding = require('backend-rs-wasm32-wasi')
} catch (err) {
console.error(err)
}
}
}
2023-07-22 20:25:52 +09:00
if (!nativeBinding) {
if (loadError) {
throw loadError
}
throw new Error(`Failed to load native binding`)
2023-07-22 20:25:52 +09:00
}
2024-02-03 22:15:40 +09:00
module.exports.EnvConfig = nativeBinding.EnvConfig
module.exports.JsDbConn = nativeBinding.JsDbConn
module.exports.AntennaSrcEnum = nativeBinding.AntennaSrcEnum
module.exports.checkWordMute = nativeBinding.checkWordMute
module.exports.connectToDatabase = nativeBinding.connectToDatabase
module.exports.convertId = nativeBinding.convertId
module.exports.convertToHiddenPost = nativeBinding.convertToHiddenPost
module.exports.extractHost = nativeBinding.extractHost
module.exports.fetchMeta = nativeBinding.fetchMeta
module.exports.formatMilliseconds = nativeBinding.formatMilliseconds
module.exports.genString = nativeBinding.genString
module.exports.getFullApAccount = nativeBinding.getFullApAccount
module.exports.hashPassword = nativeBinding.hashPassword
module.exports.hasOtherRenoteOfThisNote = nativeBinding.hasOtherRenoteOfThisNote
module.exports.IdConvertType = nativeBinding.IdConvertType
module.exports.isOldPasswordAlgorithm = nativeBinding.isOldPasswordAlgorithm
module.exports.isSelfHost = nativeBinding.isSelfHost
module.exports.metaToPugArgs = nativeBinding.metaToPugArgs
module.exports.MutedNoteReasonEnum = nativeBinding.MutedNoteReasonEnum
module.exports.nativeCreateId = nativeBinding.nativeCreateId
module.exports.nativeGetTimestamp = nativeBinding.nativeGetTimestamp
module.exports.nativeInitIdGenerator = nativeBinding.nativeInitIdGenerator
module.exports.NoteVisibilityEnum = nativeBinding.NoteVisibilityEnum
module.exports.NotificationTypeEnum = nativeBinding.NotificationTypeEnum
module.exports.nyaify = nativeBinding.nyaify
module.exports.PageVisibilityEnum = nativeBinding.PageVisibilityEnum
module.exports.PollNotevisibilityEnum = nativeBinding.PollNotevisibilityEnum
module.exports.readEnvironmentConfig = nativeBinding.readEnvironmentConfig
module.exports.readServerConfig = nativeBinding.readServerConfig
module.exports.RelayStatusEnum = nativeBinding.RelayStatusEnum
module.exports.safeForSql = nativeBinding.safeForSql
module.exports.sqlLikeEscape = nativeBinding.sqlLikeEscape
module.exports.toPuny = nativeBinding.toPuny
module.exports.toPunyOptional = nativeBinding.toPunyOptional
module.exports.UserEmojimodpermEnum = nativeBinding.UserEmojimodpermEnum
module.exports.UserProfileFfvisibilityEnum = nativeBinding.UserProfileFfvisibilityEnum
module.exports.UserProfileMutingnotificationtypesEnum = nativeBinding.UserProfileMutingnotificationtypesEnum
module.exports.verifyPassword = nativeBinding.verifyPassword