File tree Expand file tree Collapse file tree
rendering/html-image-prefetch Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,8 +15,12 @@ module.exports = {
1515 body : JSON . stringify ( {
1616 query : '{\n sponsors {\n list(kind: BACKER) {\n id\n source\n name\n joined\n website\n twitter\n avatar\n }\n }\n}\n' ,
1717 variables : { }
18- } )
18+ } ) ,
19+ signal : AbortSignal . timeout ( 10000 )
1920 } )
21+ if ( ! resp . ok ) {
22+ throw new Error ( `Contributors fetch failed with status ${ resp . status } ` )
23+ }
2024 const data = await resp . json ( )
2125 return _ . get ( data , 'data.sponsors.list' , [ ] )
2226 } catch ( err ) {
Original file line number Diff line number Diff line change @@ -96,8 +96,8 @@ module.exports = {
9696 async create ( obj , args , { req } ) {
9797 const group = await WIKI . models . groups . query ( ) . insertAndFetch ( {
9898 name : args . name ,
99- permissions : JSON . stringify ( WIKI . data . groups . defaultPermissions ) ,
100- pageRules : JSON . stringify ( WIKI . data . groups . defaultPageRules ) ,
99+ permissions : WIKI . data . groups . defaultPermissions ,
100+ pageRules : WIKI . data . groups . defaultPageRules ,
101101 isSystem : false
102102 } )
103103 await WIKI . auth . reloadGroups ( )
Original file line number Diff line number Diff line change @@ -92,7 +92,10 @@ module.exports = {
9292 if ( process . env . UPGRADE_COMPANION_REF ) {
9393 upgradeUrl . searchParams . set ( 'container' , process . env . UPGRADE_COMPANION_REF )
9494 }
95- await fetch ( upgradeUrl , { method : 'POST' } )
95+ const upgradeResp = await fetch ( upgradeUrl , { method : 'POST' , signal : AbortSignal . timeout ( 30000 ) } )
96+ if ( ! upgradeResp . ok ) {
97+ throw new Error ( `Upgrade companion returned ${ upgradeResp . status } ` )
98+ }
9699 return {
97100 responseResult : graphHelper . generateSuccess ( 'Upgrade has started.' )
98101 }
@@ -131,8 +134,8 @@ module.exports = {
131134 if ( args . groupMode === `SINGLE` ) {
132135 const singleGroup = await WIKI . models . groups . query ( ) . insert ( {
133136 name : `Import_${ curDateISO } ` ,
134- permissions : JSON . stringify ( WIKI . data . groups . defaultPermissions ) ,
135- pageRules : JSON . stringify ( WIKI . data . groups . defaultPageRules )
137+ permissions : WIKI . data . groups . defaultPermissions ,
138+ pageRules : WIKI . data . groups . defaultPageRules
136139 } )
137140 groupsCount ++
138141 assignableGroups . push ( singleGroup . id )
Original file line number Diff line number Diff line change @@ -309,10 +309,10 @@ module.exports = class Page extends Model {
309309 publishStartDate : opts . publishStartDate || '' ,
310310 title : opts . title ,
311311 toc : '[]' ,
312- extra : JSON . stringify ( {
312+ extra : {
313313 js : scriptJs ,
314314 css : scriptCss
315- } )
315+ }
316316 } )
317317 const page = await WIKI . models . pages . getPageFromDb ( {
318318 path : opts . path ,
@@ -428,11 +428,11 @@ module.exports = class Page extends Model {
428428 publishEndDate : opts . publishEndDate || '' ,
429429 publishStartDate : opts . publishStartDate || '' ,
430430 title : opts . title ,
431- extra : JSON . stringify ( {
431+ extra : {
432432 ...ogPage . extra ,
433433 js : scriptJs ,
434434 css : scriptCss
435- } )
435+ }
436436 } ) . where ( 'id' , ogPage . id )
437437 let page = await WIKI . models . pages . getPageFromDb ( ogPage . id )
438438
Original file line number Diff line number Diff line change @@ -2,13 +2,21 @@ const prefetch = async (element) => {
22 const url = element . attr ( `src` )
33 let response
44 try {
5- response = await fetch ( url )
5+ response = await fetch ( url , { signal : AbortSignal . timeout ( 10000 ) } )
66 } catch ( err ) {
77 WIKI . logger . warn ( `Failed to prefetch ${ url } ` )
88 WIKI . logger . warn ( err )
99 return
1010 }
11- const contentType = response . headers . get ( 'content-type' ) || 'image/png'
11+ if ( ! response . ok ) {
12+ WIKI . logger . warn ( `Failed to prefetch ${ url } : HTTP ${ response . status } ` )
13+ return
14+ }
15+ const contentType = response . headers . get ( 'content-type' )
16+ if ( ! contentType ) {
17+ WIKI . logger . warn ( `Failed to prefetch ${ url } : missing content-type` )
18+ return
19+ }
1220 const buffer = await response . arrayBuffer ( )
1321 const image = Buffer . from ( buffer ) . toString ( 'base64' )
1422 element . attr ( 'src' , `data:${ contentType } ;base64,${ image } ` )
Original file line number Diff line number Diff line change @@ -113,8 +113,12 @@ module.exports = {
113113 autocompleteMode : 'oneTermWithContext' ,
114114 search : q ,
115115 suggesterName : 'suggestions'
116- } )
116+ } ) ,
117+ signal : AbortSignal . timeout ( 10000 )
117118 } )
119+ if ( ! suggestResp . ok ) {
120+ throw new Error ( `Azure autocomplete returned ${ suggestResp . status } ` )
121+ }
118122 const suggestResults = await suggestResp . json ( )
119123 suggestions = suggestResults . value . map ( s => s . queryPlusText )
120124 } catch ( err ) {
You can’t perform that action at this time.
0 commit comments