-
Notifications
You must be signed in to change notification settings - Fork 208
feat: New Image Transformation editor #2752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
HarshMN2345
wants to merge
8
commits into
main
Choose a base branch
from
feat-SER-313-New-Image-transformation-flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cc18abd
show badge
HarshMN2345 d249fc8
add new storage usage column
HarshMN2345 ad99124
just a structure
HarshMN2345 0e0c62c
added grid
HarshMN2345 ebe3b13
removed some code
HarshMN2345 0420810
minimum editor
HarshMN2345 c41c73d
slider
HarshMN2345 efb46ef
used components in design panel
HarshMN2345 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { ImageFormat, type Models } from '@appwrite.io/console'; | ||
|
|
||
| export type TransformationState = { | ||
| width?: number; | ||
| height?: number; | ||
| gravity?: string; // focal point: 'top-left', 'top', 'top-right', 'left', 'center', 'right', 'bottom-left', 'bottom', 'bottom-right' | ||
| borderWidth?: number; | ||
| borderColor?: string; // hex without # | ||
| borderOpacity?: number; // 0-100 | ||
| borderRadius?: number; | ||
| background?: string; // hex without # | ||
| quality?: number; // 1-100 | ||
| output?: ImageFormat; | ||
| rotation?: number; // 0-360 | ||
| }; | ||
|
|
||
| export function generateTransformationParams( | ||
| state: TransformationState | ||
| ): Record<string, string | number> { | ||
| const params: Record<string, string | number> = {}; | ||
|
|
||
| if (state.width) params.width = state.width; | ||
| if (state.height) params.height = state.height; | ||
| if (state.gravity && state.gravity !== 'center') { | ||
| params.gravity = state.gravity; | ||
| } | ||
| if (state.borderWidth && state.borderWidth > 0) { | ||
| params.borderWidth = state.borderWidth; | ||
| if (state.borderColor) { | ||
| params.borderColor = state.borderColor.replace('#', ''); | ||
| } | ||
| } | ||
| if (state.borderRadius && state.borderRadius > 0) { | ||
| params.borderRadius = state.borderRadius; | ||
| } | ||
| if (state.background) { | ||
| params.background = state.background.replace('#', ''); | ||
| } | ||
| if (state.quality && state.quality < 100) { | ||
| params.quality = state.quality; | ||
| } | ||
| if (state.output) { | ||
| params.output = state.output; | ||
| } | ||
| if (state.rotation && state.rotation !== 0) { | ||
| params.rotation = state.rotation; | ||
| } | ||
|
|
||
| return params; | ||
| } | ||
|
|
||
| export function generateSDKCode( | ||
| state: TransformationState, | ||
| bucketId: string, | ||
| fileId: string, | ||
| sdk: 'js' | 'python' | 'flutter' | 'swift' | 'kotlin' | ||
| ): string { | ||
| const params = generateTransformationParams(state); | ||
| const paramStrings: string[] = []; | ||
|
|
||
| // Build parameter object/string | ||
| Object.entries(params).forEach(([key, value]) => { | ||
| if (sdk === 'js' || sdk === 'python') { | ||
| paramStrings.push(` ${key}: ${typeof value === 'string' ? `'${value}'` : value}`); | ||
| } else if (sdk === 'flutter' || sdk === 'swift' || sdk === 'kotlin') { | ||
| paramStrings.push(` ${key}: ${typeof value === 'string' ? `"${value}"` : value}`); | ||
| } | ||
| }); | ||
|
|
||
| const paramsBlock = paramStrings.length > 0 ? `,\n${paramStrings.join(',\n')}` : ''; | ||
|
|
||
| switch (sdk) { | ||
| case 'js': | ||
| return `storage.getFilePreview({ | ||
| bucketId: '${bucketId}', | ||
| fileId: '${fileId}'${paramsBlock} | ||
| });`; | ||
|
|
||
| case 'python': | ||
| return `storage.get_file_preview( | ||
| bucket_id='${bucketId}', | ||
| file_id='${fileId}'${paramsBlock.replace(/(\w+):/g, '$1=')} | ||
| );`; | ||
|
|
||
| case 'flutter': | ||
| return `Storage.getFilePreview( | ||
| bucketId: '${bucketId}', | ||
| fileId: '${fileId}'${paramsBlock} | ||
| );`; | ||
|
|
||
| case 'swift': | ||
| return `storage.getFilePreview( | ||
| bucketId: "${bucketId}", | ||
| fileId: "${fileId}"${paramsBlock} | ||
| )`; | ||
|
|
||
| case 'kotlin': | ||
| return `storage.getFilePreview( | ||
| bucketId = "${bucketId}", | ||
| fileId = "${fileId}"${paramsBlock.replace(/(\w+):/g, '$1 =')} | ||
| )`; | ||
|
|
||
| default: | ||
| return ''; | ||
| } | ||
| } | ||
|
|
||
| export function getFormatLabel(format: ImageFormat): string { | ||
| switch (format) { | ||
| case ImageFormat.Jpg: | ||
| return 'JPG'; | ||
| case ImageFormat.Png: | ||
| return 'PNG'; | ||
| case ImageFormat.Gif: | ||
| return 'GIF'; | ||
| case ImageFormat.Webp: | ||
| return 'WEBP'; | ||
| case ImageFormat.Avif: | ||
| return 'AVIF'; | ||
| default: | ||
| return 'JPG'; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: appwrite/console
Length of output: 173
🏁 Script executed:
Repository: appwrite/console
Length of output: 517
Remove unused helper functions or document their intended purpose.
Verification confirms these functions are exported but have zero external usages in the codebase—only internal usage within
isLargeImage. While the implementation follows guidelines (pure functions, camelCase naming), exporting unused code creates maintenance burden.Either remove
isImageFileandisLargeFileif not needed, or add a TODO comment documenting their intended use in future features.🤖 Prompt for AI Agents