Skip to content

Image field type - #5396

Merged
emmatown merged 91 commits into
masterfrom
image-field-type
Apr 16, 2021
Merged

emmatown merged 91 commits into
masterfrom
image-field-type

Conversation

@rohan-deshpande

Copy link
Copy Markdown
Contributor

Added

  • Image field type and API for handling image I/O
  • Image config to Keystone config
  • Required packages for image I/O processes

Notes

  • This is completely untested and may or may not work. I want to get into writing tests for it but would like someone's eyes across it first who is maybe a bit more familiar with the sharp API.
  • Some of the blurhash code is lifted from nodejs implementation woltapp/blurhash#43 (comment) there's maybe some stuff they are doing here that we don't need to do... I'm not too sure
  • If the REST endpoint is also going to use getDataFromStream then 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 like writeStreamToFile
  • I'm really, really not a fan of the upload key in the config. While I am also not a fan of mode as it is just super generic, I feel it's easier to document than upload so I would be in favour of changing this key to mode. We at least wouldn't have to do something like this since we are calling it mode in every other instance
const { upload: mode } = config;

@vercel

vercel Bot commented Apr 7, 2021 •

Copy link
Copy Markdown

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/EAeRVwNp9Cs7CBkGCM6nDQWAJtwK
✅ Preview: https://keystone-next-docs-git-image-field-type-keystonejs.vercel.app

@changeset-bot

changeset-bot Bot commented Apr 7, 2021 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ec3a1e2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 14 packages
Name Type
@keystone-next/admin-ui Minor
@keystone-next/app-basic Patch
@keystone-next/fields Minor
@keystone-next/types Minor
@keystone-next/keystone Minor
@keystone-next/auth Major
@keystone-next/test-utils-legacy Patch
@keystone-next/example-auth Patch
@keystone-next/example-ecommerce Patch
keystone-next-app Patch
@keystone-next/example-roles Patch
@keystone-next/example-sandbox Patch
@keystone-next/example-todo Patch

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

@codesandbox-ci

codesandbox-ci Bot commented Apr 7, 2021 •

Copy link
Copy Markdown

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:

Sandbox Source
@keystone-next/example-sandbox Configuration

@emmatown

emmatown commented Apr 8, 2021

Copy link
Copy Markdown
Member

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.

@vercel
vercel Bot temporarily deployed to Preview April 9, 2021 00:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview April 9, 2021 01:22 Inactive
@vercel
vercel Bot temporarily deployed to Preview April 9, 2021 01:43 Inactive
@vercel
vercel Bot temporarily deployed to Preview April 9, 2021 02:17 Inactive
@vercel
vercel Bot temporarily deployed to Preview April 12, 2021 00:06 Inactive
@vercel
vercel Bot temporarily deployed to Preview April 12, 2021 02:12 Inactive

@emmatown emmatown left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread packages-next/keystone/package.json Resolved
Comment thread packages-next/keystone/package.json Resolved
@vercel
vercel Bot temporarily deployed to Preview April 15, 2021 23:17 Inactive
@vercel
vercel Bot temporarily deployed to Preview April 15, 2021 23:21 Inactive
@vercel
vercel Bot temporarily deployed to Preview April 15, 2021 23:34 Inactive
@vercel
vercel Bot temporarily deployed to Preview April 15, 2021 23:37 Inactive
@vercel
vercel Bot temporarily deployed to Preview April 15, 2021 23:39 Inactive
…geref to exports from utils-legacy, added isValidImageRef to utils-legacy, updated callsites
@vercel
vercel Bot temporarily deployed to Preview April 16, 2021 03:26 Inactive
}

export function validateRef({ ref }: { ref: string }) {
if (!isValidImageRef(ref)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mitchellhamilton ended up exporting isValidImageRef from utils-legacy because calling parseIamgeRef from here has a couple of issues:

  • parseImageRef throws 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.
  • parseImageRef expects 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>
@vercel
vercel Bot temporarily deployed to Preview April 16, 2021 03:36 Inactive
Comment thread packages/utils/src/index.ts Resolved
Comment thread packages/utils/src/index.ts Resolved
@vercel
vercel Bot temporarily deployed to Preview April 16, 2021 03:51 Inactive
@gwyneplaine
gwyneplaine requested a review from emmatown April 16, 2021 03:54
@vercel
vercel Bot temporarily deployed to Preview April 16, 2021 04:14 Inactive
Comment thread packages/utils/src/index.ts Resolved

This branch was previously deployed

1 inactive deployment
Preview — ec3a1e2a Deployed Apr 16, 2021 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants