Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Photos: every picture address takes the version mark, and the suites read it

Yashwanth Kamireddia576a0dcd5e5
diff --git a/.uiverify/photos-slideshow.mjs b/.uiverify/photos-slideshow.mjs
index 405494f..11bb6fc 100644
--- a/.uiverify/photos-slideshow.mjs
+++ b/.uiverify/photos-slideshow.mjs
@@ -41,7 +41,7 @@ async function open(reduced) {
await ctx.route(`${PICS}/**`, async (route) => {
const path = decodeURIComponent(route.request().url().slice(PICS.length + 1));
asked.push(path);
- const [, id, size] = /pic\/([^/]+)\/(\w+)/.exec(path) ?? [];
+ const [, id, size] = /pic\/([^/~]+)(?:~[0-9a-z]+)?\/(\w+)/.exec(path) ?? [];
const c = COLOURS[id] ?? [128, 128, 128];
const long = /^fit(\d+)/.test(size) ? +size.slice(3) : 512;
// A slow picture now and then, as one made from the network is: the show waits for it.
@@ -82,7 +82,7 @@ const first = await page.evaluate(() => {
return { src: decodeURIComponent(img?.src ?? ""), w: img?.naturalWidth, dpr: devicePixelRatio, W: innerWidth, H: innerHeight };
});
const step = +(/fit(\d+)/.exec(first.src)?.[1] ?? 0);
-ok(/p1\/fit/.test(first.src) && step >= Math.min(first.W, (first.H * 4) / 3) * first.dpr, `the photo is made the size of the screen, never smaller (${first.src.split("/").pop()} for ${first.W}×${first.H} at ${first.dpr}×)`);
+ok(/p1(~[0-9a-z]+)?\/fit/.test(first.src) && step >= Math.min(first.W, (first.H * 4) / 3) * first.dpr, `the photo is made the size of the screen, never smaller (${first.src.split("/").pop()} for ${first.W}×${first.H} at ${first.dpr}×)`);
// Each frame of the dissolve into the next photo, as the page sets it: the layers' opacities
// and whether the picture of each is decoded. The screen behind is never left uncovered.
@@ -122,7 +122,7 @@ const film = await page.waitForFunction(() => {
const v = [...document.querySelectorAll(".px-slide video")].find((x) => x.getAttribute("src"));
return v && { src: v.getAttribute("src"), o: v.style.opacity, t: v.currentTime, poster: decodeURIComponent(v.closest(".px-slide").querySelector("img").src) };
}, null, { timeout: 5000 }).then((h) => h.jsonValue());
-ok(film.src === `${base}/p3/video` && /p3\/fit/.test(film.poster), `a video shows its picture and plays its film from the app's server ${film.src}`);
+ok(film.src === `${base}/p3/video` && /p3(~[0-9a-z]+)?\/fit/.test(film.poster), `a video shows its picture and plays its film from the app's server ${film.src}`);
const shownFilm = await page.waitForFunction(() => {
const v = [...document.querySelectorAll(".px-slide video")].find((x) => x.getAttribute("src"));
return v && v.style.opacity === "1" && v.currentTime > 0 ? v.currentTime : null;
diff --git a/.uiverify/photos-strip.mjs b/.uiverify/photos-strip.mjs
index 7fb2b42..5834136 100644
--- a/.uiverify/photos-strip.mjs
+++ b/.uiverify/photos-strip.mjs
@@ -49,7 +49,7 @@ await page.waitForTimeout(700);
ok((await centred()) <= 1 && (await page.locator(".px-slip").count()) <= 2 * Math.max(30, Math.ceil(1280 / 28 / 2) + 12) + 1, "stepping far along, still in the middle and still few");
// A wheel or a two-finger swipe over the strip skims: four notches of 40 go four photos on,
// and the slips glide on the compositor, never jump.
-const which = async () => (await page.locator(".px-slip.is-shown img").getAttribute("src")).split("pic%2F")[1].split("%2F")[0];
+const which = async () => (await page.locator(".px-slip.is-shown img").getAttribute("src")).split("pic%2F")[1].split("%2F")[0].split("~")[0];
const before = await which();
const strip = await page.locator(".px-strip").boundingBox();
await page.mouse.move(strip.x + strip.width / 2, strip.y + strip.height / 2);
diff --git a/.uiverify/photos-viewer-frames.mjs b/.uiverify/photos-viewer-frames.mjs
index 3e8f07f..c8586fc 100644
--- a/.uiverify/photos-viewer-frames.mjs
+++ b/.uiverify/photos-viewer-frames.mjs
@@ -41,7 +41,7 @@ await ctx.addInitScript(([v, pics]) => {
}, [base, PICS]);
await ctx.route(`${PICS}/**`, async (route) => {
const path = decodeURIComponent(route.request().url().slice(PICS.length + 1));
- const [, id, size] = /pic\/([^/]+)\/(\w+)/.exec(path) ?? [];
+ const [, id, size] = /pic\/([^/~]+)(?:~[0-9a-z]+)?\/(\w+)/.exec(path) ?? [];
const c = COLOURS[id] ?? [128, 128, 128];
const long = /^fit(\d+)/.test(size) ? +size.slice(3) : 512;
// The viewer's pictures are slow to come, as ones made from the network are: what stands in
@@ -106,7 +106,7 @@ await page.evaluate(() => {
window.__seen = [];
const tick = () => {
const v = document.querySelector(".px-stage video");
- if (v) window.__seen.push({ o: v.style.opacity, t: v.currentTime, poster: !!document.querySelector(".px-player-poster") && decodeURIComponent(document.querySelector(".px-player-poster").src).includes("p3/fit") });
+ if (v) window.__seen.push({ o: v.style.opacity, t: v.currentTime, poster: !!document.querySelector(".px-player-poster") && decodeURIComponent(document.querySelector(".px-player-poster").src).match(/p3(~[0-9a-z]+)?\/fit/) !== null });
if (window.__seen.length < 120) requestAnimationFrame(tick);
};
requestAnimationFrame(tick);
diff --git a/src-tauri/src/photos.rs b/src-tauri/src/photos.rs
index 7c2f1e0..40da57b 100644
--- a/src-tauri/src/photos.rs
+++ b/src-tauri/src/photos.rs
@@ -148,11 +148,13 @@ pub async fn upload_picture(app: &AppHandle, id: &str) -> UiResult<Vec<u8>> {
}
/// The photo and picture a `quince://` request asks for: `pic/<asset id>/<size>`, escaped as
-/// Tauri escapes it.
+/// Tauri escapes it — or `pic/<asset id>~<mark>/<size>`, marked as fitted pictures are (see
+/// [`requested_fit`]): the same photo, whichever address the window built.
pub fn requested(path: &str) -> Option<(String, Size)> {
let path = crate::percent_decode(path.trim_start_matches('/'));
let rest = path.strip_prefix("pic/")?;
let (id, size) = rest.rsplit_once('/')?;
+ let (id, _) = unmarked(id)?;
let size = match size {
"thumb" => Size::Thumb,
"medium" => Size::Medium,
@@ -172,6 +174,25 @@ pub fn requested(path: &str) -> Option<(String, Size)> {
Some((id.to_string(), size))
}
+/// An asset id from an address's id part, and whether it carried a mark (`<id>~<mark>`, the
+/// window's `pictureVersion`). A mark is a few lowercase letters and digits, never a path; an
+/// address with a bad one asks for nothing.
+fn unmarked(id: &str) -> Option<(&str, bool)> {
+ match id.split_once('~') {
+ Some((id, mark))
+ if !mark.is_empty()
+ && mark.len() <= 16
+ && mark
+ .chars()
+ .all(|c| c.is_ascii_digit() || c.is_ascii_lowercase()) =>
+ {
+ Some((id, true))
+ }
+ Some(_) => None,
+ None => Some((id, false)),
+ }
+}
+
/// The widths a picture is made at for the screen (its longer side), in steps — so a photo
/// is made a handful of times, not once per window size.
pub const FITS: [u32; 11] = [128, 256, 384, 512, 768, 1024, 1536, 2048, 2560, 3072, 3840];
@@ -184,19 +205,7 @@ pub fn requested_fit(path: &str) -> Option<(String, u32, bool)> {
let path = crate::percent_decode(path.trim_start_matches('/'));
let (id, size) = path.strip_prefix("pic/")?.rsplit_once('/')?;
let long: u32 = size.strip_prefix("fit")?.parse().ok()?;
- let (id, marked) = match id.split_once('~') {
- Some((id, mark))
- if !mark.is_empty()
- && mark.len() <= 16
- && mark
- .chars()
- .all(|c| c.is_ascii_digit() || c.is_ascii_lowercase()) =>
- {
- (id, true)
- }
- Some(_) => return None,
- None => (id, false),
- };
+ let (id, marked) = unmarked(id)?;
if !FITS.contains(&long)
|| id.is_empty()
|| !id
@@ -2965,6 +2974,22 @@ mod tests {
assert_eq!(requested_fit("/pic/~ab/fit256"), None);
assert_eq!(requested_fit("/pic/..~ab/fit256"), None);
assert_eq!(requested_fit("/pic/A1~0123456789abcdefg/fit256"), None);
+ // Every other picture of the photo takes the mark too, and the old address still works.
+ assert_eq!(
+ requested("pic%2FA1-b~1x9z%2Fthumb"),
+ Some(("A1-b".into(), Size::Thumb))
+ );
+ assert_eq!(
+ requested("/pic/A1~k3/video"),
+ Some(("A1".into(), Size::Video))
+ );
+ assert_eq!(
+ requested("/pic/A1/original"),
+ Some(("A1".into(), Size::Original))
+ );
+ assert_eq!(requested("/pic/A1~X/full"), None);
+ assert_eq!(requested("/pic/~ab/full"), None);
+ assert_eq!(requested("/pic/..~ab/full"), None);
assert!(fit_cache(true).contains("immutable"));
assert!(!fit_cache(false).contains("immutable"));
}