File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -3,14 +3,19 @@ import { processSource } from "./process";
3
3
4
4
export const createImageDerivatives = functions . firestore
5
5
. document ( "images/{imageId}" )
6
- . onCreate ( async ( snap , context ) => {
7
- const { source } = snap . data ( ) ;
8
- const { imageId } = context . params ;
6
+ . onWrite ( async ( snap , context ) => {
7
+ const source = snap . after . data ( ) ?. source ;
9
8
if ( ! source ) {
10
9
console . log ( "No source field, ignoring write" ) ;
11
10
return ;
12
11
}
13
12
13
+ if ( source === snap . before . data ( ) ?. source ) {
14
+ console . log ( "Source field not updated, ignoring write" ) ;
15
+ return ;
16
+ }
17
+
18
+ const { imageId } = context . params ;
14
19
const outputs = await processSource ( source , imageId ) ;
15
20
16
21
await Promise . all (
@@ -28,5 +33,5 @@ export const createImageDerivatives = functions.firestore
28
33
} ;
29
34
} ) ;
30
35
31
- await snap . ref . update ( { formats } ) ;
36
+ await snap . after . ref . update ( { formats } ) ;
32
37
} ) ;
You can’t perform that action at this time.
0 commit comments