Allow more frequent exports, give more data on account page

This commit is contained in:
Jackson Harper
2024-11-02 14:50:38 +08:00
parent 8e8bae9e1a
commit 75365f4811
3 changed files with 58 additions and 5 deletions

View File

@ -3,8 +3,9 @@ import express, { Router } from 'express'
import { TaskState } from '../generated/graphql'
import { jobStateToTaskState } from '../queue-processor'
import {
countExportsWithin24Hours,
countExportsWithin6Hours,
countExportsWithinMinute,
findExports,
saveExport,
} from '../services/export'
import { getClaimsByToken, getTokenByRequest } from '../utils/auth'
@ -42,9 +43,9 @@ export function exportRouter() {
})
}
const exportsWithin24Hours = await countExportsWithin24Hours(userId)
const exportsWithin24Hours = await countExportsWithin6Hours(userId)
if (exportsWithin24Hours >= 3) {
logger.error('User has reached the limit of exports within 24 hours', {
logger.error('User has reached the limit of exports within 6 hours', {
userId,
exportsWithin24Hours,
})
@ -97,5 +98,37 @@ export function exportRouter() {
}
})
// eslint-disable-next-line @typescript-eslint/no-misused-promises
router.get('/list', cors<express.Request>(corsConfig), async (req, res) => {
const token = getTokenByRequest(req)
// get claims from token
const claims = await getClaimsByToken(token)
if (!claims) {
logger.error('Token not found')
return res.status(401).send({
error: 'UNAUTHORIZED',
})
}
// get user by uid from claims
const userId = claims.uid
try {
const exports = await findExports(userId)
res.send({
exports,
})
} catch (error) {
logger.error('Error fetching exports', {
userId,
error,
})
return res.status(500).send({
error: 'INTERNAL_ERROR',
})
}
})
return router
}

View File

@ -5,6 +5,8 @@ import { TaskState } from './mutations/exportToIntegrationMutation'
type Export = {
id: string
state: TaskState
totalItems?: number
processedItems?: number
createdAt: string
signedUrl: string
}

View File

@ -535,13 +535,31 @@ const ExportSection = (): JSX.Element => {
return (
<HStack
key={item.id}
css={{ width: '100% ' }}
css={{ width: '100%', height: '55px' }}
distribution="start"
alignment="center"
>
<SpanBox css={{ width: '180px' }} title={item.createdAt}>
{timeAgo(item.createdAt)}
</SpanBox>
<SpanBox>{item.state}</SpanBox>
<SpanBox css={{ width: '180px' }}>{item.state}</SpanBox>
{item.totalItems && (
<VStack css={{ width: '180px', height: '50px', pt: '12px' }}>
<ProgressBar
fillPercentage={
((item.processedItems ?? 0) / item.totalItems) * 100
}
fillColor={theme.colors.omnivoreCtaYellow.toString()}
backgroundColor={theme.colors.grayText.toString()}
borderRadius={'2px'}
/>
<StyledText style="footnote" css={{ mt: '0px' }}>
{`${item.processedItems ?? 0} of ${
item.totalItems
} items.`}
</StyledText>
</VStack>
)}
{item.signedUrl && (
<SpanBox css={{ marginLeft: 'auto' }}>
<a href={item.signedUrl} target="_blank" rel="noreferrer">