feat: 缺失文件扫描支持清理并发布 v2.1.1
构建与发布 / 发布 GitHub Release (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
构建与发布 / 单测与集成测试 (push) Waiting to run
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
构建与发布 / 发布 GitHub Release (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, linux, ubuntu-24.04-arm) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, linux, ubuntu-24.04) (push) Blocked by required conditions
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (x64, windows, windows-2025) (push) Blocked by required conditions
构建与发布 / 单测与集成测试 (push) Waiting to run
构建与发布 / 打包 ${{ matrix.platform }} ${{ matrix.arch }} (arm64, macos, macos-15) (push) Blocked by required conditions
This commit is contained in:
+33
-1
@@ -978,6 +978,38 @@ function removeMany(ids, deleteFiles) {
|
||||
return { removed: doomed.length };
|
||||
}
|
||||
|
||||
function removeMissing() {
|
||||
load();
|
||||
const doomed = items.filter((item) => {
|
||||
const files = item.files || [];
|
||||
return files.length > 0 && files.every((file) => !fs.existsSync(toAbsolute(file.path)));
|
||||
});
|
||||
if (!doomed.length) return { removed: 0, shelvesRemoved: 0, tagsRemoved: 0 };
|
||||
|
||||
const ids = new Set(doomed.map((item) => item.id));
|
||||
const candidateShelves = new Set(doomed.map((item) => item.shelfId).filter(Boolean));
|
||||
const candidateTags = new Set(doomed.flatMap((item) => normalizeTags(item.tags).map(tagKey)));
|
||||
const nextItems = items.filter((item) => !ids.has(item.id));
|
||||
const usedShelves = new Set(nextItems.map((item) => item.shelfId).filter(Boolean));
|
||||
const usedTags = new Set(nextItems.flatMap((item) => normalizeTags(item.tags).map(tagKey)));
|
||||
const nextShelves = shelves.filter((shelf) => (
|
||||
!candidateShelves.has(shelf.id) || usedShelves.has(shelf.id)
|
||||
));
|
||||
const nextTags = tags.filter((tag) => (
|
||||
!candidateTags.has(tagKey(tag.name)) || usedTags.has(tagKey(tag.name))
|
||||
));
|
||||
const shelvesRemoved = shelves.length - nextShelves.length;
|
||||
const tagsRemoved = tags.length - nextTags.length;
|
||||
|
||||
commit(nextItems, true, nextShelves, nextTags);
|
||||
for (const item of doomed) removeCoverFile(item.id);
|
||||
return {
|
||||
removed: doomed.length,
|
||||
shelvesRemoved,
|
||||
tagsRemoved
|
||||
};
|
||||
}
|
||||
|
||||
function remove(id, deleteFiles) {
|
||||
load();
|
||||
const it = items.find((x) => x.id === id);
|
||||
@@ -1311,7 +1343,7 @@ function importLegacy(legacyDir) {
|
||||
module.exports = {
|
||||
init, getRoot, filesDir, allocFilePath, sanitize,
|
||||
list, get, findBySource, listShelves, listTags,
|
||||
add, importLocal, update, updateMany, remove, removeMany, attachFile,
|
||||
add, importLocal, update, updateMany, remove, removeMany, removeMissing, attachFile,
|
||||
addShelf, updateShelf, removeShelf,
|
||||
addTag, updateTag, removeTag,
|
||||
scan, migrateTo, finalizeMigration, rollbackMigration, importLegacy,
|
||||
|
||||
Reference in New Issue
Block a user