Skip to content

Commit c5e60ba

Browse files
authored
Fix posting images on web (bluesky-social#7105)
* Fix uploadBlob to handle blob: URI * Patch expo-image-manipulator to support "compress" argument * Narrow down the fix
1 parent 55222c5 commit c5e60ba

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff --git a/node_modules/expo-image-manipulator/src/ImageManipulator.ts b/node_modules/expo-image-manipulator/src/ImageManipulator.ts
2+
index a80d9c8..babbb3b 100644
3+
--- a/node_modules/expo-image-manipulator/src/ImageManipulator.ts
4+
+++ b/node_modules/expo-image-manipulator/src/ImageManipulator.ts
5+
@@ -43,7 +43,7 @@ export async function manipulateAsync(
6+
context.extent(action.extent);
7+
}
8+
}
9+
- const image = await context.renderAsync();
10+
+ const image = await context.renderAsync(saveOptions.compress);
11+
const result = await image.saveAsync({ format, ...rest });
12+
13+
// These shared objects will not be used anymore, so free up some memory.
14+
diff --git a/node_modules/expo-image-manipulator/src/ImageManipulatorContext.ts b/node_modules/expo-image-manipulator/src/ImageManipulatorContext.ts
15+
index 120d8d3..f8aa49c 100644
16+
--- a/node_modules/expo-image-manipulator/src/ImageManipulatorContext.ts
17+
+++ b/node_modules/expo-image-manipulator/src/ImageManipulatorContext.ts
18+
@@ -52,7 +52,7 @@ export declare class ImageManipulatorContext extends SharedObject {
19+
/**
20+
* Awaits for all manipulation tasks to finish and resolves with a reference to the resulted native image.
21+
*/
22+
- renderAsync(): Promise<ImageRef>;
23+
+ renderAsync(compress?: number): Promise<ImageRef>;
24+
}
25+
26+
export default ExpoImageManipulator.Context as typeof ImageManipulatorContext;
27+
diff --git a/node_modules/expo-image-manipulator/src/web/ImageManipulatorContext.web.ts b/node_modules/expo-image-manipulator/src/web/ImageManipulatorContext.web.ts
28+
index 428848c..363a57a 100644
29+
--- a/node_modules/expo-image-manipulator/src/web/ImageManipulatorContext.web.ts
30+
+++ b/node_modules/expo-image-manipulator/src/web/ImageManipulatorContext.web.ts
31+
@@ -41,7 +41,7 @@ export default class ImageManipulatorContext extends SharedObject {
32+
return this;
33+
}
34+
35+
- async renderAsync(): Promise<ImageManipulatorImageRef> {
36+
+ async renderAsync(compress?: number): Promise<ImageManipulatorImageRef> {
37+
const canvas = await this.currentTask;
38+
39+
return new Promise((resolve) => {
40+
@@ -49,7 +49,7 @@ export default class ImageManipulatorContext extends SharedObject {
41+
const url = blob ? URL.createObjectURL(blob) : canvas.toDataURL();
42+
43+
resolve(new ImageManipulatorImageRef(url, canvas.width, canvas.height));
44+
- });
45+
+ }, typeof compress === 'number' ? 'image/jpeg' : undefined, compress);
46+
});
47+
}
48+

src/lib/api/upload-blob.web.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export async function uploadBlob(
1111
input: string | Blob,
1212
encoding?: string,
1313
): Promise<ComAtprotoRepoUploadBlob.Response> {
14-
if (typeof input === 'string' && input.startsWith('data:')) {
14+
if (
15+
typeof input === 'string' &&
16+
(input.startsWith('data:') || input.startsWith('blob:'))
17+
) {
1518
const blob = await fetch(input).then(r => r.blob())
1619
return agent.uploadBlob(blob, {encoding})
1720
}

0 commit comments

Comments
 (0)