This commit is contained in:
Your Name
2026-08-27 14:04:28 +08:00
parent f7720831be
commit 334890171e
3016 changed files with 263403 additions and 27971 deletions
+10
View File
@@ -0,0 +1,10 @@
$ErrorActionPreference = 'Stop'
$go = Join-Path $PSScriptRoot '..\.tools\go\bin\go.exe'
if (-not (Test-Path -LiteralPath $go)) { $go = 'go' }
$env:IM_DB_DSN = if ($env:IM_DB_DSN) { $env:IM_DB_DSN } else { 'root:root@tcp(127.0.0.1:3306)/im?charset=utf8mb4&parseTime=True&loc=Local' }
$env:IM_ENV = if ($env:IM_ENV) { $env:IM_ENV } else { 'development' }
$env:IM_SEED_DEMO = if ($env:IM_SEED_DEMO) { $env:IM_SEED_DEMO } else { 'true' }
$env:IM_BOOTSTRAP_ADMIN_USERNAME = if ($env:IM_BOOTSTRAP_ADMIN_USERNAME) { $env:IM_BOOTSTRAP_ADMIN_USERNAME } else { 'admin' }
$env:IM_BOOTSTRAP_ADMIN_PASSWORD = if ($env:IM_BOOTSTRAP_ADMIN_PASSWORD) { $env:IM_BOOTSTRAP_ADMIN_PASSWORD } else { 'Admin@123' }
Push-Location (Join-Path $PSScriptRoot '..\backend')
try { & $go run .\cmd\server } finally { Pop-Location }
+33
View File
@@ -0,0 +1,33 @@
$ErrorActionPreference = 'Stop'
$env:MYSQL_PWD = if ($env:IM_DB_PASSWORD) { $env:IM_DB_PASSWORD } else { 'root' }
$mysql = if ($env:IM_MYSQL_BIN) { $env:IM_MYSQL_BIN } else { 'mysql' }
$hostName = if ($env:IM_DB_HOST) { $env:IM_DB_HOST } else { '127.0.0.1' }
$userName = if ($env:IM_DB_USER) { $env:IM_DB_USER } else { 'root' }
$database = if ($env:IM_DB_NAME) { $env:IM_DB_NAME } else { 'im' }
$baseArgs = @('-h', $hostName, '-u', $userName, '--default-character-set=utf8mb4', '--batch', '--skip-column-names', $database)
& $mysql @baseArgs --execute "CREATE TABLE IF NOT EXISTS schema_migrations (version VARCHAR(255) NOT NULL PRIMARY KEY, checksum CHAR(64) NOT NULL, applied_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
if ($LASTEXITCODE -ne 0) { throw 'Could not initialize schema_migrations.' }
Get-ChildItem -LiteralPath "$PSScriptRoot\..\backend\migrations" -Filter '*.sql' |
Sort-Object Name |
ForEach-Object {
$version = $_.Name.Replace("'", "''")
$checksum = (Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256).Hash.ToLowerInvariant()
$existing = (& $mysql @baseArgs --execute "SELECT checksum FROM schema_migrations WHERE version='$version'") -join ''
if ($LASTEXITCODE -ne 0) { throw "Could not inspect migration: $($_.Name)" }
$existing = $existing.Trim()
if ($existing) {
if ($existing -ne $checksum) { throw "Migration checksum mismatch: $($_.Name)" }
Write-Host "Already applied $($_.Name)."
return
}
Write-Host "Applying $($_.Name)..."
$migrationPath = $_.FullName.Replace('\', '/')
& $mysql @baseArgs --execute "source $migrationPath"
if ($LASTEXITCODE -ne 0) { throw "Migration failed: $($_.Name)" }
& $mysql @baseArgs --execute "INSERT INTO schema_migrations(version,checksum) VALUES('$version','$checksum')"
if ($LASTEXITCODE -ne 0) { throw "Could not record migration: $($_.Name)" }
}
Write-Host 'Database migrations completed.'
+99
View File
@@ -0,0 +1,99 @@
$ErrorActionPreference = 'Stop'
$base = 'http://127.0.0.1:8888'
function Invoke-Json {
param(
[Parameter(Mandatory = $true)][string]$Method,
[Parameter(Mandatory = $true)][string]$Uri,
[object]$Body,
[string]$Token = ''
)
$headers = @{}
if ($Token) { $headers.Authorization = "Bearer $Token" }
$parameters = @{ Method = $Method; Uri = $Uri; Headers = $headers }
if ($null -ne $Body) {
$parameters.ContentType = 'application/json; charset=utf-8'
$parameters.Body = $Body | ConvertTo-Json -Depth 10 -Compress
}
$response = Invoke-RestMethod @parameters
if ($response.code -ne 0) { throw "API returned code $($response.code): $($response.message)" }
return $response.data
}
$health = Invoke-RestMethod -Method Get -Uri "$base/healthz"
if ($health.code -ne 0 -or $health.data.status -ne 'ok') { throw 'Health check failed' }
$userSession = Invoke-Json -Method Post -Uri "$base/api/v1/auth/login/password" -Body @{
phone = '13800138000'
password = '123456'
deviceId = 'smoke-test'
}
$userToken = $userSession.accessToken
$me = Invoke-Json -Method Get -Uri "$base/api/v1/me" -Token $userToken
$discover = Invoke-Json -Method Get -Uri "$base/api/v1/discover/recommendations" -Token $userToken
$nearby = Invoke-Json -Method Get -Uri "$base/api/v1/nearby/users?latitude=31.2304&longitude=121.4737" -Token $userToken
$feed = Invoke-Json -Method Get -Uri "$base/api/v1/feed" -Token $userToken
$plans = Invoke-Json -Method Get -Uri "$base/api/v1/membership/plans"
$channels = Invoke-Json -Method Get -Uri "$base/api/v1/payment/channels"
$search = Invoke-Json -Method Get -Uri "$base/api/v1/users/search?q=%E5%B0%8F%E9%B9%BF" -Token $userToken
$privacy = Invoke-Json -Method Get -Uri "$base/api/v1/me/privacy" -Token $userToken
$following = Invoke-Json -Method Get -Uri "$base/api/v1/me/following" -Token $userToken
$sms = Invoke-Json -Method Post -Uri "$base/api/v1/auth/sms/send" -Body @{
phone = '13900000001'
scene = 'reset'
}
$conversation = Invoke-Json -Method Post -Uri "$base/api/v1/im/conversations/direct" -Token $userToken -Body @{ userId = 2 }
$clientMessageId = ('smoke-' + [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds())
$messageBody = @{ clientMsgId = $clientMessageId; type = 1; content = @{ text = 'smoke test' } }
$message = Invoke-Json -Method Post -Uri "$base/api/v1/im/conversations/$($conversation.id)/messages" -Token $userToken -Body $messageBody
$duplicate = Invoke-Json -Method Post -Uri "$base/api/v1/im/conversations/$($conversation.id)/messages" -Token $userToken -Body $messageBody
if ($message.id -ne $duplicate.id) { throw 'IM idempotency check failed' }
$messages = Invoke-Json -Method Get -Uri "$base/api/v1/im/conversations/$($conversation.id)/messages" -Token $userToken
$adminSession = Invoke-Json -Method Post -Uri "$base/admin/v1/auth/login" -Body @{
username = 'admin'
password = 'Admin@123'
}
$adminToken = $adminSession.accessToken
$overview = Invoke-Json -Method Get -Uri "$base/admin/v1/dashboard/overview" -Token $adminToken
$adminUsers = Invoke-Json -Method Get -Uri "$base/admin/v1/users?page=1&size=20" -Token $adminToken
$adminPosts = Invoke-Json -Method Get -Uri "$base/admin/v1/posts?page=1&size=20" -Token $adminToken
$adminReports = Invoke-Json -Method Get -Uri "$base/admin/v1/reports?page=1&size=20" -Token $adminToken
$adminPlans = Invoke-Json -Method Get -Uri "$base/admin/v1/membership/plans" -Token $adminToken
$orders = Invoke-Json -Method Get -Uri "$base/admin/v1/orders?page=1&size=20" -Token $adminToken
$configs = Invoke-Json -Method Get -Uri "$base/admin/v1/system/configs" -Token $adminToken
$smsConfig = Invoke-Json -Method Get -Uri "$base/admin/v1/integrations/sms" -Token $adminToken
$paymentConfig = Invoke-Json -Method Get -Uri "$base/admin/v1/integrations/payment" -Token $adminToken
$smsTest = Invoke-Json -Method Post -Uri "$base/admin/v1/integrations/sms/test" -Token $adminToken
$paymentTest = Invoke-Json -Method Post -Uri "$base/admin/v1/integrations/payment/test" -Token $adminToken
$audit = Invoke-Json -Method Get -Uri "$base/admin/v1/audit-logs?page=1&size=20" -Token $adminToken
[pscustomobject]@{
health = $health.data.status
user = $me.nickname
recommendations = $discover.total
nearby = $nearby.total
feed = $feed.total
plans = $plans.items.Count
paymentChannels = $channels.items.Count
searchResults = $search.total
following = $following.total
privacyLoaded = ($null -ne $privacy.allowSearch)
smsDebug = ($sms.provider -eq 'debug')
conversation = $conversation.id
messages = $messages.items.Count
imIdempotent = ($message.id -eq $duplicate.id)
adminUsers = $adminUsers.total
adminPosts = $adminPosts.total
reports = $adminReports.total
orders = $orders.total
configs = $configs.items.Count
smsConfigReady = $smsConfig.configured
paymentConfigReady = $paymentConfig.configured
smsTest = $smsTest.success
paymentTest = $paymentTest.success
auditLogs = $audit.total
overviewUsers = $overview.metrics.users
} | Format-List