Skip to content

Commit

Permalink
fix: 唤起一次更新会检查全部文件
Browse files Browse the repository at this point in the history
  • Loading branch information
SALTWOOD committed Aug 27, 2024
1 parent 22f278e commit 7156765
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class Server {
console.log(`...file list was successfully updated. Found ${this.files.length} files`);
if (checkClusters) {
for (const cluster of this.clusters.filter(c => c.isOnline)) {
const message = await Utilities.checkSpecfiedFiles(Utilities.findDifferences(this.files, oldFiles), cluster);
const message = await Utilities.checkSpecfiedFiles(Utilities.findDifferences(oldFiles, this.files, true), cluster); // 只查找新增的文件,不然删文件会把全部节点踢了
if (message) {
cluster.downReason = message;
cluster.isOnline = false;
Expand Down
24 changes: 13 additions & 11 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,19 @@ export class Utilities {
return results;
}

public static findDifferences<T>(array1: T[], array2: T[]): T[] {
const set1 = new Set(array1);
const set2 = new Set(array2);
const result: T[] = [];
for (const item of set1) {
if (!set2.has(item)) {
result.push(item);
}
}
return result;
}
public static findDifferences(
fileArray1: File[],
fileArray2: File[],
onlyRight: boolean = false
): File[] {
const hashSet1 = new Set<string>(fileArray1.map(f => f.hash));
const hashSet2 = new Set<string>(fileArray2.map(f => f.hash));

return [
...onlyRight ? [] : fileArray1.filter(f =>!hashSet2.has(f.hash)), // 存在于 fileArray1 但不存在于 fileArray2
...fileArray2.filter(f =>!hashSet1.has(f.hash)) // 存在于 fileArray2 但不存在于 fileArray1
]
}

public static async checkSpecfiedFiles(files: File[], cluster: ClusterEntity): Promise<string | null> {
let result: string | null = "Error: This value should never be returned. if you see this message, please contact to the administrator.";
Expand Down

0 comments on commit 7156765

Please sign in to comment.