mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-04-28 02:56:44 +00:00
Compare commits
21 Commits
codex/ci-a
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
634babfba4 | ||
|
|
e7fe1afe19 | ||
|
|
171762d676 | ||
|
|
76e091900b | ||
|
|
bfa4ceab90 | ||
|
|
b18cfa797a | ||
|
|
8a117a41e8 | ||
|
|
17ba41320e | ||
|
|
476c0bfefc | ||
|
|
1c6691d785 | ||
|
|
36ae290cb6 | ||
|
|
597715ce33 | ||
|
|
a8a08c1dcc | ||
|
|
7757729efd | ||
|
|
b246bfdac7 | ||
|
|
d35393ba22 | ||
|
|
c893dd7095 | ||
|
|
9bdb18d833 | ||
|
|
58fc1af74f | ||
|
|
1b3cf33bf0 | ||
|
|
c9005d0c04 |
34
.github/scripts/deploy_windows_winrm.py
vendored
34
.github/scripts/deploy_windows_winrm.py
vendored
@@ -29,10 +29,18 @@ def main() -> int:
|
|||||||
port = optional_env("KK_DEPLOY_PORT", "5985")
|
port = optional_env("KK_DEPLOY_PORT", "5985")
|
||||||
username = require_env("KK_DEPLOY_USERNAME")
|
username = require_env("KK_DEPLOY_USERNAME")
|
||||||
password = require_env("KK_DEPLOY_PASSWORD")
|
password = require_env("KK_DEPLOY_PASSWORD")
|
||||||
deploy_root = optional_env("KK_DEPLOY_ROOT", r"C:\kkFileView-5.0")
|
env_pairs = {
|
||||||
health_url = optional_env("KK_DEPLOY_HEALTH_URL", "http://127.0.0.1:8012/")
|
"KK_DEPLOY_ROOT": optional_env("KK_DEPLOY_ROOT", r"C:\kkFileView-5.0"),
|
||||||
artifact_url = require_env("KK_DEPLOY_ARTIFACT_URL")
|
"KK_DEPLOY_HEALTH_URL": optional_env("KK_DEPLOY_HEALTH_URL", "http://127.0.0.1:8012/"),
|
||||||
dry_run = optional_env("KK_DEPLOY_DRY_RUN", "false").lower()
|
"KK_DEPLOY_REPO_URL": optional_env("KK_DEPLOY_REPO_URL", "https://github.com/kekingcn/kkFileView.git"),
|
||||||
|
"KK_DEPLOY_BRANCH": optional_env("KK_DEPLOY_BRANCH", "master"),
|
||||||
|
"KK_DEPLOY_SOURCE_ROOT": optional_env("KK_DEPLOY_SOURCE_ROOT", r"C:\kkFileView-source"),
|
||||||
|
"KK_DEPLOY_JAVA_HOME": optional_env("KK_DEPLOY_JAVA_HOME", r"C:\Program Files\jdk-21.0.2"),
|
||||||
|
"KK_DEPLOY_GIT_EXE": optional_env("KK_DEPLOY_GIT_EXE", r"C:\kkFileView-tools\git\cmd\git.exe"),
|
||||||
|
"KK_DEPLOY_MVN_CMD": optional_env("KK_DEPLOY_MVN_CMD", r"C:\kkFileView-tools\maven\bin\mvn.cmd"),
|
||||||
|
"KK_DEPLOY_MAVEN_SETTINGS": optional_env("KK_DEPLOY_MAVEN_SETTINGS", ""),
|
||||||
|
"KK_DEPLOY_DRY_RUN": optional_env("KK_DEPLOY_DRY_RUN", "false").lower(),
|
||||||
|
}
|
||||||
|
|
||||||
script_path = pathlib.Path(__file__).with_name("remote_windows_deploy.ps1")
|
script_path = pathlib.Path(__file__).with_name("remote_windows_deploy.ps1")
|
||||||
script_body = script_path.read_text(encoding="utf-8")
|
script_body = script_path.read_text(encoding="utf-8")
|
||||||
@@ -74,17 +82,19 @@ $ErrorActionPreference = 'Stop'
|
|||||||
$raw = Get-Content -LiteralPath '{ps_quote(remote_b64_path)}' -Raw
|
$raw = Get-Content -LiteralPath '{ps_quote(remote_b64_path)}' -Raw
|
||||||
[System.IO.File]::WriteAllBytes('{ps_quote(remote_ps1_path)}', [Convert]::FromBase64String($raw))
|
[System.IO.File]::WriteAllBytes('{ps_quote(remote_ps1_path)}', [Convert]::FromBase64String($raw))
|
||||||
try {{
|
try {{
|
||||||
$env:KK_DEPLOY_ARTIFACT_URL = '{ps_quote(artifact_url)}'
|
"""
|
||||||
$env:KK_DEPLOY_ROOT = '{ps_quote(deploy_root)}'
|
+ "\n".join(
|
||||||
$env:KK_DEPLOY_HEALTH_URL = '{ps_quote(health_url)}'
|
f" $env:{key} = '{ps_quote(value)}'" for key, value in env_pairs.items()
|
||||||
$env:KK_DEPLOY_DRY_RUN = '{ps_quote(dry_run)}'
|
)
|
||||||
|
+ f"""
|
||||||
powershell -NoProfile -ExecutionPolicy Bypass -File '{ps_quote(remote_ps1_path)}' `
|
powershell -NoProfile -ExecutionPolicy Bypass -File '{ps_quote(remote_ps1_path)}' `
|
||||||
$code = $LASTEXITCODE
|
$code = $LASTEXITCODE
|
||||||
}} finally {{
|
}} finally {{
|
||||||
Remove-Item Env:KK_DEPLOY_ARTIFACT_URL -ErrorAction SilentlyContinue
|
"""
|
||||||
Remove-Item Env:KK_DEPLOY_ROOT -ErrorAction SilentlyContinue
|
+ "\n".join(
|
||||||
Remove-Item Env:KK_DEPLOY_HEALTH_URL -ErrorAction SilentlyContinue
|
f" Remove-Item Env:{key} -ErrorAction SilentlyContinue" for key in env_pairs
|
||||||
Remove-Item Env:KK_DEPLOY_DRY_RUN -ErrorAction SilentlyContinue
|
)
|
||||||
|
+ f"""
|
||||||
Remove-Item '{ps_quote(remote_b64_path)}' -Force -ErrorAction SilentlyContinue
|
Remove-Item '{ps_quote(remote_b64_path)}' -Force -ErrorAction SilentlyContinue
|
||||||
Remove-Item '{ps_quote(remote_ps1_path)}' -Force -ErrorAction SilentlyContinue
|
Remove-Item '{ps_quote(remote_ps1_path)}' -Force -ErrorAction SilentlyContinue
|
||||||
}}
|
}}
|
||||||
|
|||||||
206
.github/scripts/remote_windows_deploy.ps1
vendored
206
.github/scripts/remote_windows_deploy.ps1
vendored
@@ -1,4 +1,5 @@
|
|||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$ProgressPreference = 'SilentlyContinue'
|
||||||
|
|
||||||
function Write-Step {
|
function Write-Step {
|
||||||
param([string]$Message)
|
param([string]$Message)
|
||||||
@@ -30,17 +31,22 @@ function Get-OptionalEnv {
|
|||||||
return $Value
|
return $Value
|
||||||
}
|
}
|
||||||
|
|
||||||
$ArtifactDownloadUrl = Get-RequiredEnv 'KK_DEPLOY_ARTIFACT_URL'
|
|
||||||
$DeployRoot = Get-OptionalEnv 'KK_DEPLOY_ROOT' 'C:\kkFileView-5.0'
|
$DeployRoot = Get-OptionalEnv 'KK_DEPLOY_ROOT' 'C:\kkFileView-5.0'
|
||||||
$HealthUrl = Get-OptionalEnv 'KK_DEPLOY_HEALTH_URL' 'http://127.0.0.1:8012/'
|
$HealthUrl = Get-OptionalEnv 'KK_DEPLOY_HEALTH_URL' 'http://127.0.0.1:8012/'
|
||||||
|
$RepoUrl = Get-OptionalEnv 'KK_DEPLOY_REPO_URL' 'https://github.com/kekingcn/kkFileView.git'
|
||||||
|
$Branch = Get-OptionalEnv 'KK_DEPLOY_BRANCH' 'master'
|
||||||
|
$SourceRoot = Get-OptionalEnv 'KK_DEPLOY_SOURCE_ROOT' 'C:\kkFileView-source'
|
||||||
|
$JavaHome = Get-OptionalEnv 'KK_DEPLOY_JAVA_HOME' 'C:\Program Files\jdk-21.0.2'
|
||||||
|
$GitExe = Get-OptionalEnv 'KK_DEPLOY_GIT_EXE' 'C:\kkFileView-tools\git\cmd\git.exe'
|
||||||
|
$MvnCmd = Get-OptionalEnv 'KK_DEPLOY_MVN_CMD' 'C:\kkFileView-tools\maven\bin\mvn.cmd'
|
||||||
|
$MavenSettings = Get-OptionalEnv 'KK_DEPLOY_MAVEN_SETTINGS' ''
|
||||||
$DryRun = Get-OptionalEnv 'KK_DEPLOY_DRY_RUN' 'false'
|
$DryRun = Get-OptionalEnv 'KK_DEPLOY_DRY_RUN' 'false'
|
||||||
|
|
||||||
$BinDir = Join-Path $DeployRoot 'bin'
|
$BinDir = Join-Path $DeployRoot 'bin'
|
||||||
$StartupScript = Join-Path $BinDir 'startup.bat'
|
$StartupScript = Join-Path $BinDir 'startup.bat'
|
||||||
$ReleaseDir = Join-Path $DeployRoot 'releases'
|
$ReleaseDir = Join-Path $DeployRoot 'releases'
|
||||||
$DeployTmp = Join-Path $DeployRoot 'deploy-tmp'
|
$DeployTmp = Join-Path $DeployRoot 'deploy-tmp'
|
||||||
$ArtifactZip = Join-Path $DeployTmp 'artifact.zip'
|
$BuildOutputDir = Join-Path (Join-Path $SourceRoot 'server') 'target'
|
||||||
$ExtractDir = Join-Path $DeployTmp 'artifact'
|
|
||||||
|
|
||||||
if (-not (Test-Path $DeployRoot)) {
|
if (-not (Test-Path $DeployRoot)) {
|
||||||
throw "Deploy root not found: $DeployRoot"
|
throw "Deploy root not found: $DeployRoot"
|
||||||
@@ -59,6 +65,23 @@ if (-not $CurrentJar) {
|
|||||||
throw "No kkFileView jar found in $BinDir"
|
throw "No kkFileView jar found in $BinDir"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$JavaExe = Join-Path $JavaHome 'bin\java.exe'
|
||||||
|
if (-not (Test-Path $JavaExe)) {
|
||||||
|
throw "JDK 21 java executable not found: $JavaExe"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path $GitExe)) {
|
||||||
|
throw "Git executable not found: $GitExe"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path $MvnCmd)) {
|
||||||
|
throw "Maven executable not found: $MvnCmd"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($MavenSettings) -and -not (Test-Path $MavenSettings)) {
|
||||||
|
throw "Maven settings file not found: $MavenSettings"
|
||||||
|
}
|
||||||
|
|
||||||
$JarName = $CurrentJar.Name
|
$JarName = $CurrentJar.Name
|
||||||
$JarPath = $CurrentJar.FullName
|
$JarPath = $CurrentJar.FullName
|
||||||
|
|
||||||
@@ -66,6 +89,74 @@ Write-Step "Deploy root: $DeployRoot"
|
|||||||
Write-Step "Current jar: $JarPath"
|
Write-Step "Current jar: $JarPath"
|
||||||
Write-Step "Startup script: $StartupScript"
|
Write-Step "Startup script: $StartupScript"
|
||||||
Write-Step "Health url: $HealthUrl"
|
Write-Step "Health url: $HealthUrl"
|
||||||
|
Write-Step "Source root: $SourceRoot"
|
||||||
|
Write-Step "Branch: $Branch"
|
||||||
|
Write-Step "Git exe: $GitExe"
|
||||||
|
Write-Step "Maven cmd: $MvnCmd"
|
||||||
|
Write-Step "Java home: $JavaHome"
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($MavenSettings)) {
|
||||||
|
Write-Step "Maven settings: $MavenSettings"
|
||||||
|
}
|
||||||
|
|
||||||
|
function Invoke-External {
|
||||||
|
param(
|
||||||
|
[string]$FilePath,
|
||||||
|
[string[]]$Arguments,
|
||||||
|
[string]$WorkingDirectory = $null
|
||||||
|
)
|
||||||
|
|
||||||
|
$previous = $null
|
||||||
|
if ($WorkingDirectory) {
|
||||||
|
$previous = Get-Location
|
||||||
|
Set-Location $WorkingDirectory
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
& $FilePath @Arguments
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
throw "Command failed ($LASTEXITCODE): $FilePath $($Arguments -join ' ')"
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if ($previous) {
|
||||||
|
Set-Location $previous
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Assert-SafeSourceRoot {
|
||||||
|
param([string]$PathToCheck)
|
||||||
|
|
||||||
|
$FullPath = [System.IO.Path]::GetFullPath($PathToCheck)
|
||||||
|
$RootPath = [System.IO.Path]::GetPathRoot($FullPath)
|
||||||
|
if ($FullPath.TrimEnd('\') -eq $RootPath.TrimEnd('\')) {
|
||||||
|
throw "Refusing to use drive root as source root: $FullPath"
|
||||||
|
}
|
||||||
|
|
||||||
|
$DangerousLeafNames = @(
|
||||||
|
'Windows',
|
||||||
|
'Users',
|
||||||
|
'Program Files',
|
||||||
|
'Program Files (x86)',
|
||||||
|
'ProgramData'
|
||||||
|
)
|
||||||
|
$LeafName = Split-Path -Leaf $FullPath.TrimEnd('\')
|
||||||
|
if ($DangerousLeafNames -contains $LeafName) {
|
||||||
|
throw "Refusing to use a high-risk source root path: $FullPath"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$env:JAVA_HOME = $JavaHome
|
||||||
|
$env:Path = (Join-Path $JavaHome 'bin') + ';' + (Split-Path -Parent $GitExe) + ';' + (Split-Path -Parent $MvnCmd) + ';' + $env:Path
|
||||||
|
|
||||||
|
Write-Step 'Validating Git executable'
|
||||||
|
Invoke-External -FilePath $GitExe -Arguments @('--version')
|
||||||
|
|
||||||
|
Write-Step 'Validating Maven executable'
|
||||||
|
$MavenVersionArgs = @('-version')
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($MavenSettings)) {
|
||||||
|
$MavenVersionArgs = @('-s', $MavenSettings, '-version')
|
||||||
|
}
|
||||||
|
Invoke-External -FilePath $MvnCmd -Arguments $MavenVersionArgs
|
||||||
|
|
||||||
if ($DryRun -eq 'true') {
|
if ($DryRun -eq 'true') {
|
||||||
Write-Step "Dry run enabled, remote validation finished"
|
Write-Step "Dry run enabled, remote validation finished"
|
||||||
@@ -75,41 +166,51 @@ if ($DryRun -eq 'true') {
|
|||||||
New-Item -ItemType Directory -Force -Path $ReleaseDir | Out-Null
|
New-Item -ItemType Directory -Force -Path $ReleaseDir | Out-Null
|
||||||
New-Item -ItemType Directory -Force -Path $DeployTmp | Out-Null
|
New-Item -ItemType Directory -Force -Path $DeployTmp | Out-Null
|
||||||
|
|
||||||
if (Test-Path $ArtifactZip) {
|
function Sync-Repository {
|
||||||
Remove-Item $ArtifactZip -Force
|
Assert-SafeSourceRoot -PathToCheck $SourceRoot
|
||||||
|
|
||||||
|
if (-not (Test-Path (Join-Path $SourceRoot '.git'))) {
|
||||||
|
if (Test-Path $SourceRoot) {
|
||||||
|
Remove-Item $SourceRoot -Recurse -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
$parent = Split-Path -Parent $SourceRoot
|
||||||
|
if ($parent) {
|
||||||
|
New-Item -ItemType Directory -Force -Path $parent | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Step "Cloning repository from $RepoUrl"
|
||||||
|
Invoke-External -FilePath $GitExe -Arguments @('clone', '--depth', '1', '--branch', $Branch, '--single-branch', $RepoUrl, $SourceRoot)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Step "Fetching latest branch state from origin/$Branch"
|
||||||
|
Invoke-External -FilePath $GitExe -Arguments @('remote', 'set-url', 'origin', $RepoUrl) -WorkingDirectory $SourceRoot
|
||||||
|
Invoke-External -FilePath $GitExe -Arguments @('fetch', '--prune', '--depth', '1', 'origin', $Branch) -WorkingDirectory $SourceRoot
|
||||||
|
Invoke-External -FilePath $GitExe -Arguments @('checkout', '-B', $Branch, "origin/$Branch") -WorkingDirectory $SourceRoot
|
||||||
|
Invoke-External -FilePath $GitExe -Arguments @('reset', '--hard', "origin/$Branch") -WorkingDirectory $SourceRoot
|
||||||
|
Invoke-External -FilePath $GitExe -Arguments @('clean', '-fd') -WorkingDirectory $SourceRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Test-Path $ExtractDir) {
|
function Build-KkFileView {
|
||||||
Remove-Item $ExtractDir -Recurse -Force
|
Write-Step 'Building kkFileView from source'
|
||||||
|
$BuildArgs = @('-B', 'clean', 'package', '-Dmaven.test.skip=true', '--file', 'pom.xml')
|
||||||
|
if (-not [string]::IsNullOrWhiteSpace($MavenSettings)) {
|
||||||
|
$BuildArgs = @('-s', $MavenSettings) + $BuildArgs
|
||||||
|
}
|
||||||
|
Invoke-External -FilePath $MvnCmd -Arguments $BuildArgs -WorkingDirectory $SourceRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Step 'Downloading workflow artifact via signed URL'
|
Sync-Repository
|
||||||
$PreviousProgressPreference = $ProgressPreference
|
Build-KkFileView
|
||||||
$ProgressPreference = 'SilentlyContinue'
|
|
||||||
try {
|
|
||||||
Invoke-WebRequest -Uri $ArtifactDownloadUrl -OutFile $ArtifactZip -UseBasicParsing -TimeoutSec 120
|
|
||||||
} finally {
|
|
||||||
$ProgressPreference = $PreviousProgressPreference
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not (Test-Path $ArtifactZip)) {
|
$DownloadedJars = Get-ChildItem $BuildOutputDir -Filter 'kkFileView-*.jar' -File
|
||||||
throw "Artifact zip was not created: $ArtifactZip"
|
|
||||||
}
|
|
||||||
|
|
||||||
$ArtifactZipInfo = Get-Item $ArtifactZip
|
|
||||||
if ($ArtifactZipInfo.Length -le 0) {
|
|
||||||
throw "Downloaded artifact zip is empty: $ArtifactZip"
|
|
||||||
}
|
|
||||||
|
|
||||||
Expand-Archive -LiteralPath $ArtifactZip -DestinationPath $ExtractDir -Force
|
|
||||||
|
|
||||||
$DownloadedJars = Get-ChildItem $ExtractDir -Filter 'kkFileView-*.jar' -Recurse
|
|
||||||
if (-not $DownloadedJars) {
|
if (-not $DownloadedJars) {
|
||||||
throw 'No kkFileView jar found inside downloaded workflow artifact'
|
throw "No kkFileView jar found in build output: $BuildOutputDir"
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($DownloadedJars.Count -ne 1) {
|
if ($DownloadedJars.Count -ne 1) {
|
||||||
throw "Expected exactly one kkFileView jar inside downloaded workflow artifact, found $($DownloadedJars.Count)"
|
throw "Expected exactly one kkFileView jar in build output, found $($DownloadedJars.Count)"
|
||||||
}
|
}
|
||||||
|
|
||||||
$DownloadedJar = $DownloadedJars[0]
|
$DownloadedJar = $DownloadedJars[0]
|
||||||
@@ -118,27 +219,33 @@ $Timestamp = Get-Date -Format 'yyyyMMddHHmmss'
|
|||||||
$BackupJar = Join-Path $ReleaseDir ("{0}.{1}.bak" -f $JarName, $Timestamp)
|
$BackupJar = Join-Path $ReleaseDir ("{0}.{1}.bak" -f $JarName, $Timestamp)
|
||||||
|
|
||||||
function Stop-KkFileView {
|
function Stop-KkFileView {
|
||||||
|
foreach ($Process in @(Get-KkFileViewJavaProcesses) + @(Get-KkFileViewLauncherProcesses)) {
|
||||||
|
Write-Step "Stopping process $($Process.ProcessId)"
|
||||||
|
Stop-Process -Id $Process.ProcessId -Force -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-KkFileViewJavaProcesses {
|
||||||
$JarPattern = [regex]::Escape($JarName)
|
$JarPattern = [regex]::Escape($JarName)
|
||||||
$Processes = Get-CimInstance Win32_Process | Where-Object {
|
return Get-CimInstance Win32_Process | Where-Object {
|
||||||
$_.Name -match '^java(\.exe)?$' -and $_.CommandLine -and $_.CommandLine -match $JarPattern
|
$_.Name -match '^java(\.exe)?$' -and $_.CommandLine -and $_.CommandLine -match $JarPattern
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($Process in $Processes) {
|
function Get-KkFileViewLauncherProcesses {
|
||||||
Write-Step "Stopping java process $($Process.ProcessId)"
|
$StartupPattern = [regex]::Escape([System.IO.Path]::GetFileName($StartupScript))
|
||||||
Stop-Process -Id $Process.ProcessId -Force -ErrorAction SilentlyContinue
|
return Get-CimInstance Win32_Process | Where-Object {
|
||||||
|
$_.Name -ieq 'cmd.exe' -and $_.CommandLine -and $_.CommandLine -match $StartupPattern
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Wait-KkFileViewStopped {
|
function Wait-KkFileViewStopped {
|
||||||
param([int]$TimeoutSeconds = 30)
|
param([int]$TimeoutSeconds = 30)
|
||||||
|
|
||||||
$JarPattern = [regex]::Escape($JarName)
|
|
||||||
for ($i = 0; $i -lt $TimeoutSeconds; $i++) {
|
for ($i = 0; $i -lt $TimeoutSeconds; $i++) {
|
||||||
$Processes = Get-CimInstance Win32_Process | Where-Object {
|
$JavaProcesses = @(Get-KkFileViewJavaProcesses)
|
||||||
$_.Name -match '^java(\.exe)?$' -and $_.CommandLine -and $_.CommandLine -match $JarPattern
|
$CmdProcesses = @(Get-KkFileViewLauncherProcesses)
|
||||||
}
|
if ((@($JavaProcesses).Count + @($CmdProcesses).Count) -eq 0) {
|
||||||
|
|
||||||
if (-not $Processes) {
|
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,20 +257,37 @@ function Wait-KkFileViewStopped {
|
|||||||
|
|
||||||
function Start-KkFileView {
|
function Start-KkFileView {
|
||||||
Write-Step "Starting kkFileView"
|
Write-Step "Starting kkFileView"
|
||||||
Start-Process -FilePath 'cmd.exe' -ArgumentList '/c', "`"$StartupScript`"" -WorkingDirectory $BinDir -WindowStyle Hidden
|
$CreateResult = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{
|
||||||
|
CommandLine = ('cmd.exe /c ""' + $StartupScript + '""')
|
||||||
|
CurrentDirectory = $BinDir
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($CreateResult.ReturnValue -ne 0) {
|
||||||
|
throw "Failed to start kkFileView launcher, Win32_Process.Create returned $($CreateResult.ReturnValue)"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Step "Launcher process created with pid $($CreateResult.ProcessId)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Wait-Health {
|
function Wait-Health {
|
||||||
param([string]$Url)
|
param([string]$Url)
|
||||||
|
|
||||||
|
$SuccessfulChecks = 0
|
||||||
for ($i = 0; $i -lt 24; $i++) {
|
for ($i = 0; $i -lt 24; $i++) {
|
||||||
Start-Sleep -Seconds 5
|
Start-Sleep -Seconds 5
|
||||||
try {
|
try {
|
||||||
$Response = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 5
|
$Response = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 5
|
||||||
if ($Response.StatusCode -eq 200) {
|
if ($Response.StatusCode -eq 200 -and @(Get-KkFileViewJavaProcesses).Count -gt 0) {
|
||||||
|
$SuccessfulChecks++
|
||||||
|
} else {
|
||||||
|
$SuccessfulChecks = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($SuccessfulChecks -ge 3) {
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
$SuccessfulChecks = 0
|
||||||
Start-Sleep -Milliseconds 200
|
Start-Sleep -Milliseconds 200
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
57
.github/workflows/master-auto-deploy.yml
vendored
57
.github/workflows/master-auto-deploy.yml
vendored
@@ -11,46 +11,24 @@ concurrency:
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
actions: read
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up JDK 21
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
java-version: '21'
|
|
||||||
distribution: temurin
|
|
||||||
cache: maven
|
|
||||||
|
|
||||||
- name: Build with Maven
|
|
||||||
run: mvn -B package -Dmaven.test.skip=true --file pom.xml
|
|
||||||
|
|
||||||
- name: Upload server jar artifact
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: kkfileview-server-jar
|
|
||||||
path: server/target/kkFileView-*.jar
|
|
||||||
retention-days: 7
|
|
||||||
|
|
||||||
deploy-windows:
|
deploy-windows:
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
env:
|
env:
|
||||||
GITHUB_REPOSITORY_NAME: ${{ github.repository }}
|
|
||||||
GITHUB_RUN_ID_VALUE: ${{ github.run_id }}
|
|
||||||
KK_DEPLOY_HOST: ${{ secrets.KK_DEPLOY_HOST }}
|
KK_DEPLOY_HOST: ${{ secrets.KK_DEPLOY_HOST }}
|
||||||
KK_DEPLOY_PORT: ${{ secrets.KK_DEPLOY_PORT }}
|
KK_DEPLOY_PORT: ${{ secrets.KK_DEPLOY_PORT }}
|
||||||
KK_DEPLOY_USERNAME: ${{ secrets.KK_DEPLOY_USERNAME }}
|
KK_DEPLOY_USERNAME: ${{ secrets.KK_DEPLOY_USERNAME }}
|
||||||
KK_DEPLOY_PASSWORD: ${{ secrets.KK_DEPLOY_PASSWORD }}
|
KK_DEPLOY_PASSWORD: ${{ secrets.KK_DEPLOY_PASSWORD }}
|
||||||
KK_DEPLOY_ROOT: ${{ secrets.KK_DEPLOY_ROOT }}
|
KK_DEPLOY_ROOT: ${{ secrets.KK_DEPLOY_ROOT }}
|
||||||
KK_DEPLOY_HEALTH_URL: ${{ secrets.KK_DEPLOY_HEALTH_URL }}
|
KK_DEPLOY_HEALTH_URL: ${{ secrets.KK_DEPLOY_HEALTH_URL }}
|
||||||
KK_DEPLOY_ARTIFACT_NAME: kkfileview-server-jar
|
KK_DEPLOY_REPO_URL: ${{ vars.KK_DEPLOY_REPO_URL }}
|
||||||
|
KK_DEPLOY_BRANCH: ${{ vars.KK_DEPLOY_BRANCH }}
|
||||||
|
KK_DEPLOY_SOURCE_ROOT: ${{ vars.KK_DEPLOY_SOURCE_ROOT }}
|
||||||
|
KK_DEPLOY_JAVA_HOME: ${{ vars.KK_DEPLOY_JAVA_HOME }}
|
||||||
|
KK_DEPLOY_GIT_EXE: ${{ vars.KK_DEPLOY_GIT_EXE }}
|
||||||
|
KK_DEPLOY_MVN_CMD: ${{ vars.KK_DEPLOY_MVN_CMD }}
|
||||||
|
KK_DEPLOY_MAVEN_SETTINGS: ${{ vars.KK_DEPLOY_MAVEN_SETTINGS }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
@@ -70,26 +48,5 @@ jobs:
|
|||||||
test -n "$KK_DEPLOY_USERNAME" || (echo "Missing secret: KK_DEPLOY_USERNAME" && exit 1)
|
test -n "$KK_DEPLOY_USERNAME" || (echo "Missing secret: KK_DEPLOY_USERNAME" && exit 1)
|
||||||
test -n "$KK_DEPLOY_PASSWORD" || (echo "Missing secret: KK_DEPLOY_PASSWORD" && exit 1)
|
test -n "$KK_DEPLOY_PASSWORD" || (echo "Missing secret: KK_DEPLOY_PASSWORD" && exit 1)
|
||||||
|
|
||||||
- name: Resolve artifact download URL
|
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ github.token }}
|
|
||||||
run: |
|
|
||||||
artifact_json=$(curl -fsSL \
|
|
||||||
-H "Authorization: Bearer $GH_TOKEN" \
|
|
||||||
-H "Accept: application/vnd.github+json" \
|
|
||||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
||||||
"https://api.github.com/repos/$GITHUB_REPOSITORY_NAME/actions/runs/$GITHUB_RUN_ID_VALUE/artifacts")
|
|
||||||
artifact_id=$(ARTIFACT_JSON="$artifact_json" ARTIFACT_NAME="$KK_DEPLOY_ARTIFACT_NAME" python -c "import json, os; payload=json.loads(os.environ['ARTIFACT_JSON']); name=os.environ['ARTIFACT_NAME']; matches=[artifact for artifact in payload.get('artifacts', []) if artifact.get('name') == name]; matches or (_ for _ in ()).throw(SystemExit(f\"Artifact '{name}' not found for run\")); len(matches) == 1 or (_ for _ in ()).throw(SystemExit(f\"Expected one artifact named '{name}', found {len(matches)}\")); print(matches[0]['id'])")
|
|
||||||
headers_file=$(mktemp)
|
|
||||||
curl -fsS -D "$headers_file" -o /dev/null \
|
|
||||||
-H "Authorization: Bearer $GH_TOKEN" \
|
|
||||||
-H "Accept: application/vnd.github+json" \
|
|
||||||
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
||||||
"https://api.github.com/repos/$GITHUB_REPOSITORY_NAME/actions/artifacts/$artifact_id/zip"
|
|
||||||
artifact_url=$(awk 'BEGIN{IGNORECASE=1} /^location:/ { sub(/\r$/, "", $0); print substr($0, index($0, ":") + 2); exit }' "$headers_file")
|
|
||||||
test -n "$artifact_url" || (echo "Failed to resolve artifact download redirect URL" && exit 1)
|
|
||||||
rm -f "$headers_file"
|
|
||||||
echo "KK_DEPLOY_ARTIFACT_URL=$artifact_url" >> "$GITHUB_ENV"
|
|
||||||
|
|
||||||
- name: Deploy to Windows server
|
- name: Deploy to Windows server
|
||||||
run: python .github/scripts/deploy_windows_winrm.py
|
run: python .github/scripts/deploy_windows_winrm.py
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -26,6 +26,7 @@ nbdist/
|
|||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.artifacts/
|
||||||
|
|
||||||
server/src/main/cache/
|
server/src/main/cache/
|
||||||
server/src/main/file/
|
server/src/main/file/
|
||||||
|
|||||||
230
AGENTS.md
Normal file
230
AGENTS.md
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
# AGENTS.md
|
||||||
|
|
||||||
|
This document is for coding agents and automation tools working in this repository.
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
- Project: `kkFileView`
|
||||||
|
- Stack: Spring Boot + Freemarker + Redis/Redisson (optional) + JODConverter + front-end preview pages
|
||||||
|
- Main module: `server`
|
||||||
|
- Default local URL: `http://127.0.0.1:8012/`
|
||||||
|
- Production demo: `https://file.kkview.cn/`
|
||||||
|
|
||||||
|
This repository is a document preview service. Most user-facing work falls into one of these areas:
|
||||||
|
|
||||||
|
1. preview routing and file-type dispatch
|
||||||
|
2. conversion pipelines for Office / PDF / CAD / archives / images
|
||||||
|
3. Freemarker preview templates under `server/src/main/resources/web`
|
||||||
|
4. CI, E2E fixtures, and production deployment automation
|
||||||
|
|
||||||
|
## Repository Layout
|
||||||
|
|
||||||
|
- `server/`
|
||||||
|
Main application code, templates, config, packaged artifacts
|
||||||
|
- `server/src/main/java/cn/keking/`
|
||||||
|
Core Java application code
|
||||||
|
- `server/src/main/resources/web/`
|
||||||
|
Freemarker preview templates
|
||||||
|
- `server/src/main/resources/static/`
|
||||||
|
Front-end static assets used by preview pages
|
||||||
|
- `server/src/main/config/`
|
||||||
|
Main runtime config files
|
||||||
|
- `server/src/main/bin/`
|
||||||
|
Local startup/dev scripts
|
||||||
|
- `tests/e2e/`
|
||||||
|
Playwright-based end-to-end tests and fixtures
|
||||||
|
- `.github/workflows/`
|
||||||
|
CI and deployment workflows
|
||||||
|
- `.github/scripts/`
|
||||||
|
Windows production deployment scripts over WinRM
|
||||||
|
|
||||||
|
## Key Entry Points
|
||||||
|
|
||||||
|
- App entry:
|
||||||
|
- `server/src/main/java/cn/keking/ServerMain.java`
|
||||||
|
- Preview controller:
|
||||||
|
- `server/src/main/java/cn/keking/web/controller/OnlinePreviewController.java`
|
||||||
|
- File attribute parsing / request handling:
|
||||||
|
- `server/src/main/java/cn/keking/service/FileHandlerService.java`
|
||||||
|
- Office preview flow:
|
||||||
|
- `server/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java`
|
||||||
|
- PDF preview flow:
|
||||||
|
- `server/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java`
|
||||||
|
- Archive extraction:
|
||||||
|
- `server/src/main/java/cn/keking/service/CompressFileReader.java`
|
||||||
|
|
||||||
|
## Important Templates
|
||||||
|
|
||||||
|
- `server/src/main/resources/web/compress.ftl`
|
||||||
|
Archive directory/tree preview page
|
||||||
|
- `server/src/main/resources/web/pdf.ftl`
|
||||||
|
PDF preview container page
|
||||||
|
- `server/src/main/resources/web/picture.ftl`
|
||||||
|
Single image preview page
|
||||||
|
- `server/src/main/resources/web/officePicture.ftl`
|
||||||
|
Office/PDF image-mode preview page
|
||||||
|
- `server/src/main/resources/web/officeweb.ftl`
|
||||||
|
Front-end xlsx/html preview page
|
||||||
|
|
||||||
|
When debugging UX issues, inspect the exact template selected by the preview flow first. Do not assume two similar preview pages share the same CSS or behavior.
|
||||||
|
|
||||||
|
## Local Development
|
||||||
|
|
||||||
|
### Recommended dev mode
|
||||||
|
|
||||||
|
Use:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./server/src/main/bin/dev.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
This runs Spring Boot with resource hot reload using:
|
||||||
|
|
||||||
|
- `spring-boot:run`
|
||||||
|
- `-Dspring-boot.run.addResources=true`
|
||||||
|
- `server/src/main/config/application.properties`
|
||||||
|
|
||||||
|
For front-end template or CSS/JS edits, prefer `dev.sh` over rebuilding jars repeatedly.
|
||||||
|
|
||||||
|
### Jar build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn -q -pl server -DskipTests package
|
||||||
|
```
|
||||||
|
|
||||||
|
### Main test command used in CI
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn -B package -Dmaven.test.skip=true --file pom.xml
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration Notes
|
||||||
|
|
||||||
|
Primary runtime config used by the scripts and defaults committed in this repository:
|
||||||
|
|
||||||
|
- `server/src/main/config/application.properties`
|
||||||
|
|
||||||
|
Optional environment-specific config:
|
||||||
|
|
||||||
|
- `server/src/main/config/test.properties`
|
||||||
|
|
||||||
|
Be careful: the repository defaults point at `application.properties`. If a deployment environment explicitly starts the app with `test.properties`, treat that as an environment-specific override rather than the repository default. Always verify the actual startup command before assuming which config file is active.
|
||||||
|
|
||||||
|
Examples of config that commonly affects behavior:
|
||||||
|
|
||||||
|
- `office.preview.type`
|
||||||
|
- `office.preview.switch.disabled`
|
||||||
|
- `trust.host`
|
||||||
|
- `not.trust.host`
|
||||||
|
- `file.upload.disable`
|
||||||
|
|
||||||
|
## Preview Behavior Notes
|
||||||
|
|
||||||
|
- Office files can render in `pdf` mode or `image` mode.
|
||||||
|
- PDF preview uses `pdf.ftl`.
|
||||||
|
- Single images use `picture.ftl`.
|
||||||
|
- Office image-mode previews use `officePicture.ftl`.
|
||||||
|
- Archive previews are not simple file lists; they can load nested previews via the archive UI in `compress.ftl`.
|
||||||
|
|
||||||
|
When changing preview defaults, verify both:
|
||||||
|
|
||||||
|
1. server-side default config
|
||||||
|
2. front-end mode-switch links/buttons
|
||||||
|
|
||||||
|
## Archive Preview Notes
|
||||||
|
|
||||||
|
Archive preview is a sensitive area because it combines:
|
||||||
|
|
||||||
|
- directory tree generation
|
||||||
|
- extraction to disk
|
||||||
|
- nested preview URL construction
|
||||||
|
- inline iframe loading
|
||||||
|
|
||||||
|
If an archive-contained Office file gets stuck on loading:
|
||||||
|
|
||||||
|
1. verify the extracted file on disk is not corrupted
|
||||||
|
2. verify conversion output exists
|
||||||
|
3. verify the preview template points to the correct generated artifact
|
||||||
|
4. verify the running Office manager / LibreOffice process is healthy
|
||||||
|
|
||||||
|
Do not assume “loading forever” is a front-end issue.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
### Targeted Java tests
|
||||||
|
|
||||||
|
Example targeted test:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mvn -q -pl server -Dtest=PdfViewerCompatibilityTests test
|
||||||
|
```
|
||||||
|
|
||||||
|
### E2E tests
|
||||||
|
|
||||||
|
See:
|
||||||
|
|
||||||
|
- `tests/e2e/README.md`
|
||||||
|
|
||||||
|
PR E2E currently covers:
|
||||||
|
|
||||||
|
- common preview smoke tests
|
||||||
|
- Office smoke tests
|
||||||
|
- archive smoke tests
|
||||||
|
- basic security and performance checks
|
||||||
|
|
||||||
|
## CI / Deployment
|
||||||
|
|
||||||
|
### CI
|
||||||
|
|
||||||
|
- `maven.yml`
|
||||||
|
- builds on `push` to `master`
|
||||||
|
- builds on PRs targeting `master`
|
||||||
|
- `pr-e2e-mvp.yml`
|
||||||
|
- runs E2E on PRs to `master`
|
||||||
|
|
||||||
|
### Production deployment
|
||||||
|
|
||||||
|
- `master-auto-deploy.yml`
|
||||||
|
- triggers on push to `master`
|
||||||
|
- deploys to Windows over WinRM
|
||||||
|
|
||||||
|
Deployment script:
|
||||||
|
|
||||||
|
- `.github/scripts/remote_windows_deploy.ps1`
|
||||||
|
|
||||||
|
Important operational detail:
|
||||||
|
|
||||||
|
- the committed `bin/startup.bat` in this repo points at `..\config\application.properties`
|
||||||
|
- if production uses a different config file, treat that as an out-of-repo server override rather than a repository default
|
||||||
|
|
||||||
|
If a production config change “does not take effect”, inspect the actual startup command or deployed `startup.bat` on the server first and verify which config file path it is using.
|
||||||
|
|
||||||
|
## Working Conventions For Agents
|
||||||
|
|
||||||
|
- Prefer minimal, targeted changes over wide refactors.
|
||||||
|
- Inspect the active preview template before editing CSS.
|
||||||
|
- Verify whether behavior is controlled by config, back-end routing, or front-end template logic before changing code.
|
||||||
|
- For production/debug tasks, distinguish clearly between:
|
||||||
|
- repository source defaults
|
||||||
|
- deployed server config
|
||||||
|
- runtime process arguments
|
||||||
|
- When changing defaults, mention whether the change affects:
|
||||||
|
- local dev only
|
||||||
|
- repository default config
|
||||||
|
- deployed server config
|
||||||
|
- existing query-param overrides
|
||||||
|
|
||||||
|
## Suggested Validation Checklist
|
||||||
|
|
||||||
|
For preview-related changes, validate as many of these as apply:
|
||||||
|
|
||||||
|
1. target URL returns `200`
|
||||||
|
2. selected template is the expected one
|
||||||
|
3. generated intermediate artifacts exist when required
|
||||||
|
4. target UI element or style change is actually present in rendered HTML
|
||||||
|
5. targeted Java test passes
|
||||||
|
6. relevant E2E path is still compatible
|
||||||
|
|
||||||
|
## Non-Goals
|
||||||
|
|
||||||
|
This file is not a replacement for user-facing product documentation. Keep it focused on helping coding agents navigate the codebase and make correct changes faster.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM keking/kkfileview-base:4.4.0
|
FROM keking/kkfileview-base:5.0.0
|
||||||
ADD server/target/kkFileView-*.tar.gz /opt/
|
ADD server/target/kkFileView-*.tar.gz /opt/
|
||||||
ENV KKFILEVIEW_BIN_FOLDER=/opt/kkFileView-4.4.0/bin
|
ENV KKFILEVIEW_BIN_FOLDER=/opt/kkFileView-5.0.0/bin
|
||||||
ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-Dspring.config.location=/opt/kkFileView-4.4.0/config/application.properties","-jar","/opt/kkFileView-4.4.0/bin/kkFileView-4.4.0.jar"]
|
ENTRYPOINT ["java","-Dfile.encoding=UTF-8","-Dspring.config.location=/opt/kkFileView-5.0.0/config/application.properties","-jar","/opt/kkFileView-5.0.0/bin/kkFileView-5.0.0.jar"]
|
||||||
|
|||||||
15
README.cn.md
15
README.cn.md
@@ -149,7 +149,7 @@ pdf预览模式预览效果如下
|
|||||||
|
|
||||||
### 历史更新记录
|
### 历史更新记录
|
||||||
|
|
||||||
#### > 2026年01月20日,v5.0 版本发布 :
|
#### > 2026年04月14日,v5.0.0 版本发布 :
|
||||||
#### 优化内容
|
#### 优化内容
|
||||||
1. xlsx 前端解析优化 - 提升Excel文件前端渲染性能
|
1. xlsx 前端解析优化 - 提升Excel文件前端渲染性能
|
||||||
2. 图片解析优化 - 改进图片处理机制
|
2. 图片解析优化 - 改进图片处理机制
|
||||||
@@ -159,6 +159,10 @@ pdf预览模式预览效果如下
|
|||||||
6. ftp多客户端接入优化 - 提升FTP服务兼容性
|
6. ftp多客户端接入优化 - 提升FTP服务兼容性
|
||||||
7. 首页目录访问优化 - 采用post服务端分页机制
|
7. 首页目录访问优化 - 采用post服务端分页机制
|
||||||
8. marked 解析优化 - 改进Markdown渲染
|
8. marked 解析优化 - 改进Markdown渲染
|
||||||
|
9. 压缩包预览页重构为单工作区布局,支持目录折叠与右侧内嵌预览
|
||||||
|
10. 优化压缩包内文件类型标识,以及单图预览页的展示样式
|
||||||
|
11. 补充面向工程自动化与编码代理的仓库说明文档
|
||||||
|
12. 重构演示门户页面,包括首页、接入说明、版本记录与赞助页
|
||||||
|
|
||||||
#### 新增功能
|
#### 新增功能
|
||||||
1. msg邮件解析 - 新增msg格式邮件文件预览支持
|
1. msg邮件解析 - 新增msg格式邮件文件预览支持
|
||||||
@@ -179,6 +183,12 @@ pdf预览模式预览效果如下
|
|||||||
2. 安全问题 - 修复安全漏洞
|
2. 安全问题 - 修复安全漏洞
|
||||||
3. 图片水印不全问题 - 修复水印显示不完整
|
3. 图片水印不全问题 - 修复水印显示不完整
|
||||||
4. SSL自签证书接入问题 - 修复自签名证书兼容性
|
4. SSL自签证书接入问题 - 修复自签名证书兼容性
|
||||||
|
5. 修复压缩包内 Office 文件在重复解压后被追加写坏,导致一直卡在加载中的问题
|
||||||
|
6. Office 默认预览改为 PDF 模式,且 PDF 预览默认打开缩略图侧栏
|
||||||
|
7. 启动脚本改为自动发现当前发布包中的 jar,移除过时的硬编码 jar 名称
|
||||||
|
8. 更新 Docker 与发布辅助文档,使其与 5.0.0 发布线保持一致
|
||||||
|
9. 修复 OFD 表格竖线溢出导致的渲染异常
|
||||||
|
10. 修复 PDF.js 兼容性补丁,避免兼容环境下的预览报错
|
||||||
|
|
||||||
#### 更新内容
|
#### 更新内容
|
||||||
1. JDK版本要求 - 强制要求JDK 21及以上版本
|
1. JDK版本要求 - 强制要求JDK 21及以上版本
|
||||||
@@ -189,6 +199,8 @@ pdf预览模式预览效果如下
|
|||||||
6. tif后端异步转换优化 - 实现多线程异步转换
|
6. tif后端异步转换优化 - 实现多线程异步转换
|
||||||
7. 视频后端异步转换优化 - 实现多线程异步转换
|
7. 视频后端异步转换优化 - 实现多线程异步转换
|
||||||
8. CAD后端异步转换优化 - 实现多线程异步转换
|
8. CAD后端异步转换优化 - 实现多线程异步转换
|
||||||
|
9. 默认预览配置策略调整 - Office 预览默认切换为 PDF 模式,默认隐藏图片/PDF 模式切换按钮,且 PDF 预览默认展开缩略图侧栏。若升级后仍需保持旧的图片优先体验,请显式设置 `office.preview.type=image` 和 `office.preview.switch.disabled=false`。
|
||||||
|
10. 信任域名配置匹配策略扩展 - `trust.host` 及相关规则现已支持通配符和 CIDR 匹配,升级后如果你依赖域名/IP 模式匹配,需要重新检查白名单和黑名单的实际生效范围
|
||||||
|
|
||||||
#### > 2025年01月16日,v4.4.0 版本发布 :
|
#### > 2025年01月16日,v4.4.0 版本发布 :
|
||||||
|
|
||||||
@@ -468,4 +480,3 @@ dcm医疗数位影像 引用于 [dcmjs](https://github.com/dcmjs-org/dcmjs )开
|
|||||||
- 本项目诞生于[凯京集团],在取得公司高层同意后以 Apache 协议开源出来反哺社区,在此特别感谢凯京集团,以及集团领导[@唐老大](https://github.com/tangshd)的支持、@端木详笑的贡献。
|
- 本项目诞生于[凯京集团],在取得公司高层同意后以 Apache 协议开源出来反哺社区,在此特别感谢凯京集团,以及集团领导[@唐老大](https://github.com/tangshd)的支持、@端木详笑的贡献。
|
||||||
- 本项目已脱离公司由[KK开源社区]维护发展壮大,感谢所有给 kkFileView 提 Issue 、Pr 开发者
|
- 本项目已脱离公司由[KK开源社区]维护发展壮大,感谢所有给 kkFileView 提 Issue 、Pr 开发者
|
||||||
- 本项目引入的第三方组件已在 '关于引用' 列表列出,感谢这些项目,让 kkFileView 更出色
|
- 本项目引入的第三方组件已在 '关于引用' 列表列出,感谢这些项目,让 kkFileView 更出色
|
||||||
|
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -65,9 +65,9 @@ URL:[https://file.kkview.cn](https://file.kkview.cn)
|
|||||||
|
|
||||||
## Change History
|
## Change History
|
||||||
|
|
||||||
### Version 5.0 (January 20, 2026)
|
### Version 5.0.0 (April 14, 2026)
|
||||||
|
|
||||||
#### Optimizations
|
#### Improvements
|
||||||
1. Enhanced xlsx front-end parsing - Improved Excel file front-end rendering performance
|
1. Enhanced xlsx front-end parsing - Improved Excel file front-end rendering performance
|
||||||
2. Optimized image parsing - Enhanced image processing mechanism
|
2. Optimized image parsing - Enhanced image processing mechanism
|
||||||
3. Improved tif parsing - Enhanced TIF format support
|
3. Improved tif parsing - Enhanced TIF format support
|
||||||
@@ -76,6 +76,10 @@ URL:[https://file.kkview.cn](https://file.kkview.cn)
|
|||||||
6. Optimized ftp multi-client access - Improved FTP service compatibility
|
6. Optimized ftp multi-client access - Improved FTP service compatibility
|
||||||
7. Enhanced home page directory access - Implemented post server-side pagination mechanism
|
7. Enhanced home page directory access - Implemented post server-side pagination mechanism
|
||||||
8. Improved marked parsing - Enhanced Markdown rendering
|
8. Improved marked parsing - Enhanced Markdown rendering
|
||||||
|
9. Redesigned archive preview into a single workspace with a collapsible tree and inline file preview
|
||||||
|
10. Improved archive preview file-type badges and single-image preview styling
|
||||||
|
11. Added an agent-focused repository guide for engineering automation and maintenance
|
||||||
|
12. Refreshed the demo portal pages, including the index, integration guide, release record, and sponsor pages
|
||||||
|
|
||||||
#### New Features
|
#### New Features
|
||||||
1. msg email parsing - Added support for msg format email file preview
|
1. msg email parsing - Added support for msg format email file preview
|
||||||
@@ -96,6 +100,12 @@ URL:[https://file.kkview.cn](https://file.kkview.cn)
|
|||||||
2. Security issues - Fixed security vulnerabilities
|
2. Security issues - Fixed security vulnerabilities
|
||||||
3. Incomplete image watermark issues - Fixed incomplete watermark display
|
3. Incomplete image watermark issues - Fixed incomplete watermark display
|
||||||
4. SSL self-signed certificate access issues - Fixed compatibility with self-signed certificates
|
4. SSL self-signed certificate access issues - Fixed compatibility with self-signed certificates
|
||||||
|
5. Fixed archive-contained Office files that could stay stuck on loading because repeated extraction appended to existing files
|
||||||
|
6. Default Office preview now prefers PDF mode, and PDF preview opens with the thumbnail sidebar visible by default
|
||||||
|
7. Updated startup scripts to discover the packaged jar dynamically instead of relying on stale hard-coded jar names
|
||||||
|
8. Updated Docker and release helper docs to align with the 5.0.0 release line
|
||||||
|
9. Fixed OFD table border overflow rendering issues
|
||||||
|
10. Refined the PDF.js compatibility polyfill to avoid preview errors in compatibility environments
|
||||||
|
|
||||||
#### Updates
|
#### Updates
|
||||||
1. JDK version requirement - Mandatory requirement for JDK 21 or higher
|
1. JDK version requirement - Mandatory requirement for JDK 21 or higher
|
||||||
@@ -106,6 +116,8 @@ URL:[https://file.kkview.cn](https://file.kkview.cn)
|
|||||||
6. tif backend async conversion optimization - Implemented multi-threaded asynchronous conversion
|
6. tif backend async conversion optimization - Implemented multi-threaded asynchronous conversion
|
||||||
7. Video backend async conversion optimization - Implemented multi-threaded asynchronous conversion
|
7. Video backend async conversion optimization - Implemented multi-threaded asynchronous conversion
|
||||||
8. CAD backend async conversion optimization - Implemented multi-threaded asynchronous conversion
|
8. CAD backend async conversion optimization - Implemented multi-threaded asynchronous conversion
|
||||||
|
9. Default preview configuration strategy adjusted - Office preview now defaults to PDF mode, the mode switch is hidden by default, and PDF preview opens with the thumbnail sidebar visible. If you need the previous image-first behavior after upgrade, explicitly set `office.preview.type=image` and `office.preview.switch.disabled=false`.
|
||||||
|
10. Trust host configuration matching expanded - `trust.host` and related rules now support wildcard and CIDR matching, which may broaden or narrow effective allow/deny behavior after upgrade depending on your patterns
|
||||||
|
|
||||||
### Version 4.4.0 (January 16, 2025)
|
### Version 4.4.0 (January 16, 2025)
|
||||||
|
|
||||||
|
|||||||
@@ -3,22 +3,19 @@
|
|||||||
当前线上 Windows 服务器的实际部署信息如下:
|
当前线上 Windows 服务器的实际部署信息如下:
|
||||||
|
|
||||||
- 部署根目录:`C:\kkFileView-5.0`
|
- 部署根目录:`C:\kkFileView-5.0`
|
||||||
- 运行 jar:`C:\kkFileView-5.0\bin\kkFileView-5.0.jar`
|
- 运行 jar:`C:\kkFileView-5.0\bin\kkFileView-<当前项目版本>.jar`
|
||||||
- 启动脚本:`C:\kkFileView-5.0\bin\startup.bat`
|
- 启动脚本:`C:\kkFileView-5.0\bin\startup.bat`
|
||||||
- 运行配置:`C:\kkFileView-5.0\config\test.properties`
|
- 运行配置:`C:\kkFileView-5.0\config\test.properties`
|
||||||
- 健康检查地址:`http://127.0.0.1:8012/`
|
- 健康检查地址:`http://127.0.0.1:8012/`
|
||||||
|
|
||||||
服务器当前没有安装 `git` 和 `mvn`,因此自动部署链路采用:
|
当前自动部署链路采用服务器拉最新源码并本机编译的方式:
|
||||||
|
|
||||||
1. GitHub Actions 在 `master` 合并后构建 `kkFileView-*.jar`
|
1. 通过 WinRM 连接 Windows 服务器
|
||||||
2. 由 GitHub Actions runner 解析当前 workflow artifact 的临时下载地址
|
2. 在服务器上的源码目录执行 `git fetch/reset/clean`,同步到 `origin/$KK_DEPLOY_BRANCH`(默认 `master`)
|
||||||
3. 通过 WinRM 连接 Windows 服务器
|
3. 使用服务器上的 JDK 21 和 Maven 执行 `mvn clean package -Dmaven.test.skip=true`
|
||||||
4. 由服务器通过临时下载地址拉取 jar artifact
|
4. 备份线上 jar,替换为新构建产物
|
||||||
5. 备份线上 jar,替换为新版本
|
5. 使用现有 `startup.bat` 重启,并做健康检查
|
||||||
6. 使用现有 `startup.bat` 重启,并做健康检查
|
6. 如果健康检查失败,则自动回滚旧 jar 并重新拉起
|
||||||
7. 如果健康检查失败,则自动回滚旧 jar 并重新拉起
|
|
||||||
|
|
||||||
这样做的目的是不把 GitHub token 下发到生产服务器,服务器只接触一次性 artifact 下载链接。
|
|
||||||
|
|
||||||
## 需要配置的 GitHub Secrets
|
## 需要配置的 GitHub Secrets
|
||||||
|
|
||||||
@@ -26,16 +23,35 @@
|
|||||||
- `KK_DEPLOY_USERNAME`
|
- `KK_DEPLOY_USERNAME`
|
||||||
- `KK_DEPLOY_PASSWORD`
|
- `KK_DEPLOY_PASSWORD`
|
||||||
|
|
||||||
下面这些可以不配,未配置时会使用默认值:
|
以下部署参数当前由 workflow 从 GitHub Secrets 读取;如果未单独配置,则使用脚本默认值:
|
||||||
|
|
||||||
- `KK_DEPLOY_PORT=5985`
|
- `KK_DEPLOY_PORT=5985`
|
||||||
- `KK_DEPLOY_ROOT=C:\kkFileView-5.0`
|
- `KK_DEPLOY_ROOT=C:\kkFileView-5.0`
|
||||||
- `KK_DEPLOY_HEALTH_URL=http://127.0.0.1:8012/`
|
- `KK_DEPLOY_HEALTH_URL=http://127.0.0.1:8012/`
|
||||||
|
|
||||||
|
下面这些非敏感参数可以通过 workflow env 或 GitHub Variables 覆盖;未配置时会使用默认值:
|
||||||
|
- `KK_DEPLOY_REPO_URL=https://github.com/kekingcn/kkFileView.git`
|
||||||
|
- `KK_DEPLOY_BRANCH=master`
|
||||||
|
- `KK_DEPLOY_SOURCE_ROOT=C:\kkFileView-source`
|
||||||
|
- `KK_DEPLOY_JAVA_HOME=C:\Program Files\jdk-21.0.2`
|
||||||
|
- `KK_DEPLOY_GIT_EXE=C:\kkFileView-tools\git\cmd\git.exe`
|
||||||
|
- `KK_DEPLOY_MVN_CMD=C:\kkFileView-tools\maven\bin\mvn.cmd`
|
||||||
|
- `KK_DEPLOY_MAVEN_SETTINGS=`
|
||||||
|
|
||||||
|
如果服务器到 GitHub 的拉取速度不稳定,也可以把 `KK_DEPLOY_REPO_URL` 改成你自己的 Git 镜像地址。
|
||||||
|
如果服务器访问 Maven Central 不稳定,也可以通过 `KK_DEPLOY_MAVEN_SETTINGS` 指向自定义 `settings.xml`,切换到就近镜像仓库。
|
||||||
|
|
||||||
|
## 服务器前置环境
|
||||||
|
|
||||||
|
服务器需要具备以下工具:
|
||||||
|
|
||||||
|
- Git for Windows(推荐安装在 `C:\kkFileView-tools\git`)
|
||||||
|
- Apache Maven 3.9.x(推荐安装在 `C:\kkFileView-tools\maven`)
|
||||||
|
- JDK 21(当前线上已存在:`C:\Program Files\jdk-21.0.2`)
|
||||||
|
|
||||||
## Workflow
|
## Workflow
|
||||||
|
|
||||||
新增 workflow:`.github/workflows/master-auto-deploy.yml`
|
新增 workflow:`.github/workflows/master-auto-deploy.yml`
|
||||||
|
|
||||||
- 触发条件:`push` 到 `master`,或手动 `workflow_dispatch`
|
- 触发条件:`push` 到 `master`,或手动 `workflow_dispatch`
|
||||||
- 构建产物:`kkfileview-server-jar`
|
- 部署方式:WinRM + 服务器源码同步 + 服务器本机 Maven 编译 + jar 替换/回滚
|
||||||
- 部署方式:WinRM + runner 侧解析 artifact 临时下载地址 + Windows 服务器拉取 artifact
|
|
||||||
|
|||||||
@@ -7,10 +7,10 @@
|
|||||||
然后使用 kkfileview-base 作为基础镜像进行构建,加快 kkfileview docker 镜像构建与发布。
|
然后使用 kkfileview-base 作为基础镜像进行构建,加快 kkfileview docker 镜像构建与发布。
|
||||||
|
|
||||||
执行如下命令即可构建基础镜像:
|
执行如下命令即可构建基础镜像:
|
||||||
> 这里镜像 tag 以 4.4.0 为例,本项目所维护的 Dockerfile 文件考虑了跨平台兼容性。 如果你需要用到 arm64 架构镜像, 则在arm64 架构机器上同样执行下面的构建命令即可
|
> 这里镜像 tag 以 5.0.0 为例,本项目所维护的 Dockerfile 文件考虑了跨平台兼容性。 如果你需要用到 arm64 架构镜像, 则在arm64 架构机器上同样执行下面的构建命令即可
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker build --tag keking/kkfileview-base:4.4.0 .
|
docker build --tag keking/kkfileview-base:5.0.0 .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -46,5 +46,5 @@ docker build --tag keking/kkfileview-base:4.4.0 .
|
|||||||
现在就可以愉快地开始构建了,构建命令示例:
|
现在就可以愉快地开始构建了,构建命令示例:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker buildx build --platform=linux/amd64,linux/arm64 -t keking/kkfileview-base:4.4.0 --push .
|
docker buildx build --platform=linux/amd64,linux/arm64 -t keking/kkfileview-base:5.0.0 --push .
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ Then, use kkfileview-base as the base image to build and speed up the kkfileview
|
|||||||
|
|
||||||
To build the base image, run the following command:
|
To build the base image, run the following command:
|
||||||
|
|
||||||
> In this example, the image tag is 4.4.0. The Dockerfile maintained in this project considers cross-platform compatibility. If you need an arm64 architecture image, run the same build command on an arm64 architecture machine.
|
> In this example, the image tag is 5.0.0. The Dockerfile maintained in this project considers cross-platform compatibility. If you need an arm64 architecture image, run the same build command on an arm64 architecture machine.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker build --tag keking/kkfileview-base:4.4.0 .
|
docker build --tag keking/kkfileview-base:5.0.0 .
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -49,5 +49,5 @@ Assuming the current machine is amd64 (x86_64) architecture, you'll need to enab
|
|||||||
Now you can enjoy the building. Here’s an example build command:
|
Now you can enjoy the building. Here’s an example build command:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
docker buildx build --platform=linux/amd64,linux/arm64 -t keking/kkfileview-base:4.4.0 --push .
|
docker buildx build --platform=linux/amd64,linux/arm64 -t keking/kkfileview-base:5.0.0 --push .
|
||||||
```
|
```
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.keking</groupId>
|
<groupId>cn.keking</groupId>
|
||||||
<artifactId>kkFileView-parent</artifactId>
|
<artifactId>kkFileView-parent</artifactId>
|
||||||
<version>5.0</version>
|
<version>5.0.0</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- ========== Java 和编译配置 ========== -->
|
<!-- ========== Java 和编译配置 ========== -->
|
||||||
@@ -110,4 +110,4 @@
|
|||||||
<system>github</system>
|
<system>github</system>
|
||||||
<url>https://github.com/kekingcn/kkFileView/issues</url>
|
<url>https://github.com/kekingcn/kkFileView/issues</url>
|
||||||
</issueManagement>
|
</issueManagement>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>kkFileView-parent</artifactId>
|
<artifactId>kkFileView-parent</artifactId>
|
||||||
<groupId>cn.keking</groupId>
|
<groupId>cn.keking</groupId>
|
||||||
<version>5.0</version>
|
<version>5.0.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>kkFileView</artifactId>
|
<artifactId>kkFileView</artifactId>
|
||||||
|
|||||||
@@ -1,10 +1,20 @@
|
|||||||
@echo off
|
@echo off
|
||||||
set "KKFILEVIEW_BIN_FOLDER=%cd%"
|
set "KKFILEVIEW_BIN_FOLDER=%cd%"
|
||||||
cd "%KKFILEVIEW_BIN_FOLDER%"
|
cd "%KKFILEVIEW_BIN_FOLDER%"
|
||||||
|
set "JAR_NAME="
|
||||||
|
for %%F in (kkFileView-*.jar) do (
|
||||||
|
set "JAR_NAME=%%~nxF"
|
||||||
|
goto :jar_found
|
||||||
|
)
|
||||||
|
echo Error: kkFileView jar not found in %KKFILEVIEW_BIN_FOLDER%
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:jar_found
|
||||||
echo Using KKFILEVIEW_BIN_FOLDER %KKFILEVIEW_BIN_FOLDER%
|
echo Using KKFILEVIEW_BIN_FOLDER %KKFILEVIEW_BIN_FOLDER%
|
||||||
|
echo Using JAR_NAME %JAR_NAME%
|
||||||
echo Starting kkFileView...
|
echo Starting kkFileView...
|
||||||
echo Please check log file in ../log/kkFileView.log for more information
|
echo Please check log file in ../log/kkFileView.log for more information
|
||||||
echo You can get help in our official home site: https://kkview.cn
|
echo You can get help in our official home site: https://kkview.cn
|
||||||
echo If you need further help, please join our kk opensource community: https://t.zsxq.com/09ZHSXbsQ
|
echo If you need further help, please join our kk opensource community: https://t.zsxq.com/09ZHSXbsQ
|
||||||
echo If this project is helpful to you, please star it on https://gitee.com/kekingcn/file-online-preview/stargazers
|
echo If this project is helpful to you, please star it on https://gitee.com/kekingcn/file-online-preview/stargazers
|
||||||
java -Dspring.config.location=..\config\application.properties -jar kkFileView-4.4.0.jar -> ..\log\kkFileView.log
|
java -Dspring.config.location=..\config\application.properties -jar "%JAR_NAME%" > ..\log\kkFileView.log 2>&1
|
||||||
|
|||||||
@@ -49,9 +49,16 @@ else
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
JAR_PATH=$(ls kkFileView-*.jar 2>/dev/null | head -n 1)
|
||||||
|
if [ -z "${JAR_PATH}" ]; then
|
||||||
|
echo "kkFileView jar not found in ${KKFILEVIEW_BIN_FOLDER}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
## 启动kkFileView
|
## 启动kkFileView
|
||||||
echo "Starting kkFileView..."
|
echo "Starting kkFileView..."
|
||||||
nohup java -Dfile.encoding=UTF-8 -Dspring.config.location=../config/application.properties -jar kkFileView-4.4.0.jar > ../log/kkFileView.log 2>&1 &
|
echo "Using jar ${JAR_PATH}"
|
||||||
|
nohup java -Dfile.encoding=UTF-8 -Dspring.config.location=../config/application.properties -jar "${JAR_PATH}" > ../log/kkFileView.log 2>&1 &
|
||||||
echo "Please execute ./showlog.sh to check log for more information"
|
echo "Please execute ./showlog.sh to check log for more information"
|
||||||
echo "You can get help in our official home site: https://kkview.cn"
|
echo "You can get help in our official home site: https://kkview.cn"
|
||||||
echo "If you need further help, please join our kk opensource community: https://t.zsxq.com/09ZHSXbsQ"
|
echo "If you need further help, please join our kk opensource community: https://t.zsxq.com/09ZHSXbsQ"
|
||||||
|
|||||||
@@ -96,12 +96,12 @@ office.documentopenpasswords = ${KK_OFFICE_DOCUMENTOPENPASSWORD:true}
|
|||||||
office.type.web = ${KK_OFFICE_TYPE_WEB:web}
|
office.type.web = ${KK_OFFICE_TYPE_WEB:web}
|
||||||
|
|
||||||
# Office文档预览类型
|
# Office文档预览类型
|
||||||
# 支持动态配置,可选值:image/pdf
|
# 支持动态配置,可选值:image/pdf,默认使用pdf模式
|
||||||
office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:image}
|
office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:pdf}
|
||||||
|
|
||||||
# 是否关闭Office预览模式切换开关,默认为false(允许切换)
|
# 是否关闭Office预览模式切换开关,默认为true(关闭切换)
|
||||||
# 设置为true时,用户无法在图片和PDF模式间切换
|
# 设置为false时,用户可以在图片和PDF模式间切换
|
||||||
office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:false}
|
office.preview.switch.disabled = ${KK_OFFICE_PREVIEW_SWITCH_DISABLED:true}
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@@ -475,4 +475,4 @@ kk.scriptjs = true
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# 纯文本文件类型,直接显示
|
# 纯文本文件类型,直接显示
|
||||||
simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}
|
simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package cn.keking.config;
|
package cn.keking.config;
|
||||||
|
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.redisson.Redisson;
|
import org.redisson.Redisson;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
@@ -13,8 +12,8 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redisson 客户端配置
|
* Redisson 客户端配置(完善版)
|
||||||
* Created by kl on 2017/09/26.
|
* 支持 single / cluster / master-slave / sentinel 四种模式,配置完整,统一参数。
|
||||||
*/
|
*/
|
||||||
@ConditionalOnExpression("'${cache.type:default}'.equals('redis')")
|
@ConditionalOnExpression("'${cache.type:default}'.equals('redis')")
|
||||||
@ConfigurationProperties(prefix = "spring.redisson")
|
@ConfigurationProperties(prefix = "spring.redisson")
|
||||||
@@ -22,114 +21,71 @@ import org.springframework.util.ClassUtils;
|
|||||||
public class RedissonConfig {
|
public class RedissonConfig {
|
||||||
|
|
||||||
// ========================== 连接配置 ==========================
|
// ========================== 连接配置 ==========================
|
||||||
private static String address;
|
private String address;
|
||||||
private static String password;
|
private String password;
|
||||||
private static String clientName;
|
private String clientName;
|
||||||
private static int database = 0;
|
private int database = 0;
|
||||||
private static String mode = "single";
|
private String mode = "single";
|
||||||
private static String masterName = "kkfile";
|
private String masterName = "kkfile";
|
||||||
|
|
||||||
// ========================== 超时配置 ==========================
|
// ========================== 超时配置 ==========================
|
||||||
private static int idleConnectionTimeout = 10000;
|
private int idleConnectionTimeout = 10000;
|
||||||
private static int connectTimeout = 10000;
|
private int connectTimeout = 10000;
|
||||||
private static int timeout = 3000;
|
private int timeout = 3000;
|
||||||
|
|
||||||
// ========================== 重试配置 ==========================
|
// ========================== 重试配置 ==========================
|
||||||
private static int retryAttempts = 3;
|
private int retryAttempts = 3;
|
||||||
private static int retryInterval = 1500;
|
private int retryInterval = 1500;
|
||||||
|
|
||||||
// ========================== 连接池配置 ==========================
|
// ========================== 连接池配置 ==========================
|
||||||
private static int connectionMinimumIdleSize = 10;
|
private int connectionMinimumIdleSize = 10;
|
||||||
private static int connectionPoolSize = 64;
|
private int connectionPoolSize = 64;
|
||||||
private static int subscriptionsPerConnection = 5;
|
private int subscriptionsPerConnection = 5;
|
||||||
private static int subscriptionConnectionMinimumIdleSize = 1;
|
private int subscriptionConnectionMinimumIdleSize = 1;
|
||||||
private static int subscriptionConnectionPoolSize = 50;
|
private int subscriptionConnectionPoolSize = 50;
|
||||||
|
|
||||||
|
// ========================== 集群专用配置 ==========================
|
||||||
|
private int scanInterval = 2000;
|
||||||
|
|
||||||
// ========================== 其他配置 ==========================
|
// ========================== 其他配置 ==========================
|
||||||
private static int dnsMonitoringInterval = 5000;
|
private int dnsMonitoringInterval = 5000;
|
||||||
private static int thread; // 当前处理核数量 * 2
|
private int threads; // 默认为0,表示使用 CPU 核数 * 2
|
||||||
private static String codec = "org.redisson.codec.JsonJacksonCodec";
|
private String codec = "org.redisson.codec.JsonJacksonCodec";
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public static RedissonClient config() throws Exception {
|
public RedissonClient redissonClient() {
|
||||||
Config config = new Config();
|
Config config = new Config();
|
||||||
|
|
||||||
// 密码处理
|
// 密码处理:空字符串转为 null
|
||||||
if (StringUtils.isBlank(password)) {
|
String pwd = StringUtils.isBlank(password) ? null : password;
|
||||||
password = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据模式创建对应的 Redisson 配置
|
// 根据模式构建配置
|
||||||
switch (mode) {
|
switch (mode.toLowerCase()) {
|
||||||
case "cluster":
|
case "cluster":
|
||||||
configureClusterMode(config);
|
configureClusterMode(config, pwd);
|
||||||
break;
|
break;
|
||||||
case "master-slave":
|
case "master-slave":
|
||||||
configureMasterSlaveMode(config);
|
configureMasterSlaveMode(config, pwd);
|
||||||
break;
|
break;
|
||||||
case "sentinel":
|
case "sentinel":
|
||||||
configureSentinelMode(config);
|
configureSentinelMode(config, pwd);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
configureSingleMode(config);
|
configureSingleMode(config, pwd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 公共配置:编码器、线程数
|
||||||
|
applyCommonConfig(config);
|
||||||
return Redisson.create(config);
|
return Redisson.create(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================== 配置方法 ==========================
|
// ========================== 配置方法 ==========================
|
||||||
|
|
||||||
/**
|
private void configureSingleMode(Config config, String pwd) {
|
||||||
* 配置集群模式
|
String normalizedAddress = normalizeAddress(address);
|
||||||
*/
|
|
||||||
private static void configureClusterMode(Config config) {
|
|
||||||
String[] clusterAddresses = address.split(",");
|
|
||||||
config.useClusterServers()
|
|
||||||
.setScanInterval(2000)
|
|
||||||
.addNodeAddress(clusterAddresses)
|
|
||||||
.setPassword(password)
|
|
||||||
.setRetryAttempts(retryAttempts)
|
|
||||||
.setTimeout(timeout)
|
|
||||||
.setMasterConnectionPoolSize(100)
|
|
||||||
.setSlaveConnectionPoolSize(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置主从模式
|
|
||||||
*/
|
|
||||||
private static void configureMasterSlaveMode(Config config) {
|
|
||||||
String[] masterSlaveAddresses = address.split(",");
|
|
||||||
validateMasterSlaveAddresses(masterSlaveAddresses);
|
|
||||||
|
|
||||||
String[] slaveAddresses = new String[masterSlaveAddresses.length - 1];
|
|
||||||
System.arraycopy(masterSlaveAddresses, 1, slaveAddresses, 0, slaveAddresses.length);
|
|
||||||
|
|
||||||
config.useMasterSlaveServers()
|
|
||||||
.setDatabase(database)
|
|
||||||
.setPassword(password)
|
|
||||||
.setMasterAddress(masterSlaveAddresses[0])
|
|
||||||
.addSlaveAddress(slaveAddresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置哨兵模式
|
|
||||||
*/
|
|
||||||
private static void configureSentinelMode(Config config) {
|
|
||||||
String[] sentinelAddresses = address.split(",");
|
|
||||||
config.useSentinelServers()
|
|
||||||
.setDatabase(database)
|
|
||||||
.setPassword(password)
|
|
||||||
.setMasterName(masterName)
|
|
||||||
.addSentinelAddress(sentinelAddresses);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置单机模式
|
|
||||||
*/
|
|
||||||
private static void configureSingleMode(Config config) throws Exception {
|
|
||||||
config.useSingleServer()
|
config.useSingleServer()
|
||||||
.setAddress(address)
|
.setAddress(normalizedAddress)
|
||||||
.setConnectionMinimumIdleSize(connectionMinimumIdleSize)
|
.setConnectionMinimumIdleSize(connectionMinimumIdleSize)
|
||||||
.setConnectionPoolSize(connectionPoolSize)
|
.setConnectionPoolSize(connectionPoolSize)
|
||||||
.setDatabase(database)
|
.setDatabase(database)
|
||||||
@@ -143,183 +99,184 @@ public class RedissonConfig {
|
|||||||
.setTimeout(timeout)
|
.setTimeout(timeout)
|
||||||
.setConnectTimeout(connectTimeout)
|
.setConnectTimeout(connectTimeout)
|
||||||
.setIdleConnectionTimeout(idleConnectionTimeout)
|
.setIdleConnectionTimeout(idleConnectionTimeout)
|
||||||
.setPassword(StringUtils.trimToNull(password));
|
.setPassword(pwd);
|
||||||
|
|
||||||
// 设置编码器
|
|
||||||
Class<?> codecClass = ClassUtils.forName(getCodec(), ClassUtils.getDefaultClassLoader());
|
|
||||||
Codec codecInstance = (Codec) codecClass.getDeclaredConstructor().newInstance();
|
|
||||||
config.setCodec(codecInstance);
|
|
||||||
// 设置线程和事件循环组
|
|
||||||
config.setThreads(thread);
|
|
||||||
config.setEventLoopGroup(new NioEventLoopGroup());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void configureClusterMode(Config config, String pwd) {
|
||||||
* 验证主从模式地址
|
String[] nodeAddresses = normalizeAddresses(address.split(","));
|
||||||
*/
|
config.useClusterServers()
|
||||||
private static void validateMasterSlaveAddresses(String[] addresses) {
|
.setScanInterval(scanInterval)
|
||||||
if (addresses.length == 1) {
|
.addNodeAddress(nodeAddresses)
|
||||||
throw new IllegalArgumentException(
|
.setPassword(pwd)
|
||||||
"redis.redisson.address MUST have multiple redis addresses for master-slave mode.");
|
.setRetryAttempts(retryAttempts)
|
||||||
|
.setRetryInterval(retryInterval)
|
||||||
|
.setTimeout(timeout)
|
||||||
|
.setConnectTimeout(connectTimeout)
|
||||||
|
.setIdleConnectionTimeout(idleConnectionTimeout)
|
||||||
|
.setMasterConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSlaveConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize)
|
||||||
|
.setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize)
|
||||||
|
.setSubscriptionsPerConnection(subscriptionsPerConnection)
|
||||||
|
.setClientName(clientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureMasterSlaveMode(Config config, String pwd) {
|
||||||
|
String[] addresses = address.split(",");
|
||||||
|
validateMasterSlaveAddresses(addresses);
|
||||||
|
String[] normalizedAddresses = normalizeAddresses(addresses);
|
||||||
|
String masterAddress = normalizedAddresses[0];
|
||||||
|
String[] slaveAddresses = new String[normalizedAddresses.length - 1];
|
||||||
|
System.arraycopy(normalizedAddresses, 1, slaveAddresses, 0, slaveAddresses.length);
|
||||||
|
|
||||||
|
config.useMasterSlaveServers()
|
||||||
|
.setDatabase(database)
|
||||||
|
.setPassword(pwd)
|
||||||
|
.setMasterAddress(masterAddress)
|
||||||
|
.addSlaveAddress(slaveAddresses)
|
||||||
|
.setRetryAttempts(retryAttempts)
|
||||||
|
.setRetryInterval(retryInterval)
|
||||||
|
.setTimeout(timeout)
|
||||||
|
.setConnectTimeout(connectTimeout)
|
||||||
|
.setIdleConnectionTimeout(idleConnectionTimeout)
|
||||||
|
.setMasterConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSlaveConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize)
|
||||||
|
.setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize)
|
||||||
|
.setSubscriptionsPerConnection(subscriptionsPerConnection)
|
||||||
|
.setClientName(clientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureSentinelMode(Config config, String pwd) {
|
||||||
|
String[] sentinelAddresses = normalizeAddresses(address.split(","));
|
||||||
|
config.useSentinelServers()
|
||||||
|
.setDatabase(database)
|
||||||
|
.setPassword(pwd)
|
||||||
|
.setMasterName(masterName)
|
||||||
|
.addSentinelAddress(sentinelAddresses)
|
||||||
|
.setRetryAttempts(retryAttempts)
|
||||||
|
.setRetryInterval(retryInterval)
|
||||||
|
.setTimeout(timeout)
|
||||||
|
.setConnectTimeout(connectTimeout)
|
||||||
|
.setIdleConnectionTimeout(idleConnectionTimeout)
|
||||||
|
.setMasterConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSlaveConnectionPoolSize(connectionPoolSize)
|
||||||
|
.setSubscriptionConnectionPoolSize(subscriptionConnectionPoolSize)
|
||||||
|
.setSubscriptionConnectionMinimumIdleSize(subscriptionConnectionMinimumIdleSize)
|
||||||
|
.setSubscriptionsPerConnection(subscriptionsPerConnection)
|
||||||
|
.setClientName(clientName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyCommonConfig(Config config) {
|
||||||
|
// 设置编码器
|
||||||
|
if (StringUtils.isNotBlank(codec)) {
|
||||||
|
try {
|
||||||
|
Class<?> codecClass = ClassUtils.forName(codec, ClassUtils.getDefaultClassLoader());
|
||||||
|
Codec codecInstance = (Codec) codecClass.getDeclaredConstructor().newInstance();
|
||||||
|
config.setCodec(codecInstance);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException("Failed to create Redisson codec: " + codec, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 设置线程数(大于0时生效,否则Redisson使用默认值:CPU核数*2)
|
||||||
|
if (threads > 0) {
|
||||||
|
config.setThreads(threads);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================== Getter和Setter方法 ==========================
|
// ========================== 辅助方法 ==========================
|
||||||
|
|
||||||
// 连接配置
|
/**
|
||||||
public String getAddress() {
|
* 自动补齐 Redis 地址协议前缀(redis:// 或 rediss://)
|
||||||
return address;
|
*/
|
||||||
|
private String normalizeAddress(String addr) {
|
||||||
|
if (addr == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
addr = addr.trim();
|
||||||
|
if (!addr.startsWith("redis://") && !addr.startsWith("rediss://")) {
|
||||||
|
addr = "redis://" + addr;
|
||||||
|
}
|
||||||
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAddress(String address) {
|
private String[] normalizeAddresses(String[] addresses) {
|
||||||
RedissonConfig.address = address;
|
String[] normalized = new String[addresses.length];
|
||||||
|
for (int i = 0; i < addresses.length; i++) {
|
||||||
|
normalized[i] = normalizeAddress(addresses[i]);
|
||||||
|
}
|
||||||
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
private void validateMasterSlaveAddresses(String[] addresses) {
|
||||||
return password;
|
if (addresses.length < 2) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Master-slave mode requires at least 2 addresses: master and at least one slave. " +
|
||||||
|
"Current addresses: " + String.join(",", addresses));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
// ========================== Getter / Setter(供 Spring 绑定配置) ==========================
|
||||||
RedissonConfig.password = password;
|
// 以下所有字段都需要提供 getter/setter,示例中只列出关键字段,实际使用时请补全所有字段。
|
||||||
}
|
// 建议使用 Lombok @Data 或 IDE 自动生成。这里只展示部分,避免篇幅过长。
|
||||||
|
|
||||||
public String getClientName() {
|
public String getAddress() { return address; }
|
||||||
return clientName;
|
public void setAddress(String address) { this.address = address; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setClientName(String clientName) {
|
public String getPassword() { return password; }
|
||||||
RedissonConfig.clientName = clientName;
|
public void setPassword(String password) { this.password = password; }
|
||||||
}
|
|
||||||
|
|
||||||
public int getDatabase() {
|
public String getClientName() { return clientName; }
|
||||||
return database;
|
public void setClientName(String clientName) { this.clientName = clientName; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setDatabase(int database) {
|
public int getDatabase() { return database; }
|
||||||
RedissonConfig.database = database;
|
public void setDatabase(int database) { this.database = database; }
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMode() {
|
public String getMode() { return mode; }
|
||||||
return mode;
|
public void setMode(String mode) { this.mode = mode; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setMode(String mode) {
|
public String getMasterName() { return masterName; }
|
||||||
RedissonConfig.mode = mode;
|
public void setMasterName(String masterName) { this.masterName = masterName; }
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMasterNamee() {
|
public int getIdleConnectionTimeout() { return idleConnectionTimeout; }
|
||||||
return masterName;
|
public void setIdleConnectionTimeout(int idleConnectionTimeout) { this.idleConnectionTimeout = idleConnectionTimeout; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setMasterNamee(String masterName) {
|
public int getConnectTimeout() { return connectTimeout; }
|
||||||
RedissonConfig.masterName = masterName;
|
public void setConnectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; }
|
||||||
}
|
|
||||||
|
|
||||||
// 超时配置
|
public int getTimeout() { return timeout; }
|
||||||
public int getIdleConnectionTimeout() {
|
public void setTimeout(int timeout) { this.timeout = timeout; }
|
||||||
return idleConnectionTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIdleConnectionTimeout(int idleConnectionTimeout) {
|
public int getRetryAttempts() { return retryAttempts; }
|
||||||
RedissonConfig.idleConnectionTimeout = idleConnectionTimeout;
|
public void setRetryAttempts(int retryAttempts) { this.retryAttempts = retryAttempts; }
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectTimeout() {
|
public int getRetryInterval() { return retryInterval; }
|
||||||
return connectTimeout;
|
public void setRetryInterval(int retryInterval) { this.retryInterval = retryInterval; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectTimeout(int connectTimeout) {
|
public int getConnectionMinimumIdleSize() { return connectionMinimumIdleSize; }
|
||||||
RedissonConfig.connectTimeout = connectTimeout;
|
public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) { this.connectionMinimumIdleSize = connectionMinimumIdleSize; }
|
||||||
}
|
|
||||||
|
|
||||||
public int getTimeout() {
|
public int getConnectionPoolSize() { return connectionPoolSize; }
|
||||||
return timeout;
|
public void setConnectionPoolSize(int connectionPoolSize) { this.connectionPoolSize = connectionPoolSize; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setTimeout(int timeout) {
|
public int getSubscriptionsPerConnection() { return subscriptionsPerConnection; }
|
||||||
RedissonConfig.timeout = timeout;
|
public void setSubscriptionsPerConnection(int subscriptionsPerConnection) { this.subscriptionsPerConnection = subscriptionsPerConnection; }
|
||||||
}
|
|
||||||
|
|
||||||
// 重试配置
|
public int getSubscriptionConnectionMinimumIdleSize() { return subscriptionConnectionMinimumIdleSize; }
|
||||||
public int getRetryAttempts() {
|
public void setSubscriptionConnectionMinimumIdleSize(int subscriptionConnectionMinimumIdleSize) { this.subscriptionConnectionMinimumIdleSize = subscriptionConnectionMinimumIdleSize; }
|
||||||
return retryAttempts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRetryAttempts(int retryAttempts) {
|
public int getSubscriptionConnectionPoolSize() { return subscriptionConnectionPoolSize; }
|
||||||
RedissonConfig.retryAttempts = retryAttempts;
|
public void setSubscriptionConnectionPoolSize(int subscriptionConnectionPoolSize) { this.subscriptionConnectionPoolSize = subscriptionConnectionPoolSize; }
|
||||||
}
|
|
||||||
|
|
||||||
public int getRetryInterval() {
|
public int getScanInterval() { return scanInterval; }
|
||||||
return retryInterval;
|
public void setScanInterval(int scanInterval) { this.scanInterval = scanInterval; }
|
||||||
}
|
|
||||||
|
|
||||||
public void setRetryInterval(int retryInterval) {
|
public int getDnsMonitoringInterval() { return dnsMonitoringInterval; }
|
||||||
RedissonConfig.retryInterval = retryInterval;
|
public void setDnsMonitoringInterval(int dnsMonitoringInterval) { this.dnsMonitoringInterval = dnsMonitoringInterval; }
|
||||||
}
|
|
||||||
|
|
||||||
// 连接池配置
|
public int getThreads() { return threads; }
|
||||||
public int getConnectionMinimumIdleSize() {
|
public void setThreads(int threads) { this.threads = threads; }
|
||||||
return connectionMinimumIdleSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) {
|
public String getCodec() { return codec; }
|
||||||
RedissonConfig.connectionMinimumIdleSize = connectionMinimumIdleSize;
|
public void setCodec(String codec) { this.codec = codec; }
|
||||||
}
|
|
||||||
|
|
||||||
public int getConnectionPoolSize() {
|
|
||||||
return connectionPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectionPoolSize(int connectionPoolSize) {
|
|
||||||
RedissonConfig.connectionPoolSize = connectionPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSubscriptionsPerConnection() {
|
|
||||||
return subscriptionsPerConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubscriptionsPerConnection(int subscriptionsPerConnection) {
|
|
||||||
RedissonConfig.subscriptionsPerConnection = subscriptionsPerConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSubscriptionConnectionMinimumIdleSize() {
|
|
||||||
return subscriptionConnectionMinimumIdleSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubscriptionConnectionMinimumIdleSize(int subscriptionConnectionMinimumIdleSize) {
|
|
||||||
RedissonConfig.subscriptionConnectionMinimumIdleSize = subscriptionConnectionMinimumIdleSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSubscriptionConnectionPoolSize() {
|
|
||||||
return subscriptionConnectionPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSubscriptionConnectionPoolSize(int subscriptionConnectionPoolSize) {
|
|
||||||
RedissonConfig.subscriptionConnectionPoolSize = subscriptionConnectionPoolSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 其他配置
|
|
||||||
public int getDnsMonitoringInterval() {
|
|
||||||
return dnsMonitoringInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDnsMonitoringInterval(int dnsMonitoringInterval) {
|
|
||||||
RedissonConfig.dnsMonitoringInterval = dnsMonitoringInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getThread() {
|
|
||||||
return thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setThread(int thread) {
|
|
||||||
RedissonConfig.thread = thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getCodec() {
|
|
||||||
return codec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCodec(String codec) {
|
|
||||||
RedissonConfig.codec = codec;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -59,21 +59,26 @@ public class CompressFileReader {
|
|||||||
for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
|
for (final ISimpleInArchiveItem item : simpleInArchive.getArchiveItems()) {
|
||||||
if (!item.isFolder()) {
|
if (!item.isFolder()) {
|
||||||
final Path filePathInsideArchive = getFilePathInsideArchive(item, folderPath);
|
final Path filePathInsideArchive = getFilePathInsideArchive(item, folderPath);
|
||||||
ExtractOperationResult result = item.extractSlow(data -> {
|
Files.deleteIfExists(filePathInsideArchive);
|
||||||
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(filePathInsideArchive.toFile(), true))) {
|
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(filePathInsideArchive.toFile(), false))) {
|
||||||
out.write(data);
|
ExtractOperationResult result = item.extractSlow(data -> {
|
||||||
} catch (IOException e) {
|
try {
|
||||||
throw new RuntimeException(e);
|
out.write(data);
|
||||||
}
|
} catch (IOException e) {
|
||||||
return data.length;
|
throw new RuntimeException(e);
|
||||||
}, filePassword);
|
}
|
||||||
if (result != ExtractOperationResult.OK) {
|
return data.length;
|
||||||
ExtractOperationResult result1 = ExtractOperationResult.valueOf("WRONG_PASSWORD");
|
}, filePassword);
|
||||||
if (result1.equals(result)) {
|
if (result != ExtractOperationResult.OK) {
|
||||||
throw new Exception("Password");
|
ExtractOperationResult result1 = ExtractOperationResult.valueOf("WRONG_PASSWORD");
|
||||||
}else {
|
if (result1.equals(result)) {
|
||||||
throw new Exception("Failed to extract RAR file.");
|
throw new Exception("Password");
|
||||||
|
} else {
|
||||||
|
throw new Exception("Failed to extract RAR file.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileType type = FileType.typeFromUrl(filePathInsideArchive.toString());
|
FileType type = FileType.typeFromUrl(filePathInsideArchive.toString());
|
||||||
@@ -110,4 +115,4 @@ public class CompressFileReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
package cn.keking.service.cache.impl;
|
package cn.keking.service.cache.impl;
|
||||||
|
|
||||||
import cn.keking.service.cache.CacheService;
|
import cn.keking.service.cache.CacheService;
|
||||||
import org.redisson.Redisson;
|
|
||||||
import org.redisson.api.RBlockingQueue;
|
import org.redisson.api.RBlockingQueue;
|
||||||
import org.redisson.api.RMapCache;
|
import org.redisson.api.RMapCache;
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
import org.redisson.config.Config;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -23,8 +21,9 @@ public class CacheServiceRedisImpl implements CacheService {
|
|||||||
|
|
||||||
private final RedissonClient redissonClient;
|
private final RedissonClient redissonClient;
|
||||||
|
|
||||||
public CacheServiceRedisImpl(Config config) {
|
// 直接注入 Spring 容器中的 RedissonClient Bean
|
||||||
this.redissonClient = Redisson.create(config);
|
public CacheServiceRedisImpl(RedissonClient redissonClient) {
|
||||||
|
this.redissonClient = redissonClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -348,4 +348,4 @@ public class OfficeFilePreviewImpl implements FilePreview {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -547,28 +547,31 @@ a:focus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.preview-options {
|
.preview-options {
|
||||||
display: flex;
|
display: grid;
|
||||||
|
grid-template-columns: auto minmax(0, 1fr);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
margin-bottom: 14px;
|
margin-bottom: 14px;
|
||||||
overflow-x: auto;
|
overflow: visible;
|
||||||
padding-bottom: 4px;
|
padding-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-grid {
|
.preview-grid {
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-wrap: nowrap;
|
grid-template-columns: repeat(5, minmax(108px, 1fr));
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
flex: 1 1 auto;
|
min-width: 0;
|
||||||
min-width: 620px;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-grid .form-control {
|
.preview-grid .form-control {
|
||||||
flex: 1 1 0;
|
width: 100%;
|
||||||
min-width: 150px;
|
min-width: 0;
|
||||||
|
padding-left: 16px;
|
||||||
|
padding-right: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-switches {
|
.preview-switches {
|
||||||
@@ -578,7 +581,7 @@ a:focus {
|
|||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
flex: 0 0 auto;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-switches label {
|
.preview-switches label {
|
||||||
@@ -586,7 +589,7 @@ a:focus {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 10px 14px;
|
padding: 10px 12px;
|
||||||
border-radius: 999px;
|
border-radius: 999px;
|
||||||
background: rgba(255, 255, 255, 0.76);
|
background: rgba(255, 255, 255, 0.76);
|
||||||
border: 1px solid rgba(17, 19, 21, 0.08);
|
border: 1px solid rgba(17, 19, 21, 0.08);
|
||||||
@@ -1264,6 +1267,10 @@ a:focus {
|
|||||||
.archive-grid {
|
.archive-grid {
|
||||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preview-grid {
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
@@ -1304,16 +1311,8 @@ a:focus {
|
|||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-grid {
|
|
||||||
flex-wrap: wrap;
|
|
||||||
min-width: 0;
|
|
||||||
overflow-x: visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
.preview-options {
|
.preview-options {
|
||||||
display: block;
|
grid-template-columns: 1fr;
|
||||||
overflow-x: visible;
|
|
||||||
padding-bottom: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-url {
|
.preview-url {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@
|
|||||||
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
|
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"/>
|
||||||
<link rel="stylesheet" href="bootstrap-table/bootstrap-table.min.css"/>
|
<link rel="stylesheet" href="bootstrap-table/bootstrap-table.min.css"/>
|
||||||
<link rel="stylesheet" href="css/theme.css"/>
|
<link rel="stylesheet" href="css/theme.css"/>
|
||||||
<link rel="stylesheet" href="css/main-pages.css?v=v1-polish-20260411-3"/>
|
<link rel="stylesheet" href="css/main-pages.css?v=v1-polish-20260411-5"/>
|
||||||
<script type="text/javascript" src="js/jquery-3.6.1.min.js"></script>
|
<script type="text/javascript" src="js/jquery-3.6.1.min.js"></script>
|
||||||
<script type="text/javascript" src="js/jquery.form.min.js"></script>
|
<script type="text/javascript" src="js/jquery.form.min.js"></script>
|
||||||
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
|
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
|
||||||
@@ -493,8 +493,8 @@
|
|||||||
search: false,
|
search: false,
|
||||||
searchOnEnterKey: false,
|
searchOnEnterKey: false,
|
||||||
showSearchButton: false,
|
showSearchButton: false,
|
||||||
showRefresh: true,
|
showRefresh: false,
|
||||||
showColumns: true,
|
showColumns: false,
|
||||||
clickToSelect: true,
|
clickToSelect: true,
|
||||||
locale: 'zh-CN',
|
locale: 'zh-CN',
|
||||||
columns: [{
|
columns: [{
|
||||||
|
|||||||
@@ -41,10 +41,10 @@
|
|||||||
你可以先看最新版本的升级重点,再顺着时间轴继续了解历史版本细节。
|
你可以先看最新版本的升级重点,再顺着时间轴继续了解历史版本细节。
|
||||||
</p>
|
</p>
|
||||||
<div class="release-badge-row">
|
<div class="release-badge-row">
|
||||||
<span class="tag highlight">最新版本 v5.0</span>
|
<span class="tag highlight">最新版本 v5.0.0</span>
|
||||||
<span class="tag brand">发布日期 2026-01-20</span>
|
<span class="tag brand">发布日期 2026-04-14</span>
|
||||||
<span class="tag warn">JDK 21+ 强制要求</span>
|
<span class="tag warn">JDK 21+ 强制要求</span>
|
||||||
<span class="tag">PDF / TIF / CAD 异步化</span>
|
<span class="tag">压缩包工作区预览 / PDF 默认模式</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
@@ -53,9 +53,9 @@
|
|||||||
<div class="timeline-year">2026</div>
|
<div class="timeline-year">2026</div>
|
||||||
<div class="timeline-list">
|
<div class="timeline-list">
|
||||||
<article class="release-card">
|
<article class="release-card">
|
||||||
<h3>v5.0</h3>
|
<h3>v5.0.0</h3>
|
||||||
<div class="release-meta">
|
<div class="release-meta">
|
||||||
<span class="tag brand">2026-01-20</span>
|
<span class="tag brand">2026-04-14</span>
|
||||||
<span class="tag highlight">最新稳定版本</span>
|
<span class="tag highlight">最新稳定版本</span>
|
||||||
<span class="tag warn">升级需 JDK 21+</span>
|
<span class="tag warn">升级需 JDK 21+</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -66,6 +66,9 @@
|
|||||||
<li>优化 xlsx、图片、tif、svg、json 解析效果。</li>
|
<li>优化 xlsx、图片、tif、svg、json 解析效果。</li>
|
||||||
<li>优化 FTP 多客户端接入与 marked 解析。</li>
|
<li>优化 FTP 多客户端接入与 marked 解析。</li>
|
||||||
<li>首页支持目录访问,并切换为 POST 服务端分页。</li>
|
<li>首页支持目录访问,并切换为 POST 服务端分页。</li>
|
||||||
|
<li>压缩包预览页重构为单工作区布局,支持目录折叠与右侧内嵌预览。</li>
|
||||||
|
<li>优化压缩包内文件类型标识,以及单图预览页展示样式。</li>
|
||||||
|
<li>重构演示门户页面,包括首页、接入说明、版本记录与赞助页。</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="release-group">
|
<div class="release-group">
|
||||||
@@ -74,6 +77,7 @@
|
|||||||
<li>新增 msg、heic/heif、页码、高亮、AES、Basic Auth、秘钥等能力。</li>
|
<li>新增 msg、heic/heif、页码、高亮、AES、Basic Auth、秘钥等能力。</li>
|
||||||
<li>新增防重复转换、异步等待、上传限制与 cadviewer 转换方法。</li>
|
<li>新增防重复转换、异步等待、上传限制与 cadviewer 转换方法。</li>
|
||||||
<li>新增 pptm 支持。</li>
|
<li>新增 pptm 支持。</li>
|
||||||
|
<li>补充面向工程自动化与编码代理的仓库说明文档。</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="release-group">
|
<div class="release-group">
|
||||||
@@ -82,6 +86,9 @@
|
|||||||
<li>修复压缩包路径问题与安全问题。</li>
|
<li>修复压缩包路径问题与安全问题。</li>
|
||||||
<li>修复图片水印不完整。</li>
|
<li>修复图片水印不完整。</li>
|
||||||
<li>修复 SSL 自签证书接入问题。</li>
|
<li>修复 SSL 自签证书接入问题。</li>
|
||||||
|
<li>修复压缩包内 Office 文件重复解压后被追加写坏、导致一直加载中的问题。</li>
|
||||||
|
<li>Office 默认预览切到 PDF 模式,并默认展开 PDF 缩略图侧栏。</li>
|
||||||
|
<li>修复 OFD 表格竖线溢出导致的渲染异常,并修正 PDF.js 兼容性补丁。</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="release-group">
|
<div class="release-group">
|
||||||
@@ -90,6 +97,9 @@
|
|||||||
<li>JDK 版本要求升级到 21 及以上。</li>
|
<li>JDK 版本要求升级到 21 及以上。</li>
|
||||||
<li>前端解析链路升级:PDF、ODF、3D 模型。</li>
|
<li>前端解析链路升级:PDF、ODF、3D 模型。</li>
|
||||||
<li>后端异步转换升级:PDF、TIF、视频、CAD。</li>
|
<li>后端异步转换升级:PDF、TIF、视频、CAD。</li>
|
||||||
|
<li>启动脚本改为自动发现当前发布包中的 jar,并同步更新 Docker 与发布辅助文档。</li>
|
||||||
|
<li>默认配置策略调整:Office 预览默认使用 PDF 模式,默认隐藏图片/PDF 模式切换按钮;如需保留旧的图片优先体验,请显式设置 <code>office.preview.type=image</code> 与 <code>office.preview.switch.disabled=false</code>。</li>
|
||||||
|
<li>信任域名配置匹配策略扩展:<code>trust.host</code> 及相关规则支持通配符与 CIDR 匹配;升级后请重新核对白名单和黑名单的匹配范围。</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
if (kkagent === 'true' || !url.startsWith(baseUrl)) {
|
if (kkagent === 'true' || !url.startsWith(baseUrl)) {
|
||||||
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(Base64.encode(url))+ "&key=${kkkey}";
|
url = baseUrl + 'getCorsFile?urlPath=' + encodeURIComponent(Base64.encode(url))+ "&key=${kkkey}";
|
||||||
}
|
}
|
||||||
document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?file=" + encodeURIComponent(url) + "&disablepresentationmode=${pdfPresentationModeDisable}&disableopenfile=${pdfOpenFileDisable}&disableprint=${pdfPrintDisable}&disabledownload=${pdfDownloadDisable}&disablebookmark=${pdfBookmarkDisable}&disableediting=${pdfDisableEditing}";
|
document.getElementsByTagName('iframe')[0].src = "${baseUrl}pdfjs/web/viewer.html?file=" + encodeURIComponent(url) + "&disablepresentationmode=${pdfPresentationModeDisable}&disableopenfile=${pdfOpenFileDisable}&disableprint=${pdfPrintDisable}&disabledownload=${pdfDownloadDisable}&disablebookmark=${pdfBookmarkDisable}&disableediting=${pdfDisableEditing}#page=1&pagemode=thumbs";
|
||||||
document.getElementsByTagName('iframe')[0].height = document.documentElement.clientHeight - 10;
|
document.getElementsByTagName('iframe')[0].height = document.documentElement.clientHeight - 10;
|
||||||
/**
|
/**
|
||||||
* 页面变化调整高度
|
* 页面变化调整高度
|
||||||
|
|||||||
@@ -9,7 +9,15 @@
|
|||||||
<script src="js/base64.min.js"></script>
|
<script src="js/base64.min.js"></script>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: #404040;
|
background-color: #f1f3f5;
|
||||||
|
}
|
||||||
|
.viewer-container:focus {
|
||||||
|
outline: none !important;
|
||||||
|
}
|
||||||
|
.viewer-container:focus-visible {
|
||||||
|
outline: 2px solid rgba(95, 107, 122, 0.65) !important;
|
||||||
|
outline-offset: 2px;
|
||||||
|
box-shadow: 0 0 0 4px rgba(95, 107, 122, 0.14);
|
||||||
}
|
}
|
||||||
#image { width: 800px; margin: 0 auto; font-size: 0;}
|
#image { width: 800px; margin: 0 auto; font-size: 0;}
|
||||||
#image li { display: inline-block;width: 50px;height: 50px; margin-left: 1%; padding-top: 1%;}
|
#image li { display: inline-block;width: 50px;height: 50px; margin-left: 1%; padding-top: 1%;}
|
||||||
@@ -77,4 +85,4 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -26,6 +26,20 @@ public class PdfViewerCompatibilityTests {
|
|||||||
assertTrue(workerScript.contains("import \"../web/compatibility.mjs\";"));
|
assertTrue(workerScript.contains("import \"../web/compatibility.mjs\";"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldOpenPdfPreviewWithThumbnailSidebarByDefault() throws IOException {
|
||||||
|
String pdfTemplate = readResource("/web/pdf.ftl");
|
||||||
|
|
||||||
|
assertTrue(pdfTemplate.contains("#page=1&pagemode=thumbs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldPreferPdfForOfficePreviewByDefault() throws IOException {
|
||||||
|
String properties = readResource("/application.properties");
|
||||||
|
|
||||||
|
assertTrue(properties.contains("office.preview.type = ${KK_OFFICE_PREVIEW_TYPE:pdf}"));
|
||||||
|
}
|
||||||
|
|
||||||
private String readResource(String resourcePath) throws IOException {
|
private String readResource(String resourcePath) throws IOException {
|
||||||
try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) {
|
try (InputStream inputStream = getClass().getResourceAsStream(resourcePath)) {
|
||||||
assertNotNull(inputStream);
|
assertNotNull(inputStream);
|
||||||
|
|||||||
Reference in New Issue
Block a user