Repository navigation
Image field type - #5396
Image field type#5396
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/EAeRVwNp9Cs7CBkGCM6nDQWAJtwK |
🦋 Changeset detectedLatest commit: ec3a1e2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit ec3a1e2:
|
|
Given we only need to get the type and size of the iamge, could we replace sharp with https://www.npmjs.com/package/file-type + https://www.npmjs.com/package/image-size? There is one problem with that which is svg support which kinda makes things weird but we might just want to avoid supporting svg for now given it's not a binary format so it's kinda totally different to the others and doesn't(at least in my understanding) have a defined width and height in the way the other formats we have do. I'd like to avoid a dependency on a native module like sharp in keystone if we can avoid it. |
emmatown
left a comment
There was a problem hiding this comment.
Can you(@rohan-deshpande and/or @gwyneplaine) resolve the conflicts, add changesets, convert the Implementation to TypeScript like the other fields now are and originally the plan was to store the data in seperate columns rather than JSON, do we want to do that now?
…geref to exports from utils-legacy, added isValidImageRef to utils-legacy, updated callsites
| } | ||
|
|
||
| export function validateRef({ ref }: { ref: string }) { | ||
| if (!isValidImageRef(ref)) { |
There was a problem hiding this comment.
@mitchellhamilton ended up exporting isValidImageRef from utils-legacy because calling parseIamgeRef from here has a couple of issues:
parseImageRefthrows an error both on incorrect regex and on incorrect extensions. I assume we want this behaviour on the backend but we probably don't want this in our Field.parseImageRefexpects to return an object if successful, in this case all we want is a simple boolean check, exposing the check from utils-legacy seems more semantically correct and less error prone.
Not married to this idea, I think the first point is the only real problem
Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>
Added
Notes
sharpAPI.getDataFromStreamthen it probably makes sense for the file to get written to the storage layer within this function. If that's the case, then we should change the name of the function to something likewriteStreamToFileuploadkey in the config. While I am also not a fan ofmodeas it is just super generic, I feel it's easier to document thanuploadso I would be in favour of changing this key tomode. We at least wouldn't have to do something like this since we are calling itmodein every other instance