Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@
"ts-node": "^10.9.1",
"typescript": "^5.0.2"
},
"dependencies": {}
"dependencies": {
"fs-extra": "^11.1.0"
}
}
12 changes: 11 additions & 1 deletion src/features/upload-file/components/UploadEditComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ const Edit: FC<EditPropertyProps> = ({ property, record, onChange }) => {
const { params } = record
const { custom } = property as unknown as { custom: PropertyCustom }

const path = flat.get(params, custom.filePathProperty)
const key = flat.get(params, custom.keyProperty)
const file = flat.get(params, custom.fileProperty)

let path = flat.get(params, custom.filePathProperty)
if (custom.opts && custom.opts.baseUrl && path) {
const baseUrl = custom.opts.baseUrl || ''
// check if we deal with single file or multiple (string or array)
if(typeof path === 'string') {
path = `${baseUrl}/${key}`
} else if(Array.isArray(path)) {
path = path.map((singlePath, index) => (singlePath != null) ? `${baseUrl}/${key[index]}` : null)
}
}

const [originalKey, setOriginalKey] = useState(key)
const [filesToUpload, setFilesToUpload] = useState<Array<File>>([])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const updateRecordFactory = (
)))

const newParams = DB_PROPERTIES.reduce((params, propertyName: string) => {
if (properties[propertyName]) {
if (properties[propertyName] && record.get(properties[propertyName])) {
const filtered = record.get(properties[propertyName]).filter((el, i) => (
!filesToDelete.includes(i.toString())
))
Expand Down
3 changes: 2 additions & 1 deletion src/features/upload-file/providers/local-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UploadedFile } from 'adminjs'
import fs, { existsSync } from 'fs'
import fse from 'fs-extra'
import path from 'path'
import { ERROR_MESSAGES } from '../constants.js'
import { BaseProvider, ProviderOpts } from './base-provider.js'
Expand Down Expand Up @@ -33,7 +34,7 @@ export class LocalProvider extends BaseProvider {
const filePath = process.platform === 'win32' ? this.path(key) : this.path(key).slice(1) // adjusting file path according to OS

await fs.promises.mkdir(path.dirname(filePath), { recursive: true })
await fs.promises.rename(file.path, filePath)
await fse.move(file.path, filePath, { overwrite: true })
}

public async delete(key: string, bucket: string): Promise<any> {
Expand Down