mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
enqueue uploading original content after saving page
This commit is contained in:
parent
52ebf466e3
commit
5bf9d29967
2 changed files with 34 additions and 31 deletions
|
|
@ -17,6 +17,7 @@ export interface UploadContentJobData {
|
|||
userId: string
|
||||
format: ContentFormat
|
||||
filePath: string
|
||||
content?: string
|
||||
}
|
||||
|
||||
const convertContent = (
|
||||
|
|
@ -84,7 +85,7 @@ export const uploadContentJob = async (data: UploadContentJobData) => {
|
|||
throw new Error('Library item not found')
|
||||
}
|
||||
|
||||
const content = libraryItem[column]
|
||||
const content = data.content || libraryItem[column]
|
||||
|
||||
if (!content) {
|
||||
logger.error(`${column} not found`)
|
||||
|
|
|
|||
|
|
@ -21,14 +21,11 @@ import { redisDataSource } from '../redis_data_source'
|
|||
import { authTrx, getColumns, queryBuilderToRawSql } from '../repository'
|
||||
import { libraryItemRepository } from '../repository/library_item'
|
||||
import { Merge, PickTuple } from '../util'
|
||||
import { enqueueBulkUploadContentJob } from '../utils/createTask'
|
||||
import { deepDelete, setRecentlySavedItemInRedis } from '../utils/helpers'
|
||||
import { logger } from '../utils/logger'
|
||||
import { logError, logger } from '../utils/logger'
|
||||
import { parseSearchQuery } from '../utils/search'
|
||||
import {
|
||||
contentFilePath,
|
||||
downloadFromBucket,
|
||||
uploadToBucket,
|
||||
} from '../utils/uploads'
|
||||
import { contentFilePath, downloadFromBucket } from '../utils/uploads'
|
||||
import { HighlightEvent } from './highlights'
|
||||
import { addLabelsToLibraryItem, LabelEvent } from './labels'
|
||||
|
||||
|
|
@ -1103,17 +1100,22 @@ export const createOrUpdateLibraryItem = async (
|
|||
const data = deepDelete(newLibraryItem, columnsToDelete)
|
||||
await pubsub.entityCreated<ItemEvent>(EntityType.ITEM, data, userId)
|
||||
|
||||
// upload original content to GCS if it's not already uploaded
|
||||
// upload original content to GCS in a job if it's not already uploaded
|
||||
if (originalContent && !originalContentUploaded) {
|
||||
await uploadOriginalContent(
|
||||
userId,
|
||||
newLibraryItem.id,
|
||||
newLibraryItem.savedAt,
|
||||
originalContent
|
||||
)
|
||||
logger.info('Uploaded original content to GCS', {
|
||||
id: newLibraryItem.id,
|
||||
})
|
||||
try {
|
||||
await enqueueUploadOriginalContent(
|
||||
userId,
|
||||
newLibraryItem.id,
|
||||
newLibraryItem.savedAt,
|
||||
originalContent
|
||||
)
|
||||
|
||||
logger.info('Queued to upload original content in GCS', {
|
||||
id: newLibraryItem.id,
|
||||
})
|
||||
} catch (error) {
|
||||
logError(error)
|
||||
}
|
||||
}
|
||||
|
||||
return newLibraryItem
|
||||
|
|
@ -1691,27 +1693,27 @@ export const filterItemEvents = (
|
|||
throw new Error('Unexpected state.')
|
||||
}
|
||||
|
||||
export const uploadOriginalContent = async (
|
||||
export const enqueueUploadOriginalContent = async (
|
||||
userId: string,
|
||||
libraryItemId: string,
|
||||
savedAt: Date,
|
||||
originalContent: string,
|
||||
timeout = 10_000 // 10 seconds
|
||||
originalContent: string
|
||||
) => {
|
||||
await uploadToBucket(
|
||||
contentFilePath({
|
||||
const filePath = contentFilePath({
|
||||
userId,
|
||||
libraryItemId,
|
||||
savedAt,
|
||||
format: 'original',
|
||||
})
|
||||
await enqueueBulkUploadContentJob([
|
||||
{
|
||||
userId,
|
||||
libraryItemId,
|
||||
savedAt,
|
||||
filePath,
|
||||
format: 'original',
|
||||
}),
|
||||
Buffer.from(originalContent),
|
||||
{
|
||||
public: false,
|
||||
contentType: 'text/html',
|
||||
timeout,
|
||||
}
|
||||
)
|
||||
content: originalContent,
|
||||
},
|
||||
])
|
||||
}
|
||||
|
||||
export const downloadOriginalContent = async (
|
||||
|
|
|
|||
Loading…
Reference in a new issue