When saving an existing page, update the content

This commit is contained in:
Hongbo Wu 2023-03-21 13:44:00 +08:00
parent bc9ba1d976
commit 8148453503
3 changed files with 11 additions and 20 deletions

View file

@ -34,12 +34,9 @@ export const saveFile = async (
}
}
const uploadFileDetails = await getStorageFileDetails(
input.uploadFileId,
uploadFile.fileName
)
await getStorageFileDetails(input.uploadFileId, uploadFile.fileName)
const uploadFileData = await ctx.authTrx(async (tx) => {
await ctx.authTrx(async (tx) => {
return ctx.models.uploadFile.setFileUploadComplete(input.uploadFileId, tx)
})

View file

@ -101,20 +101,23 @@ export const savePage = async (
originalHtml: parseResult.domContent,
canonicalUrl: parseResult.canonicalUrl,
})
// check if the page already exists
const existingPage = await getPageByParam({
userId: saver.userId,
url: articleToSave.url,
state: ArticleSavingRequestStatus.Succeeded,
})
if (existingPage) {
pageId = existingPage.id
slug = existingPage.slug
if (
!(await updatePage(
existingPage.id,
{
savedAt: new Date(),
archivedAt: null,
// update the page with the new content
...articleToSave,
archivedAt: null, // unarchive if it was archived
id: pageId, // we don't want to update the id
slug, // we don't want to update the slug
},
ctx
))
@ -124,8 +127,6 @@ export const savePage = async (
message: 'Failed to update existing page',
}
}
pageId = existingPage.id
slug = existingPage.slug
} else if (shouldParseInBackend(input)) {
try {
await createPageSaveRequest(

View file

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { env } from '../env'
import { File, GetSignedUrlConfig, Storage } from '@google-cloud/storage'
import { env } from '../env'
/* On GAE/Prod, we shall rely on default app engine service account credentials.
* Two changes needed: 1) add default service account to our uploads GCS Bucket
@ -83,13 +83,6 @@ export const getStorageFileDetails = async (
id: string,
fileName: string
): Promise<{ md5Hash: string; fileUrl: string }> => {
// if (env.dev.isLocal) {
// return {
// md5Hash: 'some_md5_hash',
// fileUrl: 'http://localhost:3000/public/' + id + '/' + fileName,
// }
// }
const filePathName = generateUploadFilePathName(id, fileName)
const file = storage.bucket(bucketName).file(filePathName)
const [metadata] = await file.getMetadata()