cursedbelt-core 2.0.0 → 2.1.1
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/dist/core/activity/index.d.ts +2 -2
- package/dist/core/activity/index.js +1 -1
- package/dist/core/activity/model.d.ts +2 -2
- package/dist/core/analytics/index.d.ts +2 -2
- package/dist/core/analytics/index.js +2 -2
- package/dist/core/category/index.d.ts +3 -3
- package/dist/core/category/index.js +2 -2
- package/dist/core/category/memoryStore.d.ts +1 -1
- package/dist/core/category/memoryStore.js +1 -1
- package/dist/core/category/tree.d.ts +1 -1
- package/dist/core/colorScheme/index.d.ts +1 -1
- package/dist/core/colorScheme/index.js +1 -1
- package/dist/core/duplicates/index.d.ts +115 -0
- package/dist/core/duplicates/index.js +177 -0
- package/dist/core/folder-tree/actions.d.ts +1 -1
- package/dist/core/folder-tree/actions.js +1 -1
- package/dist/core/folder-tree/index.d.ts +3 -3
- package/dist/core/folder-tree/index.js +3 -3
- package/dist/core/folder-tree/tree.js +1 -1
- package/dist/core/master-lock/index.d.ts +4 -4
- package/dist/core/master-lock/index.js +4 -4
- package/dist/core/master-lock/wire.d.ts +1 -1
- package/dist/core/media/ffmpeg.d.ts +1 -1
- package/dist/core/media/format.d.ts +1 -1
- package/dist/core/media/index.d.ts +12 -12
- package/dist/core/media/index.js +11 -11
- package/dist/core/media/mediaItem.d.ts +1 -1
- package/dist/core/media/renderPlan.d.ts +1 -1
- package/dist/core/media/renderPlan.js +1 -1
- package/dist/core/media/validate.d.ts +1 -1
- package/dist/core/media/validate.js +1 -1
- package/dist/core/navigation/coverageTest.d.ts +1 -1
- package/dist/core/navigation/coverageTest.js +1 -1
- package/dist/core/navigation/index.d.ts +6 -6
- package/dist/core/navigation/index.js +6 -6
- package/dist/core/navigation/migrateNavPreferences.d.ts +1 -1
- package/dist/core/navigation/navigationSelectors.d.ts +1 -1
- package/dist/core/navigation/navigationSelectors.js +1 -1
- package/dist/core/navigation/searchCatalogue.d.ts +1 -1
- package/dist/core/palette/fuzzyRank.d.ts +1 -1
- package/dist/core/palette/index.d.ts +3 -3
- package/dist/core/palette/index.js +3 -3
- package/dist/core/sharing/index.d.ts +2 -2
- package/dist/core/sharing/index.js +1 -1
- package/dist/core/tokens/registry.d.ts +2 -2
- package/dist/core/tokens/registry.js +1 -1
- package/dist/core/uiScale/index.d.ts +2 -2
- package/dist/core/uiScale/index.js +2 -2
- package/dist/core/uiScale/uiScaleStore.js +1 -1
- package/dist/core/wire/__fixtures__/rowsMarshalWorker.js +1 -1
- package/dist/core/wire/index.d.ts +4 -4
- package/dist/core/wire/index.js +4 -4
- package/dist/core/wire/ingress.d.ts +1 -1
- package/dist/core/wire/ingress.js +3 -3
- package/dist/core/wire/marshalWorker.d.ts +1 -1
- package/dist/core/wire/marshalWorker.js +2 -2
- package/dist/core/wire/marshalling.js +1 -1
- package/dist/ctgr/chunkAccumulator.d.ts +1 -1
- package/dist/ctgr/chunkAccumulator.js +2 -2
- package/dist/ctgr/chunkStore.d.ts +1 -1
- package/dist/ctgr/chunkStore.js +2 -2
- package/dist/ctgr/codec.d.ts +1 -1
- package/dist/ctgr/codec.js +5 -5
- package/dist/ctgr/index.d.ts +9 -9
- package/dist/ctgr/index.js +9 -9
- package/dist/ctgr/v0compat.d.ts +1 -1
- package/dist/ctgr/v0compat.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/testing/index.d.ts +3 -3
- package/dist/testing/index.js +3 -3
- package/package.json +10 -4
- package/src/config/appConfig.spec.ts +1 -1
- package/src/core/activity/index.ts +2 -2
- package/src/core/activity/model.ts +2 -2
- package/src/core/analytics/index.ts +2 -2
- package/src/core/analytics/range.spec.ts +1 -1
- package/src/core/analytics/schedule.spec.ts +1 -1
- package/src/core/category/category.spec.ts +1 -1
- package/src/core/category/index.ts +3 -3
- package/src/core/category/memoryStore.ts +2 -2
- package/src/core/category/tree.ts +1 -1
- package/src/core/color.spec.ts +1 -1
- package/src/core/colorScheme/colorScheme.spec.ts +1 -1
- package/src/core/colorScheme/index.ts +1 -1
- package/src/core/download.spec.ts +1 -1
- package/src/core/duplicates/index.spec.ts +116 -0
- package/src/core/duplicates/index.ts +203 -0
- package/src/core/events/ccEventBus.spec.ts +1 -1
- package/src/core/file-tree/fileTreeModel.spec.ts +1 -1
- package/src/core/folder-tree/actions.spec.ts +2 -2
- package/src/core/folder-tree/actions.ts +2 -2
- package/src/core/folder-tree/index.ts +3 -3
- package/src/core/folder-tree/path.spec.ts +1 -1
- package/src/core/folder-tree/tree.spec.ts +1 -1
- package/src/core/folder-tree/tree.ts +1 -1
- package/src/core/master-lock/index.ts +4 -4
- package/src/core/master-lock/kdf.spec.ts +2 -2
- package/src/core/master-lock/presence.spec.ts +1 -1
- package/src/core/master-lock/wire.spec.ts +1 -1
- package/src/core/master-lock/wire.ts +1 -1
- package/src/core/media/bgRemoval.spec.ts +1 -1
- package/src/core/media/ffmpeg.spec.ts +2 -2
- package/src/core/media/ffmpeg.ts +1 -1
- package/src/core/media/format.spec.ts +1 -1
- package/src/core/media/format.ts +1 -1
- package/src/core/media/index.ts +12 -12
- package/src/core/media/mediaItem.spec.ts +2 -2
- package/src/core/media/mediaItem.ts +1 -1
- package/src/core/media/renderPlan.spec.ts +1 -1
- package/src/core/media/renderPlan.ts +2 -2
- package/src/core/media/segment.spec.ts +1 -1
- package/src/core/media/size.spec.ts +1 -1
- package/src/core/media/trim.spec.ts +1 -1
- package/src/core/media/validate.spec.ts +2 -2
- package/src/core/media/validate.ts +2 -2
- package/src/core/media/videoCuts.spec.ts +1 -1
- package/src/core/navigation/coverageTest.ts +2 -2
- package/src/core/navigation/index.ts +6 -6
- package/src/core/navigation/migrateNavPreferences.ts +1 -1
- package/src/core/navigation/navigation.spec.ts +1 -1
- package/src/core/navigation/navigationSelectors.ts +1 -1
- package/src/core/navigation/searchCatalogue.ts +1 -1
- package/src/core/net/reconnectSchedule.spec.ts +1 -1
- package/src/core/palette/fuzzyRank.ts +1 -1
- package/src/core/palette/index.ts +3 -3
- package/src/core/palette/palette.spec.ts +4 -4
- package/src/core/schema/projection.spec.ts +1 -1
- package/src/core/sharing/index.ts +2 -2
- package/src/core/sharing/model.spec.ts +1 -1
- package/src/core/tokens/registry.spec.ts +1 -1
- package/src/core/tokens/registry.ts +2 -2
- package/src/core/uiScale/index.ts +2 -2
- package/src/core/uiScale/uiScale.spec.ts +1 -1
- package/src/core/uiScale/uiScaleStore.ts +1 -1
- package/src/core/wire/__fixtures__/rowsMarshalWorker.ts +1 -1
- package/src/core/wire/index.ts +4 -4
- package/src/core/wire/ingress.spec.ts +2 -2
- package/src/core/wire/ingress.ts +3 -3
- package/src/core/wire/marshalWorker.spec.ts +2 -2
- package/src/core/wire/marshalWorker.ts +2 -2
- package/src/core/wire/marshalling.spec.ts +1 -1
- package/src/core/wire/marshalling.ts +1 -1
- package/src/core/wire/wireHub.spec.ts +1 -1
- package/src/ctgr/chunkAccumulator.ts +3 -3
- package/src/ctgr/chunkStore.spec.ts +2 -2
- package/src/ctgr/chunkStore.ts +3 -3
- package/src/ctgr/codec.spec.ts +4 -4
- package/src/ctgr/codec.ts +5 -5
- package/src/ctgr/index.ts +9 -9
- package/src/ctgr/v0compat.spec.ts +2 -2
- package/src/ctgr/v0compat.ts +3 -3
- package/src/index.ts +2 -2
- package/src/testTmpRoot.spec.ts +1 -1
- package/src/testing/index.ts +3 -3
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared duplicate rules, proved against the cases that produced them.
|
|
3
|
+
*
|
|
4
|
+
* Every assertion here is a measured incident from `binary-server` or `music`, not an
|
|
5
|
+
* invented example — see the module header for which.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it } from "bun:test";
|
|
8
|
+
import {
|
|
9
|
+
DURATION_TOLERANCE,
|
|
10
|
+
durationsClose,
|
|
11
|
+
isGenericName,
|
|
12
|
+
likelyTheSameFile,
|
|
13
|
+
normalizeName,
|
|
14
|
+
SIZE_TOLERANCE,
|
|
15
|
+
sizesClose,
|
|
16
|
+
} from "./index.js";
|
|
17
|
+
|
|
18
|
+
describe("normalizeName", () => {
|
|
19
|
+
it("reduces the marks a copy picks up to the same stem", () => {
|
|
20
|
+
expect(normalizeName("My Video (1).mp4")).toBe("myvideo");
|
|
21
|
+
expect(normalizeName("my_video.MP4")).toBe("myvideo");
|
|
22
|
+
expect(normalizeName("My-Video copy 2.mov")).toBe("myvideo");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("strips the extension, so a re-encode still pairs with its source", () => {
|
|
26
|
+
expect(normalizeName("Song.wma")).toBe(normalizeName("Song.mp3"));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("🔴 keeps a four-digit camera sequence — the 2026-08-14 flood", () => {
|
|
30
|
+
// `IMG_4595` and `IMG_4646` must NOT collapse onto each other.
|
|
31
|
+
expect(normalizeName("IMG_4595.MOV")).not.toBe(normalizeName("IMG_4646.MOV"));
|
|
32
|
+
// …while a two-digit copy marker still does.
|
|
33
|
+
expect(normalizeName("mix_2.mp3")).toBe(normalizeName("mix.mp3"));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("drops the directory", () => {
|
|
37
|
+
expect(normalizeName("Main 1/rap/Song.mp3")).toBe("song");
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("isGenericName", () => {
|
|
42
|
+
it("rejects the stems that name a device rather than a file", () => {
|
|
43
|
+
expect(isGenericName(normalizeName("IMG_1.MOV"))).toBe(true);
|
|
44
|
+
expect(isGenericName(normalizeName("Track01.mp3"))).toBe(true);
|
|
45
|
+
expect(isGenericName(normalizeName("Between U.mp3"))).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("sizesClose", () => {
|
|
50
|
+
it("accepts a re-encode and refuses a different file", () => {
|
|
51
|
+
expect(sizesClose(10_000_000, 10_400_000)).toBe(true);
|
|
52
|
+
expect(sizesClose(10_000_000, 20_000_000)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("🔴 two zero-byte files are not close — nothing is known about either", () => {
|
|
56
|
+
expect(sizesClose(0, 0)).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("is bounded by the exported tolerance", () => {
|
|
60
|
+
expect(sizesClose(100, 100 * (1 + SIZE_TOLERANCE))).toBe(true);
|
|
61
|
+
expect(sizesClose(100, 100 * (1 + SIZE_TOLERANCE * 2))).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("durationsClose", () => {
|
|
66
|
+
it("🔴 answers null when nobody has measured, never false", () => {
|
|
67
|
+
expect(durationsClose(null, 200)).toBeNull();
|
|
68
|
+
expect(durationsClose(0, 200)).toBeNull();
|
|
69
|
+
expect(durationsClose(undefined, undefined)).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("refuses the owner's 3:56-vs-1:52 pair", () => {
|
|
73
|
+
expect(durationsClose(236, 112)).toBe(false);
|
|
74
|
+
expect(durationsClose(236, 236 * (1 + DURATION_TOLERANCE / 2))).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("likelyTheSameFile", () => {
|
|
79
|
+
const facts = (name: string, sizeBytes: number, duration?: number | null) => ({
|
|
80
|
+
name,
|
|
81
|
+
sizeBytes,
|
|
82
|
+
...(duration === undefined ? {} : { duration }),
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("pairs a re-encode of the same song", () => {
|
|
86
|
+
const verdict = likelyTheSameFile(
|
|
87
|
+
facts("Between U.mp3", 8_000_000, 312),
|
|
88
|
+
facts("Between U.wma", 7_800_000, 312),
|
|
89
|
+
);
|
|
90
|
+
expect(verdict.match).toBe(true);
|
|
91
|
+
expect(verdict.reason).toContain("same name");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("does not pair two different songs of a similar size", () => {
|
|
95
|
+
expect(likelyTheSameFile(facts("A.mp3", 8_000_000), facts("B.mp3", 8_010_000)).match).toBe(
|
|
96
|
+
false,
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("🔴 a length that disagrees kills a name+size match", () => {
|
|
101
|
+
expect(
|
|
102
|
+
likelyTheSameFile(facts("Set.mp3", 8_000_000, 236), facts("Set.mp3", 8_100_000, 112)).match,
|
|
103
|
+
).toBe(false);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("🔴 an unmeasured length does not — that would find nothing in an unprobed library", () => {
|
|
107
|
+
expect(
|
|
108
|
+
likelyTheSameFile(facts("Set.mp3", 8_000_000, null), facts("Set.mp3", 8_100_000, null)).match,
|
|
109
|
+
).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("refuses a generic stem, and refuses two nameless files", () => {
|
|
113
|
+
expect(likelyTheSameFile(facts("IMG_1.MOV", 500), facts("IMG_1.MOV", 500)).match).toBe(false);
|
|
114
|
+
expect(likelyTheSameFile(facts("", 500), facts("", 500)).match).toBe(false);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Are these two files the same thing?" — the fleet's ONE answer, with no I/O in it.
|
|
3
|
+
*
|
|
4
|
+
* ── Why this is here and not in an app ──────────────────────────────────────────────────
|
|
5
|
+
* `binary-server` wrote these rules first (2026-08-13, the owner: *"make strategy to always
|
|
6
|
+
* check for duplicate binaries in same app for same user … mark likely the duplicates for
|
|
7
|
+
* users to confirm"*), and they were measured against a real store: the copy-counter cap, the
|
|
8
|
+
* camera-generic stem list and the 5% size window each exist because a wider rule proposed
|
|
9
|
+
* thousands of pairs nobody could ever review. `music` then needed the same question asked of
|
|
10
|
+
* a 5,400-track library — *"I want to see a duplicate next to the file that it is a possible
|
|
11
|
+
* duplicate of … The 'binary-server' app (bs) already has this feature for checking duplicate
|
|
12
|
+
* files. We can reuse it and enhance the customizability if needed so the main strategy is
|
|
13
|
+
* shared."*
|
|
14
|
+
*
|
|
15
|
+
* So the strategy lives once, here, and both consume it. What each app keeps for itself is the
|
|
16
|
+
* evidence only it has: bs's perceptual frame hashes, music's artist/title key.
|
|
17
|
+
*
|
|
18
|
+
* ── What is NOT here, deliberately ──────────────────────────────────────────────────────
|
|
19
|
+
* Anything that needs a database, a filesystem, a fetch or a picture decoder. This module is
|
|
20
|
+
* pure so both consumers can prove their behaviour with `bun test` instead of against a live
|
|
21
|
+
* store, and so a browser bundle may import it (music renders the pair side by side).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* How far two sizes may differ and still be called the same thing.
|
|
26
|
+
*
|
|
27
|
+
* A re-encode at a different quality is the case this exists for, and those land within a few
|
|
28
|
+
* percent. Zero would make a name match a strict subset of "same name AND same size", which
|
|
29
|
+
* misses precisely the files worth asking about; much larger starts pairing a clip with its
|
|
30
|
+
* own trailer.
|
|
31
|
+
*/
|
|
32
|
+
export const SIZE_TOLERANCE = 0.05;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* How far two playing times may differ and still be the same recording.
|
|
36
|
+
*
|
|
37
|
+
* Wide enough for a re-encode (a trim of a trailing black frame, a container that rounds), far
|
|
38
|
+
* too narrow for the owner's 2026-08-14 report of a 3:56 video paired with a 1:52 one.
|
|
39
|
+
*/
|
|
40
|
+
export const DURATION_TOLERANCE = 0.05;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The name to compare, reduced to what a human means by "the same file".
|
|
44
|
+
*
|
|
45
|
+
* Strips the directory, the extension, and the marks a copy picks up along the way —
|
|
46
|
+
* `Finder`'s ` copy`/` copy 2`, a browser's ` (1)`, a script's `_1`/`-1` — then collapses
|
|
47
|
+
* everything that is not a letter or a digit. `My Video (1).mp4`, `my_video.MP4` and
|
|
48
|
+
* `My-Video copy 2.mov` all reduce to `myvideo`.
|
|
49
|
+
*
|
|
50
|
+
* 🔴 The extension is stripped ON PURPOSE, so a re-encode (`.mov` → `.mp4`, `.wma` → `.mp3`)
|
|
51
|
+
* still pairs with its source. That is the single most common likely-duplicate in this fleet's
|
|
52
|
+
* stores and a rule that kept the extension would never see one.
|
|
53
|
+
*
|
|
54
|
+
* 🔴 **The copy-counter strip is capped at two digits**, and that cap is a measured bug fix
|
|
55
|
+
* (bs, 2026-08-14). It used to be `[-_]\d+$`, which eats a CAMERA SEQUENCE as readily as a copy
|
|
56
|
+
* marker: `IMG_4595` and `IMG_4646` both reduced to `img`, so every iPhone capture in a tenant
|
|
57
|
+
* shared one bucket and paired with every other one whose size was within 5%. `_1`…`_99` is
|
|
58
|
+
* what a copy marker actually looks like; four digits is a photo's identity, and it must
|
|
59
|
+
* survive.
|
|
60
|
+
*/
|
|
61
|
+
export function normalizeName(name: string | null | undefined): string {
|
|
62
|
+
if (!name) return "";
|
|
63
|
+
const leaf = name.split(/[\\/]/).pop() ?? "";
|
|
64
|
+
const stem = leaf.replace(/\.[a-z0-9]{1,5}$/i, "");
|
|
65
|
+
return stem
|
|
66
|
+
.toLowerCase()
|
|
67
|
+
.replace(/\s*\(\d+\)\s*$/, "")
|
|
68
|
+
.replace(/\s+copy(\s+\d+)?\s*$/, "")
|
|
69
|
+
.replace(/[-_]\d{1,2}\s*$/, "")
|
|
70
|
+
.replace(/[^a-z0-9]+/g, "");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Stems that name a CAMERA, not a file.
|
|
75
|
+
*
|
|
76
|
+
* `IMG`, `DSC`, `PXL`, `VID` are what a device calls everything it produces; two files whose
|
|
77
|
+
* names reduce to one of these have told us nothing except that they came from a phone. Even
|
|
78
|
+
* with the counter cap above, `IMG_1.MOV` still reduces to `img`, and a bucket called "img" is
|
|
79
|
+
* every photo the owner has ever taken.
|
|
80
|
+
*
|
|
81
|
+
* 🔴 This rejects a MATCH, never a file. Both copies stay wherever they are, and an
|
|
82
|
+
* identical-bytes pair is unaffected — a checksum match never consults the name.
|
|
83
|
+
*/
|
|
84
|
+
export const GENERIC_STEMS: ReadonlySet<string> = new Set([
|
|
85
|
+
"img",
|
|
86
|
+
"image",
|
|
87
|
+
"images",
|
|
88
|
+
"dsc",
|
|
89
|
+
"dscf",
|
|
90
|
+
"dscn",
|
|
91
|
+
"pxl",
|
|
92
|
+
"vid",
|
|
93
|
+
"video",
|
|
94
|
+
"movie",
|
|
95
|
+
"mov",
|
|
96
|
+
"photo",
|
|
97
|
+
"pic",
|
|
98
|
+
"picture",
|
|
99
|
+
"screenshot",
|
|
100
|
+
"screenrecording",
|
|
101
|
+
"untitled",
|
|
102
|
+
"unknown",
|
|
103
|
+
"file",
|
|
104
|
+
"download",
|
|
105
|
+
"scan",
|
|
106
|
+
"capture",
|
|
107
|
+
"copy",
|
|
108
|
+
"new",
|
|
109
|
+
"temp",
|
|
110
|
+
"tmp",
|
|
111
|
+
// Music's own version of the same problem: an untagged rip is called this by every ripper
|
|
112
|
+
// ever written, and `track01` from two albums is two different songs.
|
|
113
|
+
"track",
|
|
114
|
+
"audiotrack",
|
|
115
|
+
"unknownartist",
|
|
116
|
+
]);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A name that could belong to any file from that device tells us nothing about identity.
|
|
120
|
+
*
|
|
121
|
+
* 🔴 The trailing digit run is stripped BEFORE the lookup, and only here — never in
|
|
122
|
+
* {@link normalizeName}, where removing it is what made every camera capture one bucket. The
|
|
123
|
+
* two are asked at different moments: `normalizeName` decides whether two names are the SAME
|
|
124
|
+
* (so `img4595` and `img4646` must stay apart), and this decides whether a name that already
|
|
125
|
+
* matched is worth anything (so two files both called `Track01` have told us nothing, and a
|
|
126
|
+
* ripper names half a library that).
|
|
127
|
+
*/
|
|
128
|
+
export const isGenericName = (normalized: string): boolean =>
|
|
129
|
+
normalized.length < 3 ||
|
|
130
|
+
GENERIC_STEMS.has(normalized) ||
|
|
131
|
+
GENERIC_STEMS.has(normalized.replace(/\d+$/, ""));
|
|
132
|
+
|
|
133
|
+
/** Within {@link SIZE_TOLERANCE} of each other. Two zero-byte files are not "close" — they
|
|
134
|
+
* are two files nothing is known about. */
|
|
135
|
+
export function sizesClose(a: number, b: number, tolerance = SIZE_TOLERANCE): boolean {
|
|
136
|
+
if (a === b && a > 0) return true;
|
|
137
|
+
const larger = Math.max(a, b);
|
|
138
|
+
if (larger <= 0) return false;
|
|
139
|
+
return Math.abs(a - b) / larger <= tolerance;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Within {@link DURATION_TOLERANCE} of each other.
|
|
144
|
+
*
|
|
145
|
+
* 🔴 A missing or zero duration answers `null`, never `false`: "nobody has measured this yet"
|
|
146
|
+
* and "these are different lengths" are opposite answers, and collapsing them makes an
|
|
147
|
+
* unprobed library look like a library with no duplicates in it.
|
|
148
|
+
*/
|
|
149
|
+
export function durationsClose(
|
|
150
|
+
a: number | null | undefined,
|
|
151
|
+
b: number | null | undefined,
|
|
152
|
+
tolerance = DURATION_TOLERANCE,
|
|
153
|
+
): boolean | null {
|
|
154
|
+
if (!a || !b || a <= 0 || b <= 0) return null;
|
|
155
|
+
return Math.abs(a - b) / Math.max(a, b) <= tolerance;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** One file, reduced to what this module can reason about. Units are the caller's — pass
|
|
159
|
+
* both durations in the same unit or not at all. */
|
|
160
|
+
export interface NamedFileFacts {
|
|
161
|
+
/** The name a person would recognise: a display title, else the last path segment. */
|
|
162
|
+
name: string | null | undefined;
|
|
163
|
+
sizeBytes: number;
|
|
164
|
+
/** Playing time, in whatever unit the caller uses consistently. Null = never measured. */
|
|
165
|
+
duration?: number | null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface NameMatchVerdict {
|
|
169
|
+
match: boolean;
|
|
170
|
+
/** Written for the owner reading a review queue, never for a log. Empty when `match` is
|
|
171
|
+
* false — a non-match has nothing to explain. */
|
|
172
|
+
reason: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The shared "these look like the same thing" test: the NAME agrees after normalization, the
|
|
177
|
+
* sizes are close, and nothing about the length says otherwise.
|
|
178
|
+
*
|
|
179
|
+
* It is deliberately a QUESTION and never an action. Both consumers act only on a checksum,
|
|
180
|
+
* which is proof; this decides what is worth showing a person side by side.
|
|
181
|
+
*/
|
|
182
|
+
export function likelyTheSameFile(a: NamedFileFacts, b: NamedFileFacts): NameMatchVerdict {
|
|
183
|
+
const na = normalizeName(a.name);
|
|
184
|
+
const nb = normalizeName(b.name);
|
|
185
|
+
// Two empty names are not a match with each other — it means neither file has a name worth
|
|
186
|
+
// comparing (a bare digest key, an untitled upload), and pairing those proposes every
|
|
187
|
+
// unnamed object as a duplicate of every other.
|
|
188
|
+
if (!na || na !== nb) return { match: false, reason: "" };
|
|
189
|
+
if (isGenericName(na)) return { match: false, reason: "" };
|
|
190
|
+
if (!sizesClose(a.sizeBytes, b.sizeBytes)) return { match: false, reason: "" };
|
|
191
|
+
if (durationsClose(a.duration, b.duration) === false) return { match: false, reason: "" };
|
|
192
|
+
|
|
193
|
+
const pct = Math.round(
|
|
194
|
+
(Math.abs(a.sizeBytes - b.sizeBytes) / Math.max(a.sizeBytes, b.sizeBytes, 1)) * 100,
|
|
195
|
+
);
|
|
196
|
+
return {
|
|
197
|
+
match: true,
|
|
198
|
+
reason:
|
|
199
|
+
a.sizeBytes === b.sizeBytes
|
|
200
|
+
? "same name, same size, different bytes"
|
|
201
|
+
: `same name, size within ${pct}%, different bytes`,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
|
-
import { createCcEventBus, MAX_EVENT_DEPTH } from './ccEventBus';
|
|
2
|
+
import { createCcEventBus, MAX_EVENT_DEPTH } from './ccEventBus.js';
|
|
3
3
|
|
|
4
4
|
describe('CCEventBus', () => {
|
|
5
5
|
it('delivers to every subscriber of a type and to nobody else', async () => {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* both are pinned here side by side rather than each in isolation.
|
|
10
10
|
*/
|
|
11
11
|
import { describe, expect, test } from "bun:test";
|
|
12
|
-
import { folderMoveTargets, planFolderMergeInto } from "./actions";
|
|
13
|
-
import { buildFolderTree, planFolderMove } from "./tree";
|
|
12
|
+
import { folderMoveTargets, planFolderMergeInto } from "./actions.js";
|
|
13
|
+
import { buildFolderTree, planFolderMove } from "./tree.js";
|
|
14
14
|
|
|
15
15
|
const PATHS = [
|
|
16
16
|
"rock",
|
|
@@ -34,8 +34,8 @@ import {
|
|
|
34
34
|
isFolderPathUnder,
|
|
35
35
|
parseFolderPath,
|
|
36
36
|
serializeFolderPath,
|
|
37
|
-
} from "./path";
|
|
38
|
-
import type { FolderNode, FolderRemap } from "./tree";
|
|
37
|
+
} from "./path.js";
|
|
38
|
+
import type { FolderNode, FolderRemap } from "./tree.js";
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Move everything at or under `source` INTO `destination`, and stop `source` existing.
|
|
@@ -26,7 +26,7 @@ export {
|
|
|
26
26
|
normalizeFolderName,
|
|
27
27
|
parseFolderPath,
|
|
28
28
|
serializeFolderPath,
|
|
29
|
-
} from "./path";
|
|
29
|
+
} from "./path.js";
|
|
30
30
|
export {
|
|
31
31
|
buildFolderIndex,
|
|
32
32
|
buildFolderTree,
|
|
@@ -37,10 +37,10 @@ export {
|
|
|
37
37
|
planFolderDelete,
|
|
38
38
|
planFolderMove,
|
|
39
39
|
planFolderRename,
|
|
40
|
-
} from "./tree";
|
|
40
|
+
} from "./tree.js";
|
|
41
41
|
export {
|
|
42
42
|
type FolderDeleteMode,
|
|
43
43
|
type FolderTarget,
|
|
44
44
|
folderMoveTargets,
|
|
45
45
|
planFolderMergeInto,
|
|
46
|
-
} from "./actions";
|
|
46
|
+
} from "./actions.js";
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
normalizeFolderName,
|
|
18
18
|
parseFolderPath,
|
|
19
19
|
serializeFolderPath,
|
|
20
|
-
} from "./path";
|
|
20
|
+
} from "./path.js";
|
|
21
21
|
|
|
22
22
|
/** A node in the derived tree. `path` is the full segment array from the root; a
|
|
23
23
|
* `child` node's path is its parent's plus one segment. */
|
|
@@ -16,7 +16,7 @@ export {
|
|
|
16
16
|
isMasterLockKdfParams,
|
|
17
17
|
newMasterLockKdfParams,
|
|
18
18
|
unb64u,
|
|
19
|
-
} from "./kdf";
|
|
19
|
+
} from "./kdf.js";
|
|
20
20
|
export {
|
|
21
21
|
BASE_DELAY_MS,
|
|
22
22
|
DEFAULT_IDLE_MS,
|
|
@@ -27,7 +27,7 @@ export {
|
|
|
27
27
|
clampIdleMs,
|
|
28
28
|
delayAfter,
|
|
29
29
|
windowRemaining,
|
|
30
|
-
} from "./policy";
|
|
30
|
+
} from "./policy.js";
|
|
31
31
|
export {
|
|
32
32
|
MASTER_LOCK_COOKIE,
|
|
33
33
|
masterLockCookieName,
|
|
@@ -46,10 +46,10 @@ export {
|
|
|
46
46
|
type MasterLockSettingsRequest,
|
|
47
47
|
type MasterLockStatus,
|
|
48
48
|
type MasterLockUnlockRequest,
|
|
49
|
-
} from "./wire";
|
|
49
|
+
} from "./wire.js";
|
|
50
50
|
export {
|
|
51
51
|
PRESENCE_ATTRIBUTE,
|
|
52
52
|
type PresenceMedia,
|
|
53
53
|
isPresenceMedia,
|
|
54
54
|
isSomebodyWatching,
|
|
55
|
-
} from "./presence";
|
|
55
|
+
} from "./presence.js";
|
|
@@ -17,8 +17,8 @@ import {
|
|
|
17
17
|
deriveMasterLockVerifier,
|
|
18
18
|
isMasterLockKdfParams,
|
|
19
19
|
newMasterLockKdfParams,
|
|
20
|
-
} from ".";
|
|
21
|
-
import { b64u, unb64u } from "./kdf";
|
|
20
|
+
} from "./index.js";
|
|
21
|
+
import { b64u, unb64u } from "./kdf.js";
|
|
22
22
|
|
|
23
23
|
// The exact fixture `apps/vault/src/crypto/kdf.test.ts` derives against.
|
|
24
24
|
const FIXED: MasterLockKdfParams = {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* hole it was asked to close.
|
|
11
11
|
*/
|
|
12
12
|
import { describe, expect, test } from "bun:test";
|
|
13
|
-
import { PRESENCE_ATTRIBUTE, type PresenceMedia, isPresenceMedia, isSomebodyWatching } from "./presence";
|
|
13
|
+
import { PRESENCE_ATTRIBUTE, type PresenceMedia, isPresenceMedia, isSomebodyWatching } from "./presence.js";
|
|
14
14
|
|
|
15
15
|
const media = (over: Partial<PresenceMedia> & { presence?: string } = {}): PresenceMedia => ({
|
|
16
16
|
paused: false,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* it was told to mount and the browser would fetch what it was told to fetch.
|
|
10
10
|
*/
|
|
11
11
|
import { describe, expect, it } from "bun:test";
|
|
12
|
-
import { MASTER_LOCK_PATHS, MASTER_LOCK_PREFIX } from "./wire";
|
|
12
|
+
import { MASTER_LOCK_PATHS, MASTER_LOCK_PREFIX } from "./wire.js";
|
|
13
13
|
|
|
14
14
|
describe("MASTER_LOCK_PATHS", () => {
|
|
15
15
|
it("keeps every surface under the one prefix the guard reserves", () => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* One module both halves import, so a rename cannot make the browser talk to a route that
|
|
5
5
|
* no longer exists.
|
|
6
6
|
*/
|
|
7
|
-
import type { MasterLockKdfParams } from "./kdf";
|
|
7
|
+
import type { MasterLockKdfParams } from "./kdf.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* The mount prefix. Everything under it is reachable while LOCKED (it is how you unlock);
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
parseFfmpegProgress,
|
|
8
8
|
parseFfprobe,
|
|
9
9
|
videoCodecPlan,
|
|
10
|
-
} from './ffmpeg';
|
|
11
|
-
import type { VideoTrimSpec } from './types';
|
|
10
|
+
} from './ffmpeg.js';
|
|
11
|
+
import type { VideoTrimSpec } from './types.js';
|
|
12
12
|
|
|
13
13
|
const trim = (over: Partial<VideoTrimSpec> = {}): VideoTrimSpec => ({
|
|
14
14
|
inputPath: '/in.mp4',
|
package/src/core/media/ffmpeg.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// (`server/media-bun/video.ts` spawns these against native ffmpeg) and the browser editor
|
|
4
4
|
// (`react/media` executes the same argv against ffmpeg.wasm). Unit tested without ffmpeg.
|
|
5
5
|
|
|
6
|
-
import type { VideoFormat, VideoProgressEvent, VideoQuality, VideoTrimSpec } from './types';
|
|
6
|
+
import type { VideoFormat, VideoProgressEvent, VideoQuality, VideoTrimSpec } from './types.js';
|
|
7
7
|
|
|
8
8
|
/** Codec + rate-control plan for an output container at a quality preset. */
|
|
9
9
|
export interface VideoCodecPlan {
|
package/src/core/media/format.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Pure format helpers — MIME/extension lookup, quality clamping, thumbnail-format
|
|
2
2
|
// selection. No npm deps; shared by the server adapter, the React layer, and tests.
|
|
3
3
|
|
|
4
|
-
import type { ImageOutputFormat } from './types';
|
|
4
|
+
import type { ImageOutputFormat } from './types.js';
|
|
5
5
|
|
|
6
6
|
export const IMAGE_OUTPUT_FORMATS: readonly ImageOutputFormat[] = ['jpeg', 'png', 'webp', 'avif'];
|
|
7
7
|
|
package/src/core/media/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// (`cursedbelt/react/media`), and any consuming app/test. No React, no Bun, no npm
|
|
4
4
|
// dep — the same module loads identically everywhere.
|
|
5
5
|
|
|
6
|
-
export { type FloodFillBGOptions, floodFillBGS } from './bgRemoval';
|
|
6
|
+
export { type FloodFillBGOptions, floodFillBGS } from './bgRemoval.js';
|
|
7
7
|
export {
|
|
8
8
|
buildProbeArgs,
|
|
9
9
|
buildThumbnailArgs,
|
|
@@ -14,7 +14,7 @@ export {
|
|
|
14
14
|
parseFfprobe,
|
|
15
15
|
type VideoCodecPlan,
|
|
16
16
|
videoCodecPlan,
|
|
17
|
-
} from './ffmpeg';
|
|
17
|
+
} from './ffmpeg.js';
|
|
18
18
|
export {
|
|
19
19
|
clampQuality,
|
|
20
20
|
IMAGE_OUTPUT_FORMATS,
|
|
@@ -22,14 +22,14 @@ export {
|
|
|
22
22
|
imageFormatToMime,
|
|
23
23
|
mimeToImageFormat,
|
|
24
24
|
pickThumbnailFormat,
|
|
25
|
-
} from './format';
|
|
25
|
+
} from './format.js';
|
|
26
26
|
export {
|
|
27
27
|
isAudioItem,
|
|
28
28
|
isImageItem,
|
|
29
29
|
isVideoItem,
|
|
30
30
|
mediaItemAspect,
|
|
31
31
|
mediaItemDimensions,
|
|
32
|
-
} from './mediaItem';
|
|
32
|
+
} from './mediaItem.js';
|
|
33
33
|
export {
|
|
34
34
|
buildAtempoChain,
|
|
35
35
|
buildTimelineRenderPlan,
|
|
@@ -40,7 +40,7 @@ export {
|
|
|
40
40
|
speedFilters,
|
|
41
41
|
type TimelineRenderOptions,
|
|
42
42
|
type TimelineRenderPlan,
|
|
43
|
-
} from './renderPlan';
|
|
43
|
+
} from './renderPlan.js';
|
|
44
44
|
export {
|
|
45
45
|
closeMask,
|
|
46
46
|
createRegionSegmenter,
|
|
@@ -56,15 +56,15 @@ export {
|
|
|
56
56
|
type SegmentSource,
|
|
57
57
|
sensitivityToTolerance,
|
|
58
58
|
upscaleMask,
|
|
59
|
-
} from './segment';
|
|
60
|
-
export { formatBytes } from './size';
|
|
59
|
+
} from './segment.js';
|
|
60
|
+
export { formatBytes } from './size.js';
|
|
61
61
|
export {
|
|
62
62
|
type ClampTrimOptions,
|
|
63
63
|
clampTrimRange,
|
|
64
64
|
formatTimecode,
|
|
65
65
|
type TrimRange,
|
|
66
66
|
trimDurationSeconds,
|
|
67
|
-
} from './trim';
|
|
67
|
+
} from './trim.js';
|
|
68
68
|
export type {
|
|
69
69
|
GalleryMedia,
|
|
70
70
|
GalleryPhoto,
|
|
@@ -80,15 +80,15 @@ export type {
|
|
|
80
80
|
VideoProgressEvent,
|
|
81
81
|
VideoQuality,
|
|
82
82
|
VideoTrimSpec,
|
|
83
|
-
} from './types';
|
|
84
|
-
export { DEFAULT_UPLOAD_CHUNK_SIZE, MAX_SINGLE_UPLOAD_BYTES } from './uploadLimits';
|
|
83
|
+
} from './types.js';
|
|
84
|
+
export { DEFAULT_UPLOAD_CHUNK_SIZE, MAX_SINGLE_UPLOAD_BYTES } from './uploadLimits.js';
|
|
85
85
|
export {
|
|
86
86
|
assertValidImagePipelineSpec,
|
|
87
87
|
assertValidVideoTrimSpec,
|
|
88
88
|
type ValidationResult,
|
|
89
89
|
validateImagePipelineSpec,
|
|
90
90
|
validateVideoTrimSpec,
|
|
91
|
-
} from './validate';
|
|
91
|
+
} from './validate.js';
|
|
92
92
|
|
|
93
93
|
// Marking sections of a video to CUT OUT. Framework-free on purpose: the dialog
|
|
94
94
|
// (`react/media/VideoCutEditor`), the app route that refuses an unexecutable list and the
|
|
@@ -102,4 +102,4 @@ export {
|
|
|
102
102
|
MIN_CUT_SECONDS,
|
|
103
103
|
normalizeCuts,
|
|
104
104
|
type VideoCut,
|
|
105
|
-
} from './videoCuts';
|
|
105
|
+
} from './videoCuts.js';
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
isVideoItem,
|
|
6
6
|
mediaItemAspect,
|
|
7
7
|
mediaItemDimensions,
|
|
8
|
-
} from './mediaItem';
|
|
9
|
-
import type { MediaItem } from './types';
|
|
8
|
+
} from './mediaItem.js';
|
|
9
|
+
import type { MediaItem } from './types.js';
|
|
10
10
|
|
|
11
11
|
const item = (over: Partial<MediaItem> = {}): MediaItem => ({
|
|
12
12
|
id: '1',
|