Skip to content

Commit

Permalink
🐛 fix redirects from draft gdoc deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesau committed Aug 5, 2024
1 parent 285cc81 commit 75edba8
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions adminSiteServer/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2276,13 +2276,19 @@ deleteRouteWithRWTransaction(apiRouter, "/gdocs/:id", async (req, res, trx) => {
// Assets have TTL of one week in Cloudflare. Add a redirect to make sure
// the page is no longer accessible.
// https://developers.cloudflare.com/pages/configuration/serving-pages/#asset-retention
await db.knexRawInsert(
trx,
`INSERT INTO redirects (source, target, ttl)
VALUES (?, ?, DATE_ADD(NOW(), INTERVAL 8 DAY))`,
[getCanonicalUrl("", gdoc), "/"]
)
await triggerStaticBuild(res.locals.user, `Deleting ${gdoc.slug}`)
const gdocSlug = getCanonicalUrl("", gdoc)
if (gdoc.published) {
if (gdocSlug && gdocSlug !== "/") {
console.log(`Creating redirect for "${gdocSlug}" to "/"`)
await db.knexRawInsert(
trx,
`INSERT INTO redirects (source, target, ttl)
VALUES (?, ?, DATE_ADD(NOW(), INTERVAL 8 DAY))`,
[gdocSlug, "/"]
)
}
await triggerStaticBuild(res.locals.user, `Deleting ${gdocSlug}`)
}
return {}
})

Expand Down

0 comments on commit 75edba8

Please sign in to comment.