do not send content in the thumbnail task payload

This commit is contained in:
Hongbo Wu 2023-08-10 11:55:59 +08:00
parent d231907945
commit 163dbc73a6
6 changed files with 19 additions and 25 deletions

View file

@ -106,12 +106,8 @@ export const saveEmail = async (
// create a task to update thumbnail and pre-cache all images
try {
const taskId = await enqueueThumbnailTask(
ctx.uid,
slug,
articleToSave.content
)
logger.info('Created thumbnail task', taskId)
const taskId = await enqueueThumbnailTask(ctx.uid, slug)
logger.info('Created thumbnail task', { taskId })
} catch (e) {
logger.error('Failed to create thumbnail task', e)
}

View file

@ -187,12 +187,8 @@ export const savePage = async (
// create a task to update thumbnail and pre-cache all images
try {
const taskId = await enqueueThumbnailTask(
saver.userId,
slug,
articleToSave.content
)
logger.info('Created thumbnail task', taskId)
const taskId = await enqueueThumbnailTask(saver.userId, slug)
logger.info('Created thumbnail task', { taskId })
} catch (e) {
logger.error('Failed to create thumbnail task', e)
}

View file

@ -21,7 +21,7 @@ import View = google.cloud.tasks.v2.Task.View
// Instantiates a client.
const client = new CloudTasksClient()
const logError = (error: Error): void => {
const logError = (error: any): void => {
if (axios.isAxiosError(error)) {
logger.error(error.response)
} else {
@ -102,7 +102,12 @@ const createHttpTaskWithToken = async ({
: null,
}
return client.createTask({ parent, task })
try {
return client.createTask({ parent, task })
} catch (error) {
logError(error)
return null
}
}
export const createAppEngineTask = async ({
@ -526,14 +531,12 @@ export const enqueueImportFromIntegration = async (
export const enqueueThumbnailTask = async (
userId: string,
slug: string,
content: string
slug: string
): Promise<string> => {
const { GOOGLE_CLOUD_PROJECT } = process.env
const payload = {
userId,
slug,
content,
}
const headers = {

View file

@ -299,7 +299,7 @@ export const isUrl = (str: string): boolean => {
validateUrl(str)
return true
} catch {
logger.error('not an url', str)
logger.info('not an url', { url: str })
return false
}
}

View file

@ -505,9 +505,9 @@ export const fetchFavicon = async (
return `https://api.faviconkit.com/${domain}/128`
} catch (e) {
if (axios.isAxiosError(e)) {
logger.error('failed to get favicon:', e.response?.status)
logger.error('failed to get favicon', e.response)
} else {
logger.error('failed to get favicon:', e)
logger.error('failed to get favicon', e)
}
return undefined
}

View file

@ -32,7 +32,6 @@ interface UpdatePageResponse {
interface ThumbnailRequest {
slug: string
content: string
}
interface ImageSize {
@ -188,7 +187,7 @@ const updatePageMutation = async (
}
const isThumbnailRequest = (body: any): body is ThumbnailRequest => {
return 'slug' in body && 'content' in body
return 'slug' in body
}
const fetchImage = async (url: string): Promise<AxiosResponse | null> => {
@ -201,7 +200,7 @@ const fetchImage = async (url: string): Promise<AxiosResponse | null> => {
maxContentLength: 20000000, // 20mb
})
} catch (e) {
console.error(e)
console.log('fetch image error', e)
return null
}
}
@ -334,7 +333,7 @@ export const thumbnailHandler = Sentry.GCPFunction.wrapHttpFunction(
return res.status(400).send('BAD_REQUEST')
}
const { slug, content } = req.body
const { slug } = req.body
try {
const page = await articleQuery(uid, slug)
@ -352,7 +351,7 @@ export const thumbnailHandler = Sentry.GCPFunction.wrapHttpFunction(
console.log('pre-caching all images...')
// pre-cache all images in the content and get their sizes
const imageSizes = await fetchAllImageSizes(content)
const imageSizes = await fetchAllImageSizes(page.content)
// find thumbnail from all images if thumbnail not set
if (!page.image && imageSizes.length > 0) {
console.log('finding thumbnail...')