feat: 将 scanDir 持久化到 app_config 表,移除 localStorage 存储
This commit is contained in:
@@ -210,8 +210,8 @@ export default {
|
|||||||
starting: false, // 点完按钮后、等后端回话前的"转圈"
|
starting: false, // 点完按钮后、等后端回话前的"转圈"
|
||||||
moving: false, // 点完「移动文件」后等后端回话前的"转圈"
|
moving: false, // 点完「移动文件」后等后端回话前的"转圈"
|
||||||
cancelling: false, // 点完「中止扫描」后等后端确认的"转圈"
|
cancelling: false, // 点完「中止扫描」后等后端确认的"转圈"
|
||||||
scanDir: localStorage.getItem('scan-dir') || '', // 要扫描的目录(记住上次填的)
|
scanDir: '', // 要扫描的目录(从后端状态回填)
|
||||||
destDir: localStorage.getItem('scan-dest-dir') || '', // 整理后文件放哪(记住上次填的)
|
destDir: '', // 整理后文件放哪(从后端状态回填)
|
||||||
|
|
||||||
// ---------- 扫描进度与状态 ----------
|
// ---------- 扫描进度与状态 ----------
|
||||||
status: {
|
status: {
|
||||||
@@ -299,9 +299,10 @@ export default {
|
|||||||
const wasRunning = this.status.state === 'running' // 之前是不是在跑
|
const wasRunning = this.status.state === 'running' // 之前是不是在跑
|
||||||
const isRunning = data.state === 'running' // 现在是不是在跑
|
const isRunning = data.state === 'running' // 现在是不是在跑
|
||||||
const prevLineCount = (this.status.lines || []).length
|
const prevLineCount = (this.status.lines || []).length
|
||||||
// 第一次拿到状态时,把后端记的"上次存放目录"回填进来
|
// 第一次拿到状态时,把后端记的"上次目录"回填进来
|
||||||
if (!this.status.initialized && data.destDir) {
|
if (!this.status.initialized) {
|
||||||
this.destDir = data.destDir
|
if (data.rootDir) this.scanDir = data.rootDir
|
||||||
|
if (data.destDir) this.destDir = data.destDir
|
||||||
}
|
}
|
||||||
this.status = data
|
this.status = data
|
||||||
this.status.initialized = true
|
this.status.initialized = true
|
||||||
@@ -411,9 +412,6 @@ export default {
|
|||||||
async handleStart() {
|
async handleStart() {
|
||||||
this.starting = true
|
this.starting = true
|
||||||
try {
|
try {
|
||||||
// 记住这次填的目录,下次打开页面自动填上
|
|
||||||
localStorage.setItem('scan-dir', this.scanDir)
|
|
||||||
localStorage.setItem('scan-dest-dir', this.destDir)
|
|
||||||
const res = await request.post('/api/scan/start', {
|
const res = await request.post('/api/scan/start', {
|
||||||
dir: this.scanDir.trim(),
|
dir: this.scanDir.trim(),
|
||||||
destDir: this.destDir.trim()
|
destDir: this.destDir.trim()
|
||||||
@@ -476,10 +474,8 @@ export default {
|
|||||||
if (!this.fsData.current) return
|
if (!this.fsData.current) return
|
||||||
if (this.pickerTarget === 'dest') {
|
if (this.pickerTarget === 'dest') {
|
||||||
this.destDir = this.fsData.current
|
this.destDir = this.fsData.current
|
||||||
localStorage.setItem('scan-dest-dir', this.destDir)
|
|
||||||
} else {
|
} else {
|
||||||
this.scanDir = this.fsData.current
|
this.scanDir = this.fsData.current
|
||||||
localStorage.setItem('scan-dir', this.scanDir)
|
|
||||||
}
|
}
|
||||||
this.dirPickerVisible = false
|
this.dirPickerVisible = false
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -71,7 +71,10 @@ type ScanStatus struct {
|
|||||||
// ============================ 应用级常量 ============================
|
// ============================ 应用级常量 ============================
|
||||||
|
|
||||||
// 应用级配置键。目前只存了两个:上次使用的存放目录、色情检测服务是否真的起来了。
|
// 应用级配置键。目前只存了两个:上次使用的存放目录、色情检测服务是否真的起来了。
|
||||||
const ConfigKeyDestDir = "scan.destDir"
|
const (
|
||||||
|
ConfigKeyScanDir = "scan.scanDir"
|
||||||
|
ConfigKeyDestDir = "scan.destDir"
|
||||||
|
)
|
||||||
|
|
||||||
// nsfwDetectorReadyKey 记录最近一次扫描时色情检测服务是否真的起来了(python+nudenet 可用)。
|
// nsfwDetectorReadyKey 记录最近一次扫描时色情检测服务是否真的起来了(python+nudenet 可用)。
|
||||||
// 配置开了但检测器没起来(没装 python/模型下载失败等)也能区分出来,前端据此提示。
|
// 配置开了但检测器没起来(没装 python/模型下载失败等)也能区分出来,前端据此提示。
|
||||||
@@ -147,7 +150,13 @@ type ScanService struct {
|
|||||||
// NewScanService 创建扫描服务。
|
// NewScanService 创建扫描服务。
|
||||||
// 注意 store 可以传 nil——数据库打不开时服务照常能用,只是不记录媒体信息。
|
// 注意 store 可以传 nil——数据库打不开时服务照常能用,只是不记录媒体信息。
|
||||||
func NewScanService(st *store.Store) *ScanService {
|
func NewScanService(st *store.Store) *ScanService {
|
||||||
return &ScanService{store: st, hub: NewStatusHub(), state: ScanIdle}
|
s := &ScanService{store: st, hub: NewStatusHub(), state: ScanIdle}
|
||||||
|
// 从数据库恢复上次用过的目录,状态接口可以直接返回给前端回填
|
||||||
|
if st != nil {
|
||||||
|
s.rootDir = st.GetConfig(ConfigKeyScanDir)
|
||||||
|
s.destDir = st.GetConfig(ConfigKeyDestDir)
|
||||||
|
}
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subscribe 让调用方(通常是 WebSocket 处理器)订阅进度更新。
|
// Subscribe 让调用方(通常是 WebSocket 处理器)订阅进度更新。
|
||||||
@@ -209,8 +218,11 @@ func (s *ScanService) Start(rootDir, destDir string) error {
|
|||||||
s.ctx, s.cancel = context.WithCancel(context.Background())
|
s.ctx, s.cancel = context.WithCancel(context.Background())
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
|
|
||||||
// 把存放目录记到数据库里,下次打开页面自动填上,省得用户重敲
|
// 把扫描目录和存放目录记到数据库里,下次打开页面自动填上,省得用户重敲
|
||||||
if s.store != nil {
|
if s.store != nil {
|
||||||
|
if err := s.store.SaveConfig(ConfigKeyScanDir, rootDir); err != nil {
|
||||||
|
fmt.Printf("=== 保存扫描目录配置失败: %v\n", err)
|
||||||
|
}
|
||||||
if err := s.store.SaveConfig(ConfigKeyDestDir, destDir); err != nil {
|
if err := s.store.SaveConfig(ConfigKeyDestDir, destDir); err != nil {
|
||||||
fmt.Printf("=== 保存存放目录配置失败: %v\n", err)
|
fmt.Printf("=== 保存存放目录配置失败: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user