mirror of
https://github.com/modrinth/code.git
synced 2026-08-30 11:36:05 +00:00
lazily load c2pa client-side to reduce CF size (#7292)
This commit is contained in:
@@ -1,32 +1,35 @@
|
||||
import type { C2paSdk } from '@contentauth/c2pa-web'
|
||||
import { createC2pa, isSupportedReaderFormat } from '@contentauth/c2pa-web/inline'
|
||||
|
||||
// https://cv.iptc.org/newscodes/digitalsourcetype/
|
||||
// only detecting generative AI types
|
||||
const AI_DIGITAL_SOURCE_TYPES = [
|
||||
'http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia',
|
||||
'http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicData',
|
||||
'http://cv.iptc.org/newscodes/digitalsourcetype/compositeWithTrainedAlgorithmicMedia',
|
||||
'http://cv.iptc.org/newscodes/digitalsourcetype/compositeSynthetic',
|
||||
]
|
||||
|
||||
let c2paInstance: Promise<C2paSdk> | null = null
|
||||
|
||||
function getC2pa() {
|
||||
if (!c2paInstance) {
|
||||
c2paInstance = createC2pa()
|
||||
}
|
||||
return c2paInstance
|
||||
}
|
||||
|
||||
// reference: https://github.com/contentauth/c2pa-js/blob/main/packages/c2pa-web/README.md
|
||||
export async function fileDeclaresAi(file: File): Promise<boolean> {
|
||||
if (!import.meta.client) {
|
||||
return false
|
||||
}
|
||||
|
||||
try {
|
||||
const { createC2pa, isSupportedReaderFormat } = await import('@contentauth/c2pa-web')
|
||||
|
||||
if (!isSupportedReaderFormat(file.type)) {
|
||||
return false
|
||||
}
|
||||
|
||||
const c2pa = await getC2pa()
|
||||
if (!c2paInstance) {
|
||||
c2paInstance = import('@contentauth/c2pa-web/resources/c2pa.wasm?url').then((wasm) =>
|
||||
createC2pa({ wasmSrc: wasm.default }),
|
||||
)
|
||||
}
|
||||
|
||||
const c2pa = await c2paInstance
|
||||
|
||||
const reader = await c2pa.reader.fromBlob(file.type, file)
|
||||
const manifestStore = await reader.manifestStore()
|
||||
|
||||
Reference in New Issue
Block a user