Merge pull request #2943 from omnivore-app/fix/web-limit-csv-import-size

Limit CSV import sizes via web
This commit is contained in:
Jackson Harper
2023-10-16 17:59:50 +08:00
committed by GitHub
2 changed files with 49 additions and 42 deletions

View File

@ -122,7 +122,7 @@ export function UploadModal(props: UploadModalProps): JSX.Element {
const uploadSignedUrlForFile = async (
file: UploadingFile
): Promise<UploadInfo> => {
let { contentType } = file;
let { contentType } = file
if (
contentType == 'application/vnd.ms-excel' &&
file.name.endsWith('.csv')
@ -135,6 +135,12 @@ export function UploadModal(props: UploadModalProps): JSX.Element {
try {
const csvData = await validateCsvFile(file.file)
urlCount = csvData.data.length
if (urlCount > 500) {
return {
message:
'Due to an increase in traffic we are limiting CSV imports to 500 items.',
}
}
if (csvData.inValidData.length > 0) {
return {
message: csvData.inValidData[0].message,
@ -185,7 +191,7 @@ export function UploadModal(props: UploadModalProps): JSX.Element {
}
}
return {
message: `Invalid content type: ${contentType}`
message: `Invalid content type: ${contentType}`,
}
}
@ -215,8 +221,9 @@ export function UploadModal(props: UploadModalProps): JSX.Element {
const uploadInfo = await uploadSignedUrlForFile(file)
if (!uploadInfo.uploadSignedUrl) {
const message = uploadInfo.message || 'No upload URL available'
// close after 5 seconds
showErrorToast(message, { duration: 5000 })
showErrorToast(message, { duration: 10000 })
file.status = 'error'
setUploadFiles([...allFiles])
return
}

View File

@ -79,30 +79,30 @@ export default function Home(): JSX.Element {
}, [articleData?.article.article])
const goNextOrHome = useCallback(() => {
const listStr = localStorage.getItem('library-slug-list')
if (article && listStr && viewerData?.me) {
const libraryList = JSON.parse(listStr) as string[]
const idx = libraryList.findIndex((slug) => slug == article.slug)
if (idx != -1 && idx < libraryList.length - 1) {
const nextSlug = libraryList[idx + 1] as string
router.push(`/${viewerData?.me.profile.username}/${nextSlug}`)
return
}
}
// const listStr = localStorage.getItem('library-slug-list')
// if (article && listStr && viewerData?.me) {
// const libraryList = JSON.parse(listStr) as string[]
// const idx = libraryList.findIndex((slug) => slug == article.slug)
// if (idx != -1 && idx < libraryList.length - 1) {
// const nextSlug = libraryList[idx + 1] as string
// router.push(`/${viewerData?.me.profile.username}/${nextSlug}`)
// return
// }
// }
router.push(`/home`)
}, [router, viewerData, article])
const goPreviousOrHome = useCallback(() => {
const listStr = localStorage.getItem('library-slug-list')
if (article && listStr && viewerData?.me) {
const libraryList = JSON.parse(listStr) as string[]
const idx = libraryList.findIndex((slug) => slug == article.slug)
if (idx > 0) {
const previousSlug = libraryList[idx - 1] as string
router.push(`/${viewerData?.me.profile.username}/${previousSlug}`)
return
}
}
// const listStr = localStorage.getItem('library-slug-list')
// if (article && listStr && viewerData?.me) {
// const libraryList = JSON.parse(listStr) as string[]
// const idx = libraryList.findIndex((slug) => slug == article.slug)
// if (idx > 0) {
// const previousSlug = libraryList[idx - 1] as string
// router.push(`/${viewerData?.me.profile.username}/${previousSlug}`)
// return
// }
// }
router.push(`/home`)
}, [router, viewerData, article])
@ -418,24 +418,24 @@ export default function Home(): JSX.Element {
shortcut: ['i'],
perform: () => setShowEditModal(true),
},
{
id: 'go_previous',
section: 'Article',
name: 'Go to Previous',
shortcut: ['g', 'p'],
perform: () => {
document.dispatchEvent(new Event('goPreviousOrHome'))
},
},
{
id: 'go_next',
section: 'Article',
name: 'Go to Next',
shortcut: ['g', 'n'],
perform: () => {
document.dispatchEvent(new Event('goNextOrHome'))
},
},
// {
// id: 'go_previous',
// section: 'Article',
// name: 'Go to Previous',
// shortcut: ['g', 'p'],
// perform: () => {
// document.dispatchEvent(new Event('goPreviousOrHome'))
// },
// },
// {
// id: 'go_next',
// section: 'Article',
// name: 'Go to Next',
// shortcut: ['g', 'n'],
// perform: () => {
// document.dispatchEvent(new Event('goNextOrHome'))
// },
// },
],
[readerSettings, showHighlightsModal]
)