Mark S3 images as submitted in imgproxy job
This commit is contained in:
parent
a61d00ba8b
commit
db525e9195
@ -11,6 +11,8 @@ import { useMutation, useQuery } from '@apollo/client'
|
|||||||
|
|
||||||
const ImageContext = createContext({ unsubmitted: [] })
|
const ImageContext = createContext({ unsubmitted: [] })
|
||||||
|
|
||||||
|
const imageIdToUrl = id => `https://${process.env.NEXT_PUBLIC_AWS_UPLOAD_BUCKET}.s3.amazonaws.com/${id}`
|
||||||
|
|
||||||
export function ImageProvider ({ me, children }) {
|
export function ImageProvider ({ me, children }) {
|
||||||
const { data, loading } = useQuery(
|
const { data, loading } = useQuery(
|
||||||
gql`
|
gql`
|
||||||
@ -42,14 +44,12 @@ export function ImageProvider ({ me, children }) {
|
|||||||
})
|
})
|
||||||
const [unsubmittedImages, setUnsubmittedImages] = useState([])
|
const [unsubmittedImages, setUnsubmittedImages] = useState([])
|
||||||
|
|
||||||
const imageIdToUrl = id => `https://${process.env.NEXT_PUBLIC_AWS_UPLOAD_BUCKET}.s3.amazonaws.com/${id}`
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const images = data?.me?.images
|
const images = data?.me?.images
|
||||||
if (images) {
|
if (images) {
|
||||||
setUnsubmittedImages(images.map(img => ({ ...img, url: imageIdToUrl(img.id) })))
|
setUnsubmittedImages(images.map(img => ({ ...img, url: imageIdToUrl(img.id) })))
|
||||||
}
|
}
|
||||||
}, [loading])
|
}, [setUnsubmittedImages, loading])
|
||||||
|
|
||||||
const contextValue = {
|
const contextValue = {
|
||||||
unsubmittedImages,
|
unsubmittedImages,
|
||||||
|
@ -12,6 +12,7 @@ if (!imgProxyEnabled) {
|
|||||||
const IMGPROXY_URL = process.env.NEXT_PUBLIC_IMGPROXY_URL
|
const IMGPROXY_URL = process.env.NEXT_PUBLIC_IMGPROXY_URL
|
||||||
const IMGPROXY_SALT = process.env.IMGPROXY_SALT
|
const IMGPROXY_SALT = process.env.IMGPROXY_SALT
|
||||||
const IMGPROXY_KEY = process.env.IMGPROXY_KEY
|
const IMGPROXY_KEY = process.env.IMGPROXY_KEY
|
||||||
|
const AWS_S3_URL = `https://${process.env.NEXT_PUBLIC_AWS_UPLOAD_BUCKET}.s3.amazonaws.com/`
|
||||||
|
|
||||||
const cache = new Map()
|
const cache = new Map()
|
||||||
|
|
||||||
@ -64,10 +65,10 @@ export function imgproxy ({ models }) {
|
|||||||
let imgproxyUrls = {}
|
let imgproxyUrls = {}
|
||||||
try {
|
try {
|
||||||
if (item.text) {
|
if (item.text) {
|
||||||
imgproxyUrls = await createImgproxyUrls(id, item.text, { forceFetch })
|
imgproxyUrls = await createImgproxyUrls(id, item.text, { models, forceFetch })
|
||||||
}
|
}
|
||||||
if (item.url && !isJob(item)) {
|
if (item.url && !isJob(item)) {
|
||||||
imgproxyUrls = { ...imgproxyUrls, ...(await createImgproxyUrls(id, item.url, { forceFetch })) }
|
imgproxyUrls = { ...imgproxyUrls, ...(await createImgproxyUrls(id, item.url, { models, forceFetch })) }
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('[imgproxy] error:', err)
|
console.log('[imgproxy] error:', err)
|
||||||
@ -81,7 +82,7 @@ export function imgproxy ({ models }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createImgproxyUrls = async (id, text, { forceFetch }) => {
|
export const createImgproxyUrls = async (id, text, { models, forceFetch }) => {
|
||||||
const urls = extractUrls(text)
|
const urls = extractUrls(text)
|
||||||
console.log('[imgproxy] id:', id, '-- extracted urls:', urls)
|
console.log('[imgproxy] id:', id, '-- extracted urls:', urls)
|
||||||
// resolutions that we target:
|
// resolutions that we target:
|
||||||
@ -106,6 +107,10 @@ export const createImgproxyUrls = async (id, text, { forceFetch }) => {
|
|||||||
url = decodeOriginalUrl(url)
|
url = decodeOriginalUrl(url)
|
||||||
console.log('[imgproxy] id:', id, '-- original url:', url)
|
console.log('[imgproxy] id:', id, '-- original url:', url)
|
||||||
}
|
}
|
||||||
|
if (url.startsWith(AWS_S3_URL)) {
|
||||||
|
const s3Key = url.split('/').pop()
|
||||||
|
await models.upload.update({ data: { itemId: Number(id) }, where: { id: Number(s3Key) } })
|
||||||
|
}
|
||||||
if (!(await isImageURL(url, { forceFetch }))) {
|
if (!(await isImageURL(url, { forceFetch }))) {
|
||||||
console.log('[imgproxy] id:', id, '-- not image url:', url)
|
console.log('[imgproxy] id:', id, '-- not image url:', url)
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user