Add state and labels to the cloud task

This commit is contained in:
Hongbo Wu
2023-03-03 09:03:43 +08:00
parent 4b578bbebb
commit 52399b3702

View File

@ -73,13 +73,17 @@ const shouldHandle = (data: StorageEvent) => {
const importURL = async (
userId: string,
url: URL,
source: string
source: string,
state?: RetrievedDataState,
labels?: string[]
): Promise<string | undefined> => {
return createCloudTask(CONTENT_FETCH_URL, {
userId,
source,
url: url.toString(),
saveRequestId: uuid(),
state,
labels,
})
}
@ -129,10 +133,21 @@ const handlerForFile = (name: string): importHandlerFunc | undefined => {
return undefined
}
const urlHandler = async (ctx: ImportContext, url: URL): Promise<void> => {
const urlHandler = async (
ctx: ImportContext,
url: URL,
state?: RetrievedDataState,
labels?: string[]
): Promise<void> => {
try {
// Imports are stored in the format imports/<user id>/<type>-<uuid>.csv
const result = await importURL(ctx.userId, url, 'csv-importer')
const result = await importURL(
ctx.userId,
url,
'csv-importer',
state,
labels
)
if (result) {
ctx.countImported += 1
}