@bryce3310687963/android-toolkit 1.0.51 → 1.0.55
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 +21 -0
- package/dist/index.cjs +25 -1
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +25 -1
- package/dist/index.js.map +3 -3
- package/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1936,8 +1936,32 @@ import { promisify as promisify2 } from "node:util";
|
|
|
1936
1936
|
var execFileAsync2 = promisify2(execFile2);
|
|
1937
1937
|
var DeviceSQLite = {
|
|
1938
1938
|
query,
|
|
1939
|
-
health
|
|
1939
|
+
health,
|
|
1940
|
+
reset
|
|
1940
1941
|
};
|
|
1942
|
+
async function reset(ctx, options = {}) {
|
|
1943
|
+
const packageName = requireNonEmpty2(ctx?.packageName, "packageName");
|
|
1944
|
+
const dbNamePrefix = requireNonEmpty2(options.dbNamePrefix, "dbNamePrefix");
|
|
1945
|
+
if (!/^[A-Za-z_]\w*(?:\.[A-Za-z_]\w*)+$/.test(packageName) || !/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(dbNamePrefix)) {
|
|
1946
|
+
throw new CrawlerError({ message: "invalid_request: invalid database reset target", code: Code.InvalidRequest });
|
|
1947
|
+
}
|
|
1948
|
+
const command = [
|
|
1949
|
+
"set -e",
|
|
1950
|
+
`db_dir=${shellQuote(`/data/data/${packageName}/databases`)}`,
|
|
1951
|
+
'if [ -L "$db_dir" ]; then echo "refusing symlink database directory" >&2; exit 1; fi',
|
|
1952
|
+
'if [ ! -d "$db_dir" ]; then exit 0; fi',
|
|
1953
|
+
`for db_file in "$db_dir"/${shellQuote(dbNamePrefix)}*; do`,
|
|
1954
|
+
' [ -e "$db_file" ] || [ -L "$db_file" ] || continue',
|
|
1955
|
+
' if [ -L "$db_file" ] || [ ! -f "$db_file" ]; then echo "refusing unexpected database entry: $db_file" >&2; exit 1; fi',
|
|
1956
|
+
"done",
|
|
1957
|
+
// 主库和 WAL/SHM/journal 一起删除,避免旧日志在重建时恢复聊天记录。
|
|
1958
|
+
`rm -f -- "$db_dir"/${shellQuote(dbNamePrefix)}*`
|
|
1959
|
+
].join("\n");
|
|
1960
|
+
await adbSuShell(ctx, command, { timeoutMs: 3e4, maxBuffer: 4096 }).catch((error) => {
|
|
1961
|
+
throw CrawlerError.from(error, { code: Code.AutomationFailed, context: { packageName, dbNamePrefix } });
|
|
1962
|
+
});
|
|
1963
|
+
Logger.info("DeviceSQLite.reset", { packageName, dbNamePrefix });
|
|
1964
|
+
}
|
|
1941
1965
|
async function query(ctx, options = {}) {
|
|
1942
1966
|
if (!options.sql) {
|
|
1943
1967
|
throw new CrawlerError({
|