mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Linting fixes
This commit is contained in:
parent
53c423b714
commit
6f35740272
4 changed files with 71 additions and 31 deletions
|
|
@ -68,7 +68,6 @@ extension Sequence where Element == InternalLinkedItem {
|
|||
context.performAndWait {
|
||||
linkedItems = map { $0.asManagedObject(inContext: context) }
|
||||
|
||||
print("LINKED ITEMS", linkedItems)
|
||||
do {
|
||||
try context.save()
|
||||
print("LinkedItems saved succesfully")
|
||||
|
|
|
|||
|
|
@ -3,7 +3,12 @@
|
|||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
import express from 'express'
|
||||
import { ArticleSavingRequestStatus, CreateArticleErrorCode, PageType, UploadFileStatus } from '../generated/graphql'
|
||||
import {
|
||||
ArticleSavingRequestStatus,
|
||||
CreateArticleErrorCode,
|
||||
PageType,
|
||||
UploadFileStatus,
|
||||
} from '../generated/graphql'
|
||||
import { isSiteBlockedForParse } from '../utils/blocked'
|
||||
import cors from 'cors'
|
||||
import { env } from '../env'
|
||||
|
|
@ -13,8 +18,17 @@ import { corsConfig } from '../utils/corsConfig'
|
|||
import { createPageSaveRequest } from '../services/create_page_save_request'
|
||||
import { initModels } from '../server'
|
||||
import { kx } from '../datalayer/knex_config'
|
||||
import { fileNameForFilePath, generateSlug, isString, titleForFilePath, validateUuid } from '../utils/helpers'
|
||||
import { generateUploadFilePathName, generateUploadSignedUrl } from '../utils/uploads'
|
||||
import {
|
||||
fileNameForFilePath,
|
||||
generateSlug,
|
||||
isString,
|
||||
titleForFilePath,
|
||||
validateUuid,
|
||||
} from '../utils/helpers'
|
||||
import {
|
||||
generateUploadFilePathName,
|
||||
generateUploadSignedUrl,
|
||||
} from '../utils/uploads'
|
||||
import { Claims } from '../resolvers/types'
|
||||
import { createPage, getPageByParam, updatePage } from '../elastic/pages'
|
||||
import { createPubSubClient } from '../datalayer/pubsub'
|
||||
|
|
@ -36,10 +50,26 @@ export function pageRouter() {
|
|||
// Get the content type from the query params
|
||||
const { url, clientRequestId } = req.query
|
||||
const contentType = req.headers['content-type']
|
||||
console.log('contentType', contentType, 'url', url, 'clientRequestId', clientRequestId)
|
||||
console.log(
|
||||
'contentType',
|
||||
contentType,
|
||||
'url',
|
||||
url,
|
||||
'clientRequestId',
|
||||
clientRequestId
|
||||
)
|
||||
|
||||
if (!isString(url) || !isString(contentType) || !isString(clientRequestId)) {
|
||||
console.log('creating page from pdf failed', url, contentType, clientRequestId)
|
||||
if (
|
||||
!isString(url) ||
|
||||
!isString(contentType) ||
|
||||
!isString(clientRequestId)
|
||||
) {
|
||||
console.log(
|
||||
'creating page from pdf failed',
|
||||
url,
|
||||
contentType,
|
||||
clientRequestId
|
||||
)
|
||||
return res.status(400).send({ errorCode: 'BAD_DATA' })
|
||||
}
|
||||
|
||||
|
|
@ -61,16 +91,18 @@ export function pageRouter() {
|
|||
userId: claims.uid,
|
||||
fileName: fileName,
|
||||
status: UploadFileStatus.Initialized,
|
||||
contentType: "application/pdf",
|
||||
contentType: 'application/pdf',
|
||||
})
|
||||
|
||||
const uploadFilePathName = generateUploadFilePathName(
|
||||
uploadFileData.id,
|
||||
fileName,
|
||||
fileName
|
||||
)
|
||||
|
||||
const signedUrl = await generateUploadSignedUrl(uploadFilePathName, "application/pdf")
|
||||
|
||||
const signedUrl = await generateUploadSignedUrl(
|
||||
uploadFilePathName,
|
||||
'application/pdf'
|
||||
)
|
||||
|
||||
const page = await getPageByParam({
|
||||
userId: claims.uid,
|
||||
|
|
@ -89,22 +121,25 @@ export function pageRouter() {
|
|||
)
|
||||
} else {
|
||||
console.log('creating page')
|
||||
const pageId = await createPage({
|
||||
url: signedUrl,
|
||||
id: clientRequestId,
|
||||
userId: claims.uid,
|
||||
title: title,
|
||||
hash: uploadFilePathName,
|
||||
content: '',
|
||||
pageType: PageType.File,
|
||||
uploadFileId: uploadFileData.id,
|
||||
slug: generateSlug(uploadFilePathName),
|
||||
createdAt: new Date(),
|
||||
savedAt: new Date(),
|
||||
readingProgressPercent: 0,
|
||||
readingProgressAnchorIndex: 0,
|
||||
state: ArticleSavingRequestStatus.Processing,
|
||||
}, ctx)
|
||||
const pageId = await createPage(
|
||||
{
|
||||
url: signedUrl,
|
||||
id: clientRequestId,
|
||||
userId: claims.uid,
|
||||
title: title,
|
||||
hash: uploadFilePathName,
|
||||
content: '',
|
||||
pageType: PageType.File,
|
||||
uploadFileId: uploadFileData.id,
|
||||
slug: generateSlug(uploadFilePathName),
|
||||
createdAt: new Date(),
|
||||
savedAt: new Date(),
|
||||
readingProgressPercent: 0,
|
||||
readingProgressAnchorIndex: 0,
|
||||
state: ArticleSavingRequestStatus.Processing,
|
||||
},
|
||||
ctx
|
||||
)
|
||||
if (!pageId) {
|
||||
return res.sendStatus(500)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -256,10 +256,11 @@ export const titleForFilePath = (url: string): string => {
|
|||
}
|
||||
|
||||
export const validateUuid = (str: string): boolean => {
|
||||
const regexExp = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi;
|
||||
const regexExp =
|
||||
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/gi
|
||||
return regexExp.test(str)
|
||||
}
|
||||
|
||||
export const isString = (check: any): check is string => {
|
||||
return (typeof check === 'string' || check instanceof String)
|
||||
}
|
||||
return typeof check === 'string' || check instanceof String
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,12 @@ export const generateUploadSignedUrl = async (
|
|||
// return 'http://localhost:3000/uploads/' + filePathName
|
||||
// }
|
||||
|
||||
console.log("signed URL", filePathName, contentType, selectedBucket || bucketName)
|
||||
console.log(
|
||||
'signed URL',
|
||||
filePathName,
|
||||
contentType,
|
||||
selectedBucket || bucketName
|
||||
)
|
||||
|
||||
// These options will allow temporary uploading of file with requested content type
|
||||
const options: GetSignedUrlConfig = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue