-
Notifications
You must be signed in to change notification settings - Fork 6
[WIP] Permanently delete files #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,13 +226,13 @@ export interface RegisterOptions { | |
* Using an improper one will results in the registration being rejected. | ||
*/ | ||
deviceDesc?: | ||
| "desktop-windows" | ||
| "desktop-macos" | ||
| "desktop-linux" | ||
| "mobile-android" | ||
| "mobile-ios" | ||
| "browser-chrome" | ||
| "remarkable"; | ||
| "desktop-windows" | ||
| "desktop-macos" | ||
| "desktop-linux" | ||
| "mobile-android" | ||
| "mobile-ios" | ||
| "browser-chrome" | ||
| "remarkable"; | ||
/** | ||
* the unique id of this device | ||
* | ||
|
@@ -1381,6 +1381,38 @@ class Remarkable implements RemarkableApi { | |
return await this.bulkMove(hashes, "trash", refresh); | ||
} | ||
|
||
|
||
/** permanent delete many hashes */ | ||
async bulkPurge( | ||
hashes: readonly string[], | ||
refresh: boolean = false, | ||
): Promise<SimpleEntry[]> { | ||
const [rootHash, generation] = await this.#getRootHash(refresh); | ||
// Get the raw text of the root entry | ||
|
||
const lines = rootHash.split("\n"); | ||
|
||
if (lines[0]?.startsWith("3")) { | ||
// Remove lines that start with any hash + ":" | ||
const hashSet = new Set(hashes.map(h => h + ":")); | ||
const filtered = lines.filter(line => { | ||
for (const prefix of hashSet) { | ||
if (line.startsWith(prefix)) return false; | ||
} | ||
return true; | ||
}); | ||
// Join the remaining lines | ||
const newRootText = filtered.join("\n"); | ||
// Upload the new root entry | ||
await this.#putRootHash(newRootText, generation); | ||
|
||
const entries = await this.raw.getEntries(newRootText); | ||
return entries.map(({ id, hash }) => ({ id, hash })); | ||
} else { | ||
// Not a v3 root, do nothing or throw | ||
throw new Error("Root entry is not version 3, cannot purge."); | ||
} | ||
} | ||
|
||
/** dump the raw cache */ | ||
dumpCache(): string { | ||
return this.raw.dumpCache(); | ||
|
Uh oh!
There was an error while loading. Please reload this page.