@1-/scan 0.1.11 → 0.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/dbInit.js +13 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,12 +31,12 @@ npm install @1-/scan
|
|
|
31
31
|
Basic usage:
|
|
32
32
|
|
|
33
33
|
```javascript
|
|
34
|
-
import scan from
|
|
34
|
+
import scan from "@1-/scan";
|
|
35
35
|
|
|
36
36
|
// Scan directory and get update list
|
|
37
|
-
const [updateFiles, upsert] = await scan(
|
|
37
|
+
const [updateFiles, upsert] = await scan("/path/to/dir", "/path/to/db", ["file1.js", "file2.json"]);
|
|
38
38
|
|
|
39
|
-
console.log(
|
|
39
|
+
console.log("Files that need updating:", updateFiles);
|
|
40
40
|
|
|
41
41
|
// Save the updated metadata to database
|
|
42
42
|
await upsert();
|
|
@@ -119,12 +119,12 @@ npm install @1-/scan
|
|
|
119
119
|
基础用法:
|
|
120
120
|
|
|
121
121
|
```javascript
|
|
122
|
-
import scan from
|
|
122
|
+
import scan from "@1-/scan";
|
|
123
123
|
|
|
124
124
|
// 扫描目录并获取更新列表
|
|
125
|
-
const [updateFiles, upsert] = await scan(
|
|
125
|
+
const [updateFiles, upsert] = await scan("/path/to/dir", "/path/to/db", ["file1.js", "file2.json"]);
|
|
126
126
|
|
|
127
|
-
console.log(
|
|
127
|
+
console.log("需要更新的文件:", updateFiles);
|
|
128
128
|
|
|
129
129
|
// 将更新后的元数据保存至数据库
|
|
130
130
|
await upsert();
|
package/dbInit.js
CHANGED
|
@@ -3,16 +3,16 @@ import load from "@1-/csv/load.js";
|
|
|
3
3
|
import upsertGitignore from "@1-/upsert_gitignore";
|
|
4
4
|
import vbE from "@3-/vb/vbE.js";
|
|
5
5
|
import b64Uint8 from "@3-/base64url/b64Uint8.js";
|
|
6
|
+
import int from "@3-/int";
|
|
6
7
|
import { existsSync } from "node:fs";
|
|
7
8
|
import { join, basename } from "node:path";
|
|
8
9
|
import { MTIME, MD5 } from "./const.js";
|
|
9
10
|
|
|
10
|
-
const loadDb = async (
|
|
11
|
-
if (existsSync(
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
11
|
+
const loadDb = async (file_path, db, parseVal) => {
|
|
12
|
+
if (existsSync(file_path)) {
|
|
13
|
+
for (const [path, ...vals] of await load(file_path)) {
|
|
14
|
+
db.set(b64Uint8(path), parseVal(vals));
|
|
15
|
+
}
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
|
|
@@ -22,23 +22,19 @@ db_dir: 数据库存放目录
|
|
|
22
22
|
返回值: [db_mtime, db_md5]
|
|
23
23
|
*/
|
|
24
24
|
export default async (db_dir) => {
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const mtime_path = join(db_dir, MTIME + ".csv"),
|
|
26
|
+
md5_path = join(db_dir, MD5 + ".csv");
|
|
27
27
|
|
|
28
|
-
if (
|
|
29
|
-
upsertGitignore(
|
|
30
|
-
join(db_dir, ".gitignore"),
|
|
31
|
-
path_li.map((x) => basename(x)),
|
|
32
|
-
);
|
|
28
|
+
if (!existsSync(mtime_path)) {
|
|
29
|
+
upsertGitignore(join(db_dir, ".gitignore"), [basename(mtime_path)]);
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
const db_mtime = new BinMap(),
|
|
36
|
-
db_md5 = new BinMap()
|
|
37
|
-
[mtime_path, md5_path] = path_li;
|
|
33
|
+
db_md5 = new BinMap();
|
|
38
34
|
|
|
39
35
|
await Promise.all([
|
|
40
|
-
loadDb(mtime_path, db_mtime, ([size, mtime]) => vbE([
|
|
41
|
-
loadDb(md5_path, db_md5, ([
|
|
36
|
+
loadDb(mtime_path, db_mtime, ([size, mtime]) => vbE([int(size), int(mtime)])),
|
|
37
|
+
loadDb(md5_path, db_md5, ([md5]) => b64Uint8(md5)),
|
|
42
38
|
]);
|
|
43
39
|
|
|
44
40
|
return [db_mtime, db_md5];
|