mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Fix labels not saved correctly by saveUrl
This commit is contained in:
parent
874247661b
commit
014dc773e3
5 changed files with 63 additions and 44 deletions
|
|
@ -1,4 +1,17 @@
|
|||
import { authorized, generateRandomColor } from '../../utils/helpers'
|
||||
import { Between, ILike } from 'typeorm'
|
||||
import { createPubSubClient } from '../../datalayer/pubsub'
|
||||
import { getHighlightById } from '../../elastic/highlights'
|
||||
import {
|
||||
deleteLabel,
|
||||
setLabelsForHighlight,
|
||||
updateLabel,
|
||||
updateLabelsInPage,
|
||||
} from '../../elastic/labels'
|
||||
import { getPageById } from '../../elastic/pages'
|
||||
import { Label } from '../../entity/label'
|
||||
import { User } from '../../entity/user'
|
||||
import { getRepository, setClaims } from '../../entity/utils'
|
||||
import { env } from '../../env'
|
||||
import {
|
||||
CreateLabelError,
|
||||
CreateLabelErrorCode,
|
||||
|
|
@ -25,23 +38,10 @@ import {
|
|||
UpdateLabelErrorCode,
|
||||
UpdateLabelSuccess,
|
||||
} from '../../generated/graphql'
|
||||
import { analytics } from '../../utils/analytics'
|
||||
import { env } from '../../env'
|
||||
import { User } from '../../entity/user'
|
||||
import { Label } from '../../entity/label'
|
||||
import { Between, ILike } from 'typeorm'
|
||||
import { getRepository, setClaims } from '../../entity/utils'
|
||||
import { createPubSubClient } from '../../datalayer/pubsub'
|
||||
import { AppDataSource } from '../../server'
|
||||
import { getPageById } from '../../elastic/pages'
|
||||
import {
|
||||
deleteLabel,
|
||||
setLabelsForHighlight,
|
||||
updateLabel,
|
||||
updateLabelsInPage,
|
||||
} from '../../elastic/labels'
|
||||
import { getHighlightById } from '../../elastic/highlights'
|
||||
import { getLabelsByIds } from '../../services/labels'
|
||||
import { analytics } from '../../utils/analytics'
|
||||
import { authorized, generateRandomColor } from '../../utils/helpers'
|
||||
|
||||
export const labelsResolver = authorized<LabelsSuccess, LabelsError>(
|
||||
async (_obj, _params, { claims: { uid }, log }) => {
|
||||
|
|
|
|||
|
|
@ -153,14 +153,19 @@ export const createPageSaveRequest = async ({
|
|||
ctx
|
||||
)
|
||||
}
|
||||
const labelsInput = labels?.map((label) => ({
|
||||
name: label.name,
|
||||
color: label.color,
|
||||
description: label.description,
|
||||
}))
|
||||
// enqueue task to parse page
|
||||
await enqueueParseRequest({
|
||||
url,
|
||||
userId,
|
||||
saveRequestId: page.id,
|
||||
priority,
|
||||
archivedAt,
|
||||
labels,
|
||||
state: archivedAt ? ArticleSavingRequestStatus.Archived : undefined,
|
||||
labels: labelsInput,
|
||||
})
|
||||
|
||||
return pageToArticleSavingRequest(user, page)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { Label } from '../entity/label'
|
||||
import { ILike, In } from 'typeorm'
|
||||
import { PageContext } from '../elastic/types'
|
||||
import { User } from '../entity/user'
|
||||
import { addLabelInPage } from '../elastic/labels'
|
||||
import { getRepository } from '../entity/utils'
|
||||
import { Link } from '../entity/link'
|
||||
import DataLoader from 'dataloader'
|
||||
import { generateRandomColor } from '../utils/helpers'
|
||||
import { In } from 'typeorm'
|
||||
import { addLabelInPage } from '../elastic/labels'
|
||||
import { PageContext } from '../elastic/types'
|
||||
import { Label } from '../entity/label'
|
||||
import { Link } from '../entity/link'
|
||||
import { User } from '../entity/user'
|
||||
import { getRepository } from '../entity/utils'
|
||||
import { CreateLabelInput } from '../generated/graphql'
|
||||
import { generateRandomColor } from '../utils/helpers'
|
||||
|
||||
const batchGetLabelsFromLinkIds = async (
|
||||
linkIds: readonly string[]
|
||||
|
|
@ -40,10 +40,11 @@ export const addLabelToPage = async (
|
|||
return false
|
||||
}
|
||||
|
||||
let labelEntity = await getRepository(Label).findOneBy({
|
||||
user: { id: user.id },
|
||||
name: ILike(label.name),
|
||||
})
|
||||
let labelEntity = await getRepository(Label)
|
||||
.createQueryBuilder()
|
||||
.where({ user: { id: user.id } })
|
||||
.andWhere('LOWER(name) = LOWER(:name)', { name: label.name })
|
||||
.getOne()
|
||||
|
||||
if (!labelEntity) {
|
||||
console.log('creating new label', label.name)
|
||||
|
|
@ -87,10 +88,11 @@ export const createLabel = async (
|
|||
description?: string
|
||||
}
|
||||
): Promise<Label> => {
|
||||
const existingLabel = await getRepository(Label).findOneBy({
|
||||
user: { id: userId },
|
||||
name: ILike(label.name),
|
||||
})
|
||||
const existingLabel = await getRepository(Label)
|
||||
.createQueryBuilder()
|
||||
.where({ user: { id: userId } })
|
||||
.andWhere('LOWER(name) = LOWER(:name)', { name: label.name })
|
||||
.getOne()
|
||||
|
||||
if (existingLabel) {
|
||||
return existingLabel
|
||||
|
|
@ -117,17 +119,23 @@ export const createLabels = async (
|
|||
return []
|
||||
}
|
||||
|
||||
const labelEntities = await getRepository(Label).findBy({
|
||||
user: { id: user.id },
|
||||
name: In(labels.map((l) => l.name)),
|
||||
})
|
||||
const labelEntities = await getRepository(Label)
|
||||
.createQueryBuilder()
|
||||
.where({
|
||||
user: { id: user.id },
|
||||
})
|
||||
.andWhere('LOWER(name) IN (:...names)', {
|
||||
names: labels.map((l) => l.name.toLowerCase()),
|
||||
})
|
||||
.getMany()
|
||||
|
||||
const existingLabels = labelEntities.map((l) => l.name)
|
||||
const newLabels = labels.filter((l) => !existingLabels.includes(l.name))
|
||||
// create new labels
|
||||
const newLabelEntities = await getRepository(Label).save(
|
||||
newLabels.map((l) => ({
|
||||
...l,
|
||||
name: l.name,
|
||||
description: l.description,
|
||||
color: l.color || generateRandomColor(),
|
||||
user,
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@ import { CloudTasksClient, protos } from '@google-cloud/tasks'
|
|||
import { google } from '@google-cloud/tasks/build/protos/protos'
|
||||
import axios from 'axios'
|
||||
import { nanoid } from 'nanoid'
|
||||
import { Label, Recommendation } from '../elastic/types'
|
||||
import { Recommendation } from '../elastic/types'
|
||||
import { env } from '../env'
|
||||
import {
|
||||
ArticleSavingRequestStatus,
|
||||
CreateLabelInput,
|
||||
} from '../generated/graphql'
|
||||
import { signFeatureToken } from '../services/features'
|
||||
import { CreateTaskError } from './errors'
|
||||
import { buildLogger } from './logger'
|
||||
|
|
@ -200,7 +204,7 @@ export const enqueueParseRequest = async ({
|
|||
saveRequestId,
|
||||
priority = 'high',
|
||||
queue = env.queue.name,
|
||||
archivedAt,
|
||||
state,
|
||||
labels,
|
||||
}: {
|
||||
url: string
|
||||
|
|
@ -208,15 +212,15 @@ export const enqueueParseRequest = async ({
|
|||
saveRequestId: string
|
||||
priority?: 'low' | 'high'
|
||||
queue?: string
|
||||
archivedAt?: Date | null
|
||||
labels?: Label[]
|
||||
state?: ArticleSavingRequestStatus
|
||||
labels?: CreateLabelInput[]
|
||||
}): Promise<string> => {
|
||||
const { GOOGLE_CLOUD_PROJECT } = process.env
|
||||
const payload = {
|
||||
url,
|
||||
userId,
|
||||
saveRequestId,
|
||||
archivedAt,
|
||||
state,
|
||||
labels,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -337,6 +337,8 @@ async function fetchContent(req, res) {
|
|||
title,
|
||||
originalContent: content,
|
||||
parseResult: readabilityResult,
|
||||
state,
|
||||
labels,
|
||||
});
|
||||
|
||||
logRecord.totalTime = Date.now() - functionStartTime;
|
||||
|
|
|
|||
Loading…
Reference in a new issue