diff --git a/packages/api/src/services/save_file.ts b/packages/api/src/services/save_file.ts index 64233aab6..3664d71ad 100644 --- a/packages/api/src/services/save_file.ts +++ b/packages/api/src/services/save_file.ts @@ -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) }) diff --git a/packages/api/src/services/save_page.ts b/packages/api/src/services/save_page.ts index cc8513678..de052d10d 100644 --- a/packages/api/src/services/save_page.ts +++ b/packages/api/src/services/save_page.ts @@ -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( diff --git a/packages/api/src/utils/uploads.ts b/packages/api/src/utils/uploads.ts index 814acc143..4c73c8780 100644 --- a/packages/api/src/utils/uploads.ts +++ b/packages/api/src/utils/uploads.ts @@ -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()