fix scanner

This commit is contained in:
bwcx_jzy 2023-12-29 09:51:06 +08:00
parent 55346f647e
commit a4c04d0a6b
No known key found for this signature in database
GPG Key ID: E187D6E9DDDE8C53
4 changed files with 34 additions and 6 deletions

View File

@ -210,11 +210,11 @@ public class StaticFileStorageController extends BaseServerController {
*
* @return json
*/
@GetMapping(value = "has-file", produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping(value = "scanner", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public IJsonMessage<String> scanner(HttpServletRequest request) {
boolean scanning = staticFileStorageService.isScanning();
Assert.state(scanning, "当前正在扫描中");
Assert.state(!scanning, "当前正在扫描中");
String workspace = fileStorageService.getCheckUserWorkspace(request);
staticFileStorageService.scanByWorkspace(workspace);
return JsonMessage.success("扫描成功");

View File

@ -142,6 +142,13 @@ public class StaticFileStorageService extends BaseDbService<StaticFileStorageMod
// 开启任务
watchMonitor = new HashMap<>(list.size());
for (String s : list) {
File file = FileUtil.file(s);
if (!FileUtil.exist(file)) {
log.warn("被监控的目录不存在忽略创建监听器:{}", s);
// 自动删除已经存在的任务
this.delete(file);
continue;
}
DelayWatcher delayWatcher = new DelayWatcher(StaticFileStorageService.this, 1000);
WatchMonitor monitor = WatchUtil.createAll(s, watchMonitorMaxDepth, delayWatcher);
watchMonitor.put(s, monitor);
@ -149,7 +156,6 @@ public class StaticFileStorageService extends BaseDbService<StaticFileStorageMod
ThreadUtil.execute(monitor);
}
}
this.execute();
}
/**
@ -228,6 +234,8 @@ public class StaticFileStorageService extends BaseDbService<StaticFileStorageMod
private void scanItem(String staticDir, String item, int level, Long taskId) {
File file = FileUtil.file(item);
if (!FileUtil.exist(file)) {
// 目录不存在了自动删除
this.delete(file);
return;
}
if (FileUtil.isFile(file)) {

View File

@ -41,3 +41,11 @@ export function hasStaticFile(params) {
params: params,
});
}
export function staticScanner(params) {
return axios({
url: "/file-storage/static/scanner",
method: "get",
params: params,
});
}

View File

@ -27,6 +27,7 @@
<a-button type="primary" :loading="loading" @click="loadData">搜索</a-button>
</a-tooltip>
<!-- <a-button type="primary" @click="handleUpload">上传文件</a-button> -->
<a-button type="primary" @click="reScanner">扫描</a-button>
<a-button type="danger" :disabled="!tableSelections || tableSelections.length <= 0" @click="handleBatchDelete"> 批量删除 </a-button>
</a-space>
@ -74,7 +75,7 @@
</a-space>
</template>
</a-table>
<!-- 上传文件 -->
<!-- 上传文件
<a-modal destroyOnClose v-model="uploadVisible" :closable="!uploading" :footer="uploading ? null : undefined" :keyboard="false" :title="`上传文件`" @ok="handleUploadOk" :maskClosable="false">
<a-form-model ref="form" :rules="rules" :model="temp" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
<a-form-model-item label="选择文件" prop="file">
@ -135,7 +136,7 @@
<a-textarea v-model="temp.description" placeholder="请输入文件描述" />
</a-form-model-item>
</a-form-model>
</a-modal>
</a-modal> -->
<!-- 编辑文件 -->
<a-modal destroyOnClose v-model="editVisible" :title="`修改文件`" @ok="handleEditOk" :maskClosable="false">
<a-form-model ref="editForm" :rules="rules" :model="temp" :label-col="{ span: 4 }" :wrapper-col="{ span: 20 }">
@ -268,7 +269,7 @@
<script>
import { CHANGE_PAGE, COMPUTED_PAGINATION, PAGE_DEFAULT_LIST_QUERY, parseTime, renderSize, formatDuration, randomStr } from "@/utils/const";
// import { uploadFile, uploadFileMerge, hasFile } from "@/api/file-manager/file-storage";
import { staticFileStorageList, delFile, triggerUrl, fileEdit } from "@/api/file-manager/static-storage";
import { staticFileStorageList, delFile, triggerUrl, fileEdit, staticScanner } from "@/api/file-manager/static-storage";
// import { uploadPieces } from "@/utils/upload-pieces";
import Vue from "vue";
import releaseFile from "@/pages/file-manager/fileStorage/releaseFile";
@ -616,6 +617,17 @@ export default {
}
this.$emit("confirm", selectData);
},
//
reScanner() {
staticScanner({}).then((res) => {
if (res.code === 200) {
this.$notification.success({
message: res.msg,
});
this.loadData();
}
});
},
},
};
</script>