From 3d28acb2c915b2db06e56dba9e01b6270750c27f Mon Sep 17 00:00:00 2001 From: naskya Date: Fri, 17 May 2024 07:32:02 +0900 Subject: [PATCH] chore (backend-rs): rename types and modules --- packages/backend-rs/index.d.ts | 46 +++++++++---------- packages/backend-rs/index.js | 12 ++--- packages/backend-rs/src/init/mod.rs | 2 +- .../{hardware_stats.rs => system_info.rs} | 6 +-- packages/backend-rs/src/misc/mod.rs | 2 +- .../{hardware_stats.rs => system_info.rs} | 8 ++-- 6 files changed, 38 insertions(+), 38 deletions(-) rename packages/backend-rs/src/init/{hardware_stats.rs => system_info.rs} (85%) rename packages/backend-rs/src/misc/{hardware_stats.rs => system_info.rs} (90%) diff --git a/packages/backend-rs/index.d.ts b/packages/backend-rs/index.d.ts index 2199920310..7d9c709cbc 100644 --- a/packages/backend-rs/index.d.ts +++ b/packages/backend-rs/index.d.ts @@ -211,8 +211,8 @@ export interface Acct { } export function stringToAcct(acct: string): Acct export function acctToString(acct: Acct): string -export function showServerInfo(): void export function initializeRustLogger(): void +export function showServerInfo(): void export function addNoteToAntenna(antennaId: string, note: Note): void /** * Checks if a server is blocked. @@ -267,28 +267,6 @@ export interface NoteLikeForGetNoteSummary { hasPoll: boolean } export function getNoteSummary(note: NoteLikeForGetNoteSummary): string -export interface Cpu { - model: string - cores: number -} -export interface Memory { - /** Total memory amount in bytes */ - total: number - /** Used memory amount in bytes */ - used: number - /** Available (for (re)use) memory amount in bytes */ - available: number -} -export interface Storage { - /** Total storage space in bytes */ - total: number - /** Used storage space in bytes */ - used: number -} -export function cpuInfo(): Cpu -export function cpuUsage(): number -export function memoryUsage(): Memory -export function storageUsage(): Storage | null export function isSafeUrl(url: string): boolean export function latestVersion(): Promise export function toMastodonId(firefishId: string): string | null @@ -320,6 +298,28 @@ export function countReactions(reactions: Record): Record /** Delete all entries in the "attestation_challenge" table created at more than 5 minutes ago */ export function removeOldAttestationChallenges(): Promise +export interface Cpu { + model: string + cores: number +} +export interface Memory { + /** Total memory amount in bytes */ + total: number + /** Used memory amount in bytes */ + used: number + /** Available (for (re)use) memory amount in bytes */ + available: number +} +export interface Storage { + /** Total storage space in bytes */ + total: number + /** Used storage space in bytes */ + used: number +} +export function cpuInfo(): Cpu +export function cpuUsage(): number +export function memoryUsage(): Memory +export function storageUsage(): Storage | null export interface AbuseUserReport { id: string createdAt: Date diff --git a/packages/backend-rs/index.js b/packages/backend-rs/index.js index 36cd88dcbd..71247827a9 100644 --- a/packages/backend-rs/index.js +++ b/packages/backend-rs/index.js @@ -310,7 +310,7 @@ if (!nativeBinding) { throw new Error(`Failed to load native binding`) } -const { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, loadEnv, loadConfig, stringToAcct, acctToString, showServerInfo, initializeRustLogger, addNoteToAntenna, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, cpuInfo, cpuUsage, memoryUsage, storageUsage, isSafeUrl, latestVersion, toMastodonId, fromMastodonId, fetchMeta, metaToPugArgs, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, AntennaSrcEnum, DriveFileUsageHintEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, watchNote, unwatchNote, PushNotificationKind, sendPushNotification, publishToChannelStream, ChatEvent, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, getTimestamp, genId, genIdAt, generateSecureRandomString, generateUserToken } = nativeBinding +const { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, loadEnv, loadConfig, stringToAcct, acctToString, initializeRustLogger, showServerInfo, addNoteToAntenna, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, isSafeUrl, latestVersion, toMastodonId, fromMastodonId, fetchMeta, metaToPugArgs, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, cpuInfo, cpuUsage, memoryUsage, storageUsage, AntennaSrcEnum, DriveFileUsageHintEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, watchNote, unwatchNote, PushNotificationKind, sendPushNotification, publishToChannelStream, ChatEvent, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, getTimestamp, genId, genIdAt, generateSecureRandomString, generateUserToken } = nativeBinding module.exports.SECOND = SECOND module.exports.MINUTE = MINUTE @@ -323,8 +323,8 @@ module.exports.loadEnv = loadEnv module.exports.loadConfig = loadConfig module.exports.stringToAcct = stringToAcct module.exports.acctToString = acctToString -module.exports.showServerInfo = showServerInfo module.exports.initializeRustLogger = initializeRustLogger +module.exports.showServerInfo = showServerInfo module.exports.addNoteToAntenna = addNoteToAntenna module.exports.isBlockedServer = isBlockedServer module.exports.isSilencedServer = isSilencedServer @@ -341,10 +341,6 @@ module.exports.safeForSql = safeForSql module.exports.formatMilliseconds = formatMilliseconds module.exports.getImageSizeFromUrl = getImageSizeFromUrl module.exports.getNoteSummary = getNoteSummary -module.exports.cpuInfo = cpuInfo -module.exports.cpuUsage = cpuUsage -module.exports.memoryUsage = memoryUsage -module.exports.storageUsage = storageUsage module.exports.isSafeUrl = isSafeUrl module.exports.latestVersion = latestVersion module.exports.toMastodonId = toMastodonId @@ -359,6 +355,10 @@ module.exports.decodeReaction = decodeReaction module.exports.countReactions = countReactions module.exports.toDbReaction = toDbReaction module.exports.removeOldAttestationChallenges = removeOldAttestationChallenges +module.exports.cpuInfo = cpuInfo +module.exports.cpuUsage = cpuUsage +module.exports.memoryUsage = memoryUsage +module.exports.storageUsage = storageUsage module.exports.AntennaSrcEnum = AntennaSrcEnum module.exports.DriveFileUsageHintEnum = DriveFileUsageHintEnum module.exports.MutedNoteReasonEnum = MutedNoteReasonEnum diff --git a/packages/backend-rs/src/init/mod.rs b/packages/backend-rs/src/init/mod.rs index 6a72c210d1..252339d8fd 100644 --- a/packages/backend-rs/src/init/mod.rs +++ b/packages/backend-rs/src/init/mod.rs @@ -1,2 +1,2 @@ -pub mod hardware_stats; pub mod log; +pub mod system_info; diff --git a/packages/backend-rs/src/init/hardware_stats.rs b/packages/backend-rs/src/init/system_info.rs similarity index 85% rename from packages/backend-rs/src/init/hardware_stats.rs rename to packages/backend-rs/src/init/system_info.rs index b57cb6e47b..4fb6e3a21f 100644 --- a/packages/backend-rs/src/init/hardware_stats.rs +++ b/packages/backend-rs/src/init/system_info.rs @@ -1,16 +1,16 @@ use std::sync::{Mutex, MutexGuard, OnceLock, PoisonError}; use sysinfo::System; -pub type SystemMutexError = PoisonError>; +pub type SysinfoPoisonError = PoisonError>; // TODO: handle this in a more proper way when we move the entry point to backend-rs -pub fn system() -> Result, SystemMutexError> { +pub fn system() -> Result, SysinfoPoisonError> { pub static SYSTEM: OnceLock> = OnceLock::new(); SYSTEM.get_or_init(|| Mutex::new(System::new_all())).lock() } #[crate::export] -pub fn show_server_info() -> Result<(), SystemMutexError> { +pub fn show_server_info() -> Result<(), SysinfoPoisonError> { let system_info = system()?; tracing::info!( diff --git a/packages/backend-rs/src/misc/mod.rs b/packages/backend-rs/src/misc/mod.rs index ba1ad32c10..ed84f4ece2 100644 --- a/packages/backend-rs/src/misc/mod.rs +++ b/packages/backend-rs/src/misc/mod.rs @@ -7,7 +7,6 @@ pub mod escape_sql; pub mod format_milliseconds; pub mod get_image_size; pub mod get_note_summary; -pub mod hardware_stats; pub mod is_safe_url; pub mod latest_version; pub mod mastodon_id; @@ -16,3 +15,4 @@ pub mod nyaify; pub mod password; pub mod reaction; pub mod remove_old_attestation_challenges; +pub mod system_info; diff --git a/packages/backend-rs/src/misc/hardware_stats.rs b/packages/backend-rs/src/misc/system_info.rs similarity index 90% rename from packages/backend-rs/src/misc/hardware_stats.rs rename to packages/backend-rs/src/misc/system_info.rs index f21e4c59a5..df0fa5bb9e 100644 --- a/packages/backend-rs/src/misc/hardware_stats.rs +++ b/packages/backend-rs/src/misc/system_info.rs @@ -1,4 +1,4 @@ -use crate::init::hardware_stats::{system, SystemMutexError}; +use crate::init::system_info::{system, SysinfoPoisonError}; use sysinfo::{Disks, MemoryRefreshKind}; // TODO: i64 -> u64 (we can't export u64 to Node.js) @@ -29,7 +29,7 @@ pub struct Storage { } #[crate::export] -pub fn cpu_info() -> Result { +pub fn cpu_info() -> Result { let system_info = system()?; Ok(Cpu { @@ -45,7 +45,7 @@ pub fn cpu_info() -> Result { } #[crate::export] -pub fn cpu_usage() -> Result { +pub fn cpu_usage() -> Result { let mut system_info = system()?; system_info.refresh_cpu_usage(); @@ -56,7 +56,7 @@ pub fn cpu_usage() -> Result { } #[crate::export] -pub fn memory_usage() -> Result { +pub fn memory_usage() -> Result { let mut system_info = system()?; system_info.refresh_memory_specifics(MemoryRefreshKind::new().with_ram());