@@ -5,10 +5,11 @@ import { ParsedRequest, Theme } from './types'
5
5
export function parseRequest ( req : IncomingMessage ) {
6
6
console . log ( 'HTTP ' + req . url )
7
7
const { pathname, query } = parse ( req . url || '/' , true )
8
- // @todo : Switch to param stuctucture here: https://github.com/spinks/og-image/commit/45439b73b3a5156faf9f6757fc4f208b230f5d9a
9
- // to bypass facebook issue (facebook strips query params that appear to be urls)
10
- const { fontFamily, fontSize, images, widths, heights, theme, md } = query || { }
8
+ const { fontFamily, fontSize, images, widths, heights, theme, md, imageObj } = query || { }
11
9
10
+ if ( Array . isArray ( imageObj ) ) {
11
+ throw new Error ( 'Expected a single image Object' ) ;
12
+ }
12
13
if ( Array . isArray ( fontFamily ) ) {
13
14
throw new Error ( 'Expected a single fontFamily' )
14
15
}
@@ -19,6 +20,14 @@ export function parseRequest(req: IncomingMessage) {
19
20
throw new Error ( 'Expected a single theme' )
20
21
}
21
22
23
+ let parsedImages = JSON . parse ( imageObj || '{}' ) ;
24
+ if ( Object . keys ( parsedImages ) . length === 0 ) {
25
+ console . log ( 'Legacy image format' ) ;
26
+ parsedImages . images = getArray ( images ) ;
27
+ parsedImages . widths = getArray ( widths ) ;
28
+ parsedImages . heights = getArray ( heights ) ;
29
+ }
30
+
22
31
const arr = ( pathname || '/' ) . slice ( 1 ) . split ( '.' )
23
32
let extension = ''
24
33
let text = ''
@@ -38,9 +47,9 @@ export function parseRequest(req: IncomingMessage) {
38
47
md : md === '1' || md === 'true' ,
39
48
fontFamily : fontFamily === 'roboto-condensed' ? 'Roboto Condensed' : 'Source Sans Pro' ,
40
49
fontSize : fontSize || '96px' ,
41
- images : getArray ( images ) ,
42
- widths : getArray ( widths ) ,
43
- heights : getArray ( heights ) ,
50
+ images : parsedImages . images ,
51
+ widths : parsedImages . widths ,
52
+ heights : parsedImages . heights ,
44
53
}
45
54
parsedRequest . images = getDefaultImages (
46
55
parsedRequest . images ,
0 commit comments