Skip to content

Commit 681a9f6

Browse files
committed
fix: correct Objection 3 migration issues and fetch port errors
- Remove lingering JSON.stringify calls on 4 auto-serialized JSON columns (group create/import, page create/update) — Objection 3 handles this automatically - Add response.ok checks and AbortSignal.timeout to all 4 fetch call sites (contribute, performUpgrade, azure autocomplete, html-image-prefetch) - html-image-prefetch renderer now skips images without content-type header instead of encoding HTML error body as base64 PNG
1 parent e7265c8 commit 681a9f6

6 files changed

Lines changed: 32 additions & 13 deletions

File tree

server/graph/resolvers/contribute.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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) {

server/graph/resolvers/group.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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()

server/graph/resolvers/system.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff 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)

server/models/pages.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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

server/modules/rendering/html-image-prefetch/renderer.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff 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}`)

server/modules/search/azure/engine.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)