Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/uploads/media-utils.js
Show First 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | invariant( | ||||
mediaType === 'photo' || mediaType === 'video', | mediaType === 'photo' || mediaType === 'video', | ||||
`mediaType for ${inputMimeType} should be photo or video`, | `mediaType for ${inputMimeType} should be photo or video`, | ||||
); | ); | ||||
return { | return { | ||||
name: initialName, | name: initialName, | ||||
mime: inputMimeType, | mime: inputMimeType, | ||||
mediaType, | mediaType, | ||||
buffer: initialBuffer, | content: { storage: 'keyserver', buffer: initialBuffer }, | ||||
dimensions: inputDimensions, | dimensions: inputDimensions, | ||||
loop: inputLoop, | loop: inputLoop, | ||||
encryptionKey: inputEncryptionKey, | encryptionKey: inputEncryptionKey, | ||||
}; | }; | ||||
} | } | ||||
const { mime, mediaType } = deepFileInfoFromData(initialBuffer); | const { mime, mediaType } = deepFileInfoFromData(initialBuffer); | ||||
if (!mime || !mediaType) { | if (!mime || !mediaType) { | ||||
return null; | return null; | ||||
} | } | ||||
if (!serverCanHandleTypes.has(mime)) { | if (!serverCanHandleTypes.has(mime)) { | ||||
return null; | return null; | ||||
} | } | ||||
if (mediaType === 'video') { | if (mediaType === 'video') { | ||||
invariant( | invariant( | ||||
inputDimensions, | inputDimensions, | ||||
'inputDimensions should be set in validateAndConvert', | 'inputDimensions should be set in validateAndConvert', | ||||
); | ); | ||||
return { | return { | ||||
mime: mime, | mime: mime, | ||||
mediaType: mediaType, | mediaType: mediaType, | ||||
name: initialName, | name: initialName, | ||||
buffer: initialBuffer, | content: { storage: 'keyserver', buffer: initialBuffer }, | ||||
dimensions: inputDimensions, | dimensions: inputDimensions, | ||||
loop: inputLoop, | loop: inputLoop, | ||||
}; | }; | ||||
} | } | ||||
if (!serverTranscodableTypes.has(mime)) { | if (!serverTranscodableTypes.has(mime)) { | ||||
// This should've gotten converted on the client | // This should've gotten converted on the client | ||||
return null; | return null; | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | ): Promise<?UploadInput> { | ||||
}); | }); | ||||
if (plan.action === 'none') { | if (plan.action === 'none') { | ||||
const name = readableFilename(initialName, mime); | const name = readableFilename(initialName, mime); | ||||
invariant(name, `should be able to construct filename for ${mime}`); | invariant(name, `should be able to construct filename for ${mime}`); | ||||
return { | return { | ||||
mime, | mime, | ||||
mediaType: 'photo', | mediaType: 'photo', | ||||
name, | name, | ||||
buffer: initialBuffer, | content: { storage: 'keyserver', buffer: initialBuffer }, | ||||
dimensions: initialDimensions, | dimensions: initialDimensions, | ||||
loop: inputLoop, | loop: inputLoop, | ||||
}; | }; | ||||
} | } | ||||
console.log(`processing image with ${JSON.stringify(plan)}`); | console.log(`processing image with ${JSON.stringify(plan)}`); | ||||
const { targetMIME, compressionRatio, fitInside, shouldRotate } = plan; | const { targetMIME, compressionRatio, fitInside, shouldRotate } = plan; | ||||
if (shouldRotate) { | if (shouldRotate) { | ||||
Show All 33 Lines | ): Promise<?UploadInput> { | ||||
if (!convertedName) { | if (!convertedName) { | ||||
return null; | return null; | ||||
} | } | ||||
return { | return { | ||||
mime: targetMIME, | mime: targetMIME, | ||||
mediaType: 'photo', | mediaType: 'photo', | ||||
name: convertedName, | name: convertedName, | ||||
buffer: convertedBuffer, | content: { storage: 'keyserver', buffer: convertedBuffer }, | ||||
dimensions: convertedDimensions, | dimensions: convertedDimensions, | ||||
loop: inputLoop, | loop: inputLoop, | ||||
}; | }; | ||||
} | } | ||||
export { validateAndConvert }; | export { validateAndConvert }; |