@stoker-platform/web-app 0.5.140 → 0.5.141

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.141
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: apply maxImageWidth processing to image file rename operation
8
+
3
9
  ## 0.5.140
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.140",
3
+ "version": "0.5.141",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
package/src/Files.tsx CHANGED
@@ -38,7 +38,7 @@ import {
38
38
  Edit,
39
39
  Trash2,
40
40
  Folder,
41
- File,
41
+ File as FileIcon,
42
42
  ChevronRight,
43
43
  ArrowLeft,
44
44
  Plus,
@@ -135,7 +135,7 @@ const FileImageThumbnail = ({ storage, fullPath, fileName, pathPrefix }: FileIma
135
135
  return <div className="h-12 w-12 shrink-0 rounded-md border bg-muted animate-pulse" aria-hidden />
136
136
  }
137
137
  if (phase === "fallback" || !url) {
138
- return <File className="h-5 w-5 shrink-0 text-gray-500" aria-hidden />
138
+ return <FileIcon className="h-5 w-5 shrink-0 text-gray-500" aria-hidden />
139
139
  }
140
140
  return (
141
141
  <div className="h-12 w-12 shrink-0 rounded-md flex items-center justify-center">
@@ -781,7 +781,8 @@ export const RecordFiles = ({ collection, record }: FilesProps) => {
781
781
  return
782
782
  }
783
783
 
784
- const validationError = validateStorageName(newName.trim())
784
+ let finalName = newName.trim()
785
+ const validationError = validateStorageName(finalName)
785
786
  if (validationError) {
786
787
  toast({ title: "Invalid file name", description: validationError, variant: "destructive" })
787
788
  return
@@ -790,14 +791,39 @@ export const RecordFiles = ({ collection, record }: FilesProps) => {
790
791
  try {
791
792
  setIsRouteLoading("+", location.pathname, true)
792
793
  setRenamingFiles((prev) => new Set(prev).add(item.name))
793
- const pathParts = item.fullPath.split("/")
794
- pathParts.pop()
795
- const newPath = [...pathParts, newName].join("/")
796
794
 
797
795
  const originalRef = ref(storage, item.fullPath)
798
796
  const downloadURL = await getDownloadURL(originalRef)
799
797
  const metadata = await getMetadata(originalRef)
800
798
 
799
+ const response = await fetch(downloadURL)
800
+ const blob = await response.blob()
801
+
802
+ let uploadContent: Blob = blob
803
+ if (fileOptions?.maxImageWidth) {
804
+ const sourceFile = new File([blob], finalName, {
805
+ type: blob.type || metadata.contentType || "",
806
+ })
807
+ const prepared = await prepareFile(sourceFile, finalName, fileOptions, true)
808
+ uploadContent = prepared.file
809
+ if (prepared.filename !== finalName) {
810
+ const preparedValidationError = validateStorageName(prepared.filename)
811
+ if (preparedValidationError) {
812
+ toast({
813
+ title: "Invalid file name",
814
+ description: preparedValidationError,
815
+ variant: "destructive",
816
+ })
817
+ return
818
+ }
819
+ finalName = prepared.filename
820
+ }
821
+ }
822
+
823
+ const pathParts = item.fullPath.split("/")
824
+ pathParts.pop()
825
+ const newPath = [...pathParts, finalName].join("/")
826
+
801
827
  try {
802
828
  await runHooks("preFileUpdate", globalConfig, customization, {
803
829
  record,
@@ -807,17 +833,14 @@ export const RecordFiles = ({ collection, record }: FilesProps) => {
807
833
  return
808
834
  }
809
835
 
810
- const response = await fetch(downloadURL)
811
- const blob = await response.blob()
812
-
813
836
  const newRef = ref(storage, newPath)
814
- await uploadBytesResumable(newRef, blob, { customMetadata: metadata.customMetadata })
837
+ await uploadBytesResumable(newRef, uploadContent, { customMetadata: metadata.customMetadata })
815
838
 
816
839
  await deleteObject(originalRef)
817
840
 
818
841
  toast({
819
842
  title: "File renamed",
820
- description: `${item.name} has been renamed to ${newName}`,
843
+ description: `${item.name} has been renamed to ${finalName}`,
821
844
  })
822
845
 
823
846
  try {
@@ -848,7 +871,7 @@ export const RecordFiles = ({ collection, record }: FilesProps) => {
848
871
  setIsRouteLoading("-", location.pathname)
849
872
  }
850
873
  },
851
- [currentPath],
874
+ [currentPath, fileOptions],
852
875
  )
853
876
 
854
877
  const navigateToFolder = useCallback(
@@ -1132,7 +1155,7 @@ export const RecordFiles = ({ collection, record }: FilesProps) => {
1132
1155
  }
1133
1156
  />
1134
1157
  ) : (
1135
- <File className="h-5 w-5 shrink-0 text-gray-500" />
1158
+ <FileIcon className="h-5 w-5 shrink-0 text-gray-500" />
1136
1159
  )}
1137
1160
 
1138
1161
  {editingFile === item.name && !isDisabled ? (
@@ -33,6 +33,7 @@ export const prepareFile = async (
33
33
  file: File,
34
34
  preferredFileName: string,
35
35
  fileOptions: FileOptions,
36
+ rename: boolean = false,
36
37
  ): Promise<{ file: File; filename: string }> => {
37
38
  if (!file.type.startsWith("image/") || file.type === "image/svg+xml") {
38
39
  return { file, filename: preferredFileName }
@@ -107,7 +108,7 @@ export const prepareFile = async (
107
108
  blob.size >= file.size &&
108
109
  !didDownscale &&
109
110
  ((usePngOutput && file.type === "image/png") || (!usePngOutput && file.type === "image/jpeg"))
110
- if (noBenefit) {
111
+ if (noBenefit && !rename) {
111
112
  return { file, filename: preferredFileName }
112
113
  }
113
114