a tool for shared writing and social publishing

pass url object (#117)

* branch on "?local" in service worker

* stop double image block creation

* pass url object

authored by awarm.space and committed by

GitHub 0c5ff4c0 b1199d24

+9 -9
+1 -1
components/Blocks/ImageBlock.tsx
··· 100 100 src={ 101 101 image?.data.local && image.data.local !== rep?.clientID 102 102 ? image?.data.fallback 103 - : image?.data.src 103 + : `${image?.data.src}${image?.data.local ? "?local" : ""}` 104 104 } 105 105 height={image?.data.height} 106 106 width={image?.data.width}
+2 -1
components/Blocks/TextBlock/useHandlePaste.ts
··· 55 55 if ( 56 56 children.find((c) => 57 57 ["P", "H1", "H2", "H3", "UL", "DIV", "IMG"].includes(c.tagName), 58 - ) 58 + ) && 59 + !(children.length === 1 && children[0].tagName === "IMG") 59 60 ) { 60 61 children.forEach((child, index) => { 61 62 createBlockFromHTML(child, {
+1
public/worker.js
··· 1 1 self.addEventListener("fetch", (event) => { 2 + if (!event.request.url.includes("?local")) return; 2 3 event.respondWith( 3 4 caches.open("minilink-user-assets").then(async (cache) => { 4 5 return cache
+1 -1
src/replicache/mutations.ts
··· 306 306 ctx.runOnClient(async () => { 307 307 let cache = await caches.open("minilink-user-assets"); 308 308 for (let image of images) { 309 - await cache.delete(image.data.src); 309 + await cache.delete(image.data.src + "?local"); 310 310 } 311 311 }); 312 312 await ctx.deleteEntity(block.blockEntity);
+4 -6
src/utils/addImage.ts
··· 20 20 .data.publicUrl; 21 21 let dimensions = await getImageDimensions(file); 22 22 await cache.put( 23 - url, 23 + new URL(url + "?local"), 24 24 new Response(file, { 25 25 headers: { 26 26 "Content-Type": file.type, ··· 43 43 width: dimensions.width, 44 44 }, 45 45 }); 46 - await client.storage 47 - .from("minilink-user-assets") 48 - .upload(fileID, file, { 49 - cacheControl: "public, max-age=31560000, immutable", 50 - }); 46 + await client.storage.from("minilink-user-assets").upload(fileID, file, { 47 + cacheControl: "public, max-age=31560000, immutable", 48 + }); 51 49 await rep.mutate.assertFact({ 52 50 entity: args.entityID, 53 51 attribute: args.attribute,