Refactor Attchemnt Upload and fix bug with signing

This commit is contained in:
Mo Tarbin
2026-07-18 02:16:42 -04:00
parent bf6474a488
commit a6fb3c87c4
15 changed files with 601 additions and 163 deletions

View File

@@ -0,0 +1,26 @@
import { useEffect, useState } from 'react'
import { patchDescriptionHtml } from '../utils/ImageCache'
// Returns description HTML safe to render: embedded images with an expired
// signed src are swapped for the offline-cached blob or a freshly signed URL.
// Renders the raw HTML immediately and patches in place when needed.
export const useDescriptionHtml = (html, meta = {}) => {
const [patched, setPatched] = useState(html)
useEffect(() => {
let cancelled = false
setPatched(html)
if (!html || !html.includes('dt-data-path')) return undefined
patchDescriptionHtml(html, meta).then(result => {
if (!cancelled && result !== html) setPatched(result)
})
return () => {
cancelled = true
}
// meta is an inline object at call sites; keying on its values would
// re-run every render, so only the html triggers a re-patch.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [html])
return patched
}

View File

@@ -5,7 +5,11 @@ import { useNotification } from '../service/NotificationProvider'
import { apiClient } from '../utils/ApiClient'
import { isPlusAccount, resolvePhotoURL } from '../utils/Helpers'
export const useFileUpload = ({ entityType = 'chore_attachment', entityId, draftId } = {}) => {
export const useFileUpload = ({
entityType = 'chore_attachment',
entityId,
draftId,
} = {}) => {
const { showError } = useNotification()
const { data: userProfile } = useUserProfile()
@@ -76,7 +80,14 @@ export const useFileUpload = ({ entityType = 'chore_attachment', entityId, draft
}
const data = await response.json()
return resolvePhotoURL(data.url || data.sign)
// url is fetchable now; path is the stable storage key used to
// re-sign, delete, and cache the file later.
return {
url: resolvePhotoURL(data.sign || data.url),
path: data.path,
fileName: data.file_name || file.name,
sizeBytes: data.size_bytes,
}
} catch {
showError({
title: 'Upload Failed',